From b40729c18b631cc781af4dc9c8e8ff8b67078193 Mon Sep 17 00:00:00 2001 From: Martin Steinegger Date: Thu, 29 Aug 2024 11:43:35 +0900 Subject: [PATCH] Fix issue https://github.com/steineggerlab/foldseek/issues/312 alntmscore is now normalized by the backtrace length --- src/strucclustutils/aln2tmscore.cpp | 7 ++++--- src/strucclustutils/structurealign.cpp | 5 ++++- src/strucclustutils/structureconvertalis.cpp | 18 ++++++------------ .../structurerescorediagonal.cpp | 5 ++++- 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/strucclustutils/aln2tmscore.cpp b/src/strucclustutils/aln2tmscore.cpp index b1d3c8a5..9566a472 100644 --- a/src/strucclustutils/aln2tmscore.cpp +++ b/src/strucclustutils/aln2tmscore.cpp @@ -101,10 +101,11 @@ int aln2tmscore(int argc, const char **argv, const Command& command) { float* tdata = tcoords.read(tcadata, targetLen, tCaLength); // Matching residue index collection + unsigned int normLen = std::min(res.dbLen, res.qLen); TMaligner::TMscoreResult tmres = tmaln.computeTMscore(tdata, &tdata[targetLen], &tdata[targetLen + targetLen], targetLen, - res.qStartPos, res.dbStartPos, res.backtrace, - std::min(static_cast(res.backtrace.length()), std::min(res.dbLen, res.qLen))); - + res.qStartPos, res.dbStartPos, res.backtrace, normLen); + tmres.tmscore = (tmres.tmscore / static_cast(normLen)) + * static_cast(res.backtrace.size()); //std::cout << TMalnScore << std::endl; resultsStr.append(SSTR(dbKey)); resultsStr.push_back(' '); diff --git a/src/strucclustutils/structurealign.cpp b/src/strucclustutils/structurealign.cpp index d52bf202..157a2d1c 100644 --- a/src/strucclustutils/structurealign.cpp +++ b/src/strucclustutils/structurealign.cpp @@ -380,6 +380,7 @@ int structurealign(int argc, const char **argv, const Command& command) { size_t tCaLength = tcadbr->sequenceReader->getEntryLen(tId); float* targetCaData = tcoords.read(tcadata, res.dbLen, tCaLength); if(needTMaligner) { + unsigned int normLen = std::min(res.dbLen, res.qLen); tmres = tmaligner->computeTMscore(targetCaData, &targetCaData[res.dbLen], &targetCaData[res.dbLen + @@ -388,7 +389,9 @@ int structurealign(int argc, const char **argv, const Command& command) { res.qStartPos, res.dbStartPos, res.backtrace, - std::min(static_cast(res.backtrace.size()), std::min(res.dbLen, res.qLen))); + normLen); + tmres.tmscore = (tmres.tmscore / static_cast(normLen)) + * static_cast(res.backtrace.size()); if (tmres.tmscore < par.tmScoreThr) { continue; } diff --git a/src/strucclustutils/structureconvertalis.cpp b/src/strucclustutils/structureconvertalis.cpp index 6c0e8dae..b4f7ab78 100644 --- a/src/strucclustutils/structureconvertalis.cpp +++ b/src/strucclustutils/structureconvertalis.cpp @@ -653,12 +653,12 @@ R"html( } if(needTMaligner){ tmaligner->initQuery(queryCaData, &queryCaData[res.qLen], &queryCaData[res.qLen+res.qLen], NULL, res.qLen); + unsigned int normlen= std::min(res.qLen, res.dbLen); tmpBt = Matcher::uncompressAlignment(res.backtrace); tmres = tmaligner->computeTMscore(targetCaData, &targetCaData[res.dbLen], &targetCaData[res.dbLen+res.dbLen], res.dbLen, - res.qStartPos, res.dbStartPos, tmpBt, - std::min(std::min(res.dbLen, res.qLen), static_cast(tmpBt.size()))); + res.qStartPos, res.dbStartPos, tmpBt,normlen); + tmres.tmscore = tmres.tmscore / normlen; rmsd = tmres.rmsd; - } LDDTCalculator::LDDTScoreResult lddtres; if(needLDDT) { @@ -885,19 +885,13 @@ R"html( result.append(SSTR(tmres.t[2])); break; case LocalParameters::OUTFMT_ALNTMSCORE: - result.append(SSTR(tmres.tmscore)); + result.append(SSTR(tmres.tmscore * tmpBt.size())); break; case LocalParameters::OUTFMT_QTMSCORE: - tmres = tmaligner->computeTMscore(targetCaData, &targetCaData[res.dbLen], &targetCaData[res.dbLen+res.dbLen], res.dbLen, - res.qStartPos, res.dbStartPos, Matcher::uncompressAlignment(res.backtrace), - res.qLen); - result.append(SSTR(tmres.tmscore)); + result.append(SSTR(tmres.tmscore * res.qLen)); break; case LocalParameters::OUTFMT_TTMSCORE: - tmres = tmaligner->computeTMscore(targetCaData, &targetCaData[res.dbLen], &targetCaData[res.dbLen+res.dbLen], res.dbLen, - res.qStartPos, res.dbStartPos, Matcher::uncompressAlignment(res.backtrace), - res.dbLen); - result.append(SSTR(tmres.tmscore)); + result.append(SSTR(tmres.tmscore * res.dbLen)); break; case LocalParameters::OUTFMT_RMSD: result.append(SSTR(rmsd)); diff --git a/src/strucclustutils/structurerescorediagonal.cpp b/src/strucclustutils/structurerescorediagonal.cpp index 159f50ae..ba59b604 100644 --- a/src/strucclustutils/structurerescorediagonal.cpp +++ b/src/strucclustutils/structurerescorediagonal.cpp @@ -342,9 +342,12 @@ int structureungappedalign(int argc, const char **argv, const Command& command) char *tcadata = tcadbr->sequenceReader->getData(tId, thread_idx); size_t tCaLength = tcadbr->sequenceReader->getEntryLen(tId); float* targetCaData = tcoords.read(tcadata, res.dbLen, tCaLength); + unsigned int normLen = std::min(res.dbLen, res.qLen); TMaligner::TMscoreResult tmres = tmaligner->computeTMscore(targetCaData, &targetCaData[res.dbLen], &targetCaData[res.dbLen+res.dbLen], res.dbLen, res.qStartPos, res.dbStartPos, Matcher::uncompressAlignment(res.backtrace), - std::min(static_cast(res.backtrace.length()), std::min(res.dbLen, res.qLen))); + normLen); + tmres.tmscore = (tmres.tmscore / static_cast(normLen)) + * static_cast(res.backtrace.size()); if(tmres.tmscore < par.tmScoreThr){ continue; }