Skip to content

Commit

Permalink
Merge pull request #57 from ncbi/develop
Browse files Browse the repository at this point in the history
Fixing segfault while reading GTF with 0 at starting position for fea…
  • Loading branch information
r78v10a07 authored Aug 13, 2020
2 parents f9bbef3 + b802d67 commit b275fb3
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 22 deletions.
20 changes: 14 additions & 6 deletions includes/GenomeFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -1018,9 +1018,12 @@ namespace genome {
std::string isoformName;
std::unordered_map<std::string, std::string> fieldsMap;
GeneUnMapItr<T> it;
int wStart, wEnd;
int wStart = atoi(words[3].c_str());
int wEnd;

wStart = atoi(words[3].c_str()) - 1;
if (wStart != 0) {
wStart = wStart - 1;
}
wEnd = atoi(words[4].c_str()) - 1;
BString::split(words[8], ";", fields);
geneName = "";
Expand Down Expand Up @@ -1192,7 +1195,7 @@ namespace genome {

return currentIso;
}

std::deque<std::string> getChrOrder() const {
return chrOrder;
}
Expand All @@ -1202,8 +1205,13 @@ namespace genome {
setCurrentChr(chrName);
SPtrGene<T> g = std::make_shared<Gene < T >> ("gene", start, end);
it = currentChr->getGenes().lower_bound(g);
if (it == currentChr->getGenes().end()) --it;

if (it == currentChr->getGenes().end()) {
if (!currentChr->getGenes().empty()) {
--it;
} else {
throw exceptions::NotFoundException("Chromosome " + currentChr->getId() + " does not have genes");
}
}
return it;
}

Expand Down Expand Up @@ -1259,7 +1267,7 @@ namespace genome {
currentChr->processGTFLine(fParser.getWords(), geneIdKey, isoformIdKey);
} catch (exceptions::NotFoundException ex) {
std::cerr << ex.what() << std::endl;
std::cerr << "Error processing GTF line at Chromosome level:\n" + fParser.getLine() << std::endl;
std::cerr << "Error processing GTF line at Chromosome level:\n" + fParser.getLine() << std::endl;
exit(-1);
}
}
Expand Down
18 changes: 9 additions & 9 deletions nbproject/Makefile-Release.mk
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ FFLAGS=
ASFLAGS=

# Link Libraries and Options
LDLIBSOPTIONS=
LDLIBSOPTIONS=-L../../bamtools/lib

# Build Targets
.build-conf: ${BUILD_SUBPROJECTS}
Expand All @@ -91,32 +91,32 @@ bin/TPMCalculator: ${OBJECTFILES}
${OBJECTDIR}/src/DiffExpIR.o: src/DiffExpIR.cpp
${MKDIR} -p ${OBJECTDIR}/src
${RM} "$@.d"
$(COMPILE.cc) -O2 -Iincludes -std=c++14 -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/src/DiffExpIR.o src/DiffExpIR.cpp
$(COMPILE.cc) -O2 -Iincludes -I../../bamtools/include/bamtools -std=c++14 -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/src/DiffExpIR.o src/DiffExpIR.cpp

${OBJECTDIR}/src/FastaFactory.o: src/FastaFactory.cpp
${MKDIR} -p ${OBJECTDIR}/src
${RM} "$@.d"
$(COMPILE.cc) -O2 -Iincludes -std=c++14 -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/src/FastaFactory.o src/FastaFactory.cpp
$(COMPILE.cc) -O2 -Iincludes -I../../bamtools/include/bamtools -std=c++14 -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/src/FastaFactory.o src/FastaFactory.cpp

${OBJECTDIR}/src/RandomFactory.o: src/RandomFactory.cpp
${MKDIR} -p ${OBJECTDIR}/src
${RM} "$@.d"
$(COMPILE.cc) -O2 -Iincludes -std=c++14 -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/src/RandomFactory.o src/RandomFactory.cpp
$(COMPILE.cc) -O2 -Iincludes -I../../bamtools/include/bamtools -std=c++14 -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/src/RandomFactory.o src/RandomFactory.cpp

${OBJECTDIR}/src/ReadFactory.o: src/ReadFactory.cpp
${MKDIR} -p ${OBJECTDIR}/src
${RM} "$@.d"
$(COMPILE.cc) -O2 -Iincludes -std=c++14 -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/src/ReadFactory.o src/ReadFactory.cpp
$(COMPILE.cc) -O2 -Iincludes -I../../bamtools/include/bamtools -std=c++14 -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/src/ReadFactory.o src/ReadFactory.cpp

${OBJECTDIR}/src/Stats.o: src/Stats.cpp
${MKDIR} -p ${OBJECTDIR}/src
${RM} "$@.d"
$(COMPILE.cc) -O2 -Iincludes -std=c++14 -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/src/Stats.o src/Stats.cpp
$(COMPILE.cc) -O2 -Iincludes -I../../bamtools/include/bamtools -std=c++14 -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/src/Stats.o src/Stats.cpp

${OBJECTDIR}/src/TextParser.o: src/TextParser.cpp
${MKDIR} -p ${OBJECTDIR}/src
${RM} "$@.d"
$(COMPILE.cc) -O2 -Iincludes -std=c++14 -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/src/TextParser.o src/TextParser.cpp
$(COMPILE.cc) -O2 -Iincludes -I../../bamtools/include/bamtools -std=c++14 -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/src/TextParser.o src/TextParser.cpp

${OBJECTDIR}/src/bd0.o: src/bd0.c
${MKDIR} -p ${OBJECTDIR}/src
Expand All @@ -131,7 +131,7 @@ ${OBJECTDIR}/src/bratio.o: src/bratio.c
${OBJECTDIR}/src/bstring.o: src/bstring.cpp
${MKDIR} -p ${OBJECTDIR}/src
${RM} "$@.d"
$(COMPILE.cc) -O2 -Iincludes -std=c++14 -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/src/bstring.o src/bstring.cpp
$(COMPILE.cc) -O2 -Iincludes -I../../bamtools/include/bamtools -std=c++14 -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/src/bstring.o src/bstring.cpp

${OBJECTDIR}/src/chebyshev.o: src/chebyshev.c
${MKDIR} -p ${OBJECTDIR}/src
Expand Down Expand Up @@ -176,7 +176,7 @@ ${OBJECTDIR}/src/lgammacor.o: src/lgammacor.c
${OBJECTDIR}/src/main.o: src/main.cpp
${MKDIR} -p ${OBJECTDIR}/src
${RM} "$@.d"
$(COMPILE.cc) -O2 -Iincludes -std=c++14 -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/src/main.o src/main.cpp
$(COMPILE.cc) -O2 -Iincludes -I../../bamtools/include/bamtools -std=c++14 -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/src/main.o src/main.cpp

${OBJECTDIR}/src/pbeta.o: src/pbeta.c
${MKDIR} -p ${OBJECTDIR}/src
Expand Down
4 changes: 4 additions & 0 deletions nbproject/configurations.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
<standard>11</standard>
<incDir>
<pElem>includes</pElem>
<pElem>../../bamtools/include/bamtools</pElem>
</incDir>
<commandLine>-g</commandLine>
</ccTool>
Expand All @@ -105,6 +106,9 @@
</asmTool>
<linkerTool>
<output>bin/TPMCalculator</output>
<linkerAddLib>
<pElem>../../bamtools/lib</pElem>
</linkerAddLib>
<linkerDynSerch>
<pElem>.</pElem>
<pElem>.</pElem>
Expand Down
3 changes: 3 additions & 0 deletions nbproject/private/private.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group name="KillerMutations"/>
<group>
<file>file:/Users/veraalva/Work/Developer/C/ncbi/TPMCalculator/includes/GenomeFactory.h</file>
<file>file:/Users/veraalva/Work/Developer/C/ncbi/TPMCalculator/src/ReadFactory.cpp</file>
<file>file:/Users/veraalva/Work/Developer/C/ncbi/TPMCalculator/Dockerfile</file>
<file>file:/Users/veraalva/Work/Developer/C/ncbi/TPMCalculator/src/main.cpp</file>
</group>
</open-files>
Expand Down
18 changes: 11 additions & 7 deletions src/ReadFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,16 @@ void ReadFactory::processReadAtGenomeLevel(std::string chrName, std::string samp
GeneMultiSetNGS::iterator geneIt;
try {
if (!read_coords.empty()) {
geneIt = genomeFactory.findGeneUpperBound(chrName, read_coords.rbegin()->first, read_coords.rbegin()->second);
for (auto it = geneIt;; --it) {
this->processReadAtGeneLevel(*it, sampleName, read_coords, minOverlap);
if (done) break;
if (std::distance(it, geneIt) > 6 && (*it)->getEnd() < (*read_coords.begin()).first) done = true;
if (it == genomeFactory.getCurrentChr()->getGenes().begin()) break;
try {
geneIt = genomeFactory.findGeneUpperBound(chrName, read_coords.rbegin()->first, read_coords.rbegin()->second);
for (auto it = geneIt;; --it) {
this->processReadAtGeneLevel(*it, sampleName, read_coords, minOverlap);
if (done) break;
if (std::distance(it, geneIt) > 6 && (*it)->getEnd() < (*read_coords.begin()).first) done = true;
if (it == genomeFactory.getCurrentChr()->getGenes().begin()) break;
}
} catch (exceptions::NotFoundException ex) {
std::cerr << ex.what() << std::endl;
}
}
} catch (exceptions::NotFoundException) {
Expand Down Expand Up @@ -383,7 +387,7 @@ int ReadFactory::processReadsFromBAM(std::string bamFileName, std::string sample
}
}
reader.Close();

calculateTPMperSample(sampleName);
return count;
}
Expand Down

0 comments on commit b275fb3

Please sign in to comment.