X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=blobdiff_plain;f=fastamap.cpp;h=bf55493faece21cbd6c0043ac89149826c83c166;hp=36b072121b044490332a8926f0f3f287bf816fab;hb=1a20e24ee786195ab0e1cccd4f5aede7a88f3f4e;hpb=aa9238c0a9e6e7aa0ed8b8b606b08ad4fd7dcfe3 diff --git a/fastamap.cpp b/fastamap.cpp index 36b0721..bf55493 100644 --- a/fastamap.cpp +++ b/fastamap.cpp @@ -15,11 +15,13 @@ void FastaMap::readFastaFile(string inFileName) { try { ifstream in; - openInputFile(inFileName, in); + m->openInputFile(inFileName, in); string name, sequence, line; sequence = ""; string temp; - + map::iterator itName; + + while(!in.eof()){ if (m->control_pressed) { break; } @@ -30,7 +32,10 @@ void FastaMap::readFastaFile(string inFileName) { if(currSeq.getIsAligned()) { sequence = currSeq.getAligned(); } else { sequence = currSeq.getUnaligned(); } - seqmap[name] = sequence; + itName = seqmap.find(name); + if (itName == seqmap.end()) { seqmap[name] = sequence; } + else { m->mothurOut("You already have a sequence named " + name + ", sequence names must be unique, please correct."); m->mothurOutEndLine(); } + 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. @@ -41,7 +46,7 @@ void FastaMap::readFastaFile(string inFileName) { // data[sequence].groupnumber++; } } - gobble(in); + m->gobble(in); } in.close(); } @@ -56,21 +61,23 @@ void FastaMap::readFastaFile(string inFileName) { void FastaMap::readFastaFile(string inFastaFile, string oldNameFileName){ //prints data ifstream oldNameFile; - openInputFile(oldNameFileName, oldNameFile); + m->openInputFile(oldNameFileName, oldNameFile); map oldNameMap; + map::iterator itName; string name, list; while(!oldNameFile.eof()){ if (m->control_pressed) { break; } - oldNameFile >> name >> list; + oldNameFile >> name; m->gobble(oldNameFile); + oldNameFile >> list; oldNameMap[name] = list; - gobble(oldNameFile); + m->gobble(oldNameFile); } oldNameFile.close(); ifstream inFASTA; - openInputFile(inFastaFile, inFASTA); + m->openInputFile(inFastaFile, inFASTA); string sequence; while(!inFASTA.eof()){ if (m->control_pressed) { break; } @@ -82,6 +89,10 @@ void FastaMap::readFastaFile(string inFastaFile, string oldNameFileName){ //prin if(currSeq.getIsAligned()) { sequence = currSeq.getAligned(); } else { sequence = currSeq.getUnaligned(); } + itName = seqmap.find(name); + if (itName == seqmap.end()) { seqmap[name] = sequence; } + else { m->mothurOut("You already have a sequence named " + name + ", sequence names must be unique, please correct."); m->mothurOutEndLine(); } + seqmap[name] = sequence; map::iterator it = data.find(sequence); if (it == data.end()) { //it's unique. @@ -93,7 +104,7 @@ void FastaMap::readFastaFile(string inFastaFile, string oldNameFileName){ //prin // data[sequence].groupnumber++; } } - gobble(inFASTA); + m->gobble(inFASTA); } @@ -147,7 +158,7 @@ int FastaMap::sizeUnique(){ //returns datas size which is the number of unique s void FastaMap::printNamesFile(string outFileName){ //prints data try { ofstream outFile; - openOutputFile(outFileName, outFile); + m->openOutputFile(outFileName, outFile); // two column file created with groupname and them list of identical sequence names for (map::iterator it = data.begin(); it != data.end(); it++) { @@ -167,7 +178,7 @@ void FastaMap::printNamesFile(string outFileName){ //prints data void FastaMap::printCondensedFasta(string outFileName){ //prints data try { ofstream out; - openOutputFile(outFileName, out); + m->openOutputFile(outFileName, out); //creates a fasta file for (map::iterator it = data.begin(); it != data.end(); it++) { if (m->control_pressed) { break; }