]> git.donarmstrong.com Git - mothur.git/commitdiff
added keep dots to pcr.seqs. fixed pre.cluster name file name when group option is...
authorSarah Westcott <mothur.westcott@gmail.com>
Wed, 28 Mar 2012 18:20:50 +0000 (14:20 -0400)
committerSarah Westcott <mothur.westcott@gmail.com>
Wed, 28 Mar 2012 18:20:50 +0000 (14:20 -0400)
pcrseqscommand.h
prcseqscommand.cpp
preclustercommand.cpp
sequence.cpp

index 07ca8d5e8ed486af362933896725cb48c28b3df2..03092bca2a70da8428e77f5599e6ab200c2b8960 100644 (file)
@@ -43,7 +43,7 @@ private:
     
     vector<linePair> lines;
        bool getOligos(vector<vector<string> >&, vector<vector<string> >&, vector<vector<string> >&);
-    bool abort, keepprimer;
+    bool abort, keepprimer, keepdots;
        string fastafile, oligosfile, taxfile, groupfile, namefile, ecolifile, outputDir, nomatch;
        int start, end, pdiffs, processors, length;
        
@@ -79,11 +79,11 @@ struct pcrData {
        vector<string> primers;
     vector<string> revPrimer;
     set<string> badSeqNames;
-    bool keepprimer;
+    bool keepprimer, keepdots;
        
        
        pcrData(){}
-       pcrData(string f, string gf, string bfn, MothurOut* mout, string ol, string ec, vector<string> pr, vector<string> rpr, string nm, bool kp, int st, int en, int l, unsigned long long fst, unsigned long long fen) {
+       pcrData(string f, string gf, string bfn, MothurOut* mout, string ol, string ec, vector<string> pr, vector<string> rpr, string nm, bool kp, bool kd, int st, int en, int l, unsigned long long fst, unsigned long long fen) {
                filename = f;
         goodFasta = gf;
         badFasta = bfn;
@@ -94,6 +94,7 @@ struct pcrData {
         revPrimer = rpr;
         nomatch = nm;
         keepprimer = kp;
+        keepdots = kd;
                start = st;
                end = en;
         length = l;
@@ -216,8 +217,14 @@ static DWORD WINAPI MyPcrThreadFunction(LPVOID lpParam){
                         else{
                             //are you aligned
                             if (aligned) { 
-                                if (!pDataArray->keepprimer)    {  currSeq.padToPos(mapAligned[primerEnd]); } 
-                                else                {  currSeq.padToPos(mapAligned[primerStart]); }
+                                if (!pDataArray->keepprimer)    {  
+                                    if (pDataArray->keepdots)   { currSeq.filterToPos(mapAligned[primerEnd]);   }
+                                    else            { currSeq.setAligned(currSeq.getAligned().substr(mapAligned[primerEnd]));                                              }
+                                } 
+                                else                {  
+                                    if (pDataArray->keepdots)   { currSeq.filterToPos(mapAligned[primerStart]);  }
+                                    else            { currSeq.setAligned(currSeq.getAligned().substr(mapAligned[primerStart]));                                              }
+                                }
                             }else { 
                                 if (!pDataArray->keepprimer)    { currSeq.setAligned(currSeq.getUnaligned().substr(primerEnd)); } 
                                 else                { currSeq.setAligned(currSeq.getUnaligned().substr(primerStart)); } 
@@ -286,9 +293,14 @@ static DWORD WINAPI MyPcrThreadFunction(LPVOID lpParam){
                         else{ 
                             //are you aligned
                             if (aligned) { 
-                                if (!pDataArray->keepprimer)    {  currSeq.padFromPos(mapAligned[primerStart]); } 
-                                else                {  currSeq.padFromPos(mapAligned[primerEnd]); } 
-                            }
+                                if (!pDataArray->keepprimer)    {  
+                                    if (pDataArray->keepdots)   { currSeq.filterFromPos(mapAligned[primerStart]); }
+                                    else            { currSeq.setAligned(currSeq.getAligned().substr(0, mapAligned[primerStart]));   }
+                                } 
+                                else                {  
+                                    if (pDataArray->keepdots)   { currSeq.filterFromPos(mapAligned[primerEnd]); }
+                                    else            { currSeq.setAligned(currSeq.getAligned().substr(0, mapAligned[primerEnd]));   }
+                                }                             }
                             else { 
                                 if (!pDataArray->keepprimer)    { currSeq.setAligned(currSeq.getUnaligned().substr(0, primerStart));   } 
                                 else                { currSeq.setAligned(currSeq.getUnaligned().substr(0, primerEnd));     }
@@ -302,21 +314,38 @@ static DWORD WINAPI MyPcrThreadFunction(LPVOID lpParam){
                     else if (currSeq.getAligned().length() != pDataArray->length) {
                         pDataArray->m->mothurOut("[ERROR]: seqs are not the same length as ecoli seq. When using ecoli option your sequences must be aligned and the same length as the ecoli sequence.\n"); pDataArray->m->control_pressed = true; break; 
                     }else {
-                        currSeq.padToPos(pDataArray->start); 
-                        currSeq.padFromPos(pDataArray->end);
+                        if (pDataArray->keepdots)   { 
+                            currSeq.filterToPos(start); 
+                            currSeq.filterFromPos(end);
+                        }else {
+                            string seqString = currSeq.getAligned().substr(0, end);
+                            seqString = seqString.substr(start);
+                            currSeq.setAligned(seqString); 
+                        }
                     }
                 }else{ //using start and end to trim
                     //make sure the seqs are aligned
                     lengths.insert(currSeq.getAligned().length());
                     if (lengths.size() > 1) { pDataArray->m->mothurOut("[ERROR]: seqs are not aligned. When using start and end your sequences must be aligned.\n"); pDataArray->m->control_pressed = true; break; }
                     else {
-                        if (pDataArray->start != -1) { currSeq.padToPos(pDataArray->start); }
                         if (pDataArray->end != -1) {
                             if (pDataArray->end > currSeq.getAligned().length()) {  pDataArray->m->mothurOut("[ERROR]: end is longer than your sequence length, aborting.\n"); pDataArray->m->control_pressed = true; break; }
                             else {
-                                currSeq.padFromPos(pDataArray->end);
+                                if (pDataArray->keepdots)   { currSeq.filterFromPos(end); }
+                                else {
+                                    string seqString = currSeq.getAligned().substr(0, end);
+                                    currSeq.setAligned(seqString); 
+                                }
+                            }
+                        }
+                        if (pDataArray->start != -1) { 
+                            if (pDataArray->keepdots)   {  currSeq.filterToPos(start);  }
+                            else {
+                                string seqString = currSeq.getAligned().substr(start);
+                                currSeq.setAligned(seqString); 
                             }
                         }
+                        
                     }
                 }
                 
index d950b48eea4ec778371a439c1df89272fec03573..afedc746360b495850d588b6c7ce3839ec3f9256 100644 (file)
@@ -23,6 +23,7 @@ vector<string> PcrSeqsCommand::setParameters(){
                CommandParameter ppdiffs("pdiffs", "Number", "", "0", "", "", "",false,false); parameters.push_back(ppdiffs);
                CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors);
                CommandParameter pkeepprimer("keepprimer", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pkeepprimer);
+        CommandParameter pkeepdots("keepdots", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(pkeepdots);
         CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir);
                CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir);
         
@@ -177,6 +178,9 @@ PcrSeqsCommand::PcrSeqsCommand(string option)  {
                        temp = validParameter.validFile(parameters, "keepprimer", false);  if (temp == "not found")    {        temp = "f";     }
                        keepprimer = m->isTrue(temp);   
             
+            temp = validParameter.validFile(parameters, "keepdots", false);  if (temp == "not found")    {     temp = "t";     }
+                       keepdots = m->isTrue(temp);     
+            
                        temp = validParameter.validFile(parameters, "oligos", true);
                        if (temp == "not found"){       oligosfile = "";                }
                        else if(temp == "not open"){    oligosfile = ""; abort = true;  } 
@@ -297,7 +301,10 @@ int PcrSeqsCommand::execute(){
                
                if (m->control_pressed) {  return 0; }          
         
-        writeAccnos(badNames);      
+        //don't write or keep if blank
+        if (badNames.size() != 0)   { writeAccnos(badNames);        }   
+        if (m->isBlank(badSeqFile)) { m->mothurRemove(badSeqFile);  }
+        
         if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) {       m->mothurRemove(outputNames[i]); } return 0; }
         if (namefile != "")                    {               readName(badNames);             }   
         if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) {       m->mothurRemove(outputNames[i]); } return 0; }
@@ -434,7 +441,7 @@ int PcrSeqsCommand::createProcesses(string filename, string goodFileName, string
             if (i!=0) {extension += toString(i) + ".temp"; processIDS.push_back(i); }
             
                        // Allocate memory for thread data.
-                       pcrData* tempPcr = new pcrData(filename, goodFileName+extension, badFileName+extension, m, oligosfile, ecolifile, primers, revPrimer, nomatch, keepprimer, start, end, length, lines[i].start, lines[i].end);
+                       pcrData* tempPcr = new pcrData(filename, goodFileName+extension, badFileName+extension, m, oligosfile, ecolifile, primers, revPrimer, nomatch, keepprimer, keepdots, start, end, length, lines[i].start, lines[i].end);
                        pDataArray.push_back(tempPcr);
                        
                        //default security attributes, thread function name, argument to thread function, use default creation flags, returns the thread identifier
@@ -516,8 +523,14 @@ int PcrSeqsCommand::driverPcr(string filename, string goodFasta, string badFasta
                         else{
                             //are you aligned
                             if (aligned) { 
-                                if (!keepprimer)    {  currSeq.filterToPos(mapAligned[primerEnd]); } 
-                                else                {  currSeq.filterToPos(mapAligned[primerStart]); }
+                                if (!keepprimer)    {  
+                                    if (keepdots)   { currSeq.filterToPos(mapAligned[primerEnd]);   }
+                                    else            { currSeq.setAligned(currSeq.getAligned().substr(mapAligned[primerEnd]));                                              }
+                                } 
+                                else                {  
+                                    if (keepdots)   { currSeq.filterToPos(mapAligned[primerStart]);  }
+                                    else            { currSeq.setAligned(currSeq.getAligned().substr(mapAligned[primerStart]));                                              }
+                                }
                             }else { 
                                 if (!keepprimer)    { currSeq.setAligned(currSeq.getUnaligned().substr(primerEnd)); } 
                                 else                { currSeq.setAligned(currSeq.getUnaligned().substr(primerStart)); } 
@@ -533,8 +546,14 @@ int PcrSeqsCommand::driverPcr(string filename, string goodFasta, string badFasta
                         else{ 
                             //are you aligned
                             if (aligned) { 
-                                if (!keepprimer)    {  currSeq.filterFromPos(mapAligned[primerStart]); } 
-                                else                {  currSeq.filterFromPos(mapAligned[primerEnd]); } 
+                                if (!keepprimer)    {  
+                                    if (keepdots)   { currSeq.filterFromPos(mapAligned[primerStart]); }
+                                    else            { currSeq.setAligned(currSeq.getAligned().substr(0, mapAligned[primerStart]));   }
+                                } 
+                                else                {  
+                                    if (keepdots)   { currSeq.filterFromPos(mapAligned[primerEnd]); }
+                                    else            { currSeq.setAligned(currSeq.getAligned().substr(0, mapAligned[primerEnd]));   }
+                                } 
                             }
                             else { 
                                 if (!keepprimer)    { currSeq.setAligned(currSeq.getUnaligned().substr(0, primerStart));   } 
@@ -549,19 +568,35 @@ int PcrSeqsCommand::driverPcr(string filename, string goodFasta, string badFasta
                     else if (currSeq.getAligned().length() != length) {
                         m->mothurOut("[ERROR]: seqs are not the same length as ecoli seq. When using ecoli option your sequences must be aligned and the same length as the ecoli sequence.\n"); m->control_pressed = true; break; 
                     }else {
-                        currSeq.filterToPos(start); 
-                        currSeq.filterFromPos(end);
+                        if (keepdots)   { 
+                            currSeq.filterToPos(start); 
+                            currSeq.filterFromPos(end);
+                        }else {
+                            string seqString = currSeq.getAligned().substr(0, end);
+                            seqString = seqString.substr(start);
+                            currSeq.setAligned(seqString); 
+                        }
                     }
                 }else{ //using start and end to trim
                     //make sure the seqs are aligned
                     lengths.insert(currSeq.getAligned().length());
                     if (lengths.size() > 1) { m->mothurOut("[ERROR]: seqs are not aligned. When using start and end your sequences must be aligned.\n"); m->control_pressed = true; break; }
                     else {
-                        if (start != -1) { currSeq.filterToPos(start); }
                         if (end != -1) {
                             if (end > currSeq.getAligned().length()) {  m->mothurOut("[ERROR]: end is longer than your sequence length, aborting.\n"); m->control_pressed = true; break; }
                             else {
-                                currSeq.filterFromPos(end);
+                                if (keepdots)   { currSeq.filterFromPos(end); }
+                                else {
+                                    string seqString = currSeq.getAligned().substr(0, end);
+                                    currSeq.setAligned(seqString); 
+                                }
+                            }
+                        }
+                        if (start != -1) { 
+                            if (keepdots)   {  currSeq.filterToPos(start);  }
+                            else {
+                                string seqString = currSeq.getAligned().substr(start);
+                                currSeq.setAligned(seqString); 
                             }
                         }
                     }
index 23d738650f0e8d6aa84caff684c73becb93cdb70..f2fbc80088b1adf2927ee78d5b1e02fbf9691cb1 100644 (file)
@@ -229,6 +229,7 @@ int PreClusterCommand::execute(){
                        m->mothurOut("/******************************************/"); m->mothurOutEndLine(); 
                        
                        m->renameFile(filenames["fasta"][0], newFastaFile);
+            m->renameFile(filenames["name"][0], newNamesFile);
                        
                        m->mothurOut("It took " + toString(time(NULL) - start) + " secs to run pre.cluster."); m->mothurOutEndLine(); 
                                
index cfd8ec21498120614b94d3adbdade7275eb6a8b7..9cdbfb91cf6ba148dbf4e2f5b4252b33604c906c 100644 (file)
@@ -581,6 +581,11 @@ int Sequence::filterToPos(int start){
                aligned[j] = '.';
        }
        
+    //things like ......----------AT become ................AT
+    for(int j = start-1; j < aligned.length(); j++) {
+        if (isalpha(aligned[j])) { break; }
+        else { aligned[j] = '.'; }
+    }
     setUnaligned(aligned);
     
     return 0;
@@ -596,6 +601,11 @@ int Sequence::filterFromPos(int end){
                aligned[j] = '.';
        }
        
+    for(int j = aligned.length()-1; j < 0; j--) {
+        if (isalpha(aligned[j])) { break; }
+        else { aligned[j] = '.'; }
+    }
+    
     setUnaligned(aligned);
     
     return 0;