From: Sarah Westcott Date: Tue, 18 Dec 2012 14:24:56 +0000 (-0500) Subject: added sharedotu parameter to venn command. working of make.contigs. X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=commitdiff_plain;h=55bbd10379db27def51cec72a8819d775f73e45b added sharedotu parameter to venn command. working of make.contigs. --- diff --git a/calculator.h b/calculator.h index 218f8ea..5aba3d2 100644 --- a/calculator.h +++ b/calculator.h @@ -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) = 0; + //optional calc that returns the otus labels of shared otus + virtual EstOutput getValues(vector sv , vector&) { 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 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 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 > files = readFastqFiles(numReads); m->mothurOut("Done.\n"); - + if (m->control_pressed) { return 0; } vector > fastaFileNames; @@ -884,7 +957,7 @@ int MakeContigsCommand::driver(vector files, string outputFasta, string } } //********************************************************************************************************************** -vector< vector > MakeContigsCommand::readFastqFiles(int& count){ +vector< vector > MakeContigsCommand::readFastqFiles(unsigned long int& count){ try { vector< vector > files; @@ -947,11 +1020,13 @@ vector< vector > MakeContigsCommand::readFastqFiles(int& count){ else { ignorer = true; } vector 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 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 diff --git a/makecontigscommand.h b/makecontigscommand.h index d641ec9..3300f69 100644 --- a/makecontigscommand.h +++ b/makecontigscommand.h @@ -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 outputNames; @@ -79,7 +79,7 @@ private: //vector groupVector; fastqRead readFastq(ifstream&, bool&); - vector< vector > readFastqFiles(int&); + vector< vector > readFastqFiles(unsigned long int&); bool checkReads(fastqRead&, fastqRead&); int createProcesses(vector< vector >, string, string, string, string, string, vector >, vector >); int driver(vector, string, string, string, string, string, vector >, vector >); diff --git a/sharedsobscollectsummary.cpp b/sharedsobscollectsummary.cpp index fffed02..b53b09a 100644 --- a/sharedsobscollectsummary.cpp +++ b/sharedsobscollectsummary.cpp @@ -38,5 +38,35 @@ EstOutput SharedSobsCS::getValues(vector 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 shared, vector& 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); + } +} /***********************************************************************/ diff --git a/sharedsobscollectsummary.h b/sharedsobscollectsummary.h index d35a2ac..0429f90 100644 --- a/sharedsobscollectsummary.h +++ b/sharedsobscollectsummary.h @@ -21,6 +21,7 @@ public: SharedSobsCS() : Calculator("sharedsobs", 1, true) {}; EstOutput getValues(SAbundVector* rank){ return data; }; EstOutput getValues(vector); + EstOutput getValues(vector, vector&); string getCitation() { return "http://www.mothur.org/wiki/Sharedsobs"; } }; diff --git a/venn.cpp b/venn.cpp index 32ebb3c..2824ca8 100644 --- 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 Venn::getPic(vector lookup, vectorcontrol_pressed) { outsvg.close(); return outputNames; } //get estimates for sharedAB - vector shared = vCalcs[i]->getValues(subset); + vector labels; + vector 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 Venn::getPic(vector lookup, vectorgetName() == "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 subset; //get estimates for numA @@ -457,19 +480,54 @@ vector Venn::getPic(vector lookup, vector sharedab = vCalcs[i]->getValues(subset); + vector labels; + vector 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 sharedac = vCalcs[i]->getValues(subset); + vector 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 sharedbc = vCalcs[i]->getValues(subset); + vector 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 sharedabc = vCalcs[i]->getValues(subset); + vector 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 << "\n"; @@ -599,63 +657,163 @@ vector Venn::getPic(vector lookup, vectorgetValues(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 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 50d49d1..db26b27 100644 --- 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 getPic(SAbundVector*, vector); @@ -30,7 +30,7 @@ private: string groupComb, outputDir, inputfile; ofstream outsvg; MothurOut* m; - bool nseqs; + bool nseqs, sharedOtus; int fontSize; }; diff --git a/venncommand.cpp b/venncommand.cpp index 9c23495..70c35f7 100644 --- a/venncommand.cpp +++ b/venncommand.cpp @@ -27,6 +27,7 @@ vector 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; diff --git a/venncommand.h b/venncommand.h index 15932ec..98a59d4 100644 --- a/venncommand.h +++ b/venncommand.h @@ -44,7 +44,7 @@ private: SAbundVector* sabund; int abund, fontsize; - bool abort, allLines, nseqs, perm; + bool abort, allLines, nseqs, perm, sharedOtus; set labels; //holds labels to be used string format, groups, calc, label, outputDir, sharedfile, listfile, inputfile; vector Estimators, Groups, outputNames;