Skip to content

Commit

Permalink
Fix max length in DBReader
Browse files Browse the repository at this point in the history
Allocate CSProfile only when needed


Co-authored-by: konstin < [email protected]>
  • Loading branch information
martin-steinegger and konstin committed Oct 5, 2021
1 parent 42bf643 commit d873697
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
10 changes: 8 additions & 2 deletions src/alignment/PSSMCalculator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@

PSSMCalculator::PSSMCalculator(SubstitutionMatrix *subMat, size_t maxSeqLength, size_t maxSetSize, int pcmode,
MultiParam<PseudoCounts> pca, MultiParam<PseudoCounts> pcb, int gapOpen, int gapPseudoCount)
: subMat(subMat), ps(maxSeqLength + 1), maxSeqLength(maxSeqLength), gapOpen(gapOpen), gapPseudoCount(gapPseudoCount), pca(pca), pcb(pcb) {
: subMat(subMat), ps(NULL), maxSeqLength(maxSeqLength), gapOpen(gapOpen), gapPseudoCount(gapPseudoCount), pca(pca), pcb(pcb) {

if(gapPseudoCount == Parameters::PCMODE_CONTEXT_SPECIFIC){
ps = new CSProfile(maxSeqLength + 1);
}
this->maxSeqLength = maxSeqLength;
this->maxSetSize = maxSetSize;
this->profile = new float[(maxSeqLength + 1) * Sequence::PROFILE_AA_SIZE];
Expand Down Expand Up @@ -51,6 +54,9 @@ PSSMCalculator::PSSMCalculator(SubstitutionMatrix *subMat, size_t maxSeqLength,
}

PSSMCalculator::~PSSMCalculator() {
if(ps != NULL){
delete ps;
}
delete[] profile;
delete[] Neff_M;
free(seqWeight);
Expand Down Expand Up @@ -150,7 +156,7 @@ PSSMCalculator::Profile PSSMCalculator::computePSSMFromMSA(size_t setSize, size_
computePseudoCounts(profile, matchWeight, pseudocountsWeight, Sequence::PROFILE_AA_SIZE, Neff_M, queryLength, pca.values.normal(), pcb.values.normal());
}else if (pcmode == Parameters::PCMODE_CONTEXT_SPECIFIC && pca.values.cs() > 0.0){
fillCounteProfile(counts, matchWeight, Neff_M, queryLength);
float * csprofile = ps.computeProfileCs(static_cast<int>(queryLength), counts, Neff_M, pca.values.cs(), pcb.values.cs());
float * csprofile = ps->computeProfileCs(static_cast<int>(queryLength), counts, Neff_M, pca.values.cs(), pcb.values.cs());
for (size_t pos = 0; pos < queryLength; pos++) {
for (size_t aa = 0; aa < Sequence::PROFILE_AA_SIZE; ++aa) {
this->profile[pos * Sequence::PROFILE_AA_SIZE + aa] = csprofile[(pos * (Sequence::PROFILE_AA_SIZE + 4)) + aa];
Expand Down
2 changes: 1 addition & 1 deletion src/alignment/PSSMCalculator.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class PSSMCalculator {
BaseMatrix* subMat;

// cs profiles
CSProfile ps;
CSProfile * ps;

// contains sequence weights (global)
float * seqWeight;
Expand Down
4 changes: 3 additions & 1 deletion src/commons/DBReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,9 @@ bool DBReader<T>::readIndex(char *data, size_t indexDataSize, Index *index, size
}
}
dataSize = localDataSize;
maxSeqLen = localMaxSeqLen;
maxSeqLen = (Parameters::isEqualDbtype(dbtype, Parameters::DBTYPE_HMM_PROFILE ) ) ?
(std::max(localMaxSeqLen, 1u) - 1u) / Sequence::PROFILE_READIN_SIZE :
(std::max(localMaxSeqLen, 2u) - 2u);
lastKey = localLastKey;
return isSortedById;
}
Expand Down

0 comments on commit d873697

Please sign in to comment.