]> git.donarmstrong.com Git - mothur.git/blobdiff - chimeraslayercommand.h
sffinfo bug with flow grams right index when clipQualRight=0
[mothur.git] / chimeraslayercommand.h
index 2c6fec8d8d1082ea270f5e2c2a8832a7b57033a4..68e03b8f881930fd919fc36b2283cc4024d3a2b0 100644 (file)
@@ -15,6 +15,7 @@
 #include "chimera.h"
 #include "chimeraslayer.h"
 #include "sequenceparser.h"
+#include "sequencecountparser.h"
 
 /***********************************************************/
 
@@ -27,8 +28,10 @@ public:
        vector<string> setParameters();
        string getCommandName()                 { return "chimera.slayer";              }
        string getCommandCategory()             { return "Sequence Processing"; }
+       
        string getHelpString(); 
-       string getCitation() { return "Haas BJ, Gevers D, Earl A, Feldgarden M, Ward DV, Giannokous G, Ciulla D, Tabbaa D, Highlander SK, Sodergren E, Methe B, Desantis TZ, Petrosino JF, Knight R, Birren BW (2011). Chimeric 16S rRNA sequence formation and detection in Sanger and 454-pyrosequenced PCR amplicons. Genome Res. \nhttp://www.mothur.org/wiki/Chimera.slayer"; }
+    string getOutputPattern(string);   
+       string getCitation() { return "Haas BJ, Gevers D, Earl A, Feldgarden M, Ward DV, Giannokous G, Ciulla D, Tabbaa D, Highlander SK, Sodergren E, Methe B, Desantis TZ, Petrosino JF, Knight R, Birren BW (2011). Chimeric 16S rRNA sequence formation and detection in Sanger and 454-pyrosequenced PCR amplicons. Genome Res  21:494.\nhttp://www.mothur.org/wiki/Chimera.slayer"; }
        string getDescription()         { return "detect chimeric sequences"; }
        
        int execute(); 
@@ -50,26 +53,29 @@ private:
        int divideInHalf(Sequence, string&, string&);
        map<string, int> sortFastaFile(string, string);
        map<string, int> sortFastaFile(vector<Sequence>&, map<string, string>&, string newFile);
+    int sortFastaFile(vector<Sequence>&, map<string, int>&, string newFile);
        string getNamesFile(string&);
        //int setupChimera(string,);
        int MPIExecute(string, string, string, string, map<string, int>&);
-       int deconvoluteResults(SequenceParser*, string, string, string);
+       int deconvoluteResults(map<string, string>&, string, string, string);
        map<string, int> priority;
        int setUpForSelfReference(SequenceParser*&, map<string, string>&, map<string, map<string, int> >&, int);
-       int driverGroups(string, string, string, map<string, map<string, int> >&, map<string, string>&);
-       int createProcessesGroups(string, string, string, map<string, map<string, int> >&, map<string, string>&);
-       int MPIExecuteGroups(string, string, string, map<string, map<string, int> >&, map<string, string>&);
+    int setUpForSelfReference(SequenceCountParser*&, map<string, string>&, map<string, map<string, int> >&, int);
+       int driverGroups(string, string, string, map<string, map<string, int> >&, map<string, string>&, string);
+       int createProcessesGroups(string, string, string, map<string, map<string, int> >&, map<string, string>&, string, string);
+       int MPIExecuteGroups(string, string, string, map<string, map<string, int> >&, map<string, string>&, string, string);
 
                
        #ifdef USE_MPI
-       int driverMPI(int, int, MPI_File&, MPI_File&, MPI_File&, MPI_File&, vector<unsigned long long>&, string, map<string, int>&, bool);
+       int driverMPI(int, int, MPI_File&, MPI_File&, MPI_File&, MPI_File&, set<string>&, vector<unsigned long long>&, string, map<string, int>&, bool);
        #endif
 
-       bool abort, realign, trim, trimera, save;
-       string fastafile, groupfile, templatefile, outputDir, search, namefile, blastlocation;
+       bool abort, realign, trim, trimera, save, hasName, hasCount, dups;
+       string fastafile, groupfile, templatefile, outputDir, search, namefile, countfile, blastlocation;
        int processors, window, iters, increment, numwanted, ksize, match, mismatch, parents, minSimilarity, minCoverage, minBS, minSNP, numSeqs, templateSeqsLength;
        float divR;
        
+    map<string, map<string, string> > group2NameMap;
        vector<string> outputNames;
        vector<string> fastaFileNames;
        vector<string> nameFileNames;
@@ -86,12 +92,12 @@ struct slayerData {
        string outputFName; 
        string fasta; 
        string accnos;
-       string filename;
+       string filename, countlist;
        string templatefile;
        string search;
        string blastlocation;
        bool trimera;
-       bool trim, realign;
+       bool trim, realign, dups, hasCount;
        unsigned long long start;
        unsigned long long end;
        int ksize, match, mismatch, window, minSimilarity, minCoverage, minBS, minSNP, parents, iters, increment, numwanted;
@@ -103,6 +109,7 @@ struct slayerData {
        int threadId;
        map<string, map<string, int> > fileToPriority;
        map<string, string> fileGroup;
+    map<string, map<string, string> > group2NameMap;
        
        slayerData(){}
        slayerData(string o, string fa, string ac, string f, string te, string se, string bl, bool tri, bool trm, bool re, MothurOut* mout, unsigned long long st, unsigned long long en, int ks, int ma, int mis, int win, int minS, int minC, int miBS, int minSN, int par, int it, int inc, int numw, float div, map<string, int> prior, int tid) {
@@ -137,13 +144,17 @@ struct slayerData {
                count = 0;
                numNoParents = 0;
        }
-       slayerData(string o, string fa, string ac, string te, string se, string bl, bool tri, bool trm, bool re, MothurOut* mout, map<string, map<string, int> >& fPriority, map<string, string>& fileG, int ks, int ma, int mis, int win, int minS, int minC, int miBS, int minSN, int par, int it, int inc, int numw, float div, map<string, int> prior, int tid) {
+       slayerData(map<string, map<string, string> > g2n, bool hc, bool dps, string cl, string o, string fa, string ac, string te, string se, string bl, bool tri, bool trm, bool re, MothurOut* mout, map<string, map<string, int> >& fPriority, map<string, string>& fileG, int ks, int ma, int mis, int win, int minS, int minC, int miBS, int minSN, int par, int it, int inc, int numw, float div, map<string, int> prior, int tid) {
                outputFName = o;
                fasta = fa;
                accnos = ac;
                templatefile = te;
                search = se;
                blastlocation = bl;
+        countlist = cl;
+        dups = dps;
+        hasCount = hc;
+        group2NameMap = g2n;
                trimera = tri;
                trim = trm;
                realign = re;
@@ -208,8 +219,6 @@ static DWORD WINAPI MySlayerThreadFunction(LPVOID lpParam){
                        inFASTA.seekg(pDataArray->start-1); pDataArray->m->gobble(inFASTA); 
                }
                
-               pDataArray->count = pDataArray->end;
-               
                if (pDataArray->m->control_pressed) { out.close(); out2.close(); if (pDataArray->trim) { out3.close(); } inFASTA.close(); delete chimera;  return 0;    }
                
                if (chimera->getUnaligned()) { 
@@ -222,7 +231,7 @@ static DWORD WINAPI MySlayerThreadFunction(LPVOID lpParam){
                
                if (pDataArray->start == 0) { chimera->printHeader(out); }
                
-               int count = 0;
+               pDataArray->count = 0;
                for(int i = 0; i < pDataArray->end; i++){
                        
                        if (pDataArray->m->control_pressed) {   out.close(); out2.close(); if (pDataArray->trim) { out3.close(); } inFASTA.close(); delete chimera; return 1;   }
@@ -313,18 +322,18 @@ static DWORD WINAPI MySlayerThreadFunction(LPVOID lpParam){
                                        
                                        
                                }
-                               count++;
+                               pDataArray->count++;
                        }
                        
                        delete candidateSeq;
                        //report progress
-                       if((count) % 100 == 0){ pDataArray->m->mothurOut("Processing sequence: " + toString(count)); pDataArray->m->mothurOutEndLine();         }
+                       if((pDataArray->count) % 100 == 0){     pDataArray->m->mothurOut("Processing sequence: " + toString(pDataArray->count)); pDataArray->m->mothurOutEndLine();             }
                }
                //report progress
-               if((count) % 100 != 0){ pDataArray->m->mothurOut("Processing sequence: " + toString(count)); pDataArray->m->mothurOutEndLine();         }
+               if((pDataArray->count) % 100 != 0){     pDataArray->m->mothurOut("Processing sequence: " + toString(pDataArray->count)); pDataArray->m->mothurOutEndLine();             }
                
                pDataArray->numNoParents = chimera->getNumNoParents();
-               if (pDataArray->numNoParents == count) {        pDataArray->m->mothurOut("[WARNING]: megablast returned 0 potential parents for all your sequences. This could be due to formatdb.exe not being setup properly, please check formatdb.log for errors.\n"); }
+               if (pDataArray->numNoParents == pDataArray->count) {    pDataArray->m->mothurOut("[WARNING]: megablast returned 0 potential parents for all your sequences. This could be due to formatdb.exe not being setup properly, please check formatdb.log for errors.\n"); }
 
                out.close();
                out2.close();
@@ -348,8 +357,11 @@ static DWORD WINAPI MySlayerGroupThreadFunction(LPVOID lpParam){
        pDataArray = (slayerData*)lpParam;
        
        try {
-               
+        ofstream outCountList;
+        if (pDataArray->hasCount && pDataArray->dups) { pDataArray->m->openOutputFile(pDataArray->countlist, outCountList); }
+
                int totalSeqs = 0;
+        pDataArray->end = 0;
                
                for (map<string, map<string, int> >::iterator itFile = pDataArray->fileToPriority.begin(); itFile != pDataArray->fileToPriority.end(); itFile++) {
                        
@@ -507,10 +519,51 @@ static DWORD WINAPI MySlayerGroupThreadFunction(LPVOID lpParam){
                        if (pDataArray->trim) { out3.close(); }
                        inFASTA.close();
                        delete chimera;
-                       
+                       pDataArray->end++;
                        
                        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                        
+            //if we provided a count file with group info and set dereplicate=t, then we want to create a *.pick.count_table
+            //This table will zero out group counts for seqs determined to be chimeric by that group.
+            if (pDataArray->dups) {
+                if (!pDataArray->m->isBlank(thisaccnosFileName)) {
+                    ifstream in;
+                    pDataArray->m->openInputFile(thisaccnosFileName, in);
+                    string name;
+                    if (pDataArray->hasCount) {
+                        while (!in.eof()) {
+                            in >> name; pDataArray->m->gobble(in);
+                            outCountList << name << '\t' << pDataArray->fileGroup[thisFastaName] << endl;
+                        }
+                        in.close();
+                    }else {
+                        map<string, map<string, string> >::iterator itGroupNameMap = pDataArray->group2NameMap.find(pDataArray->fileGroup[thisFastaName]);
+                        if (itGroupNameMap != pDataArray->group2NameMap.end()) {
+                            map<string, string> thisnamemap = itGroupNameMap->second;
+                            map<string, string>::iterator itN;
+                            ofstream out;
+                            pDataArray->m->openOutputFile(thisaccnosFileName+".temp", out);
+                            while (!in.eof()) {
+                                in >> name; pDataArray->m->gobble(in);
+                                //pDataArray->m->mothurOut("here = " + name + '\t');
+                                itN = thisnamemap.find(name);
+                                if (itN != thisnamemap.end()) {
+                                    vector<string> tempNames; pDataArray->m->splitAtComma(itN->second, tempNames);
+                                    for (int j = 0; j < tempNames.size(); j++) { out << tempNames[j] << endl; }
+                                    //pDataArray->m->mothurOut(itN->second + '\n');
+                                    
+                                }else { pDataArray->m->mothurOut("[ERROR]: parsing cannot find " + name + ".\n"); pDataArray->m->control_pressed = true; }
+                            }
+                            out.close();
+                            in.close();
+                            pDataArray->m->renameFile(thisaccnosFileName+".temp", thisaccnosFileName);
+                        }else { pDataArray->m->mothurOut("[ERROR]: parsing cannot find " + pDataArray->fileGroup[thisFastaName] + ".\n"); pDataArray->m->control_pressed = true; }
+                    }
+                    
+                }
+            }
+            
+            
                        //append files
                        pDataArray->m->appendFiles(thisoutputFileName, pDataArray->outputFName); pDataArray->m->mothurRemove(thisoutputFileName); 
                        pDataArray->m->appendFiles(thisaccnosFileName, pDataArray->accnos); pDataArray->m->mothurRemove(thisaccnosFileName);
@@ -523,6 +576,7 @@ static DWORD WINAPI MySlayerGroupThreadFunction(LPVOID lpParam){
                }
                
                pDataArray->count = totalSeqs;
+        if (pDataArray->hasCount && pDataArray->dups) { outCountList.close(); }
                
                return 0;