diff --git a/src/strucclustutils/createcomplexreport.cpp b/src/strucclustutils/createcomplexreport.cpp index 293726bb..738867e5 100644 --- a/src/strucclustutils/createcomplexreport.cpp +++ b/src/strucclustutils/createcomplexreport.cpp @@ -9,7 +9,7 @@ #include "TranslateNucl.h" #include "MemoryMapped.h" #include "Coordinate16.h" -#include "complexutil.h" +#include "createcomplexreport.h" #define ZSTD_STATIC_LINKING_ONLY #include #include "LDDT.h" @@ -104,9 +104,9 @@ int createcomplexreport(int argc, const char **argv, const Command &command) { const bool isDb = par.dbOut; std::string qLookupFile = par.db1 + ".lookup"; TranslateNucl translateNucl(static_cast(par.translationTable)); + std::vector complexResVec; Matcher::result_t res; - auto complexDataHandler = ComplexDataHandler(); std::map qChainKeyToComplexIdMap; std::map> qComplexIdToChainKeyMap; std::vector qComplexIdVec; @@ -122,6 +122,10 @@ int createcomplexreport(int argc, const char **argv, const Command &command) { #ifdef OPENMP thread_idx = static_cast(omp_get_thread_num()); #endif + + Matcher::result_t res; + std::map complexAlignmentsWithAssId; + #pragma omp for schedule(dynamic, 10) for (size_t queryIdx = 0; queryIdx < qComplexIdVec.size(); queryIdx++) { progress.updateProgress(); @@ -139,32 +143,36 @@ int createcomplexreport(int argc, const char **argv, const Command &command) { getComplexNameChainName(queryId, qCompAndChainName); char *data = alnDbr.getData(queryKey, thread_idx); while (*data != '\0') { - parseScoreComplexResult(data, res, complexDataHandler); - // TODO ERROR MSG + ComplexDataHandler retComplex = parseScoreComplexResult(data, res); + if (retComplex.isValid == false){ + Debug(Debug::ERROR) << "No scorecomplex result provided"; + EXIT(EXIT_FAILURE); + } data = Util::skipLine(data); size_t tHeaderId = tDbrHeader->sequenceReader->getId(res.dbKey); const char *tHeader = tDbrHeader->sequenceReader->getData(tHeaderId, thread_idx); std::string targetId = Util::parseFastaHeader(tHeader); - unsigned int assId = complexDataHandler.assId; + unsigned int assId = retComplex.assId; auto key = ComplexAlignmentKey_t(assId, qCompAndChainName.first); unsigned int currIdx = find(complexAlignmentKeys.begin(), complexAlignmentKeys.end(), key) - complexAlignmentKeys.begin(); if (currIdx == complexAlignmentKeys.size()) { complexAlignmentKeys.emplace_back(key); - complexAlignments.emplace_back(ComplexAlignment(queryId, targetId, complexDataHandler.qTmScore, - complexDataHandler.tTmScore, complexDataHandler.t, - complexDataHandler.u)); + complexAlignments.emplace_back( + ComplexAlignment(queryId,targetId,retComplex.qTmScore,retComplex.tTmScore,retComplex.t,retComplex.u) + ); } else { complexAlignments[currIdx].qChainVector.emplace_back(queryId); complexAlignments[currIdx].tChainVector.emplace_back(targetId); } } // while end } - } // for end + }// for end } for (size_t complexAlignmentIdx = 0; complexAlignmentIdx < complexAlignmentKeys.size(); complexAlignmentIdx++) { getResult(complexAlignments[complexAlignmentIdx].qChainVector, complexAlignments[complexAlignmentIdx].tChainVector, complexResVec, complexAlignments[complexAlignmentIdx].qTMScore, complexAlignments[complexAlignmentIdx].tTMScore, complexAlignments[complexAlignmentIdx].t, complexAlignments[complexAlignmentIdx].u, complexAlignmentKeys[complexAlignmentIdx].first); } + SORT_SERIAL(complexResVec.begin(), complexResVec.end(), compareComplexResult); for (size_t i=0; i < complexResVec.size(); i++) { resultWriter.writeData(complexResVec[i].result.c_str(), complexResVec[i].result.length(), 0, localThreads - 1, false, false); @@ -178,4 +186,4 @@ int createcomplexreport(int argc, const char **argv, const Command &command) { delete tDbrHeader; } return EXIT_SUCCESS; -} \ No newline at end of file +} diff --git a/src/strucclustutils/complexutil.h b/src/strucclustutils/createcomplexreport.h similarity index 85% rename from src/strucclustutils/complexutil.h rename to src/strucclustutils/createcomplexreport.h index d982352c..1a5dff50 100644 --- a/src/strucclustutils/complexutil.h +++ b/src/strucclustutils/createcomplexreport.h @@ -2,8 +2,8 @@ // Created by Woosub Kim on 2023/06/20. // -#ifndef FOLDSEEK_COMPLEXUTIL_H -#define FOLDSEEK_COMPLEXUTIL_H +#ifndef FOLDSEEK_CREATECOMPLEXREPORT_H +#define FOLDSEEK_CREATECOMPLEXREPORT_H #include "Matcher.h" const unsigned int NOT_AVAILABLE_CHAIN_KEY = 4294967295; @@ -27,16 +27,19 @@ static bool compareComplexResult(const ComplexResult &first, const ComplexResult } struct ComplexDataHandler { - ComplexDataHandler() {} - ComplexDataHandler(unsigned int assId, double qTmScore, double tTmScore, std::string t, std::string u) - : assId(assId), qTmScore(qTmScore), tTmScore(tTmScore), t(t), u(u) {} + ComplexDataHandler(): assId(UINT_MAX), qTmScore(0.0f), tTmScore(0.0f) {} + ComplexDataHandler(bool isValid): assId(UINT_MAX), qTmScore(0.0f), tTmScore(0.0f), isValid(isValid) {} + ComplexDataHandler(unsigned int assId, double qTmScore, double tTmScore, std::string t, std::string u, bool isValid) + : assId(assId), qTmScore(qTmScore), tTmScore(tTmScore), t(t), u(u), isValid(isValid) {} unsigned int assId; double qTmScore; double tTmScore; std::string t; std::string u; + bool isValid; }; + static void getKeyToIdMapIdToKeysMapIdVec( const std::string &file, std::map &chainKeyToComplexIdLookup, @@ -68,12 +71,11 @@ static void getKeyToIdMapIdToKeysMapIdVec( lookupDB.close(); } -static bool parseScoreComplexResult(const char *data, Matcher::result_t &res, ComplexDataHandler &complexDataHandler) { +static ComplexDataHandler parseScoreComplexResult(const char *data, Matcher::result_t &res) { const char *entry[255]; size_t columns = Util::getWordsOfLine(data, entry, 255); if (columns!=16) { - std::cout << columns << std::endl; - return false; + return ComplexDataHandler(false); } char key[255]; ptrdiff_t keySize = (entry[1] - data); @@ -101,8 +103,7 @@ static bool parseScoreComplexResult(const char *data, Matcher::result_t &res, Co std::string u = std::string(entry[14], entry[15] - entry[14]-1); unsigned int assId = Util::fast_atoi(entry[15]); res = Matcher::result_t(dbKey, score, qCov, dbCov, seqId, eval, alnLength, qStartPos, qEndPos, qLen, dbStartPos, dbEndPos, dbLen, -1, -1, -1, -1, backtrace); - complexDataHandler = ComplexDataHandler(assId, qTmScore, tTmScore, t, u); - return true; + return ComplexDataHandler(assId, qTmScore, tTmScore, t, u, true); } -#endif //FOLDSEEK_COMPLEXUTIL_H +#endif //FOLDSEEK_CREATECOMPLEXREPORT_H diff --git a/src/strucclustutils/scorecomplex.cpp b/src/strucclustutils/scorecomplex.cpp index 5b43f8e5..19fb0ec3 100644 --- a/src/strucclustutils/scorecomplex.cpp +++ b/src/strucclustutils/scorecomplex.cpp @@ -10,7 +10,7 @@ #include "TMaligner.h" #include "Coordinate16.h" #include "MemoryMapped.h" -#include "complexutil.h" +#include "createcomplexreport.h" #ifdef OPENMP #include diff --git a/src/strucclustutils/structureconvertalis.cpp b/src/strucclustutils/structureconvertalis.cpp index 9b72b0c1..45404db2 100644 --- a/src/strucclustutils/structureconvertalis.cpp +++ b/src/strucclustutils/structureconvertalis.cpp @@ -13,7 +13,7 @@ #include "NcbiTaxonomy.h" #include "MappingReader.h" #include "Coordinate16.h" -#include "complexutil.h" +#include "createcomplexreport.h" #define ZSTD_STATIC_LINKING_ONLY @@ -548,12 +548,12 @@ int structureconvertalis(int argc, const char **argv, const Command &command) { } char *data = alnDbr.getData(i, thread_idx); Matcher::result_t res; - auto complexDataHandler = ComplexDataHandler(); while (*data != '\0') { const char *entry[255]; Util::getWordsOfLine(data, entry, 255); - isScoreComplexDB = parseScoreComplexResult(data, res, complexDataHandler); - if (!isScoreComplexDB) { + ComplexDataHandler retComplex = parseScoreComplexResult(data, res); + isScoreComplexDB = retComplex.isValid; + if (isScoreComplexDB == false) { res = Matcher::parseAlignmentRecord(data, true); } data = Util::skipLine(data); @@ -883,7 +883,7 @@ int structureconvertalis(int argc, const char **argv, const Command &command) { Debug(Debug::ERROR) << "The column qcomplextmscore is only for scorecomplex result.\n"; EXIT(EXIT_FAILURE); } - result.append(SSTR(complexDataHandler.qTmScore)); + result.append(SSTR(retComplex.qTmScore)); break; case LocalParameters::OUTFMT_T_COMPLEX_TMSCORE: if (!isScoreComplexDB) { @@ -891,7 +891,7 @@ int structureconvertalis(int argc, const char **argv, const Command &command) { Debug(Debug::ERROR) << "The column tcomplextmscore is only for scorecomplex result.\n"; EXIT(EXIT_FAILURE); } - result.append(SSTR(complexDataHandler.tTmScore)); + result.append(SSTR(retComplex.tTmScore)); break; case LocalParameters::OUTFMT_ASSIGN_ID: if (!isScoreComplexDB) { @@ -899,7 +899,7 @@ int structureconvertalis(int argc, const char **argv, const Command &command) { Debug(Debug::ERROR) << "The column assignid is only for scorecomplex result.\n"; EXIT(EXIT_FAILURE); } - result.append(SSTR(complexDataHandler.assId)); + result.append(SSTR(retComplex.assId)); break; } if (i < outcodes.size() - 1) {