Skip to content

Commit

Permalink
fix openmp related bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Woosub-Kim committed Aug 23, 2023
1 parent 1116bb8 commit 83d65b3
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 29 deletions.
28 changes: 18 additions & 10 deletions src/strucclustutils/createcomplexreport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <zstd.h>
#include "LDDT.h"
Expand Down Expand Up @@ -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<TranslateNucl::GenCode>(par.translationTable));

std::vector<ComplexResult> complexResVec;
Matcher::result_t res;
auto complexDataHandler = ComplexDataHandler();
std::map<unsigned int, unsigned int> qChainKeyToComplexIdMap;
std::map<unsigned int, std::vector<unsigned int>> qComplexIdToChainKeyMap;
std::vector<unsigned int> qComplexIdVec;
Expand All @@ -122,6 +122,10 @@ int createcomplexreport(int argc, const char **argv, const Command &command) {
#ifdef OPENMP
thread_idx = static_cast<unsigned int>(omp_get_thread_num());
#endif

Matcher::result_t res;
std::map<ComplexAlignmentKey_t, ComplexAlignment> complexAlignmentsWithAssId;

#pragma omp for schedule(dynamic, 10)
for (size_t queryIdx = 0; queryIdx < qComplexIdVec.size(); queryIdx++) {
progress.updateProgress();
Expand All @@ -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);
Expand All @@ -178,4 +186,4 @@ int createcomplexreport(int argc, const char **argv, const Command &command) {
delete tDbrHeader;
}
return EXIT_SUCCESS;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<unsigned int, unsigned int> &chainKeyToComplexIdLookup,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<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 ComplexDataHandler(assId, qTmScore, tTmScore, t, u, true);
}

#endif //FOLDSEEK_COMPLEXUTIL_H
#endif //FOLDSEEK_CREATECOMPLEXREPORT_H
2 changes: 1 addition & 1 deletion src/strucclustutils/scorecomplex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "TMaligner.h"
#include "Coordinate16.h"
#include "MemoryMapped.h"
#include "complexutil.h"
#include "createcomplexreport.h"

#ifdef OPENMP
#include <omp.h>
Expand Down
14 changes: 7 additions & 7 deletions src/strucclustutils/structureconvertalis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "NcbiTaxonomy.h"
#include "MappingReader.h"
#include "Coordinate16.h"
#include "complexutil.h"
#include "createcomplexreport.h"

#define ZSTD_STATIC_LINKING_ONLY

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -883,23 +883,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.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.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.assId));
break;
}
if (i < outcodes.size() - 1) {
Expand Down

0 comments on commit 83d65b3

Please sign in to comment.