]> git.donarmstrong.com Git - mothur.git/blobdiff - sequence.cpp
pat's changes to seq.error command
[mothur.git] / sequence.cpp
index 71dd3a925fab8eb7771803c6db557dfb9d10200b..42c26d59ab4df8cd9e0d75937a476617135adbd7 100644 (file)
@@ -54,29 +54,34 @@ Sequence::Sequence(istringstream& fastaString){
        
                initialize();
                fastaString >> name;
-               name = name.substr(1);
-               string sequence;
-       
-               //read comments
-               while ((name[0] == '#') && fastaString) { 
-                       while (!fastaString.eof())      {       char c = fastaString.get(); if (c == 10 || c == 13){    break;  }       } // get rest of line if there's any crap there
-                       sequence = getCommentString(fastaString);
-                       
-                       if (fastaString) {  
-                               fastaString >> name;  
-                               name = name.substr(1);  
-                       }else { 
-                               name = "";
-                               break;
-                       }
-               }
                
-               while (!fastaString.eof())      {       char c = fastaString.get();  if (c == 10 || c == 13){   break;  }       } // get rest of line if there's any crap there
+               if (name.length() != 0) { 
+               
+                       name = name.substr(1);
+                       string sequence;
+               
+                       //read comments
+                       while ((name[0] == '#') && fastaString) { 
+                               while (!fastaString.eof())      {       char c = fastaString.get(); if (c == 10 || c == 13){    break;  }       } // get rest of line if there's any crap there
+                               sequence = getCommentString(fastaString);
+                               
+                               if (fastaString) {  
+                                       fastaString >> name;  
+                                       name = name.substr(1);  
+                               }else { 
+                                       name = "";
+                                       break;
+                               }
+                       }
+                       
+                       while (!fastaString.eof())      {       char c = fastaString.get();  if (c == 10 || c == 13){ break;    }       } // get rest of line if there's any crap there
+                       
+                       sequence = getSequenceString(fastaString);              
+                       setAligned(sequence);   
+                       //setUnaligned removes any gap characters for us                                                
+                       setUnaligned(sequence);         
+               }else{ m->mothurOut("Error in reading your fastafile, at position " + toString(fastaString.tellg()) + ". Blank name."); m->mothurOutEndLine(); }
                
-               sequence = getSequenceString(fastaString);              
-               setAligned(sequence);   
-               //setUnaligned removes any gap characters for us                                                
-               setUnaligned(sequence);         
        }
        catch(exception& e) {
                m->errorOut(e, "Sequence", "Sequence");
@@ -91,29 +96,34 @@ Sequence::Sequence(istringstream& fastaString, string JustUnaligned){
        
                initialize();
                fastaString >> name;
-               name = name.substr(1);
-               string sequence;
-       
-               //read comments
-               while ((name[0] == '#') && fastaString) { 
-                       while (!fastaString.eof())      {       char c = fastaString.get(); if (c == 10 || c == 13){    break;  }       } // get rest of line if there's any crap there
-                       sequence = getCommentString(fastaString);
-                       
-                       if (fastaString) {  
-                               fastaString >> name;  
-                               name = name.substr(1);  
-                       }else { 
-                               name = "";
-                               break;
-                       }
-               }
                
-               while (!fastaString.eof())      {       char c = fastaString.get();  if (c == 10 || c == 13){   break;  }       } // get rest of line if there's any crap there
+               if (name.length() != 0) { 
                
-               sequence = getSequenceString(fastaString);              
+                       name = name.substr(1);
+                       string sequence;
+               
+                       //read comments
+                       while ((name[0] == '#') && fastaString) { 
+                               while (!fastaString.eof())      {       char c = fastaString.get(); if (c == 10 || c == 13){    break;  }       } // get rest of line if there's any crap there
+                               sequence = getCommentString(fastaString);
+                               
+                               if (fastaString) {  
+                                       fastaString >> name;  
+                                       name = name.substr(1);  
+                               }else { 
+                                       name = "";
+                                       break;
+                               }
+                       }
+                       
+                       while (!fastaString.eof())      {       char c = fastaString.get();  if (c == 10 || c == 13){ break;    }       } // get rest of line if there's any crap there
+                       
+                       sequence = getSequenceString(fastaString);              
+                       
+                       //setUnaligned removes any gap characters for us                                                
+                       setUnaligned(sequence);         
+               }else{ m->mothurOut("Error in reading your fastafile, at position " + toString(fastaString.tellg()) + ". Blank name."); m->mothurOutEndLine(); }
                
-               //setUnaligned removes any gap characters for us                                                
-               setUnaligned(sequence);         
        }
        catch(exception& e) {
                m->errorOut(e, "Sequence", "Sequence");
@@ -129,31 +139,37 @@ Sequence::Sequence(ifstream& fastaFile){
                m = MothurOut::getInstance();
                initialize();
                fastaFile >> name;
-               name = name.substr(1);
-               string sequence;
+
+               if (name.length() != 0) { 
                
-               //read comments
-               while ((name[0] == '#') && fastaFile) { 
-                       while (!fastaFile.eof())        {       char c = fastaFile.get(); if (c == 10 || c == 13){      break;  }       } // get rest of line if there's any crap there
-                       sequence = getCommentString(fastaFile);
+                       name = name.substr(1); 
                        
-                       if (fastaFile) {  
-                               fastaFile >> name;  
-                               name = name.substr(1);  
-                       }else { 
-                               name = "";
-                               break;
-                       }
-               }
+                       string sequence;
                
-               //read real sequence
-               while (!fastaFile.eof())        {       char c = fastaFile.get(); if (c == 10 || c == 13){      break;  }       } // get rest of line if there's any crap there
-               
-               sequence = getSequenceString(fastaFile);                
-               
-               setAligned(sequence);   
-               //setUnaligned removes any gap characters for us                                                
-               setUnaligned(sequence); 
+                       //read comments
+                       while ((name[0] == '#') && fastaFile) { 
+                               while (!fastaFile.eof())        {       char c = fastaFile.get(); if (c == 10 || c == 13){      break;  }       } // get rest of line if there's any crap there
+                               sequence = getCommentString(fastaFile);
+                               
+                               if (fastaFile) {  
+                                       fastaFile >> name;  
+                                       name = name.substr(1);  
+                               }else { 
+                                       name = "";
+                                       break;
+                               }
+                       }
+                       
+                       //read real sequence
+                       while (!fastaFile.eof())        {       char c = fastaFile.get(); if (c == 10 || c == 13){  break;      }       } // get rest of line if there's any crap there
+                       
+                       sequence = getSequenceString(fastaFile);                
+       
+                       setAligned(sequence);   
+                       //setUnaligned removes any gap characters for us                                                
+                       setUnaligned(sequence); 
+               }else{ m->mothurOut("Error in reading your fastafile, at position " + toString(fastaFile.tellg()) + ". Blank name."); m->mothurOutEndLine(); }
+
        }
        catch(exception& e) {
                m->errorOut(e, "Sequence", "Sequence");
@@ -167,30 +183,34 @@ Sequence::Sequence(ifstream& fastaFile, string JustUnaligned){
                m = MothurOut::getInstance();
                initialize();
                fastaFile >> name;
-               name = name.substr(1);
-               string sequence;
                
-               //read comments
-               while ((name[0] == '#') && fastaFile) { 
-                       while (!fastaFile.eof())        {       char c = fastaFile.get(); if (c == 10 || c == 13){      break;  }       } // get rest of line if there's any crap there
-                       sequence = getCommentString(fastaFile);
+               if (name.length() != 0) { 
+                       name = name.substr(1);
+                       string sequence;
                        
-                       if (fastaFile) {  
-                               fastaFile >> name;  
-                               name = name.substr(1);  
-                       }else { 
-                               name = "";
-                               break;
+                       //read comments
+                       while ((name[0] == '#') && fastaFile) { 
+                               while (!fastaFile.eof())        {       char c = fastaFile.get(); if (c == 10 || c == 13){      break;  }       } // get rest of line if there's any crap there
+                               sequence = getCommentString(fastaFile);
+                               
+                               if (fastaFile) {  
+                                       fastaFile >> name;  
+                                       name = name.substr(1);  
+                               }else { 
+                                       name = "";
+                                       break;
+                               }
                        }
-               }
-               
-               //read real sequence
-               while (!fastaFile.eof())        {       char c = fastaFile.get(); if (c == 10 || c == 13){      break;  }       } // get rest of line if there's any crap there
-               
-               sequence = getSequenceString(fastaFile);                
+                       
+                       //read real sequence
+                       while (!fastaFile.eof())        {       char c = fastaFile.get(); if (c == 10 || c == 13){       break; }       } // get rest of line if there's any crap there
+                       
+                       sequence = getSequenceString(fastaFile);                
+                       
+                       //setUnaligned removes any gap characters for us                                                
+                       setUnaligned(sequence); 
+               }else{ m->mothurOut("Error in reading your fastafile, at position " + toString(fastaFile.tellg()) + ". Blank name."); m->mothurOutEndLine(); }
                
-               //setUnaligned removes any gap characters for us                                                
-               setUnaligned(sequence); 
        }
        catch(exception& e) {
                m->errorOut(e, "Sequence", "Sequence");
@@ -234,7 +254,7 @@ string Sequence::getCommentString(ifstream& fastaFile) {
                while(fastaFile){
                        letter=fastaFile.get();
                        if((letter == '\r') || (letter == '\n')){  
-                               gobble(fastaFile);  //in case its a \r\n situation
+                               m->gobble(fastaFile);  //in case its a \r\n situation
                                break;
                        }
                }
@@ -283,7 +303,7 @@ string Sequence::getCommentString(istringstream& fastaFile) {
                while(fastaFile){
                        letter=fastaFile.get();
                        if((letter == '\r') || (letter == '\n')){  
-                               gobble(fastaFile);  //in case its a \r\n situation
+                               m->gobble(fastaFile);  //in case its a \r\n situation
                                break;
                        }
                }
@@ -461,6 +481,18 @@ int Sequence::getAmbigBases(){
 
 //********************************************************************************************************************
 
+void Sequence::removeAmbigBases(){
+       
+       for(int j=0;j<alignmentLength;j++){
+               if(aligned[j] != 'A' && aligned[j] != 'T' && aligned[j] != 'G' && aligned[j] != 'C'){
+                       aligned[j] = '-';
+               }
+       }
+       setUnaligned(aligned);
+}
+       
+//********************************************************************************************************************
+
 int Sequence::getLongHomoPolymer(){
        if(longHomoPolymer == -1){
                longHomoPolymer = 1;
@@ -533,4 +565,16 @@ void Sequence::reverseComplement(){
        aligned = temp;
        
 }
-/**************************************************************************************************/
+
+//********************************************************************************************************************
+
+void Sequence::trim(int length){
+       
+       if(numBases > length){
+               unaligned = unaligned.substr(0,length);
+               numBases = length;
+       }
+       
+}
+
+///**************************************************************************************************/