]> git.donarmstrong.com Git - mothur.git/blobdiff - fastamap.cpp
added sharedbraycurtis, sharedmorisirahorn, sharedkulczynski, sharedkulczynskicody...
[mothur.git] / fastamap.cpp
index 0e6c22e21f48aec62b4a365db1e2454cd65ce7c9..1fefdd15c144edad253892a56be7917b0ea1320b 100644 (file)
@@ -20,22 +20,24 @@ void FastaMap::readFastaFile(ifstream& in) {
        
                //read through file
                while (getline(in, line)) {
-                       if (isalnum(line.at(0))){  //if it's a sequence line
-                               sequence += line;
-                       }
-                       else{
+                       if (line != "") {
+                               if (isalnum(line.at(0))) {  //if it's a sequence line
+                                       sequence += line;
+                               }
+                               else{
                                //input sequence info into map
-                               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++;
+                                       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++;
+                                       }
+                                       name = (line.substr(1, (line.npos))); //The line you just read is a new name so rip off '>'
+                                       sequence = "";
                                }
-                               name = (line.substr(1, (line.npos))); //The line you just read is a new name so rip off '>'
-                               sequence = "";
                        }
                }
        
@@ -107,3 +109,22 @@ void FastaMap::print(ostream& out){ //prints data
        }
 }
 /*******************************************************************************/
+void FastaMap::printCondensedFasta(ostream& out){ //prints data
+       try {
+               // two column file created with groupname and them list of identical sequence names
+               for (it = data.begin(); it != data.end(); it++) {
+                       out << ">" << it->second.groupname << endl;
+                       out << it->first << endl;
+               }
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the FastaMap class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the FastaMap class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+/*******************************************************************************/
+