diff --git a/bin/fastaFromBed b/bin/fastaFromBed index 445b657484712ff76a8f1acc3c031c95fe5ff092..4a336971c4ad05e9ad8a90e2a86c23277691b693 100755 Binary files a/bin/fastaFromBed and b/bin/fastaFromBed differ diff --git a/obj/fastaFromBed.o b/obj/fastaFromBed.o index b0e62b4c1451eb1b14e06293ac96a496e2c88947..7abfc3fb170ef51c59663d526807bd2ab12d1f3b 100644 Binary files a/obj/fastaFromBed.o and b/obj/fastaFromBed.o differ diff --git a/src/fastaFromBed/fastaFromBed.cpp b/src/fastaFromBed/fastaFromBed.cpp index e935df816d46328ad8bde92c703da8aaf8039e88..879185faaabdbd1e46748351b425653651510bda 100755 --- a/src/fastaFromBed/fastaFromBed.cpp +++ b/src/fastaFromBed/fastaFromBed.cpp @@ -73,16 +73,22 @@ void Bed2Fa::ExtractDNA() { // loop through each BED entry for this chrom and // print the sequence for (unsigned int i = 0; i < bedList.size(); i++) { - - string dna = currDNA.substr(bedList[i].start, ((bedList[i].end - bedList[i].start))); + + unsigned int start = bedList[i].start; + unsigned int end = bedList[i].end; + + if ( (start < currDNA.size()) && (end < currDNA.size()) ) { + string dna = currDNA.substr(bedList[i].start, ((bedList[i].end - bedList[i].start))); - if (!(this->useName)) { - faOut << ">" << currChrom << ":" - << bedList[i].start << "-" << bedList[i].end << endl << dna << endl; - } - else { - faOut << ">" << bedList[i].name << endl << dna << endl; - } + if (!(this->useName)) { + faOut << ">" << currChrom << ":" + << bedList[i].start << "-" << bedList[i].end << endl << dna << endl; + } + else { + faOut << ">" << bedList[i].name << endl << dna << endl; + } + } + else cerr << "Feature (" << bedList[i].chrom << ":" << start << "-" << end << ") beyond chromosome size. Ignoring." << endl; } currDNA = ""; } @@ -98,16 +104,22 @@ void Bed2Fa::ExtractDNA() { // loop through each BED entry for this chrom and // print the sequence. for (unsigned int i = 0; i < bedList.size(); i++) { - - string dna = currDNA.substr(bedList[i].start, ((bedList[i].end - bedList[i].start))); + + unsigned int start = bedList[i].start; + unsigned int end = bedList[i].end; + + if ( (start < currDNA.size()) && (end < currDNA.size()) ) { + string dna = currDNA.substr(bedList[i].start, ((bedList[i].end - bedList[i].start))); - if (!(this->useName)) { - faOut << ">" << currChrom << ":" - << bedList[i].start << "-" << bedList[i].end << endl << dna << endl; - } - else { - faOut << ">" << bedList[i].name << endl << dna << endl; - } + if (!(this->useName)) { + faOut << ">" << currChrom << ":" + << bedList[i].start << "-" << bedList[i].end << endl << dna << endl; + } + else { + faOut << ">" << bedList[i].name << endl << dna << endl; + } + } + else cerr << "Feature (" << bedList[i].chrom << ":" << start << "-" << end << ") beyond chromosome size. Ignoring." << endl; } currDNA = ""; }