]> git.donarmstrong.com Git - mothur.git/blobdiff - fastamap.cpp
sffinfo bug with flow grams right index when clipQualRight=0
[mothur.git] / fastamap.cpp
index f5ac122112a633de7768b251568edda33623a81c..bf55493faece21cbd6c0043ac89149826c83c166 100644 (file)
 void FastaMap::readFastaFile(string inFileName) {
        try {
                ifstream in;
-               openInputFile(inFileName, in);
+               m->openInputFile(inFileName, in);
                string name, sequence, line;
                sequence = "";
                string temp;
-
+               map<string, string>::iterator itName;
+               
+               
                while(!in.eof()){
+                       if (m->control_pressed) { break; }
+                       
                        Sequence currSeq(in);
                        name = currSeq.getName();
                        
@@ -28,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<string,group>::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.
@@ -39,12 +46,12 @@ void FastaMap::readFastaFile(string inFileName) {
                                        //                              data[sequence].groupnumber++;
                                }       
                        }
-                       gobble(in);
+                       m->gobble(in);
                }
                in.close();             
        }
        catch(exception& e) {
-               errorOut(e, "FastaMap", "readFastaFile");
+               m->errorOut(e, "FastaMap", "readFastaFile");
                exit(1);
        }
 }
@@ -54,21 +61,27 @@ void FastaMap::readFastaFile(string inFileName) {
 void FastaMap::readFastaFile(string inFastaFile, string oldNameFileName){ //prints data
        
        ifstream oldNameFile;
-       openInputFile(oldNameFileName, oldNameFile);
+       m->openInputFile(oldNameFileName, oldNameFile);
        
        map<string,string> oldNameMap;
+       map<string, string>::iterator itName;
        string name, list;
        while(!oldNameFile.eof()){
-               oldNameFile >> name >> list;
+               if (m->control_pressed) { break; }
+               
+               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; }
+               
                Sequence currSeq(inFASTA);
                name = currSeq.getName();
                
@@ -76,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<string,group>::iterator it = data.find(sequence);
                        if (it == data.end()) {         //it's unique.
@@ -87,7 +104,7 @@ void FastaMap::readFastaFile(string inFastaFile, string oldNameFileName){ //prin
                                //                      data[sequence].groupnumber++;
                        }       
                }
-               gobble(inFASTA);
+               m->gobble(inFASTA);
        }
        
        
@@ -141,16 +158,17 @@ 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<string,group>::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);
        }
 }
@@ -160,16 +178,17 @@ 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<string,group>::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);
        }
 }