From: westcott Date: Tue, 31 Mar 2009 13:40:32 +0000 (+0000) Subject: started venn command X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=commitdiff_plain;h=62f1ae1378c4c36175ec11fec8f70a3d2d26112e started venn command --- diff --git a/Mothur.xcodeproj/project.pbxproj b/Mothur.xcodeproj/project.pbxproj index 31fc481..17bf8ae 100644 --- a/Mothur.xcodeproj/project.pbxproj +++ b/Mothur.xcodeproj/project.pbxproj @@ -15,6 +15,8 @@ 374610830F40652400460C57 /* unweighted.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 374610820F40652400460C57 /* unweighted.cpp */; }; 3746109D0F40657600460C57 /* unifracunweightedcommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3746109C0F40657600460C57 /* unifracunweightedcommand.cpp */; }; 37519A6B0F80E6EB00FED5E8 /* sharedanderbergs.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37519A6A0F80E6EB00FED5E8 /* sharedanderbergs.cpp */; }; + 37519AA10F810D0200FED5E8 /* venncommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37519AA00F810D0200FED5E8 /* venncommand.cpp */; }; + 37519AB50F810FAE00FED5E8 /* venn.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37519AB40F810FAE00FED5E8 /* venn.cpp */; }; 375873E70F7D63E90040F377 /* coverage.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 375873E50F7D63E90040F377 /* coverage.cpp */; }; 375873EC0F7D64520040F377 /* fullmatrix.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 375873EB0F7D64520040F377 /* fullmatrix.cpp */; }; 375873EF0F7D646F0040F377 /* heatmap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 375873EE0F7D646F0040F377 /* heatmap.cpp */; }; @@ -115,7 +117,6 @@ EB6F015B0F6AC1670048081A /* sharedbdiversity.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EB6F015A0F6AC1670048081A /* sharedbdiversity.cpp */; }; EB9303EB0F534D9400E8EF26 /* logsd.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EB9303EA0F534D9400E8EF26 /* logsd.cpp */; }; EB9303F90F53517300E8EF26 /* geom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EB9303F80F53517300E8EF26 /* geom.cpp */; }; - EBC564190F81479000A5AC46 /* sharedjackknife.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EBC564180F81479000A5AC46 /* sharedjackknife.cpp */; }; /* End PBXBuildFile section */ /* Begin PBXCopyFilesBuildPhase section */ @@ -147,6 +148,10 @@ 3746109C0F40657600460C57 /* unifracunweightedcommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = unifracunweightedcommand.cpp; sourceTree = ""; }; 37519A690F80E6EB00FED5E8 /* sharedanderbergs.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sharedanderbergs.h; sourceTree = ""; }; 37519A6A0F80E6EB00FED5E8 /* sharedanderbergs.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = sharedanderbergs.cpp; sourceTree = ""; }; + 37519A9F0F810D0200FED5E8 /* venncommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = venncommand.h; sourceTree = ""; }; + 37519AA00F810D0200FED5E8 /* venncommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = venncommand.cpp; sourceTree = ""; }; + 37519AB30F810FAE00FED5E8 /* venn.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = venn.h; sourceTree = ""; }; + 37519AB40F810FAE00FED5E8 /* venn.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = venn.cpp; sourceTree = ""; }; 375873E50F7D63E90040F377 /* coverage.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = coverage.cpp; sourceTree = ""; }; 375873E60F7D63E90040F377 /* coverage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = coverage.h; sourceTree = ""; }; 375873EA0F7D64520040F377 /* fullmatrix.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = fullmatrix.h; sourceTree = ""; }; @@ -359,8 +364,6 @@ EB9303EA0F534D9400E8EF26 /* logsd.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = logsd.cpp; sourceTree = ""; }; EB9303F70F53517300E8EF26 /* geom.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = geom.h; sourceTree = ""; }; EB9303F80F53517300E8EF26 /* geom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = geom.cpp; sourceTree = ""; }; - EBC564170F81479000A5AC46 /* sharedjackknife.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sharedjackknife.h; sourceTree = ""; }; - EBC564180F81479000A5AC46 /* sharedjackknife.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = sharedjackknife.cpp; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -446,6 +449,8 @@ 37D928480F21331F001D4494 /* summarydata.h */, 37D928490F21331F001D4494 /* summarydisplay.h */, 37D9284C0F21331F001D4494 /* utilities.hpp */, + 37519AB30F810FAE00FED5E8 /* venn.h */, + 37519AB40F810FAE00FED5E8 /* venn.cpp */, ); name = Source; sourceTree = ""; @@ -505,25 +510,23 @@ 37D928240F21331F001D4494 /* sharedchao1.cpp */, 37D928290F21331F001D4494 /* sharedjabund.h */, 37D928280F21331F001D4494 /* sharedjabund.cpp */, - EBC564170F81479000A5AC46 /* sharedjackknife.h */, - EBC564180F81479000A5AC46 /* sharedjackknife.cpp */, 37D9282B0F21331F001D4494 /* sharedjclass.h */, 37D9282A0F21331F001D4494 /* sharedjclass.cpp */, 37D9282D0F21331F001D4494 /* sharedjest.h */, 37D9282C0F21331F001D4494 /* sharedjest.cpp */, EB1217210F61C9AC004A865F /* sharedkstest.h */, EB1217220F61C9AC004A865F /* sharedkstest.cpp */, - 375873FE0F7D64EF0040F377 /* sharedkulczynski.cpp */, - 375873FF0F7D64EF0040F377 /* sharedlennon.cpp */, 375874000F7D64EF0040F377 /* sharedkulczynski.h */, - 375874010F7D64EF0040F377 /* sharedlennon.h */, - 375874020F7D64EF0040F377 /* sharedkulczynskicody.cpp */, + 375873FE0F7D64EF0040F377 /* sharedkulczynski.cpp */, 375874030F7D64EF0040F377 /* sharedkulczynskicody.h */, + 375874020F7D64EF0040F377 /* sharedkulczynskicody.cpp */, + 375874010F7D64EF0040F377 /* sharedlennon.h */, + 375873FF0F7D64EF0040F377 /* sharedlennon.cpp */, 375874070F7D64FC0040F377 /* sharedmorisitahorn.h */, 375874080F7D64FC0040F377 /* sharedmorisitahorn.cpp */, 375874090F7D64FC0040F377 /* sharedochiai.h */, - 3758740A0F7D64FC0040F377 /* sharednseqs.h */, 3758740B0F7D64FC0040F377 /* sharedochiai.cpp */, + 3758740A0F7D64FC0040F377 /* sharednseqs.h */, 37D928350F21331F001D4494 /* sharedsobs.h */, 37D928340F21331F001D4494 /* sharedsobs.cpp */, 37AFC71D0F445386005F492D /* sharedsobscollectsummary.h */, @@ -569,8 +572,8 @@ A70B53A60F4CD7AD0064797E /* getlabelcommand.cpp */, A70B53A90F4CD7AD0064797E /* getlinecommand.h */, A70B53A80F4CD7AD0064797E /* getlinecommand.cpp */, - 375873F00F7D64800040F377 /* heatmapcommand.cpp */, 375873F10F7D64800040F377 /* heatmapcommand.h */, + 375873F00F7D64800040F377 /* heatmapcommand.cpp */, 37D927E40F21331F001D4494 /* helpcommand.h */, 37D927E30F21331F001D4494 /* helpcommand.cpp */, 375873F30F7D648F0040F377 /* libshuffcommand.cpp */, @@ -603,6 +606,8 @@ 3746109C0F40657600460C57 /* unifracunweightedcommand.cpp */, 374610760F40645300460C57 /* unifracweightedcommand.h */, 374610770F40645300460C57 /* unifracweightedcommand.cpp */, + 37519A9F0F810D0200FED5E8 /* venncommand.h */, + 37519AA00F810D0200FED5E8 /* venncommand.cpp */, ); name = commands; sourceTree = ""; @@ -816,7 +821,8 @@ 3758740C0F7D64FC0040F377 /* sharedmorisitahorn.cpp in Sources */, 3758740D0F7D64FC0040F377 /* sharedochiai.cpp in Sources */, 37519A6B0F80E6EB00FED5E8 /* sharedanderbergs.cpp in Sources */, - EBC564190F81479000A5AC46 /* sharedjackknife.cpp in Sources */, + 37519AA10F810D0200FED5E8 /* venncommand.cpp in Sources */, + 37519AB50F810FAE00FED5E8 /* venn.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/commandfactory.cpp b/commandfactory.cpp index 56fd56b..732fc85 100644 --- a/commandfactory.cpp +++ b/commandfactory.cpp @@ -31,6 +31,7 @@ #include "unifracweightedcommand.h" #include "libshuffcommand.h" #include "heatmapcommand.h" +#include "venncommand.h" #include "mothur.h" #include "nocommands.h" @@ -77,6 +78,7 @@ Command* CommandFactory::getCommand(string commandName){ else if(commandName == "get.line") { command = new GetlineCommand(); } else if(commandName == "libshuff") { command = new LibShuffCommand(); } else if(commandName == "heatmap") { command = new HeatMapCommand(); } + else if(commandName == "venn") { command = new VennCommand(); } else { command = new NoCommand(); } return command; diff --git a/errorchecking.cpp b/errorchecking.cpp index a057e5d..59cfb66 100644 --- a/errorchecking.cpp +++ b/errorchecking.cpp @@ -223,9 +223,9 @@ bool ErrorCheck::checkInput(string input) { } } - if (commandName == "heatmap"){ + if ((commandName == "heatmap") || (commandName == "venn")) { if ((globaldata->getListFile() == "") && (globaldata->getSharedFile() == "")) { - cout << "You must read a list, or a list and a group, or a shared before you can use the heatmap command." << endl; return false; + cout << "You must read a list, or a list and a group, or a shared before you can use the heatmap or venn commands." << endl; return false; } } diff --git a/helpcommand.cpp b/helpcommand.cpp index cb8785a..c50f251 100644 --- a/helpcommand.cpp +++ b/helpcommand.cpp @@ -188,12 +188,14 @@ int HelpCommand::execute(){ cout << "Note: No spaces between parameter labels (i.e. iters), '=' and parameters (i.e.yourIters)." << "\n" << "\n"; }else if (globaldata->helpRequest == "heatmap") { cout << "The heatmap command can only be executed after a successful read.otu command." << "\n"; - cout << "The heatmap command parameters are groups, line and label. No parameters are required, but you may not use line and label at the same time." << "\n"; + cout << "The heatmap command parameters are groups, sorted, line and label. No parameters are required, but you may not use line and label at the same time." << "\n"; cout << "The groups parameter allows you to specify which of the groups in your groupfile you would like included in your heatmap." << "\n"; + cout << "The sorted parameter allows you to choose to see the file with the shared otus at the top or the exact representation of your input file. " << "\n"; cout << "The group names are separated by dashes. The line and label allow you to select what distance levels you would like a heatmap created for, and are also separated by dashes." << "\n"; - cout << "The heatmap command should be in the following format: heatmap(groups=yourGroups, line=yourLines, label=yourLabels)." << "\n"; - cout << "Example heatmap(groups=A-B-C, line=1-3-5)." << "\n"; + cout << "The heatmap command should be in the following format: heatmap(groups=yourGroups, sorted=yourSorted, line=yourLines, label=yourLabels)." << "\n"; + cout << "Example heatmap(groups=A-B-C, line=1-3-5, sorted=0)." << "\n"; cout << "The default value for groups is all the groups in your groupfile, and all lines in your inputfile will be used." << "\n"; + cout << "The default value for sorted is 1 meaning you want the shared otus on top, you may change it to 0 meaning the exact representation of your input file." << "\n"; cout << "The heatmap command outputs a .svg file for each line or label you specify." << "\n"; cout << "Note: No spaces between parameter labels (i.e. groups), '=' and parameters (i.e.yourGroups)." << "\n" << "\n"; }else if (globaldata->helpRequest == "quit") { diff --git a/validcommands.cpp b/validcommands.cpp index 2127758..20dd588 100644 --- a/validcommands.cpp +++ b/validcommands.cpp @@ -30,6 +30,7 @@ ValidCommands::ValidCommands() { commands["unifrac.unweighted"] = "unifrac.unweighted"; commands["libshuff"] = "libshuff"; commands["heatmap"] = "heatmap"; + commands["venn"] = "venn"; commands["get.group"] = "get.group"; commands["get.label"] = "get.label"; commands["get.line"] = "get.line"; diff --git a/validparameter.cpp b/validparameter.cpp index 11e7bf9..4ba29a7 100644 --- a/validparameter.cpp +++ b/validparameter.cpp @@ -286,6 +286,9 @@ void ValidParameters::initCommandParameters() { string heatmapArray[] = {"group","line","label","sorted"}; commandParameters["heatmap"] = addParameters(heatmapArray, sizeof(heatmapArray)/sizeof(string)); + string vennArray[] = {"group","line","label"}; + commandParameters["venn"] = addParameters(vennArray, sizeof(vennArray)/sizeof(string)); + string quitArray[] = {}; commandParameters["quit"] = addParameters(quitArray, sizeof(quitArray)/sizeof(string)); diff --git a/venn.cpp b/venn.cpp new file mode 100644 index 0000000..282ca98 --- /dev/null +++ b/venn.cpp @@ -0,0 +1,231 @@ +/* + * venn.cpp + * Mothur + * + * Created by Sarah Westcott on 3/30/09. + * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved. + * + */ + +#include "venn.h" + +//********************************************************************************************************************** +Venn::Venn(){ + try { + globaldata = GlobalData::getInstance(); + format = globaldata->getFormat(); + + } + catch(exception& e) { + cout << "Standard Error: " << e.what() << " has occurred in the Venn class Function Venn. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + catch(...) { + cout << "An unknown error has occurred in the Venn class function Venn. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } +} +//********************************************************************************************************************** +void Venn::getPic(OrderVector* order) { + try { + + rabund = order->getRAbundVector(); + + string filenamesvg = globaldata->inputFileName + ".venn." + order->getLabel() + ".svg"; + + openOutputFile(filenamesvg, outsvg); + + + //svg image + outsvg << "\n"; + outsvg << "\n"; + + outsvg << ""; + outsvg << "" + toString(rabund.getNumBins()) + "\n"; + outsvg << "\n\n"; + + outsvg.close(); + } + catch(exception& e) { + cout << "Standard Error: " << e.what() << " has occurred in the Venn class Function getPic. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + catch(...) { + cout << "An unknown error has occurred in the Venn class function getPic. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } +} +//********************************************************************************************************************** +void Venn::getPic(SharedOrderVector* sharedorder) { + try { + + //fills vector of sharedsabunds - lookup + getSharedVectors(sharedorder); + + string filenamesvg = globaldata->inputFileName + ".venn." + sharedorder->getLabel() + "." + groupComb + ".svg"; + openOutputFile(filenamesvg, outsvg); + + //image window + outsvg << "\n"; + outsvg << "\n"; + + if (lookup.size() == 1) { + outsvg << ""; + outsvg << "" + toString(lookup[0]->getNumBins()) + "\n"; + outsvg << "\n\n"; + + }else if (lookup.size() == 2) { + //calc the shared otu + int shared = 0; + int numA = 0; + int numB = 0; + + float rScaler; + + //for each bin + for (int i = 0; i < lookup[0]->size(); i++) { + if (lookup[0]->getAbundance(i) != 0) { numA++; } + if (lookup[1]->getAbundance(i) != 0) { numB++; } + //are they shared + if ((lookup[0]->getAbundance(i) != 0) && (lookup[1]->getAbundance(i) != 0)) { shared++; } + } + + if (numA > numB) { rScaler = 150 / float(numA); } + else { rScaler = 150 / float(numB); } + + //to determine how far over to overlap b onto a. + float percentOverlap = shared / (float) numA; + + int bx = 200 + (numA * rScaler) - ((2 * (numA * rScaler)) * percentOverlap) + (numB * rScaler); + int leftedgeB = bx - (numB * rScaler); //center b - b's radius + int leftedgeA = 200 - (numA * rScaler); //center a - a's radius + int rightedgeB = bx + (numB * rScaler); //center b + b's radius + int rightedgeA = 200 + (numA * rScaler); //center a + a's radius + + int mida = leftedgeA + ((leftedgeB - leftedgeA) / 2); + int midb = rightedgeA + ((rightedgeB - rightedgeA) / 2); + int midab = leftedgeB + ((rightedgeA - leftedgeB) / 2); + + //draw circles + outsvg << ""; + outsvg << "Venn Diagram at distance " + sharedorder->getLabel() + "\n"; + outsvg << ""; + outsvg << ""; + outsvg << "" + toString(numA-shared) + "\n"; + outsvg << "" + toString(shared) + "\n"; + outsvg << "" + toString(numB-shared) + "\n"; + outsvg << "Percentage of species that are shared is " + toString((shared / (float)(numA + numB - shared))) + "\n"; + + }else if (lookup.size() == 3) { + //calc the shared otu + int sharedABC = 0; + int numA = 0; int numB = 0; int numC = 0; + int sharedAB = 0; int sharedAC = 0; int sharedBC = 0; + + //float scalerB; + + //for each bin + for (int i = 0; i < lookup[0]->size(); i++) { + if (lookup[0]->getAbundance(i) != 0) { numA++; } + if (lookup[1]->getAbundance(i) != 0) { numB++; } + if (lookup[2]->getAbundance(i) != 0) { numC++; } + //are they shared by 2 + if ((lookup[0]->getAbundance(i) != 0) && (lookup[1]->getAbundance(i) != 0)) { sharedAB++; } + if ((lookup[0]->getAbundance(i) != 0) && (lookup[2]->getAbundance(i) != 0)) { sharedAC++; } + if ((lookup[2]->getAbundance(i) != 0) && (lookup[1]->getAbundance(i) != 0)) { sharedBC++; } + + //are they shared by all + if ((lookup[0]->getAbundance(i) != 0) && (lookup[1]->getAbundance(i) != 0) && (lookup[2]->getAbundance(i) != 0)) { sharedABC++; } + } + + //draw circles + outsvg << ""; + outsvg << "Venn Diagram at distance " + sharedorder->getLabel() + "\n"; + outsvg << ""; + outsvg << ""; + outsvg << ""; + + //place labels within overlaps + outsvg << "" + toString(numA-sharedAB-sharedAC+sharedABC) + "\n"; + outsvg << "" + toString(sharedAB) + "\n"; + outsvg << "" + toString(numB-sharedAB-sharedBC+sharedABC) + "\n"; + outsvg << "" + toString(sharedAC) + "\n"; + outsvg << "" + toString(numC-sharedAC-sharedBC+sharedABC) + "\n"; + outsvg << "" + toString(sharedBC) + "\n"; + outsvg << "" + toString(sharedABC) + "\n"; + + outsvg << "Percentage of species that are shared in groups " + globaldata->Groups[0] + " and " + globaldata->Groups[1] + " is " + toString((sharedAB / (float)(numA + numB - sharedAB))) + "\n"; + outsvg << "Percentage of species that are shared in groups " + globaldata->Groups[0] + " and " + globaldata->Groups[2] + " is " + toString((sharedAC / (float)(numA + numC - sharedAC))) + "\n"; + outsvg << "Percentage of species that are shared in groups " + globaldata->Groups[1] + " and " + globaldata->Groups[2] + " is " + toString((sharedBC / (float)(numB + numC - sharedBC))) + "\n"; + outsvg << "Percentage of species that are shared in groups " + globaldata->Groups[0] + ", " + globaldata->Groups[1] + " and " + globaldata->Groups[2] + " is " + toString((sharedABC / (float)(numA + numB + numC - sharedAB - sharedAC - sharedBC - (2 * sharedABC)))) + "\n"; + } + + outsvg << "\n\n"; + outsvg.close(); + + + + } + catch(exception& e) { + cout << "Standard Error: " << e.what() << " has occurred in the Venn class Function getPic. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + catch(...) { + cout << "An unknown error has occurred in the Venn class function getPic. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } +} +//********************************************************************************************************************** +void Venn::getSharedVectors(SharedOrderVector* order){ + try { + + //delete lookup + for (int j = 0; j < lookup.size(); j++) { + delete lookup[j]; + } + + lookup.clear(); + + groupComb = ""; + + //create and initialize vector of sharedvectors, one for each group + for (int i = 0; i < globaldata->Groups.size(); i++) { + SharedRAbundVector* temp = new SharedRAbundVector(order->getNumBins()); + temp->setLabel(order->getLabel()); + temp->setGroup(globaldata->Groups[i]); + groupComb += globaldata->Groups[i]; + lookup.push_back(temp); + } + + int numSeqs = order->size(); + //sample all the members + for(int i=0;iget(i); + int abundance; + + //set info for sharedvector in chosens group + for (int j = 0; j < lookup.size(); j++) { + if (chosen.group == lookup[j]->getGroup()) { + abundance = lookup[j]->getAbundance(chosen.bin); + lookup[j]->set(chosen.bin, (abundance + 1), chosen.group); + break; + } + } + } + + } + catch(exception& e) { + cout << "Standard Error: " << e.what() << " has occurred in the Venn class Function getSharedVectors. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + catch(...) { + cout << "An unknown error has occurred in the Venn class function getSharedVectors. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + +} +//********************************************************************************************************************** + + + diff --git a/venn.h b/venn.h new file mode 100644 index 0000000..fbb6cf1 --- /dev/null +++ b/venn.h @@ -0,0 +1,46 @@ +#ifndef VENN_H +#define VENN_H +/* + * venn.h + * Mothur + * + * Created by Sarah Westcott on 3/30/09. + * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved. + * + */ + +using namespace std; + +#include "ordervector.hpp" +#include "rabundvector.hpp" +#include "sharedrabundvector.h" +#include "sharedordervector.h" +#include "datavector.hpp" +#include "globaldata.hpp" + +/***********************************************************************/ + +class Venn { + + public: + Venn(); + ~Venn(){}; + + void getPic(OrderVector*); + void getPic(SharedOrderVector*); + + private: + void getSharedVectors(SharedOrderVector*); + + RAbundVector rabund; + GlobalData* globaldata; + vector lookup; + string format, groupComb; + ofstream outsvg; + + +}; +/***********************************************************************/ + +#endif + diff --git a/venncommand.cpp b/venncommand.cpp new file mode 100644 index 0000000..c8a7dbf --- /dev/null +++ b/venncommand.cpp @@ -0,0 +1,183 @@ +/* + * venncommand.cpp + * Mothur + * + * Created by Sarah Westcott on 3/30/09. + * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved. + * + */ + +#include "venncommand.h" + +//********************************************************************************************************************** + +VennCommand::VennCommand(){ + try { + globaldata = GlobalData::getInstance(); + venn = new Venn(); + format = globaldata->getFormat(); + + } + catch(exception& e) { + cout << "Standard Error: " << e.what() << " has occurred in the VennCommand class Function VennCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + catch(...) { + cout << "An unknown error has occurred in the VennCommand class function VennCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } +} +//********************************************************************************************************************** + +VennCommand::~VennCommand(){ + delete input; + delete read; + delete venn; +} + +//********************************************************************************************************************** + +int VennCommand::execute(){ + try { + int count = 1; + + if (format == "sharedfile") { + //you have groups + read = new ReadPhilFile(globaldata->inputFileName); + read->read(&*globaldata); + + input = globaldata->ginput; + order = input->getSharedOrderVector(); + }else if (format == "shared") { + //you are using a list and a groupfile + read = new ReadPhilFile(globaldata->inputFileName); + read->read(&*globaldata); + + input = globaldata->ginput; + SharedList = globaldata->gSharedList; + order = SharedList->getSharedOrderVector(); + }else if (format == "list") { + //you are using just a list file and have only one group + read = new ReadPhilFile(globaldata->inputFileName); + read->read(&*globaldata); + + ordersingle = globaldata->gorder; + input = globaldata->ginput; + } + + + if (format != "list") { + + setGroups(); + + while(order != NULL){ + + if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(order->getLabel()) == 1){ + + cout << order->getLabel() << '\t' << count << endl; + venn->getPic(order); + + } + + //get next line to process + if (format == "sharedfile") { + order = input->getSharedOrderVector(); + }else { + //you are using a list and a groupfile + SharedList = input->getSharedListVector(); //get new list vector to process + if (SharedList != NULL) { + order = SharedList->getSharedOrderVector(); //gets new order vector with group info. + }else { + break; + } + } + count++; + } + + //reset groups parameter + globaldata->Groups.clear(); globaldata->setGroups(""); + + }else{ + while(ordersingle != NULL){ + + if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(ordersingle->getLabel()) == 1){ + + cout << ordersingle->getLabel() << '\t' << count << endl; + venn->getPic(ordersingle); + + } + + ordersingle = (input->getOrderVector()); + count++; + } + } + + return 0; + } + catch(exception& e) { + cout << "Standard Error: " << e.what() << " has occurred in the VennCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + catch(...) { + cout << "An unknown error has occurred in the VennCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } +} + +//********************************************************************************************************************** +void VennCommand::setGroups() { + try { + //if the user has not entered specific groups to analyze then do them all + if (globaldata->Groups.size() != 0) { + if (globaldata->Groups[0] != "all") { + //check that groups are valid + for (int i = 0; i < globaldata->Groups.size(); i++) { + if (globaldata->gGroupmap->isValidGroup(globaldata->Groups[i]) != true) { + cout << globaldata->Groups[i] << " is not a valid group, and will be disregarded." << endl; + // erase the invalid group from globaldata->Groups + globaldata->Groups.erase(globaldata->Groups.begin()+i); + } + } + + //if the user only entered invalid groups + if (globaldata->Groups.size() == 0) { + cout << "When using the groups parameter you must have at least 1 valid group. I will run the command using the first three groups in your groupfile." << endl; + for (int i = 0; i < globaldata->gGroupmap->namesOfGroups.size(); i++) { + globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]); + } + } + }else{//user has enter "all" and wants the default groups + globaldata->Groups.clear(); + for (int i = 0; i < globaldata->gGroupmap->namesOfGroups.size(); i++) { + globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]); + } + globaldata->setGroups(""); + } + }else { + for (int i = 0; i < globaldata->gGroupmap->namesOfGroups.size(); i++) { + globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]); + } + } + + + //check to make sure their are only 3 groups + if (globaldata->Groups.size() > 3) { + cout << "You may only use 3 groups at a time with this command. I will choose the first three and disregard the rest." << endl; + for (int i = 3; i < globaldata->Groups.size(); i++) { + globaldata->Groups.erase(globaldata->Groups.begin()+i); + } + } + + } + catch(exception& e) { + cout << "Standard Error: " << e.what() << " has occurred in the VennCommand class Function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + catch(...) { + cout << "An unknown error has occurred in the VennCommand class function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + +} +/***********************************************************/ + diff --git a/venncommand.h b/venncommand.h new file mode 100644 index 0000000..f8151c1 --- /dev/null +++ b/venncommand.h @@ -0,0 +1,45 @@ +#ifndef VENNCOMMAND_H +#define VENNCOMMAND_H +/* + * venncommand.h + * Mothur + * + * Created by Sarah Westcott on 3/30/09. + * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved. + * + */ + +#include "command.hpp" +#include "inputdata.h" +#include "readmatrix.hpp" +#include "sharedlistvector.h" +#include "venn.h" + + +class GlobalData; + + +class VennCommand : public Command { + +public: + VennCommand(); + ~VennCommand(); + int execute(); + +private: + GlobalData* globaldata; + ReadMatrix* read; + InputData* input; + SharedListVector* SharedList; + SharedOrderVector* order; + OrderVector* ordersingle; + Venn* venn; + string format; + + void setGroups(); + +}; + + + +#endif \ No newline at end of file