Skip to content

Commit

Permalink
Rewrite createcomplexreport
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-steinegger committed Aug 22, 2023
1 parent d4a4a7d commit c97a0f5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 21 deletions.
27 changes: 18 additions & 9 deletions src/strucclustutils/createcomplexreport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,18 @@ int createcomplexreport(int argc, const char **argv, const Command &command) {
const bool isDb = par.dbOut;
TranslateNucl translateNucl(static_cast<TranslateNucl::GenCode>(par.translationTable));
Debug::Progress progress(alnDbr.getSize());
std::vector<ComplexResult> complexResVec;
Matcher::result_t res;
auto complexDataHandler = ComplexDataHandler();
std::map<ComplexAlignmentKey_t, ComplexAlignment> complexAlignmentsWithAssId;
std::map<ComplexAlignmentKey_t, ComplexAlignment> allAlignmentsWithAssId;

#pragma omp parallel num_threads(localThreads)
{
unsigned int thread_idx = 0;
#ifdef OPENMP
thread_idx = static_cast<unsigned int>(omp_get_thread_num());
#endif

std::map<ComplexAlignmentKey_t, ComplexAlignment> complexAlignmentsWithAssId;

#pragma omp for schedule(dynamic, 10)
for (size_t i = 0; i < alnDbr.getSize(); i++) {
progress.updateProgress();
Expand All @@ -125,29 +126,37 @@ int createcomplexreport(int argc, const char **argv, const Command &command) {
getComplexNameChainName(queryId, qCompAndChainName);
char *data = alnDbr.getData(i, thread_idx);
while (*data != '\0') {
bool isValid = parseScoreComplexResult(data, res, complexDataHandler);
if (!isValid) {
std::cout << "error message";
std::pair<bool, ComplexDataHandler> retComplex = parseScoreComplexResult(data, res);
if (retComplex.first == 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.second.assId;
auto key = ComplexAlignmentKey_t(assId, qCompAndChainName.first);
if (complexAlignmentsWithAssId.find(key) == complexAlignmentsWithAssId.end()){
complexAlignmentsWithAssId.insert({key, ComplexAlignment(queryId, targetId, complexDataHandler.qTmScore, complexDataHandler.tTmScore)});
complexAlignmentsWithAssId.insert({key, ComplexAlignment(queryId, targetId, retComplex.second.qTmScore, retComplex.second.tTmScore)});
} else {
complexAlignmentsWithAssId[key].qChainVector.emplace_back(queryId);
complexAlignmentsWithAssId[key].tChainVector.emplace_back(targetId);
}
} // while end
} // for end
#pragma omp critical
{
allAlignmentsWithAssId.insert(complexAlignmentsWithAssId.begin(), complexAlignmentsWithAssId.end());
}
}
std::map<ComplexAlignmentKey_t, ComplexAlignment>::iterator iter;
for (iter = complexAlignmentsWithAssId.begin(); iter != complexAlignmentsWithAssId.end(); iter++) {
std::vector<ComplexResult> complexResVec;

for (iter = allAlignmentsWithAssId.begin(); iter != allAlignmentsWithAssId.end(); iter++) {
getResult(iter->second.qChainVector, iter->second.tChainVector, complexResVec, iter->second.qTMScore, iter->second.tTMScore, iter->first.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);
Expand Down
12 changes: 6 additions & 6 deletions src/strucclustutils/createcomplexreport.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ static bool compareComplexResult(const ComplexResult &first, const ComplexResult
}

struct ComplexDataHandler {
ComplexDataHandler() {}
ComplexDataHandler(): assId(UINT_MAX), qTmScore(0.0f), tTmScore(0.0f) {}
ComplexDataHandler(unsigned int assId, double qTmScore, double tTmScore, std::string t, std::string u)
: assId(assId), qTmScore(qTmScore), tTmScore(tTmScore), t(t), u(u) {}
unsigned int assId;
Expand All @@ -35,11 +35,12 @@ struct ComplexDataHandler {
std::string u;
};

static bool parseScoreComplexResult(const char *data, Matcher::result_t &res, ComplexDataHandler &complexDataHandler) {
static std::pair<bool, ComplexDataHandler> parseScoreComplexResult(const char *data, Matcher::result_t &res) {
const char *entry[255];
size_t columns = Util::getWordsOfLine(data, entry, 255);
if (columns!=16)
return false;
if (columns!=16) {
return std::make_pair(false, ComplexDataHandler());
}
char key[255];
ptrdiff_t keySize = (entry[1] - data);
strncpy(key, data, keySize);
Expand All @@ -66,8 +67,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<unsigned int>(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 std::make_pair(true, ComplexDataHandler(assId, qTmScore, tTmScore, t, u));
}

#endif //FOLDSEEK_CREATECOMPLEXREPORT_H
11 changes: 5 additions & 6 deletions src/strucclustutils/structureconvertalis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -548,12 +548,11 @@ 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) {
std::pair<bool, ComplexDataHandler> retComplex = parseScoreComplexResult(data, res);
if (retComplex.first == false) {
res = Matcher::parseAlignmentRecord(data, true);
}
data = Util::skipLine(data);
Expand Down Expand Up @@ -883,23 +882,23 @@ 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.second.qTmScore));
break;
case LocalParameters::OUTFMT_T_COMPLEX_TMSCORE:
if (!isScoreComplexDB) {
// TODO
Debug(Debug::ERROR) << "The column tcomplextmscore is only for scorecomplex result.\n";
EXIT(EXIT_FAILURE);
}
result.append(SSTR(complexDataHandler.tTmScore));
result.append(SSTR(retComplex.second.tTmScore));
break;
case LocalParameters::OUTFMT_ASSIGN_ID:
if (!isScoreComplexDB) {
// TODO
Debug(Debug::ERROR) << "The column assignid is only for scorecomplex result.\n";
EXIT(EXIT_FAILURE);
}
result.append(SSTR(complexDataHandler.assId));
result.append(SSTR(retComplex.second.assId));
break;
}
if (i < outcodes.size() - 1) {
Expand Down

0 comments on commit c97a0f5

Please sign in to comment.