Skip to content
Permalink
Browse files

offsetalignments now correctly returns a nucleotide backtrace if needed

convertalis does not need to deal with backtrace translation anymore
  • Loading branch information
RuoshiZhang authored and milot-mirdita committed Oct 23, 2019
1 parent 34da346 commit 0a1348be78bd84137bdb373ba32e0e8c054b3e1c
Showing with 25 additions and 15 deletions.
  1. +4 −15 src/util/convertalignments.cpp
  2. +21 −0 src/util/offsetalignment.cpp
@@ -18,6 +18,7 @@
#include <omp.h>
#endif


void printSeqBasedOnAln(std::string &out, const char *seq, unsigned int offset,
const std::string &bt, bool reverse, bool isReverseStrand,
bool translateSequence, const TranslateNucl &translateNucl) {
@@ -211,8 +212,8 @@ int convertalignments(int argc, const char **argv, const Command &command) {
tDbrHeader = new IndexReader(par.db2, par.threads, IndexReader::SRC_HEADERS, (touch) ? (IndexReader::PRELOAD_INDEX | IndexReader::PRELOAD_DATA) : 0);
}

bool queryNucs = Parameters::isEqualDbtype(qDbr.sequenceReader->getDbtype(), Parameters::DBTYPE_NUCLEOTIDES);
bool targetNucs = Parameters::isEqualDbtype(tDbr->sequenceReader->getDbtype(), Parameters::DBTYPE_NUCLEOTIDES);
const bool queryNucs = Parameters::isEqualDbtype(qDbr.sequenceReader->getDbtype(), Parameters::DBTYPE_NUCLEOTIDES);
const bool targetNucs = Parameters::isEqualDbtype(tDbr->sequenceReader->getDbtype(), Parameters::DBTYPE_NUCLEOTIDES);
if (needSequenceDB) {
// try to figure out if search was translated. This is can not be solved perfectly.
bool seqtargetAA = false;
@@ -269,7 +270,6 @@ int convertalignments(int argc, const char **argv, const Command &command) {
const bool isDb = par.dbOut;
TranslateNucl translateNucl(static_cast<TranslateNucl::GenCode>(par.translationTable));


if (format == Parameters::FORMAT_ALIGNMENT_SAM) {
char buffer[1024];
unsigned int lastKey = tDbr->sequenceReader->getLastKey();
@@ -511,10 +511,6 @@ int convertalignments(int argc, const char **argv, const Command &command) {
result.append(SSTR(res.score));
break;
case Parameters::OUTFMT_CIGAR:
if(isTranslatedSearch == true && targetNucs == true && queryNucs == true ){
Matcher::result_t::protein2nucl(res.backtrace, newBacktrace);
res.backtrace = newBacktrace;
}
result.append(SSTR(res.backtrace));
newBacktrace.clear();
break;
@@ -635,14 +631,7 @@ int convertalignments(int argc, const char **argv, const Command &command) {
continue;
}
result.append(buffer, count);
if (isTranslatedSearch == true && targetNucs == true && queryNucs == true) {
Matcher::result_t::protein2nucl(res.backtrace, newBacktrace);
result.append(newBacktrace);
newBacktrace.clear();

} else {
result.append(res.backtrace);
}
result.append(res.backtrace);
result.append("\t*\t0\t0\t");
int start = std::min(res.qStartPos, res.qEndPos);
int end = std::max(res.qStartPos, res.qEndPos);
@@ -351,6 +351,9 @@ int offsetalignment(int argc, const char **argv, const Command &command) {
results.reserve(300);
tmp.reserve(300);

std::string newBacktrace;
newBacktrace.reserve(300);

#pragma omp for schedule(dynamic, 10)
for (size_t i = 0; i < entryCount; ++i) {
progress.updateProgress();
@@ -389,6 +392,12 @@ int offsetalignment(int argc, const char **argv, const Command &command) {
for(size_t i = 0; i < results.size(); i++) {
Matcher::result_t &res = results[i];
bool hasBacktrace = (res.backtrace.size() > 0);
if (isNuclNuclSearch == false && hasBacktrace) {
newBacktrace.reserve(res.backtrace.length() * 3);
Matcher::result_t::protein2nucl(res.backtrace, newBacktrace);
res.backtrace = newBacktrace;
newBacktrace.clear();
}
size_t len = Matcher::resultToBuffer(buffer, res, hasBacktrace, false);
ss.append(buffer, len);
}
@@ -414,6 +423,12 @@ int offsetalignment(int argc, const char **argv, const Command &command) {
for(size_t i = 0; i < results.size(); i++){
Matcher::result_t &res = results[i];
bool hasBacktrace = (res.backtrace.size() > 0);
if (isNuclNuclSearch == false && hasBacktrace) {
newBacktrace.reserve(res.backtrace.length() * 3);
Matcher::result_t::protein2nucl(res.backtrace, newBacktrace);
res.backtrace = newBacktrace;
newBacktrace.clear();
}
size_t len = Matcher::resultToBuffer(buffer, res, hasBacktrace, false);
ss.append(buffer, len);
}
@@ -423,6 +438,12 @@ int offsetalignment(int argc, const char **argv, const Command &command) {
for(size_t i = 0; i < tmp.size(); i++){
Matcher::result_t &res = tmp[i];
bool hasBacktrace = (res.backtrace.size() > 0);
if (isNuclNuclSearch == false && hasBacktrace) {
newBacktrace.reserve(res.backtrace.length() * 3);
Matcher::result_t::protein2nucl(res.backtrace, newBacktrace);
res.backtrace = newBacktrace;
newBacktrace.clear();
}
size_t len = Matcher::resultToBuffer(buffer, res, hasBacktrace, false);
ss.append(buffer, len);
}

0 comments on commit 0a1348b

Please sign in to comment.
You can’t perform that action at this time.