]> git.donarmstrong.com Git - mothur.git/commitdiff
added sharedotu parameter to venn command. working of make.contigs.
authorSarah Westcott <mothur.westcott@gmail.com>
Tue, 18 Dec 2012 14:24:56 +0000 (09:24 -0500)
committerSarah Westcott <mothur.westcott@gmail.com>
Tue, 18 Dec 2012 14:24:56 +0000 (09:24 -0500)
calculator.h
makecontigscommand.cpp
makecontigscommand.h
sharedsobscollectsummary.cpp
sharedsobscollectsummary.h
venn.cpp
venn.h
venncommand.cpp
venncommand.h

index 218f8eab74270dbb680aea0d1cf8c4ab823930ff..5aba3d29b1c15480ef8b8b29674b6a24d45db9e7 100644 (file)
@@ -27,6 +27,8 @@ public:
        Calculator(string n, int c, bool f, bool a) : name(n), cols(c), multiple(f), needsAll(a) { m = MothurOut::getInstance(); };
        virtual EstOutput getValues(SAbundVector*) = 0; 
        virtual EstOutput getValues(vector<SharedRAbundVector*>) = 0;
+    //optional calc that returns the otus labels of shared otus
+    virtual EstOutput getValues(vector<SharedRAbundVector*> sv , vector<string>&) { data = getValues(sv); return data; }
        virtual void print(ostream& f)  { f.setf(ios::fixed, ios::floatfield); f.setf(ios::showpoint);
                                                                          f << data[0]; for(int i=1;i<data.size();i++){ f << '\t' << data[i];   }}
        virtual string getName()                {       return name;    }
index bf55165dc96a6792a8f1de079dfb259b702df061..7a84f88ed86fbdcfc3c03d6759f46e99f935c836 100644 (file)
 //**********************************************************************************************************************
 vector<string> MakeContigsCommand::setParameters(){    
        try {
-               CommandParameter pfasta("ffastq", "InputTypes", "", "", "none", "none", "none","fasta-qfile",false,true,true); parameters.push_back(pfasta);
-        CommandParameter prfasta("rfastq", "InputTypes", "", "", "none", "none", "none","fasta-qfile",false,true,true); parameters.push_back(prfasta);
+               CommandParameter pfastq("ffastq", "InputTypes", "", "", "FastaFastqFile", "FastaFastqFile", "fastqGroup","fasta-qfile",false,false,true); parameters.push_back(pfastq);
+        CommandParameter prfastq("rfastq", "InputTypes", "", "", "none", "none", "fastqGroup","fasta-qfile",false,false,true); parameters.push_back(prfastq);
+        CommandParameter pfasta("ffasta", "InputTypes", "", "", "FastaFastqFile", "FastaFastqFile", "fastaGroup","fasta",false,false,true); parameters.push_back(pfasta);
+        CommandParameter prfasta("rfasta", "InputTypes", "", "", "none", "none", "none","fastaGroup",false,false,true); parameters.push_back(prfasta);
+        CommandParameter pfqual("fqfile", "InputTypes", "", "", "none", "none", "qfileGroup","qfile",false,false,true); parameters.push_back(pfqual);
+        CommandParameter prqual("rqfile", "InputTypes", "", "", "none", "none", "qfileGroup","qfile",false,false,true); parameters.push_back(prqual);
+        CommandParameter pfile("file", "InputTypes", "", "", "FastaFastqFile", "FastaFastqFile", "none","fasta-qfile",false,false,true); parameters.push_back(pfile);
         CommandParameter poligos("oligos", "InputTypes", "", "", "none", "none", "none","group",false,false,true); parameters.push_back(poligos);
                CommandParameter ppdiffs("pdiffs", "Number", "", "0", "", "", "","",false,false,true); parameters.push_back(ppdiffs);
                CommandParameter pbdiffs("bdiffs", "Number", "", "0", "", "", "","",false,false,true); parameters.push_back(pbdiffs);
@@ -44,10 +49,14 @@ vector<string> MakeContigsCommand::setParameters(){
 string MakeContigsCommand::getHelpString(){    
        try {
                string helpString = "";
-               helpString += "The make.contigs command reads a forward fastq file and a reverse fastq file and outputs new fasta and quality files.\n";
+               helpString += "The make.contigs command reads a file, forward fastq file and a reverse fastq file or forward fasta and reverse fasta files and outputs new fasta.  It will also provide new quality files if the fastq or file parameter is used.\n";
         helpString += "If an oligos file is provided barcodes and primers will be trimmed, and a group file will be created.\n";
                helpString += "The make.contigs command parameters are ffastq, rfastq, oligos, tdiffs, bdiffs, ldiffs, sdiffs, pdiffs, align, match, mismatch, gapopen, gapextend, allfiles and processors.\n";
-               helpString += "The ffastq and rfastq parameters are required.\n";
+               helpString += "The ffastq and rfastq, file, or ffasta and rfasta parameters are required.\n";
+        helpString += "The file parameter is 2 column file containing the forward fastq files in the first column and their matching reverse fastq files in the second column.  Mothur will process each pair and create a combined fasta and qual file with all the sequences.\n";
+        helpString += "The ffastq and rfastq parameters are used to provide a forward fastq and reverse fastq file to process.  If you provide one, you must provide the other.\n";
+        helpString += "The ffasta and rfasta parameters are used to provide a forward fasta and reverse fasta file to process.  If you provide one, you must provide the other.\n";
+        helpString += "The fqfile and rqfile parameters are used to provide a forward quality and reverse quality files to process with the ffasta and rfasta parameters.  If you provide one, you must provide the other.\n";
                helpString += "The align parameter allows you to specify the alignment method to use.  Your options are: gotoh and needleman. The default is needleman.\n";
         helpString += "The tdiffs parameter is used to specify the total number of differences allowed in the sequence. The default is pdiffs + bdiffs + sdiffs + ldiffs.\n";
                helpString += "The bdiffs parameter is used to specify the number of differences allowed in the barcode. The default is 0.\n";
@@ -157,6 +166,46 @@ MakeContigsCommand::MakeContigsCommand(string option)  {
                                        if (path == "") {       parameters["rfastq"] = inputDir + it->second;           }
                                }
                 
+                it = parameters.find("ffasta");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = m->hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["ffasta"] = inputDir + it->second;           }
+                               }
+                
+                it = parameters.find("rfasta");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = m->hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["rfasta"] = inputDir + it->second;           }
+                               }
+                
+                it = parameters.find("fqfile");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = m->hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["fqfile"] = inputDir + it->second;           }
+                               }
+                
+                it = parameters.find("rqfile");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = m->hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["rqfile"] = inputDir + it->second;           }
+                               }
+                
+                it = parameters.find("file");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = m->hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["file"] = inputDir + it->second;             }
+                               }
+                
                 it = parameters.find("oligos");
                                //user has given a template file
                                if(it != parameters.end()){ 
@@ -167,12 +216,36 @@ MakeContigsCommand::MakeContigsCommand(string option)  {
             }
             
             ffastqfile = validParameter.validFile(parameters, "ffastq", true);
-                       if (ffastqfile == "not open") { ffastqfile = ""; abort = true; }        
-                       else if (ffastqfile == "not found") { ffastqfile = ""; abort=true;  m->mothurOut("The ffastq parameter is required.\n"); }
+                       if (ffastqfile == "not open") {  abort = true; }        
+                       else if (ffastqfile == "not found") { ffastqfile = ""; }
                        
                        rfastqfile = validParameter.validFile(parameters, "rfastq", true);
-                       if (rfastqfile == "not open") { rfastqfile = ""; abort = true; }        
-                       else if (rfastqfile == "not found") { rfastqfile = ""; abort=true;  m->mothurOut("The rfastq parameter is required.\n"); }
+                       if (rfastqfile == "not open") {  abort = true; }        
+                       else if (rfastqfile == "not found") { rfastqfile = "";  }
+            
+            ffastafile = validParameter.validFile(parameters, "ffasta", true);
+                       if (ffastafile == "not open") {  abort = true; }        
+                       else if (ffastafile == "not found") { ffastafile = ""; }
+                       
+                       rfastafile = validParameter.validFile(parameters, "rfasta", true);
+                       if (rfastafile == "not open") {  abort = true; }        
+                       else if (rfastafile == "not found") { rfastafile = "";  }
+            
+            fqualfile = validParameter.validFile(parameters, "fqfile", true);
+                       if (fqualfile == "not open") {  abort = true; } 
+                       else if (fqualfile == "not found") { fqualfile = ""; }
+                       
+                       rqualfile = validParameter.validFile(parameters, "rqfile", true);
+                       if (rqualfile == "not open") {  abort = true; } 
+                       else if (rqualfile == "not found") { rqualfile = "";  }
+            
+            file = validParameter.validFile(parameters, "file", true);
+                       if (file == "not open") {  abort = true; }      
+                       else if (file == "not found") { file = "";  }
+            
+            if ((file == "") && (ffastafile == "") && (ffastqfile == "")) { abort = true; m->mothurOut("[ERROR]: ffastq and rfastq parameters are required.\n"); }
+            if ((ffastqfile != "") && (rfastqfile == "")) {  abort = true; }
+            if ((ffastqfile == "") && (rfastqfile != "")) {  abort = true; }
             
             oligosfile = validParameter.validFile(parameters, "oligos", true);
                        if (oligosfile == "not found")      {   oligosfile = "";        }
@@ -249,13 +322,13 @@ int MakeContigsCommand::execute(){
         //read ffastq and rfastq files creating fasta and qual files.
         //this function will create a forward and reverse, fasta and qual files for each processor.
         //files has an entry for each processor. files[i][0] = forwardFasta, files[i][1] = forwardQual, files[i][2] = reverseFasta, files[i][3] = reverseQual
-        int numReads = 0;
+        unsigned long int numReads = 0;
         int start = time(NULL);
         longestBase = 1000;
         m->mothurOut("Reading fastq data...\n"); 
         vector< vector<string> > files = readFastqFiles(numReads);  
         m->mothurOut("Done.\n");
-    
+       
         if (m->control_pressed) { return 0; }
         
         vector<vector<string> > fastaFileNames;
@@ -884,7 +957,7 @@ int MakeContigsCommand::driver(vector<string> files, string outputFasta, string
        }
 }
 //**********************************************************************************************************************
-vector< vector<string> > MakeContigsCommand::readFastqFiles(int& count){
+vector< vector<string> > MakeContigsCommand::readFastqFiles(unsigned long int& count){
     try {
         vector< vector<string> > files;
         
@@ -947,11 +1020,13 @@ vector< vector<string> > MakeContigsCommand::readFastqFiles(int& count){
             else { ignorer = true; }
             
             vector<pairFastqRead> reads = getReads(ignoref, ignorer, thisFread, thisRread, uniques);
-            
+           
             for (int i = 0; i < reads.size(); i++) {
                 fastqRead fread = reads[i].forward;
                 fastqRead rread = reads[i].reverse;
                 
+                if (m->debug) { m->mothurOut(toString(count) + '\t' + fread.name + '\t' + rread.name + '\n'); }
+               
                 if (checkReads(fread, rread)) {
                     if (m->control_pressed) { for (it = tempfiles.begin(); it!=tempfiles.end(); it++) { for (int i = 0; i < (it->second).size(); i++) { (*(it->second)[i]).close();  delete (it->second)[i]; } } for (int i = 0; i < files.size(); i++) {  for(int j = 0; j < files[i].size(); j++) { m->mothurRemove(files[i][j]); } } inForward.close(); inReverse.close(); return files; }
                     
@@ -1015,25 +1090,42 @@ vector<pairFastqRead> MakeContigsCommand::getReads(bool ignoref, bool ignorer, f
                 pairFastqRead temp(forward, reverse);
                 reads.push_back(temp);
             }else {
-                //look for forward pair
-                itUniques = uniques.find(forward.name);
-                if (itUniques != uniques.end()) {  //we have the pair for this read
-                    pairFastqRead temp(forward, itUniques->second);
-                    reads.push_back(temp);
-                    uniques.erase(itUniques);
-                }else { //save this read for later
-                    uniques[forward.name] = forward;
+                bool match = false;
+                //if no match are the names only different by 1 and 2?
+                string tempFRead = forward.name.substr(0, forward.name.length()-1);
+                string tempRRead = reverse.name.substr(0, reverse.name.length()-1);
+                if (tempFRead == tempRRead) {
+                    if ((forward.name[forward.name.length()-1] == '1') && (reverse.name[reverse.name.length()-1] == '2')) {
+                        forward.name = tempFRead;
+                        reverse.name = tempRRead;
+                        pairFastqRead temp(forward, reverse);
+                        reads.push_back(temp);
+                        match = true;
+                    }
                 }
                 
-                //look for reverse pair
-                itUniques = uniques.find(reverse.name);
-                if (itUniques != uniques.end()) {  //we have the pair for this read
-                    pairFastqRead temp(itUniques->second, reverse);
-                    reads.push_back(temp);
-                    uniques.erase(itUniques);
-                }else { //save this read for later
-                    uniques[reverse.name] = reverse;
+                if (!match) {
+                    //look for forward pair
+                    itUniques = uniques.find(forward.name);
+                    if (itUniques != uniques.end()) {  //we have the pair for this read
+                        pairFastqRead temp(forward, itUniques->second);
+                        reads.push_back(temp);
+                        uniques.erase(itUniques);
+                    }else { //save this read for later
+                        uniques[forward.name] = forward;
+                    }
+                    
+                    //look for reverse pair
+                    itUniques = uniques.find(reverse.name);
+                    if (itUniques != uniques.end()) {  //we have the pair for this read
+                        pairFastqRead temp(itUniques->second, reverse);
+                        reads.push_back(temp);
+                        uniques.erase(itUniques);
+                    }else { //save this read for later
+                        uniques[reverse.name] = reverse;
+                    }
                 }
+                                
             }
         }else if (!ignoref && ignorer) { //ignore reverse keep forward
             //look for forward pair
index d641ec9b26065723ec91eabc70367017ac2f160d..3300f692df857ca66d28a22501e63b848daa7625 100644 (file)
@@ -60,7 +60,7 @@ public:
     
 private:
     bool abort, allFiles, createGroup;
-    string outputDir, ffastqfile, rfastqfile, align, oligosfile;
+    string outputDir, ffastqfile, rfastqfile, align, oligosfile, rfastafile, ffastafile, rqualfile, fqualfile, file;
        float match, misMatch, gapOpen, gapExtend;
        int processors, longestBase, threshold, tdiffs, bdiffs, pdiffs, ldiffs, sdiffs;
     vector<string> outputNames;
@@ -79,7 +79,7 @@ private:
     //vector<string> groupVector;
     
     fastqRead readFastq(ifstream&, bool&);
-    vector< vector<string> > readFastqFiles(int&);
+    vector< vector<string> > readFastqFiles(unsigned long int&);
     bool checkReads(fastqRead&, fastqRead&);
     int createProcesses(vector< vector<string> >, string, string, string, string, string, vector<vector<string> >, vector<vector<string> >);
     int driver(vector<string>, string, string, string, string, string, vector<vector<string> >, vector<vector<string> >);
index fffed0290b1136da46e42d31c99542da19ec9a0a..b53b09afc0091e91baf6609aa9c8d5b0ab528b63 100644 (file)
@@ -38,5 +38,35 @@ EstOutput SharedSobsCS::getValues(vector<SharedRAbundVector*> shared){
                exit(1);
        }
 }
+/***********************************************************************/
+//This returns the number of shared species observed in several groups.  
+//The shared vector is each groups sharedrabundvector.
+
+EstOutput SharedSobsCS::getValues(vector<SharedRAbundVector*> shared, vector<string>& labels){
+       try {
+               data.resize(1,0);
+               double observed = 0;
+               int numGroups = shared.size();
+        labels.clear();
+        
+               for (int i = 0; i < shared[0]->getNumBins(); i++) {
+                       //get bin values and set sharedByAll 
+                       bool sharedByAll = true;
+                       for (int j = 0; j < numGroups; j++) {
+                               if (shared[j]->getAbundance(i) == 0) { sharedByAll = false; }
+                       }
+                       
+                       //they are shared
+                       if (sharedByAll == true) {  observed++;  labels.push_back(m->currentBinLabels[i]); }
+               }
+        
+               data[0] = observed;
+               return data;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "SharedSobsCS", "getValues");
+               exit(1);
+       }
+}
 
 /***********************************************************************/
index d35a2ac56e852eba082235b871365c663496fa11..0429f90b8cbe67fd9feb3192017b1271c59fe187 100644 (file)
@@ -21,6 +21,7 @@ public:
        SharedSobsCS() : Calculator("sharedsobs", 1, true) {};
        EstOutput getValues(SAbundVector* rank){ return data; };
        EstOutput getValues(vector<SharedRAbundVector*>);
+    EstOutput getValues(vector<SharedRAbundVector*>, vector<string>&);
        string getCitation() { return "http://www.mothur.org/wiki/Sharedsobs"; }
 };
 
index 32ebb3c9c8b4f96b0ad556450e9505f08dc2546d..2824ca8f6921c52993857472399beced96d4c26f 100644 (file)
--- a/venn.cpp
+++ b/venn.cpp
@@ -17,7 +17,7 @@
 
 
 //**********************************************************************************************************************
-Venn::Venn(string o, bool n, string f, int fs) : outputDir(o), nseqs(n), inputfile(f), fontSize(fs) {
+Venn::Venn(string o, bool n, string f, int fs, bool so) : outputDir(o), nseqs(n), inputfile(f), fontSize(fs), sharedOtus(so) {
        try {
                m = MothurOut::getInstance();
        }
@@ -155,16 +155,30 @@ vector<string> Venn::getPic(vector<SharedRAbundVector*> lookup, vector<Calculato
                                if (m->control_pressed) { outsvg.close(); return outputNames; }
                                
                                //get estimates for sharedAB
-                               vector<double> shared = vCalcs[i]->getValues(subset);
+                vector<string> labels;
+                               vector<double> shared = vCalcs[i]->getValues(subset, labels);
                                
                                //in essence you want to run it like a single 
                                if (vCalcs[i]->getName() == "sharedsobs") {
                                        singleCalc = new Sobs();
+                    if (sharedOtus) {
+                        string filenameShared = outputDir + m->getRootName(m->getSimpleName(inputfile)) + lookup[0]->getLabel() + "." + vCalcs[i]->getName() + ".sharedotus";
+                        
+                        outputNames.push_back(filenameShared);
+                        ofstream outShared;
+                        m->openOutputFile(filenameShared, outShared);
+                        outShared << "Groups\tNumShared\tOTULabels\n";
+                        outShared << lookup[0]->getGroup() + "-" + lookup[1]->getGroup() << '\t' << labels.size() << '\t';
+                        for (int k = 0; k < labels.size()-1; k++) {
+                            outShared << labels[k] << ",";
+                        }
+                        if (labels.size() != 0) { outShared << labels[labels.size()-1]; }
+                        outShared  << endl;
+                        outShared.close();
+                    }
                                }else if (vCalcs[i]->getName() == "sharedchao") {
                                        singleCalc = new Chao1();
-                               }//else if (vCalcs[i]->getName() == "sharedace") {
-                                       //singleCalc = new Ace(10);
-                               //}
+                               }
                                
                                int sharedVal, numSeqsA, numSeqsB, uniqSeqsToA, uniqSeqsToB;
                                if (nseqs) {
@@ -439,6 +453,15 @@ vector<string> Venn::getPic(vector<SharedRAbundVector*> lookup, vector<Calculato
                                        
                                }else { //sharedchao and sharedsobs are multigroup
                                        
+                    ofstream outShared;
+                    if (sharedOtus && (vCalcs[i]->getName() == "sharedsobs")) {
+                        string filenameShared = outputDir + m->getRootName(m->getSimpleName(inputfile)) + lookup[0]->getLabel() + "." + vCalcs[i]->getName() + ".sharedotus";
+                        
+                        outputNames.push_back(filenameShared);
+                       
+                        m->openOutputFile(filenameShared, outShared);
+                        outShared << "Groups\tNumShared\tOTULabels\n";
+                    }
                                        vector<SharedRAbundVector*> subset;
 
                                        //get estimates for numA
@@ -457,19 +480,54 @@ vector<string> Venn::getPic(vector<SharedRAbundVector*> lookup, vector<Calculato
 
                                        subset.clear();
                                        subset.push_back(lookup[0]); subset.push_back(lookup[1]);
-                                       vector<double> sharedab =  vCalcs[i]->getValues(subset);
+                    vector<string> labels;
+                                       vector<double> sharedab =  vCalcs[i]->getValues(subset, labels);
+                    if (sharedOtus && (vCalcs[i]->getName() == "sharedsobs")) {
+                        outShared << lookup[0]->getGroup() + "-" + lookup[1]->getGroup() << '\t' << labels.size() << '\t';
+                        for (int k = 0; k < labels.size()-1; k++) {
+                            outShared << labels[k] << ",";
+                        }
+                        if (labels.size() != 0) { outShared << labels[labels.size()-1]; }
+                        outShared << endl;
+                    }
                                        
                                        subset.clear(); 
                                        subset.push_back(lookup[0]); subset.push_back(lookup[2]);
-                                       vector<double> sharedac =  vCalcs[i]->getValues(subset);
+                                       vector<double> sharedac =  vCalcs[i]->getValues(subset, labels);
+                    if (sharedOtus && (vCalcs[i]->getName() == "sharedsobs")) {
+                        outShared << lookup[0]->getGroup() + "-" + lookup[2]->getGroup() << '\t'<< labels.size() << '\t';
+                        for (int k = 0; k < labels.size()-1; k++) {
+                            outShared << labels[k] << ",";
+                        }
+                        if (labels.size() != 0) { outShared << labels[labels.size()-1]; }
+                        outShared << endl;
+                    }
                                        
                                        subset.clear(); 
                                        subset.push_back(lookup[1]); subset.push_back(lookup[2]);
-                                       vector<double> sharedbc =  vCalcs[i]->getValues(subset);
+                                       vector<double> sharedbc =  vCalcs[i]->getValues(subset, labels);
+                    if (sharedOtus && (vCalcs[i]->getName() == "sharedsobs")) {
+                        outShared << lookup[1]->getGroup() + "-" + lookup[2]->getGroup() << '\t'<< labels.size() << '\t';
+                        for (int k = 0; k < labels.size()-1; k++) {
+                            outShared << labels[k] << ",";
+                        }
+                        if (labels.size() != 0) { outShared << labels[labels.size()-1]; }
+                        outShared << endl;
+                    }
+
                                        
                                        subset.clear(); 
                                        subset.push_back(lookup[0]); subset.push_back(lookup[1]); subset.push_back(lookup[2]);
-                                       vector<double> sharedabc =  vCalcs[i]->getValues(subset);
+                                       vector<double> sharedabc =  vCalcs[i]->getValues(subset, labels);
+                    if (sharedOtus && (vCalcs[i]->getName() == "sharedsobs")) {
+                        outShared << lookup[0]->getGroup() + "-" + lookup[1]->getGroup() + "-" + lookup[2]->getGroup() << '\t'<< labels.size() << '\t';
+                        for (int k = 0; k < labels.size()-1; k++) {
+                            outShared << labels[k] << ",";
+                        }
+                        if (labels.size() != 0) { outShared << labels[labels.size()-1]; }
+                        outShared << endl;
+                        outShared.close();
+                    }
                                        
                                        //image window
                                        outsvg << "<svg xmlns:svg=\"http://www.w3.org/2000/svg\" xmlns=\"http://www.w3.org/2000/svg\" width=\"100%\" height=\"100%\" viewBox=\"0 0 " +  toString(width) + " " + toString(windowSize) + " \" >\n";
@@ -599,63 +657,163 @@ vector<string> Venn::getPic(vector<SharedRAbundVector*> lookup, vector<Calculato
                                        data = singleCalc->getValues(sabundD);
                                        numD = data[0];
 //cout << "num d = " << numD << endl;  
+                    
+                    ofstream outShared;
+                    if (sharedOtus && (vCalcs[i]->getName() == "sharedsobs")) {
+                        string filenameShared = outputDir + m->getRootName(m->getSimpleName(inputfile)) + lookup[0]->getLabel() + "." + vCalcs[i]->getName() + ".sharedotus";
+                        
+                        outputNames.push_back(filenameShared);
+                        
+                        m->openOutputFile(filenameShared, outShared);
+                        outShared << "Groups\tNumShared\tOTULabels\n";
+                    }
 
                                        //get estimates for pairs
                                        subset.clear();
+                    vector<string> labels;
                                        subset.push_back(lookup[0]); subset.push_back(lookup[1]);
-                                       data = vCalcs[i]->getValues(subset);
+                                       data = vCalcs[i]->getValues(subset, labels);
                                        sharedAB = data[0];
+                    if (sharedOtus && (vCalcs[i]->getName() == "sharedsobs")) {
+                        outShared << lookup[0]->getGroup() + "-" + lookup[1]->getGroup() << '\t'<< labels.size() << '\t';
+                        for (int k = 0; k < labels.size()-1; k++) {
+                            outShared << labels[k] << ",";
+                        }
+                        if (labels.size() != 0) { outShared << labels[labels.size()-1]; }
+                        outShared << endl;
+                    }
        //cout << "num ab = " << sharedAB << endl;                      
                                        subset.clear();
                                        subset.push_back(lookup[0]); subset.push_back(lookup[2]);
-                                       data = vCalcs[i]->getValues(subset);
+                                       data = vCalcs[i]->getValues(subset, labels);
                                        sharedAC = data[0];
+                    if (sharedOtus && (vCalcs[i]->getName() == "sharedsobs")) {
+                        outShared << lookup[0]->getGroup() + "-" + lookup[2]->getGroup() << '\t'<< labels.size() << '\t';
+                        for (int k = 0; k < labels.size()-1; k++) {
+                            outShared << labels[k] << ",";
+                        }
+                        if (labels.size() != 0) { outShared << labels[labels.size()-1]; }
+                        outShared << endl;
+                    }
        //cout << "num ac = " << sharedAC << endl;                              
                                        subset.clear();
                                        subset.push_back(lookup[0]); subset.push_back(lookup[3]);
-                                       data = vCalcs[i]->getValues(subset);
+                                       data = vCalcs[i]->getValues(subset, labels);
                                        sharedAD = data[0];
+                    if (sharedOtus && (vCalcs[i]->getName() == "sharedsobs")) {
+                        outShared << lookup[0]->getGroup() + "-" + lookup[3]->getGroup() << '\t'<< labels.size() << '\t';
+                        for (int k = 0; k < labels.size()-1; k++) {
+                            outShared << labels[k] << ",";
+                        }
+                        if (labels.size() != 0) { outShared << labels[labels.size()-1]; }
+                        outShared << endl;
+                    }
        //cout << "num ad = " << sharedAD << endl;                      
                                        subset.clear();
                                        subset.push_back(lookup[1]); subset.push_back(lookup[2]);
-                                       data = vCalcs[i]->getValues(subset);
+                                       data = vCalcs[i]->getValues(subset, labels);
                                        sharedBC = data[0];
+                    if (sharedOtus && (vCalcs[i]->getName() == "sharedsobs")) {
+                        outShared << lookup[1]->getGroup() + "-" + lookup[2]->getGroup() << '\t'<< labels.size() << '\t';
+                        for (int k = 0; k < labels.size()-1; k++) {
+                            outShared << labels[k] << ",";
+                        }
+                        if (labels.size() != 0) { outShared << labels[labels.size()-1]; }
+                        outShared << endl;
+                    }
        //cout << "num bc = " << sharedBC << endl;                              
                                        subset.clear();
                                        subset.push_back(lookup[1]); subset.push_back(lookup[3]);
-                                       data = vCalcs[i]->getValues(subset);
+                                       data = vCalcs[i]->getValues(subset, labels);
                                        sharedBD = data[0];
+                    if (sharedOtus && (vCalcs[i]->getName() == "sharedsobs")) {
+                        outShared << lookup[1]->getGroup() + "-" + lookup[3]->getGroup() << '\t'<< labels.size() << '\t';
+                        for (int k = 0; k < labels.size()-1; k++) {
+                            outShared << labels[k] << ",";
+                        }
+                        if (labels.size() != 0) { outShared << labels[labels.size()-1]; }
+                        outShared << endl;
+                    }
                //cout << "num bd = " << sharedBD << endl;                                              
                                        subset.clear();
                                        subset.push_back(lookup[2]); subset.push_back(lookup[3]);
-                                       data = vCalcs[i]->getValues(subset);
+                                       data = vCalcs[i]->getValues(subset, labels);
                                        sharedCD = data[0];
+                    if (sharedOtus && (vCalcs[i]->getName() == "sharedsobs")) {
+                        outShared << lookup[2]->getGroup() + "-" + lookup[3]->getGroup() << '\t'<< labels.size() << '\t';
+                        for (int k = 0; k < labels.size()-1; k++) {
+                            outShared << labels[k] << ",";
+                        }
+                        if (labels.size() != 0) { outShared << labels[labels.size()-1]; }
+                        outShared << endl;
+                    }
                                                
        //cout << "num cd = " << sharedCD << endl;                              
                                        //get estimates for combos of 3
                                        subset.clear();
                                        subset.push_back(lookup[0]); subset.push_back(lookup[1]); subset.push_back(lookup[2]);
-                                       data = vCalcs[i]->getValues(subset);
+                                       data = vCalcs[i]->getValues(subset, labels);
                                        sharedABC = data[0];
+                    if (sharedOtus && (vCalcs[i]->getName() == "sharedsobs")) {
+                        outShared << lookup[0]->getGroup() + "-" + lookup[1]->getGroup()+ "-" + lookup[2]->getGroup()<< '\t'<< labels.size() << '\t';
+                        for (int k = 0; k < labels.size()-1; k++) {
+                            outShared << labels[k] << ",";
+                        }
+                        if (labels.size() != 0) { outShared << labels[labels.size()-1]; }
+                        outShared << endl;
+                    }
                //cout << "num abc = " << sharedABC << endl;                                    
                                        subset.clear();
                                        subset.push_back(lookup[0]); subset.push_back(lookup[2]); subset.push_back(lookup[3]);
-                                       data = vCalcs[i]->getValues(subset);
+                                       data = vCalcs[i]->getValues(subset, labels);
                                        sharedACD = data[0];
+                    if (sharedOtus && (vCalcs[i]->getName() == "sharedsobs")) {
+                        outShared << lookup[0]->getGroup() + "-" + lookup[2]->getGroup()+ "-" + lookup[3]->getGroup()<< '\t'<< labels.size() << '\t';
+                        for (int k = 0; k < labels.size()-1; k++) {
+                            outShared << labels[k] << ",";
+                        }
+                        if (labels.size() != 0) { outShared << labels[labels.size()-1]; }
+                        outShared << endl;
+                    }
                        //cout << "num acd = " << sharedACD << endl;    
                                        subset.clear();
                                        subset.push_back(lookup[1]); subset.push_back(lookup[2]); subset.push_back(lookup[3]);
-                                       data = vCalcs[i]->getValues(subset);
+                                       data = vCalcs[i]->getValues(subset,labels);
                                        sharedBCD = data[0];
+                    if (sharedOtus && (vCalcs[i]->getName() == "sharedsobs")) {
+                        outShared << lookup[1]->getGroup() + "-" + lookup[2]->getGroup()+ "-" + lookup[3]->getGroup()<< '\t'<< labels.size() << '\t';
+                        for (int k = 0; k < labels.size()-1; k++) {
+                            outShared << labels[k] << ",";
+                        }
+                        if (labels.size() != 0) { outShared << labels[labels.size()-1]; }
+                        outShared << endl;
+                    }
                //cout << "num bcd = " << sharedBCD << endl;            
                                        subset.clear();
                                        subset.push_back(lookup[0]); subset.push_back(lookup[1]); subset.push_back(lookup[3]);
-                                       data = vCalcs[i]->getValues(subset);
+                                       data = vCalcs[i]->getValues(subset, labels);
                                        sharedABD = data[0];
+                    if (sharedOtus && (vCalcs[i]->getName() == "sharedsobs")) {
+                        outShared << lookup[0]->getGroup() + "-" + lookup[1]->getGroup()+ "-" + lookup[3]->getGroup()<< '\t'<< labels.size() << '\t';
+                        for (int k = 0; k < labels.size()-1; k++) {
+                            outShared << labels[k] << ",";
+                        }
+                        if (labels.size() != 0) { outShared << labels[labels.size()-1]; }
+                        outShared << endl;
+                    }
 //cout << "num abd = " << sharedABD << endl;
                                        //get estimate for all four
-                                       data = vCalcs[i]->getValues(lookup);
+                                       data = vCalcs[i]->getValues(lookup, labels);
                                        sharedABCD = data[0];
+                    if (sharedOtus && (vCalcs[i]->getName() == "sharedsobs")) {
+                        outShared << lookup[0]->getGroup() + "-" + lookup[1]->getGroup() + "-" + lookup[2]->getGroup()+ "-" + lookup[3]->getGroup()<< '\t'<< labels.size() << '\t';
+                        for (int k = 0; k < labels.size()-1; k++) {
+                            outShared << labels[k] << ",";
+                        }
+                        if (labels.size() != 0) { outShared << labels[labels.size()-1]; }
+                        outShared << endl;
+                        outShared.close();
+                    }
                //cout << "num abcd = " << sharedABCD << endl << endl;  
                                        int sharedVal, sharedABCVal, sharedABDVal, sharedACDVal, sharedBCDVal, sharedABVal, sharedACVal, sharedADVal, sharedBCVal, sharedBDVal, sharedCDVal, numSeqsA, numSeqsB, numSeqsC, numSeqsD;
                                                                                                
diff --git a/venn.h b/venn.h
index 50d49d1b98c4c364faed44366534daf91d017b55..db26b272045458540cfb4ab7ca2f44bd563ba4bc 100644 (file)
--- a/venn.h
+++ b/venn.h
@@ -19,7 +19,7 @@
 
 class Venn {
 public:
-       Venn(string, bool, string, int);
+       Venn(string, bool, string, int, bool);
        ~Venn(){};
 
        vector<string> getPic(SAbundVector*, vector<Calculator*>);
@@ -30,7 +30,7 @@ private:
        string groupComb, outputDir, inputfile;
        ofstream outsvg;
        MothurOut* m;
-       bool nseqs;
+       bool nseqs, sharedOtus;
        int fontSize;
 };
 
index 9c234959f0e96040c2d6655649d69f10c0ee66a6..70c35f713bd02a6a1f786668ed00b79784f05293 100644 (file)
@@ -27,6 +27,7 @@ vector<string> VennCommand::setParameters(){
                CommandParameter pcalc("calc", "String", "", "", "", "", "","",false,false); parameters.push_back(pcalc);
                CommandParameter pabund("abund", "Number", "", "10", "", "", "","",false,false); parameters.push_back(pabund);
                CommandParameter pnseqs("nseqs", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(pnseqs);
+        CommandParameter psharedotus("sharedotus", "Boolean", "", "t", "", "", "","",false,false); parameters.push_back(psharedotus);
                CommandParameter pfontsize("fontsize", "Number", "", "24", "", "", "","",false,false); parameters.push_back(pfontsize);
                CommandParameter ppermute("permute", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(ppermute);
                CommandParameter pinputdir("inputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(pinputdir);
@@ -215,6 +216,9 @@ VennCommand::VennCommand(string option)  {
 
                        temp = validParameter.validFile(parameters, "permute", false);          if (temp == "not found"){       temp = "f";                             }
                        perm = m->isTrue(temp); 
+            
+            temp = validParameter.validFile(parameters, "sharedotus", false);          if (temp == "not found"){       temp = "t";                             }
+                       sharedOtus = m->isTrue(temp); 
                        
                        temp = validParameter.validFile(parameters, "fontsize", false);         if (temp == "not found") { temp = "24"; }
                        m->mothurConvert(temp, fontsize);
@@ -266,7 +270,7 @@ int VennCommand::execute(){
                //if the users entered no valid calculators don't execute command
                if (vennCalculators.size() == 0) { m->mothurOut("No valid calculators given, please correct."); m->mothurOutEndLine(); return 0;  }
                
-               venn = new Venn(outputDir, nseqs, inputfile, fontsize); 
+               venn = new Venn(outputDir, nseqs, inputfile, fontsize, sharedOtus); 
                input = new InputData(inputfile, format);
                
                string lastLabel;
index 15932ecd5cdc2da8cbc362d0a3b55ff206a748b0..98a59d404099dcb32052e07e93644be9f01e2869 100644 (file)
@@ -44,7 +44,7 @@ private:
        SAbundVector* sabund;
        int abund, fontsize;
        
-       bool abort, allLines, nseqs, perm;
+       bool abort, allLines, nseqs, perm, sharedOtus;
        set<string> labels; //holds labels to be used
        string format, groups, calc, label, outputDir, sharedfile, listfile, inputfile;
        vector<string> Estimators, Groups, outputNames;