X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=fastamap.cpp;h=36b072121b044490332a8926f0f3f287bf816fab;hb=44b464979e91c2a1f144ac45ca12c14fcf6579f0;hp=57754667da593265618aa0d9e5c046e18b2b7203;hpb=510b1cfc25cd79391d6973ca20c5ec25fb1bb3b2;p=mothur.git diff --git a/fastamap.cpp b/fastamap.cpp index 5775466..36b0721 100644 --- a/fastamap.cpp +++ b/fastamap.cpp @@ -21,29 +21,32 @@ void FastaMap::readFastaFile(string inFileName) { string temp; while(!in.eof()){ + if (m->control_pressed) { break; } + Sequence currSeq(in); name = currSeq.getName(); - if(currSeq.getIsAligned()) { sequence = currSeq.getAligned(); } - else { sequence = currSeq.getUnaligned(); } - - seqmap[name] = sequence; - map::iterator it = data.find(sequence); - if (it == data.end()) { //it's unique. - data[sequence].groupname = name; //group name will be the name of the first duplicate sequence found. -// data[sequence].groupnumber = 1; - data[sequence].names = name; - }else { // its a duplicate. - data[sequence].names += "," + name; -// data[sequence].groupnumber++; - } - + if (name != "") { + if(currSeq.getIsAligned()) { sequence = currSeq.getAligned(); } + else { sequence = currSeq.getUnaligned(); } + + seqmap[name] = sequence; + map::iterator it = data.find(sequence); + if (it == data.end()) { //it's unique. + data[sequence].groupname = name; //group name will be the name of the first duplicate sequence found. + // data[sequence].groupnumber = 1; + data[sequence].names = name; + }else { // its a duplicate. + data[sequence].names += "," + name; + // data[sequence].groupnumber++; + } + } gobble(in); } in.close(); } catch(exception& e) { - errorOut(e, "FastaMap", "readFastaFile"); + m->errorOut(e, "FastaMap", "readFastaFile"); exit(1); } } @@ -58,6 +61,8 @@ void FastaMap::readFastaFile(string inFastaFile, string oldNameFileName){ //prin map oldNameMap; string name, list; while(!oldNameFile.eof()){ + if (m->control_pressed) { break; } + oldNameFile >> name >> list; oldNameMap[name] = list; gobble(oldNameFile); @@ -68,23 +73,26 @@ void FastaMap::readFastaFile(string inFastaFile, string oldNameFileName){ //prin openInputFile(inFastaFile, inFASTA); string sequence; while(!inFASTA.eof()){ + if (m->control_pressed) { break; } + Sequence currSeq(inFASTA); name = currSeq.getName(); - if(currSeq.getIsAligned()) { sequence = currSeq.getAligned(); } - else { sequence = currSeq.getUnaligned(); } - - seqmap[name] = sequence; - map::iterator it = data.find(sequence); - if (it == data.end()) { //it's unique. - data[sequence].groupname = name; //group name will be the name of the first duplicate sequence found. -// data[sequence].groupnumber = 1; - data[sequence].names = oldNameMap[name]; - }else { // its a duplicate. - data[sequence].names += "," + oldNameMap[name]; -// data[sequence].groupnumber++; - } - + if (name != "") { + if(currSeq.getIsAligned()) { sequence = currSeq.getAligned(); } + else { sequence = currSeq.getUnaligned(); } + + seqmap[name] = sequence; + map::iterator it = data.find(sequence); + if (it == data.end()) { //it's unique. + data[sequence].groupname = name; //group name will be the name of the first duplicate sequence found. + // data[sequence].groupnumber = 1; + data[sequence].names = oldNameMap[name]; + }else { // its a duplicate. + data[sequence].names += "," + oldNameMap[name]; + // data[sequence].groupnumber++; + } + } gobble(inFASTA); } @@ -143,12 +151,13 @@ void FastaMap::printNamesFile(string outFileName){ //prints data // two column file created with groupname and them list of identical sequence names for (map::iterator it = data.begin(); it != data.end(); it++) { + if (m->control_pressed) { break; } outFile << it->second.groupname << '\t' << it->second.names << endl; } outFile.close(); } catch(exception& e) { - errorOut(e, "FastaMap", "printNamesFile"); + m->errorOut(e, "FastaMap", "printNamesFile"); exit(1); } } @@ -161,13 +170,14 @@ void FastaMap::printCondensedFasta(string outFileName){ //prints data openOutputFile(outFileName, out); //creates a fasta file for (map::iterator it = data.begin(); it != data.end(); it++) { + if (m->control_pressed) { break; } out << ">" << it->second.groupname << endl; out << it->first << endl; } out.close(); } catch(exception& e) { - errorOut(e, "FastaMap", "printCondensedFasta"); + m->errorOut(e, "FastaMap", "printCondensedFasta"); exit(1); } }