372E12700F26365B0095CF7E /* readotucommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 372E126F0F26365B0095CF7E /* readotucommand.cpp */; };
372E12960F263D5A0095CF7E /* readdistcommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 372E12950F263D5A0095CF7E /* readdistcommand.cpp */; };
372E12ED0F264D320095CF7E /* commandfactory.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 372E12EC0F264D320095CF7E /* commandfactory.cpp */; };
+ 3731C1F30F8CFC0A0065A2AD /* treegroupscommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3731C1F20F8CFC0A0065A2AD /* treegroupscommand.cpp */; };
374610780F40645300460C57 /* unifracweightedcommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 374610770F40645300460C57 /* unifracweightedcommand.cpp */; };
3746107E0F4064D100460C57 /* weighted.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3746107D0F4064D100460C57 /* weighted.cpp */; };
374610830F40652400460C57 /* unweighted.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 374610820F40652400460C57 /* unweighted.cpp */; };
37AFC71F0F445386005F492D /* sharedsobscollectsummary.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37AFC71E0F445386005F492D /* sharedsobscollectsummary.cpp */; };
37B28F680F27590100808A62 /* deconvolutecommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37B28F670F27590100808A62 /* deconvolutecommand.cpp */; };
37C1D9730F86506E0059E3F0 /* binsequencecommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37C1D9720F86506E0059E3F0 /* binsequencecommand.cpp */; };
+ 37C7F3A90F8E90AD00E91C2B /* sharedutilities.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37C7F3A80F8E90AD00E91C2B /* sharedutilities.cpp */; };
37D928550F21331F001D4494 /* ace.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D927B80F21331F001D4494 /* ace.cpp */; };
37D928560F21331F001D4494 /* averagelinkage.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D927BA0F21331F001D4494 /* averagelinkage.cpp */; };
37D928570F21331F001D4494 /* bootstrap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D927BB0F21331F001D4494 /* bootstrap.cpp */; };
372E12940F263D5A0095CF7E /* readdistcommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = readdistcommand.h; sourceTree = "<group>"; };
372E12950F263D5A0095CF7E /* readdistcommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = readdistcommand.cpp; sourceTree = "<group>"; };
372E12EC0F264D320095CF7E /* commandfactory.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = commandfactory.cpp; sourceTree = "<group>"; };
+ 3731C1F10F8CFC0A0065A2AD /* treegroupscommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = treegroupscommand.h; sourceTree = "<group>"; };
+ 3731C1F20F8CFC0A0065A2AD /* treegroupscommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = treegroupscommand.cpp; sourceTree = "<group>"; };
374610760F40645300460C57 /* unifracweightedcommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = unifracweightedcommand.h; sourceTree = "<group>"; };
374610770F40645300460C57 /* unifracweightedcommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = unifracweightedcommand.cpp; sourceTree = "<group>"; };
3746107C0F4064D100460C57 /* weighted.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = weighted.h; sourceTree = "<group>"; };
37B28F670F27590100808A62 /* deconvolutecommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = deconvolutecommand.cpp; sourceTree = "<group>"; };
37C1D9710F86506E0059E3F0 /* binsequencecommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = binsequencecommand.h; sourceTree = "<group>"; };
37C1D9720F86506E0059E3F0 /* binsequencecommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = binsequencecommand.cpp; sourceTree = "<group>"; };
+ 37C7F3A70F8E90AD00E91C2B /* sharedutilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sharedutilities.h; sourceTree = "<group>"; };
+ 37C7F3A80F8E90AD00E91C2B /* sharedutilities.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = sharedutilities.cpp; sourceTree = "<group>"; };
37D927B80F21331F001D4494 /* ace.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ace.cpp; sourceTree = "<group>"; };
37D927B90F21331F001D4494 /* ace.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ace.h; sourceTree = "<group>"; };
37D927BA0F21331F001D4494 /* averagelinkage.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = averagelinkage.cpp; sourceTree = "<group>"; };
37D928490F21331F001D4494 /* summarydisplay.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = summarydisplay.h; sourceTree = "<group>"; };
37D9284A0F21331F001D4494 /* summarysharedcommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = summarysharedcommand.cpp; sourceTree = "<group>"; };
37D9284B0F21331F001D4494 /* summarysharedcommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = summarysharedcommand.h; sourceTree = "<group>"; };
- 37D9284C0F21331F001D4494 /* utilities.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = utilities.hpp; sourceTree = "<group>"; };
37D9284D0F21331F001D4494 /* uvest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = uvest.cpp; sourceTree = "<group>"; };
37D9284E0F21331F001D4494 /* uvest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = uvest.h; sourceTree = "<group>"; };
37D9284F0F21331F001D4494 /* validcalculator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = validcalculator.cpp; sourceTree = "<group>"; };
37D9281C0F21331F001D4494 /* sequence.cpp */,
37D928210F21331F001D4494 /* shared.h */,
37D928200F21331F001D4494 /* shared.cpp */,
+ 37C7F3A70F8E90AD00E91C2B /* sharedutilities.h */,
+ 37C7F3A80F8E90AD00E91C2B /* sharedutilities.cpp */,
37D928420F21331F001D4494 /* singlelinkage.cpp */,
37D928480F21331F001D4494 /* summarydata.h */,
37D928490F21331F001D4494 /* summarydisplay.h */,
- 37D9284C0F21331F001D4494 /* utilities.hpp */,
37519AB30F810FAE00FED5E8 /* venn.h */,
37519AB40F810FAE00FED5E8 /* venn.cpp */,
);
37D928460F21331F001D4494 /* summarycommand.cpp */,
37D9284B0F21331F001D4494 /* summarysharedcommand.h */,
37D9284A0F21331F001D4494 /* summarysharedcommand.cpp */,
+ 3731C1F10F8CFC0A0065A2AD /* treegroupscommand.h */,
+ 3731C1F20F8CFC0A0065A2AD /* treegroupscommand.cpp */,
3746109B0F40657600460C57 /* unifracunweightedcommand.h */,
3746109C0F40657600460C57 /* unifracunweightedcommand.cpp */,
374610760F40645300460C57 /* unifracweightedcommand.h */,
37519AB50F810FAE00FED5E8 /* venn.cpp in Sources */,
37C1D9730F86506E0059E3F0 /* binsequencecommand.cpp in Sources */,
370B88070F8A4EE4005AB382 /* getoturepcommand.cpp in Sources */,
+ 3731C1F30F8CFC0A0065A2AD /* treegroupscommand.cpp in Sources */,
+ 37C7F3A90F8E90AD00E91C2B /* sharedutilities.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
#ifndef AVERAGE_H
#define AVERAGE_H
+
+#include "mothur.h"
#include "cluster.hpp"
#include "rabundvector.hpp"
#include "sparsematrix.hpp"
-#include "mothur.h"
/* This class implements the average UPGMA, average neighbor clustering algorithm */
*/
#include "bergerparker.h"
-#include "calculator.h"
/***************************************************************/
*
*/
+/* The bin.seqs command outputs a .fasta file for each distance you specify appending the OTU number to each name. */
#include "command.hpp"
#include "inputdata.h"
*/
#include "bstick.h"
-#include "calculator.h"
+
/***********************************************************************/
double BStick::invSum(int index, double numSpec)
using namespace std;
#include "mothur.h"
-#include "utilities.hpp"
#include "sabundvector.hpp"
#include "sharedsabundvector.h"
#include "rabundvector.hpp"
#include "cluster.hpp"
#include "rabundvector.hpp"
#include "listvector.hpp"
+#include "sparsematrix.hpp"
/***********************************************************************/
using namespace std;
#include "mothur.h"
-#include "utilities.hpp"
#include "sparsematrix.hpp"
-#include "rabundvector.hpp"
class RAbundVector;
class ListVector;
#include "collect.h"
-
/***********************************************************************/
void Collect::getCurve(int increment = 1){
using namespace std;
+
#include "collectorscurvedata.h"
#include "display.h"
#include "ordervector.hpp"
#include "command.hpp"
#include "ordervector.hpp"
#include "inputdata.h"
-//#include "groupmap.h"
+#include "groupmap.h"
#include "collect.h"
#include "display.h"
#include "readmatrix.hpp"
#include "calculator.h"
#include "fileoutput.h"
#include "display.h"
-#include <vector>
+
using namespace std;
fileNameRoot = getRootName(globaldata->inputFileName);
format = globaldata->getFormat();
validCalculator = new ValidCalculators();
+ util = new SharedUtil();
int i;
for (i=0; i<globaldata->Estimators.size(); i++) {
delete input;
delete cCurve;
delete read;
+ delete util;
}
//**********************************************************************************************************************
set<string> orderList;
//set users groups
- setGroups();
+ util->setGroups(globaldata->Groups, globaldata->gGroupmap->namesOfGroups, "collect");
+ util->updateGroupIndex(globaldata->Groups, globaldata->gGroupmap->groupIndex);
while(order != NULL){
orderList.insert(order->getLabel());
}
}
-
-//**********************************************************************************************************************
-void CollectSharedCommand::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) || (globaldata->Groups.size() == 1)) {
- cout << "When using the groups parameter you must have at least 2 valid groups. I will run the command using all the 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]);
- }
- }
-
- }
- catch(exception& e) {
- cout << "Standard Error: " << e.what() << " has occurred in the CollectSharedCommand class Function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
- exit(1);
- }
- catch(...) {
- cout << "An unknown error has occurred in the CollectSharedCommand class function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
- exit(1);
- }
-
-}
/***********************************************************/
#include "display.h"
#include "readmatrix.hpp"
#include "validcalculator.h"
+#include "sharedutilities.h"
/* The collect.shared() command:
The collect command generates a collector's curve from the given file representing several groups.
private:
GlobalData* globaldata;
+ SharedUtil* util;
GroupMap* groupmap;
SharedListVector* SharedList;
ReadMatrix* read;
vector<Display*> cDisplays;
int freq;
string format;
- void setGroups();
};
#include "libshuffcommand.h"
#include "heatmapcommand.h"
#include "venncommand.h"
-#include "mothur.h"
#include "nocommands.h"
#include "binsequencecommand.h"
#include "getoturepcommand.h"
+#include "treegroupscommand.h"
/***********************************************************/
else if(commandName == "venn") { command = new VennCommand(); }
else if(commandName == "bin.seqs") { command = new BinSeqCommand(); }
else if(commandName == "get.oturep") { command = new GetOTURepCommand(); }
+ else if(commandName == "tree.groups") { command = new TreeGroupCommand(); }
else { command = new NoCommand(); }
return command;
*
*/
+#include "mothur.h"
+
class Command;
class CommandFactory {
using namespace std;
+
#include "globaldata.hpp"
#include "commandoptionparser.hpp"
-#include "mothur.h"
+
//**********************************************************************************************************************
//This Function parses through the command line and pulls out the command then sends the options to the parseGlobalData
#ifndef COMMANDOPTIONPARSER_HPP
#define COMMANDOPTIONPARSER_HPP
+#include "mothur.h"
+
//**********************************************************************************************************************
class CommandOptionParser {
using namespace std;
-#include "mothur.h"
+
#include "sequence.hpp"
#include "database.hpp"
*
*/
+#include "mothur.h"
+
class Database {
public:
Database(string);
*/
#include "command.hpp"
-#include "utilities.hpp"
#include "fastamap.h"
#include "globaldata.hpp"
*/
using namespace std;
-
-#include "utilities.hpp"
-#include "globaldata.hpp"
-#include "commandoptionparser.hpp"
-#include "command.hpp"
-#include "commandfactory.hpp"
-#include "errorchecking.h"
#include "engine.hpp"
/***********************************************************************/
#include "mothur.h"
+#include "globaldata.hpp"
+#include "commandoptionparser.hpp"
+#include "command.hpp"
+#include "commandfactory.hpp"
+#include "errorchecking.h"
+
using namespace std;
if (parameter == "abund" ) { abund = value; }
if (parameter == "random" ) { randomtree = value; }
if (parameter == "sorted" ) { sorted = value; }
+ if (parameter == "scaler" ) { scaler = value; }
+
}
//gets the last parameter and value
if (parameter == "random" ) { randomtree = value; }
if (parameter == "abund" ) { abund = value; }
if (parameter == "sorted" ) { sorted = value; }
+ if (parameter == "scaler" ) { scaler = value; }
}
}
if ((globaldata->getListFile() == "") && (globaldata->getRabundFile() == "") && (globaldata->getSabundFile() == "")) { cout << "You must read a list, sabund or rabund before you can use the collect.single, rarefaction.single or summary.single commands." << endl; return false; }
}
- if ((commandName == "collect.shared") || (commandName == "rarefaction.shared") || (commandName == "summary.shared") ){
+ if ((commandName == "collect.shared") || (commandName == "rarefaction.shared") || (commandName == "summary.shared") || (commandName == "tree.groups") ){
if (globaldata->getSharedFile() == "") {
- if (globaldata->getListFile() == "") { cout << "You must read a list and a group, or a shared before you can use the collect.shared, rarefaction.shared or summary.shared commands." << endl; return false; }
- else if (globaldata->getGroupFile() == "") { cout << "You must read a list and a group, or a shared before you can use the collect.shared, rarefaction.shared or summary.shared commands." << endl; return false; }
+ if (globaldata->getListFile() == "") { cout << "You must read a list and a group, or a shared before you can use the collect.shared, rarefaction.shared, summary.shared or tree.groups commands." << endl; return false; }
+ else if (globaldata->getGroupFile() == "") { cout << "You must read a list and a group, or a shared before you can use the collect.shared, rarefaction.shared, summary.shared or tree.groups commands." << endl; return false; }
}
}
#include "globaldata.hpp"
#include "validcommands.h"
#include "validparameter.h"
-#include "utilities.hpp"
+
class ErrorCheck {
public:
void clear();
void refresh();
string phylipfile, columnfile, listfile, rabundfile, sabundfile, namefile, groupfile, orderfile, fastafile, treefile, sharedfile, cutoff, format;
- string precision, method, fileroot, label, line, iters, jumble, freq, single, rarefaction, shared, summary, randomtree, abund, sorted;
+ string precision, method, fileroot, label, line, iters, jumble, freq, single, rarefaction, shared, summary, randomtree, abund, sorted, scaler;
string commandName, optionText;
bool errorFree;
using namespace std;
#include "mothur.h"
-#include "utilities.hpp"
/* This class represents the fasta file. It reads a fasta file a populates the internal data structure "data".
outFile.close();
}
counter = 1;
+
remove(inName.c_str());
- rename(outName.c_str(), inName.c_str());
+ renameOk = rename(outName.c_str(), inName.c_str());
+
+ //checks to make sure user was able to rename and remove successfully
+ if ((renameOk != 0)) { cout << "Unable to rename necessary files." << endl; }
+
}
catch(exception& e) {
cout << "Standard Error: " << e.what() << " has occurred in the ThreeColumnFile class Function resetFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
/***********************************************************************/
/***********************************************************************/
+ThreeColumnFile2::~ThreeColumnFile2(){
+
+ inFile.close();
+ outFile.close();
+ remove(outName.c_str());
+};
+
+/***********************************************************************/
+
+void ThreeColumnFile2::initFile(string label, vector<string> tags){
+ try {
+ if(counter != 0){
+ openOutputFile(outName, outFile);
+ openInputFile(inName, inFile);
+
+ string inputBuffer;
+ getline(inFile, inputBuffer);
+
+ outFile << inputBuffer << '\t';
+ for(int i = 1; i < tags.size(); i++) {
+ outFile << label + tags[i] << '\t';
+ }
+ outFile << endl;
+ }
+ else{
+ openOutputFile(outName, outFile);
+ for(int i = 0; i < tags.size(); i++) {
+ outFile << label + tags[i] << '\t';
+ }
+ outFile << endl;
+
+ }
+
+ outFile.setf(ios::fixed, ios::floatfield);
+ outFile.setf(ios::showpoint);
+ }
+ catch(exception& e) {
+ cout << "Standard Error: " << e.what() << " has occurred in the ThreeColumnFile class Function initFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+ catch(...) {
+ cout << "An unknown error has occurred in the ThreeColumnFile class function initFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+}
+
+/***********************************************************************/
+
+void ThreeColumnFile2::output(vector<double> data){
+ try {
+
+ if(counter != 0){
+ string inputBuffer;
+ getline(inFile, inputBuffer);
+
+ outFile << inputBuffer << '\t' << setprecision(6) << data[0] << setprecision(globaldata->getIters().length()) << '\t' << data[1] << '\t' << data[2] << endl;
+ }
+ else{
+ outFile << setprecision(6) << data[0] << setprecision(globaldata->getIters().length()) << '\t' << data[1] << '\t' << data[2] << endl;
+
+ }
+
+ }
+ catch(exception& e) {
+ cout << "Standard Error: " << e.what() << " has occurred in the ThreeColumnFile2 class Function output. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+ catch(...) {
+ cout << "An unknown error has occurred in the ThreeColumnFile2 class function output. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+};
+
+/***********************************************************************/
+
+void ThreeColumnFile2::resetFile(){
+ try {
+ if(counter != 0){
+ outFile.close();
+ inFile.close();
+ }
+ else{
+ outFile.close();
+ }
+ counter = 1;
+
+ remove(inName.c_str());
+ renameOk = rename(outName.c_str(), inName.c_str());
+
+ //checks to make sure user was able to rename and remove successfully
+ if ((renameOk != 0)) { cout << "Unable to rename necessary files." << endl; }
+
+ }
+ catch(exception& e) {
+ cout << "Standard Error: " << e.what() << " has occurred in the ThreeColumnFile2 class Function resetFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+ catch(...) {
+ cout << "An unknown error has occurred in the ThreeColumnFile2 class function resetFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+}
+
+/***********************************************************************/
+/***********************************************************************/
+
SharedThreeColumnFile::~SharedThreeColumnFile(){
inFile.close();
}
counter = 1;
remove(inName.c_str());
- rename(outName.c_str(), inName.c_str());
+ renameOk = rename(outName.c_str(), inName.c_str());
+
+ //checks to make sure user was able to rename and remove successfully
+ if ((renameOk != 0)) { cout << "Unable to rename necessary files." << endl; }
+
}
catch(exception& e) {
cout << "Standard Error: " << e.what() << " has occurred in the SharedThreeColumnFile class Function resetFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
}
counter = 1;
remove(inName.c_str());
- rename(outName.c_str(), inName.c_str());
+ renameOk = rename(outName.c_str(), inName.c_str());
+
+ //checks to make sure user was able to rename and remove successfully
+ if ((renameOk != 0)) { cout << "Unable to rename necessary files." << endl; }
+
}
catch(exception& e) {
cout << "Standard Error: " << e.what() << " has occurred in the OneColumnFile class Function resetFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
outFile.close();
}
counter = 1;
+
remove(inName.c_str());
- rename(outName.c_str(), inName.c_str());
+ renameOk = rename(outName.c_str(), inName.c_str());
+
+ //checks to make sure user was able to rename and remove successfully
+ if ((renameOk != 0)) { cout << "Unable to rename necessary files." << endl; }
+
+
}
catch(exception& e) {
cout << "Standard Error: " << e.what() << " has occurred in the OneColumnFile class Function resetFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
#define FILEOUTPUT_H
#include "mothur.h"
-#include "utilities.hpp"
#include "globaldata.hpp"
using namespace std;
virtual void initFile(string) = 0;
virtual void resetFile() = 0;
virtual string getFileName() = 0;
+ virtual void initFile(string, vector<string>) = 0;
+ virtual void output(vector<double>) = 0;
+
+protected:
+ GlobalData* globaldata;
+ int renameOk;
};
void output(int, vector<double>);
void resetFile();
string getFileName() { return inName; };
+
+ void initFile(string, vector<string>) {};
+ void output(vector<double>) {};
+
private:
string inName;
string outName;
void initFile(string);
void resetFile();
string getFileName() { return inName; };
+
+ void initFile(string, vector<string>) {};
+ void output(vector<double>) {};
+
private:
string outName;
void initFile(string);
void resetFile();
string getFileName() { return inName; };
+
+ void initFile(string, vector<string>) {};
+ void output(vector<double>) {};
+
private:
string outName;
void output(int, vector<double>);
void resetFile();
string getFileName() { return inName; };
+
+
+ void initFile(string, vector<string>) {};
+ void output(vector<double>) {};
+
private:
string inName, groupLabel;
string outName;
int counter, numGroup;
};
+/***********************************************************************/
+
+class ThreeColumnFile2 : public FileOutput {
+
+public:
+ ThreeColumnFile2(string n) : FileOutput(), inName(n), counter(0), outName(getPathName(n) + ".temp." + getSimpleName(n)) { globaldata = GlobalData::getInstance(); };
+ ~ThreeColumnFile2();
+
+ //to make compatible with parent class
+ void output(int, vector<double>){};
+ void initFile(string){};
+
+ void initFile(string, vector<string>);
+ void output(vector<double>);
+ void resetFile();
+ string getFileName() { return inName; };
+private:
+ string inName;
+ string outName;
+ ifstream inFile;
+ ofstream outFile;
+ int counter;
+};
+/***********************************************************************/
#endif
*/
#include "geom.h"
-#include "calculator.h"
/***********************************************************************/
* Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
*
*/
+
+ /* The get.oturep command outputs a .fastarep file for each distance you specify, selecting one OTU representative for each bin. */
#include "command.hpp"
#include "globaldata.hpp"
#include "globaldata.hpp"
-#include "sparsematrix.hpp"
#include "tree.h"
-#include "rabundvector.hpp"
-#include "sabundvector.hpp"
-#include "listvector.hpp"
+#include "sparsematrix.hpp"
/*******************************************************/
if (key == "step") { step = value; }
if (key == "form") { form = value; }
if (key == "sorted") { sorted = value; }
+ if (key == "scaler") { scaler = value; }
if (key == "step") { step = value; }
if (key == "form") { form = value; }
if (key == "sorted") { sorted = value; }
+ if (key == "scaler") { scaler = value; }
+
if (key == "line") {//stores lines to be used in a vector
lines.clear();
if (line != "all") { splitAtDash(value, lines); allLines = 0; }
else { allLines = 1; }
}
+
if (key == "label") {//stores lines to be used in a vector
labels.clear();
lines.clear();
Estimators.clear();
splitAtDash(calc, Estimators);
}
+ if (commandName == "tree.groups") {
+ if (calc != "") {
+ Estimators.clear();
+ splitAtDash(calc, Estimators);
+ }else { cout << "You have not specified any calculators." << endl; }
+ }
+
//if you have done a read.otu with a groupfile but don't want to use it anymore because you want to do single commands
if ((commandName == "collect.single") || (commandName == "rarefaction.single") || (commandName == "summary.single")) {
string GlobalData::getStep() { return step; }
string GlobalData::getForm() { return form; }
string GlobalData::getSorted() { return sorted; }
+string GlobalData::getScaler() { return scaler; }
void GlobalData::setListFile(string file) { listfile = file; inputFileName = file;}
void GlobalData::setRabundFile(string file) { rabundfile = file; inputFileName = file;}
void GlobalData::setSabundFile(string file) { sabundfile = file; inputFileName = file;}
step = "0.01";
form = "integral";
sorted = "1"; //0 means don't sort, 1 means sort.
+ scaler = "log2";
}
//*******************************************************/
#include "groupmap.h"
#include "treemap.h"
+#include "rabundvector.hpp"
+#include "sabundvector.hpp"
+#include "listvector.hpp"
+
+
using namespace std;
class ListVector;
class GroupMap;
class TreeMap;
class SAbundVector;
+class RAbundVector;
class GlobalData {
public:
string getStep();
string getForm();
string getSorted();
+ string getScaler();
void setListFile(string);
void setPhylipFile(string);
private:
string phylipfile, columnfile, listfile, rabundfile, sabundfile, namefile, groupfile, orderfile, fastafile, treefile, sharedfile, line, label, randomtree, groups;
- string cutoff, format, precision, method, fileroot, iters, jumble, freq, calc, abund, step, form, sorted;
+ string cutoff, format, precision, method, fileroot, iters, jumble, freq, calc, abund, step, form, sorted, scaler;
static GlobalData* _uniqueInstance;
GlobalData( const GlobalData& ); // Disable copy constructor
*/
#include "mothur.h"
-#include "utilities.hpp"
/* This class is a representation of the groupfile. It is used by all the shared commands to determine what group a
certain sequence belongs to. */
globaldata = GlobalData::getInstance();
format = globaldata->getFormat();
sorted = globaldata->getSorted();
+ util = new SharedUtil();
}
catch(exception& e) {
if(it->second.length() == 1) { it->second = "0" + it->second; }
}
- string filenamesvg = globaldata->inputFileName + ".heatmap." + order->getLabel() + ".svg";
+ string filenamesvg = getRootName(globaldata->inputFileName) + order->getLabel() + ".heatmap.svg";
openOutputFile(filenamesvg, outsvg);
colorScale.clear();
//fills vector of sharedsabunds - lookup
- getSharedVectors(sharedorder);
+ util->getSharedVectors(globaldata->Groups, lookup, sharedorder); //fills group vectors from order vector.
//sort lookup so shared bins are on top
if (sorted == "1") { sortSharedVectors(); }
- //get maxBin
+ //get users scaling method
+ scaler = globaldata->getScaler();
+
+ int maxbin = 0;
for (int i = 0; i < lookup.size(); i++) {
for (int j = 0; j < lookup[i]->size(); j++) {
- colorScale[lookup[i]->getAbundance(j)] = "";
+ //if (lookup[i]->getAbundance(j) != 0) { //don't want log value of 0.
+ //if (scaler == "log10") {
+ // colorScale[-log((log10(lookup[i]->getAbundance(j)) / (float)lookup[i]->getNumSeqs()))] = "";
+ //cout << "abundance = " << lookup[i]->getAbundance(j) << '\t' << " relative adundance = " << (lookup[i]->getAbundance(j) / (float)lookup[i]->getNumSeqs()) << '\t';
+ //cout << -log((log10(lookup[i]->getAbundance(j)) / lookup[i]->getNumSeqs())) << endl;
+ //}else if (scaler == "log2") {
+ //colorScale[-log((log2(lookup[i]->getAbundance(j)) / (float)lookup[i]->getNumSeqs()))] = ""; //cout << (int)log2(lookup[i]->getAbundance(j)) << endl;
+ //cout << "abundance = " << lookup[i]->getAbundance(j) << '\t' << " relative adundance = " << lookup[i]->getAbundance(j) / (float)lookup[i]->getNumSeqs() << '\t';
+ //cout << -log((log2(lookup[i]->getAbundance(j)) / lookup[i]->getNumSeqs())) << endl;
+ // }else if (scaler == "linear") {
+ colorScale[lookup[i]->getAbundance(j)] = "";
+ if (maxbin < lookup[i]->getAbundance(j)) { maxbin = lookup[i]->getAbundance(j); }
+ //cout << "abundance = " << lookup[i]->getAbundance(j) << '\t' << " relative adundance = " << lookup[i]->getAbundance(j) / (float)lookup[i]->getNumSeqs() << '\t';
+ //cout << lookup[i]->getAbundance(j) /(float) lookup[i]->getNumSeqs() << endl;
+ //}else { //if user enters invalid scaler option.
+ // cout << scaler << " is not a valid scaler option. I will use log10." << endl;
+ // colorScale[-log(log10(lookup[i]->getAbundance(j) / lookup[i]->getNumSeqs()))] = "";
+ //}
+ //}else { colorScale[0] = "00"; }
+
}
}
//get scaler
- float scaler = 255 / (float) colorScale.size();
+ float scalers = 255 / (float) maxbin;
//go through map and give each score a color value
for (it = colorScale.begin(); it != colorScale.end(); it++) {
- it->second = toHex(int(float(it->first) * scaler));
+ it->second = toHex(int(float(it->first) * scalers));
if(it->second.length() == 1) { it->second = "0" + it->second; }
+//cout << it->first << " " << it->second << endl;
}
- string filenamesvg = globaldata->inputFileName + ".heatmap." + sharedorder->getLabel() + "." + groupComb + ".svg";
+ string filenamesvg = getRootName(globaldata->inputFileName) + sharedorder->getLabel() + ".heatmap.svg";
openOutputFile(filenamesvg, outsvg);
//svg image
- outsvg << "<svg width=\"100%\" height=\"100%\" viewBox=\"0 0 " + toString(lookup.size() * 300) + " " + toString((lookup[0]->getNumBins()*5 + 15)) + "\">\n";
+ outsvg << "<svg width=\"100%\" height=\"100%\" viewBox=\"0 0 " + toString(lookup.size() * 300) + " " + toString((lookup[0]->getNumBins()*5 + 120)) + "\">\n";
outsvg << "<g>\n";
- int x = 15;
- int y = 15;
+ //white backround
+ outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"" + toString(lookup.size() * 300) + "\" height=\"" + toString((lookup[0]->getNumBins()*5 + 120)) + "\"/>";
+ outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString((lookup.size() * 150) - 40) + "\" y=\"25\">Heatmap at distance " + sharedorder->getLabel() + "</text>\n";
+
+ //column labels
+ for (int h = 0; h < lookup.size(); h++) {
+ outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(((300 * (h+1)) - 150) - ((int)lookup[h]->getGroup().length() / 2)) + "\" y=\"50\">" + lookup[h]->getGroup() + "</text>\n";
+ }
+
+
+ //output legend and color labels
+ //go through map and give each score a color value
string color;
-
- for (int i = 0; i <= lookup[0]->getNumBins(); i++) {
+ int x = 0;
+ int y = 90 + (lookup[0]->getNumBins()*5);
+ for (it = colorScale.begin(); it != colorScale.end(); it++) {
+ color = it->second;
+ outsvg << "<rect fill=\"#" + color + "0000\" stroke=\"#" + color + "0000\" x=\"" + toString(x) + "\" y=\"" + toString(y) + "\" width=\"25\" height=\"10\"/>\n";
+ outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(x) + "\" y=\"" + toString(y) + "\">" + toString(it->first) + "</text>\n";
+ x += 25;
+ }
+
+ x = 0;
+ y = 70;
+ //start at 1 since bin 0 is nothing
+ for (int i = 1; i <= lookup[0]->getNumBins(); i++) {
for (int j = 0; j < lookup.size(); j++) {
-
- color = colorScale[lookup[j]->getAbundance(i)];
-
+
+ //if (lookup[j]->getAbundance(i) != 0) { //don't want log value of 0.
+ //if (scaler == "log10") {
+ // color = colorScale[(int)log10(lookup[j]->getAbundance(i))];
+ //}else if (scaler == "log2") {
+ // color = colorScale[(int)log2(lookup[j]->getAbundance(i))];
+ // }else if (scaler == "linear") {
+ color = colorScale[lookup[j]->getAbundance(i)];
+ //}else { color = colorScale[(int)log10(lookup[j]->getAbundance(i))]; }
+ //}else { color = "OO"; }
+
+
outsvg << "<rect fill=\"#" + color + "0000\" stroke=\"#" + color + "0000\" x=\"" + toString(x) + "\" y=\"" + toString(y) + "\" width=\"300\" height=\"5\"/>\n";
x += 300;
}
- x = 15;
+ x = 0;
y += 5;
}
+
outsvg << "</g>\n</svg>\n";
outsvg.close();
exit(1);
}
}
-//**********************************************************************************************************************
-void HeatMap::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;i<numSeqs;i++){
- //get first sample
- individual chosen = order->get(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 HeatMap class Function getSharedVectors. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
- exit(1);
- }
- catch(...) {
- cout << "An unknown error has occurred in the HeatMap class function getSharedVectors. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
- exit(1);
- }
-
-}
-
//**********************************************************************************************************************
void HeatMap::sortSharedVectors(){
//if they are then insert in the front
//if not push to back
- bool shared;
vector<SharedRAbundVector*> looktemp;
+ map<int, int> place; //spot in lookup where you insert shared by, ie, 3 -> 2 if they are shared by 3 inset into location 2.
+ map<int, int>::iterator it;
+ int count;
//create and initialize looktemp as a copy of lookup
for (int i = 0; i < lookup.size(); i++) {
//create and initialize lookup to empty vectors
for (int i = 0; i < looktemp.size(); i++) {
SharedRAbundVector* temp = new SharedRAbundVector();
- lookup.push_back(temp);
+ temp->setLabel(looktemp[i]->getLabel());
+ temp->setGroup(looktemp[i]->getGroup());
+ lookup.push_back(temp);
+
+ //initialize place map
+ place[i] = 0;
}
+
//for each bin
for (int i = 0; i < looktemp[0]->size(); i++) {
- shared = true;
+ count = 0;
+ bool updatePlace = false;
//for each group
for (int j = 0; j < looktemp.size(); j++) {
- if (looktemp[j]->getAbundance(i) == 0) { shared = false; }
+ if (looktemp[j]->getAbundance(i) != 0) { count++; }
}
//fill lookup
for (int j = 0; j < looktemp.size(); j++) {
//if they are not shared then push to back, if they are not insert in front
- if (shared == false) { lookup[j]->push_back(looktemp[j]->getAbundance(i), i, looktemp[j]->getGroup()); }
- else { lookup[j]->push_front(looktemp[j]->getAbundance(i), i, looktemp[j]->getGroup()); }
+ if (count < 2) { lookup[j]->push_back(looktemp[j]->getAbundance(i), i, looktemp[j]->getGroup()); }
+ //they are shared by some
+ else { lookup[j]->insert(looktemp[j]->getAbundance(i), place[count], looktemp[j]->getGroup()); updatePlace = true; }
+ }
+
+ if (updatePlace == true) {
+ //move place holders below where you entered up to "make space" for you entry
+ for (it = place.begin(); it!= place.end(); it++) {
+ if (it->first < count) { it->second++; }
+ }
}
}
#include "sharedordervector.h"
#include "datavector.hpp"
#include "globaldata.hpp"
+#include "sharedutilities.h"
/***********************************************************************/
public:
HeatMap();
- ~HeatMap(){};
+ ~HeatMap(){ delete util; };
void getPic(OrderVector*);
void getPic(SharedOrderVector*);
private:
- void getSharedVectors(SharedOrderVector*);
void sortSharedVectors();
GlobalData* globaldata;
+ SharedUtil* util;
vector<SharedRAbundVector*> lookup;
RAbundVector rabund;
- string format, sorted, groupComb;
+ string format, sorted, groupComb, scaler;
ofstream outsvg;
- map<int, string> colorScale;
- map<int, string>::iterator it;
+ map<float, string> colorScale;
+ map<float, string>::iterator it;
};
globaldata = GlobalData::getInstance();
heatmap = new HeatMap();
format = globaldata->getFormat();
+ util = new SharedUtil();
}
catch(exception& e) {
delete input;
delete read;
delete heatmap;
+ delete util;
}
//**********************************************************************************************************************
ordersingle = globaldata->gorder;
input = globaldata->ginput;
}
-
+
if (format != "list") {
-
- setGroups();
-
+
+ util->setGroups(globaldata->Groups, globaldata->gGroupmap->namesOfGroups, "heat");
+ globaldata->setGroups("");
+
+
while(order != NULL){
if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(order->getLabel()) == 1){
}
//reset groups parameter
- globaldata->Groups.clear(); globaldata->setGroups("");
+ globaldata->Groups.clear();
}else{
while(ordersingle != NULL){
}
//**********************************************************************************************************************
-void HeatMapCommand::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 groups. I will run the command using all the 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]);
- }
- }
-
- }
- catch(exception& e) {
- cout << "Standard Error: " << e.what() << " has occurred in the HeatMapCommand class Function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
- exit(1);
- }
- catch(...) {
- cout << "An unknown error has occurred in the HeatMapCommand class function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
- exit(1);
- }
-}
-/***********************************************************/
#include "readmatrix.hpp"
#include "sharedlistvector.h"
#include "heatmap.h"
+#include "sharedutilities.h"
class GlobalData;
private:
GlobalData* globaldata;
ReadMatrix* read;
+ SharedUtil* util;
InputData* input;
SharedListVector* SharedList;
SharedOrderVector* order;
OrderVector* ordersingle;
HeatMap* heatmap;
string format;
-
- void setGroups();
};
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, sorted, 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, scaler, 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 sorted parameter allows you to choose to see the file with the shared otus at the top or the otus in the order they appear in your input file. " << "\n";
+ cout << "The scaler parameter allows you to choose the range of color your bin information will be displayed with." << "\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, sorted=yourSorted, line=yourLines, label=yourLabels)." << "\n";
- cout << "Example heatmap(groups=A-B-C, line=1-3-5, sorted=0)." << "\n";
+ cout << "Example heatmap(groups=A-B-C, line=1-3-5, sorted=0, scaler=log10)." << "\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 default value for scaler is log2; your other options are log10 and linear." << "\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 == "venn") {
cout << "Example venn(groups=A-B-C, line=1-3-5, calc=sharedsobs-sharedchao)." << "\n";
cout << "The default value for groups is all the groups in your groupfile up to 4, and all lines in your inputfile will be used." << "\n";
cout << "The default value for calc is sobs if you have only read a list file or if you have selected only one group, and sharedsobs if you have multiple groups." << "\n";
+ cout << "The default available estimators for calc are sobs, chao and ace if you have only read a list file, and sharedsobs, sharedchao and sharedace if you have read a list and group file or a shared file." << "\n";
+ cout << "The only estmiator available four 4 groups is sharedsobs." << "\n";
cout << "The venn command outputs a .svg file for each calculator you specify at each distance you choose." << "\n";
cout << "Note: No spaces between parameter labels (i.e. groups), '=' and parameters (i.e.yourGroups)." << "\n" << "\n";
}else if (globaldata->helpRequest == "bin.seqs") {
#include "inputdata.h"
#include "ordervector.hpp"
#include "listvector.hpp"
-#include "utilities.hpp"
/***********************************************************************/
using namespace std;
-#include "mothur.h"
+
#include "kmer.hpp"
/**************************************************************************************************/
*
*/
+#include "mothur.h"
+
/**************************************************************************************************/
class Kmer {
using namespace std;
-#include "mothur.h"
+
#include "sequence.hpp"
#include "kmer.hpp"
#include "database.hpp"
*
*/
+#include "mothur.h"
+
class KmerDB : public Database {
public:
#include "sabundvector.hpp"
#include "rabundvector.hpp"
#include "ordervector.hpp"
-#include "utilities.hpp"
#include "listvector.hpp"
*/
#include "logsd.h"
-#include "calculator.h"
/***********************************************************************/
using namespace std;
+/**************************************************************************************************/
+
GlobalData* GlobalData::_uniqueInstance = 0;
int main(int argc, char *argv[]){
}
}
+/**************************************************************************************************/
+
*
*/
-/* This file contains all the standard incudes we use in the project. */
+/* This file contains all the standard incudes we use in the project as well as some common utilities. */
//io libraries
#include <math.h>
#include <algorithm>
+typedef unsigned long long ull;
+
+
+/***********************************************************************/
+
+// snagged from http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.2
+// works for now, but there should be a way to do it without killing the whole program
+
+class BadConversion : public runtime_error {
+public:
+ BadConversion(const string& s) : runtime_error(s){ }
+};
+
+//**********************************************************************************************************************
+
+template<typename T>
+inline void convert(const string& s, T& x, bool failIfLeftoverChars = true){
+ istringstream i(s);
+ char c;
+ if (!(i >> x) || (failIfLeftoverChars && i.get(c)))
+ throw BadConversion(s);
+}
+//**********************************************************************************************************************
+
+template<typename T>
+inline bool convertTest(const string& s, T& x, bool failIfLeftoverChars = true){
+ istringstream i(s);
+ char c;
+ if (!(i >> x) || (failIfLeftoverChars && i.get(c)))
+ {
+ cout << "'" << s << "' is unable to be converted into an integer.\n";
+ return false;
+ }
+ return true;
+}
+
+//**********************************************************************************************************************
+
+template<typename T>
+string toString(const T&x){
+ stringstream output;
+ output << x;
+ return output.str();
+}
+
+//**********************************************************************************************************************
+
+template<typename T>
+string toHex(const T&x){
+ stringstream output;
+
+ output << hex << x;
+
+ return output.str();
+}
+
+//**********************************************************************************************************************
+
+template<typename T>
+string toString(const T&x, int i){
+ stringstream output;
+
+ output.precision(i);
+ output << fixed << x;
+
+ return output.str();
+}
+
+
+/***********************************************************************/
+
+inline void gobble(istream& f){
+
+ char d;
+ while(isspace(d=f.get())) {;}
+ f.putback(d);
+
+}
+
+/***********************************************************************/
+
+inline float roundDist(float dist, int precision){
+
+ return int(dist * precision + 0.5)/float(precision);
+
+}
+
+/***********************************************************************/
+
+inline int getNumNames(string names){
+
+ int count = 0;
+
+ if(names != ""){
+ count = 1;
+ for(int i=0;i<names.size();i++){
+ if(names[i] == ','){
+ count++;
+ }
+ }
+ }
+
+ return count;
+
+}
+
+/**************************************************************************************************/
+
+inline vector<vector<double> > binomial(int maxOrder){
+
+ vector<vector<double> > binomial(maxOrder+1);
+
+ for(int i=0;i<=maxOrder;i++){
+ binomial[i].resize(maxOrder+1);
+ binomial[i][0]=1;
+ binomial[0][i]=0;
+ }
+ binomial[0][0]=1;
+
+ binomial[1][0]=1;
+ binomial[1][1]=1;
+
+ for(int i=2;i<=maxOrder;i++){
+ binomial[1][i]=0;
+ }
+
+ for(int i=2;i<=maxOrder;i++){
+ for(int j=1;j<=maxOrder;j++){
+ if(i==j){ binomial[i][j]=1; }
+ if(j>i) { binomial[i][j]=0; }
+ else { binomial[i][j]=binomial[i-1][j-1]+binomial[i-1][j]; }
+ }
+ }
+
+ return binomial;
+}
+
+/***********************************************************************/
+
+inline string getRootName(string longName){
+
+ string rootName = longName;
+
+ if(longName.find_last_of(".") != longName.npos){
+ int pos = longName.find_last_of('.')+1;
+ rootName = longName.substr(0, pos);
+ }
+
+ return rootName;
+}
+/***********************************************************************/
+
+inline string getSimpleName(string longName){
+
+ string simpleName = longName;
+
+ if(longName.find_last_of("/") != longName.npos){
+ int pos = longName.find_last_of('/')+1;
+ simpleName = longName.substr(pos, longName.length());
+ }
+
+ return simpleName;
+}
+
+/***********************************************************************/
+
+inline string getPathName(string longName){
+
+ string rootPathName = longName;
+
+ if(longName.find_last_of("/") != longName.npos){
+ int pos = longName.find_last_of('/')+1;
+ rootPathName = longName.substr(0, pos);
+ }
+
+ return rootPathName;
+}
+
+/***********************************************************************/
+
+inline int openInputFile(string fileName, ifstream& fileHandle){
+
+ fileHandle.open(fileName.c_str());
+ if(!fileHandle) {
+ cerr << "Error: Could not open " << fileName << endl;
+ return 1;
+ }
+ else {
+ return 0;
+ }
+
+}
+
+/***********************************************************************/
+
+inline int openOutputFile(string fileName, ofstream& fileHandle){
+
+ fileHandle.open(fileName.c_str(), ios::trunc);
+ if(!fileHandle) {
+ cerr << "Error: Could not open " << fileName << endl;
+ return 1;
+ }
+ else {
+ return 0;
+ }
+
+}
+
+/***********************************************************************/
+
+//This function parses the estimator options and puts them in a vector
+inline void splitAtDash(string& estim, vector<string>& container) {
+ try {
+ string individual;
+
+ while (estim.find_first_of('-') != -1) {
+ individual = estim.substr(0,estim.find_first_of('-'));
+ if ((estim.find_first_of('-')+1) <= estim.length()) { //checks to make sure you don't have dash at end of string
+ estim = estim.substr(estim.find_first_of('-')+1, estim.length());
+ container.push_back(individual);
+ }
+ }
+ //get last one
+ container.push_back(estim);
+ }
+ catch(exception& e) {
+ cout << "Standard Error: " << e.what() << " has occurred in the mothur class Function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+ catch(...) {
+ cout << "An unknown error has occurred in the mothur class function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+
+}
+
+/***********************************************************************/
+//This function parses the label options and puts them in a set
+inline void splitAtDash(string& estim, set<string>& container) {
+ try {
+ string individual;
+
+ while (estim.find_first_of('-') != -1) {
+ individual = estim.substr(0,estim.find_first_of('-'));
+ if ((estim.find_first_of('-')+1) <= estim.length()) { //checks to make sure you don't have dash at end of string
+ estim = estim.substr(estim.find_first_of('-')+1, estim.length());
+ container.insert(individual);
+ }
+ }
+ //get last one
+ container.insert(estim);
+ }
+ catch(exception& e) {
+ cout << "Standard Error: " << e.what() << " has occurred in the mothur class Function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+ catch(...) {
+ cout << "An unknown error has occurred in the mothur class function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+
+}
+/***********************************************************************/
+//This function parses the line options and puts them in a set
+inline void splitAtDash(string& estim, set<int>& container) {
+ try {
+ string individual;
+ int lineNum;
+
+ while (estim.find_first_of('-') != -1) {
+ individual = estim.substr(0,estim.find_first_of('-'));
+ if ((estim.find_first_of('-')+1) <= estim.length()) { //checks to make sure you don't have dash at end of string
+ estim = estim.substr(estim.find_first_of('-')+1, estim.length());
+ convert(individual, lineNum); //convert the string to int
+ container.insert(lineNum);
+ }
+ }
+ //get last one
+ convert(estim, lineNum); //convert the string to int
+ container.insert(lineNum);
+ }
+ catch(exception& e) {
+ cout << "Standard Error: " << e.what() << " has occurred in the mothur class Function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+ catch(...) {
+ cout << "An unknown error has occurred in the mothur class function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+
+}
+/***********************************************************************/
+//This function parses the a string and puts peices in a vector
+inline void splitAtComma(string& estim, vector<string>& container) {
+ try {
+ string individual;
+
+ while (estim.find_first_of(',') != -1) {
+ individual = estim.substr(0,estim.find_first_of(','));
+ if ((estim.find_first_of(',')+1) <= estim.length()) { //checks to make sure you don't have comma at end of string
+ estim = estim.substr(estim.find_first_of(',')+1, estim.length());
+ container.push_back(individual);
+ }
+ }
+ //get last one
+ container.push_back(estim);
+ }
+ catch(exception& e) {
+ cout << "Standard Error: " << e.what() << " has occurred in the mothur class Function splitAtComma. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+ catch(...) {
+ cout << "An unknown error has occurred in the mothur class function splitAtComma. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+}
+/***********************************************************************/
+
+//This function splits up the various option parameters
+inline void splitAtComma(string& prefix, string& suffix){
+ try {
+ prefix = suffix.substr(0,suffix.find_first_of(','));
+ if ((suffix.find_first_of(',')+2) <= suffix.length()) { //checks to make sure you don't have comma at end of string
+ suffix = suffix.substr(suffix.find_first_of(',')+1, suffix.length());
+ string space = " ";
+ while(suffix.at(0) == ' ')
+ suffix = suffix.substr(1, suffix.length());
+ }
+
+ }
+ catch(exception& e) {
+ cout << "Standard Error: " << e.what() << " has occurred in the mothur class Function splitAtComma. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+ catch(...) {
+ cout << "An unknown error has occurred in the mothur class function splitAtComma. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+
+}
+/***********************************************************************/
+
+//This function separates the key value from the option value i.e. dist=96_...
+inline void splitAtEquals(string& key, string& value){
+ try {
+ if(value.find_first_of('=') != -1){
+ key = value.substr(0,value.find_first_of('='));
+ if ((value.find_first_of('=')+1) <= value.length()) {
+ value = value.substr(value.find_first_of('=')+1, value.length());
+ }
+ }else{
+ key = value;
+ value = 1;
+ }
+ }
+ catch(exception& e) {
+ cout << "Standard Error: " << e.what() << " has occurred in the mothur class Function splitAtEquals. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+ catch(...) {
+ cout << "An unknown error has occurred in the mothur class function splitAtEquals. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+
+}
+/**************************************************************************************************/
+
+inline bool inUsersGroups(string groupname, vector<string> Groups) {
+ try {
+ for (int i = 0; i < Groups.size(); i++) {
+ if (groupname == Groups[i]) { return true; }
+ }
+ return false;
+ }
+ catch(exception& e) {
+ cout << "Standard Error: " << e.what() << " has occurred in the mothur class Function inUsersGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+ catch(...) {
+ cout << "An unknown error has occurred in the mothur class function inUsersGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+}
+
+/**************************************************************************************************/
+
+
#endif
using namespace std;
#include "mothur.h"
-#include "utilities.hpp"
#include "listvector.hpp"
class NameAssignment : public map<string,int> {
using namespace std;
#include "ordervector.hpp"
-#include "utilities.hpp"
/***********************************************************************/
}
//set users groups to analyze
- setGroups();
+ util = new SharedUtil();
+ util->setGroups(globaldata->Groups, tmap->namesOfGroups, allGroups, numGroups, "unweighted"); //sets the groups the user wants to analyze
+ util->getCombos(groupComb, globaldata->Groups, numComp);
+ globaldata->setGroups("");
+
+ //ABC
+ if (numComp != 1) {
+ groupComb.push_back(allGroups);
+ numComp++;
+ }
+
convert(globaldata->getIters(), iters); //how many random trees to generate
pars = new Parsimony(tmap);
counter = 0;
//reset randomTree parameter to ""
globaldata->setRandomTree("");
//reset groups parameter
- globaldata->Groups.clear(); globaldata->setGroups("");
+ globaldata->Groups.clear();
return 0;
exit(1);
}
}
-/***********************************************************/
-
-void ParsimonyCommand::setGroups() {
- try {
- string allGroups = "";
- numGroups = 0;
- //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 (tmap->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 all the groups in your groupfile." << endl;
- for (int i = 0; i < tmap->namesOfGroups.size(); i++) {
- if (tmap->namesOfGroups[i] != "xxx") {
- allGroups += tmap->namesOfGroups[i] + "-";
- globaldata->Groups.push_back(tmap->namesOfGroups[i]);
- numGroups++;
- }
- }
- allGroups = allGroups.substr(0, allGroups.length()-1);
- }else {
- for (int i = 0; i < globaldata->Groups.size(); i++) {
- allGroups += globaldata->Groups[i] + "-";
- numGroups++;
- }
- allGroups = allGroups.substr(0, allGroups.length()-1);
- }
- }else{//user has enter "all" and wants the default groups
- globaldata->Groups.clear();
- for (int i = 0; i < tmap->namesOfGroups.size(); i++) {
- if (tmap->namesOfGroups[i] != "xxx") {
- globaldata->Groups.push_back(tmap->namesOfGroups[i]);
- numGroups++;
- allGroups += tmap->namesOfGroups[i] + "-";
- }
- }
- allGroups = allGroups.substr(0, allGroups.length()-1);
- globaldata->setGroups("");
- }
- }else {
- for (int i = 0; i < tmap->namesOfGroups.size(); i++) {
- if (tmap->namesOfGroups[i] != "xxx") {
- allGroups += tmap->namesOfGroups[i] + "-";
- }
- }
- allGroups = allGroups.substr(0, allGroups.length()-1);
- numGroups = 1;
- }
-
- //calculate number of comparsions
- numComp = 0;
- for (int r=0; r<numGroups; r++) {
- for (int l = r+1; l < numGroups; l++) {
- groupComb.push_back(globaldata->Groups[r]+ "-" +globaldata->Groups[l]);
- numComp++;
- }
- }
-
- //ABC
- if (numComp != 1) {
- groupComb.push_back(allGroups);
- numComp++;
- }
-
- }
- catch(exception& e) {
- cout << "Standard Error: " << e.what() << " has occurred in the ParsimonyCommand class Function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
- exit(1);
- }
- catch(...) {
- cout << "An unknown error has occurred in the ParsimonyCommand class function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
- exit(1);
- }
-
-}
/*****************************************************************/
void ParsimonyCommand::initFile(string label){
#include "parsimony.h"
#include "treemap.h"
#include "progress.hpp"
+#include "sharedutilities.h"
using namespace std;
public:
ParsimonyCommand();
- ~ParsimonyCommand() { delete pars; }
+ ~ParsimonyCommand() { delete pars; delete util; }
int execute();
private:
GlobalData* globaldata;
+ SharedUtil* util;
vector<Tree*> T; //user trees
Tree* randT; //random tree
Tree* copyUserTree;
TreeMap* savetmap;
Parsimony* pars;
vector<string> groupComb; // AB. AC, BC...
- string parsFile, parsFileout, sumFile, randomtree;
+ string parsFile, parsFileout, sumFile, randomtree, allGroups;
int iters, numGroups, numComp, counter;
vector<int> numEachGroup; //vector containing the number of sequences in each group the users wants for random distrib.
vector< vector<float> > userTreeScores; //scores for users trees for each comb.
void printParsimonyFile();
void printUSummaryFile();
void getUserInput();
- void setGroups();
void initFile(string);
void output(vector<double>);
void resetFile();
*/
#include "qstat.h"
-#include "calculator.h"
+
/***********************************************************************/
*/
using namespace std;
-
-#include "utilities.hpp"
#include "rabundvector.hpp"
#include "sabundvector.hpp"
#include "ordervector.hpp"
sabundvector = 2 1 1 0 0 1
ordervector = 1 1 1 1 1 1 2 2 2 3 3 4 5 */
+//class SAbundVector;
+//class OrderVector;
+
class RAbundVector : public DataVector {
public:
nIters++;
remove(tempInName.c_str());
- rename(tempOutName.c_str(), tempInName.c_str());
+ renameOk = rename(tempOutName.c_str(), tempInName.c_str());
+
+ //checks to make sure user was able to rename and remove successfully
+ if (renameOk != 0) { cout << "Unable to rename the necessary temp files." << endl; }
}
catch(exception& e) {
cout << "Standard Error: " << e.what() << " has occurred in the RareDisplay class Function reset. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
remove(tempInName.c_str());
remove(tempOutName.c_str());
-
+
nIters = 1;
output->resetFile();
}
string tempInName, tempOutName;
ifstream tempInFile;
ofstream tempOutFile;
+ int renameOk;
};
*/
#include "rarefact.h"
-#include "ordervector.hpp"
+//#include "ordervector.hpp"
/***********************************************************************/
#include "rarefactioncurvedata.h"
#include "raredisplay.h"
#include "ordervector.hpp"
-
+#include "mothur.h"
class Rarefact {
fileNameRoot = getRootName(globaldata->inputFileName);
format = globaldata->getFormat();
validCalculator = new ValidCalculators();
+ util = new SharedUtil();
int i;
for (i=0; i<globaldata->Estimators.size(); i++) {
delete input;
delete rCurve;
delete read;
+ delete util;
}
//**********************************************************************************************************************
}
//set users groups
- setGroups();
+ util->setGroups(globaldata->Groups, globaldata->gGroupmap->namesOfGroups, "rarefact");
while(order != NULL){
//**********************************************************************************************************************
-
-void RareFactSharedCommand::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) || (globaldata->Groups.size() == 1)) {
- cout << "When using the groups parameter you must have at least 2 valid groups. I will run the command using all the 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]);
- }
- }
-
- }
- catch(exception& e) {
- cout << "Standard Error: " << e.what() << " has occurred in the RareFactSharedCommand class Function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
- exit(1);
- }
- catch(...) {
- cout << "An unknown error has occurred in the RareFactSharedCommand class function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
- exit(1);
- }
-
-}
-/***********************************************************/
-
#include "display.h"
#include "readmatrix.hpp"
#include "validcalculator.h"
+#include "sharedutilities.h"
/* The rarefaction.shared() command:
The rarefaction command generates a rarefaction curve from a given file representing several groups.
int execute();
private:
- void setGroups();
GlobalData* globaldata;
+ SharedUtil* util;
SharedListVector* SharedList;
ReadMatrix* read;
SharedOrderVector* order;
using namespace std;
-#include "utilities.hpp"
#include "sparsematrix.hpp"
#include "progress.hpp"
#include "listvector.hpp"
*
*/
+#include "mothur.h"
#include "rabundvector.hpp"
#include "listvector.hpp"
#include "sharedlistvector.h"
using namespace std;
+#include "mothur.h"
#include "globaldata.hpp"
-#include "utilities.hpp"
#include "tree.h"
#define MAX_LINE 513
using namespace std;
#include "sabundvector.hpp"
-#include "utilities.hpp"
#include "calculator.h"
/***********************************************************************/
using namespace std;
+#include "mothur.h"
#include "sharedrabundvector.h"
#include "sharedlistvector.h"
#include "globaldata.hpp"
*/
#include "sharedbdiversity.h"
-#include "calculator.h"
/***********************************************************************/
*/
#include "sharedkstest.h"
-#include "calculator.h"
-#include <algorithm>
/***********************************************************************/
#include "sabundvector.hpp"
#include "rabundvector.hpp"
#include "ordervector.hpp"
-#include "utilities.hpp"
#include "sharedlistvector.h"
#include "sharedordervector.h"
*
*/
-
-
-
#include "calculator.h"
/***********************************************************************/
#include "sharedordervector.h"
-#include "utilities.hpp"
/***********************************************************************/
#define SHAREDORDER_H
/*
* sharedorder.h
- * Dotur
+ * Mothur
*
* Created by Sarah Westcott on 12/9/08.
* Copyright 2008 Schloss Lab UMASS Amherst. All rights reserved.
#include "sharedsabundvector.h"
#include "globaldata.hpp"
#include "groupmap.h"
+//#include "globaldata.hpp"
+
+class GlobalData;
class SharedOrderVector : public DataVector {
using namespace std;
#include "sharedrabundvector.h"
-#include "utilities.hpp"
#include "sabundvector.hpp"
#include "ordervector.hpp"
-#include <algorithm>
/***********************************************************************/
}
}
+/***********************************************************************/
+
+void SharedRAbundVector::insert(int binSize, int otu, string groupName){
+ try {
+ individual newGuy;
+ newGuy.abundance = binSize;
+ newGuy.group = groupName;
+ newGuy.bin = otu;
+
+ data.insert(data.begin()+otu, newGuy);
+ numBins++;
+
+ if(binSize > maxRank){
+ maxRank = binSize;
+ }
+
+ numSeqs += binSize;
+ }
+ catch(exception& e) {
+ cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function insert. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+ catch(...) {
+ cout << "An unknown error has occurred in the SharedRAbundVector class function insert. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+}
/***********************************************************************/
int numNZ();
void sortD(); //Sorts the data in descending order.
void push_front(int, int, string); //abundance, otu, groupname
+ void insert(int, int, string); //abundance, otu, groupname
void push_back(int, int, string); //abundance, otu, groupname
void pop_back();
void resize(int);
#include "sharedsabundvector.h"
#include "sabundvector.hpp"
-#include "utilities.hpp"
using namespace std;
--- /dev/null
+/*
+ * sharedutilities.cpp
+ * Mothur
+ *
+ * Created by Sarah Westcott on 4/9/09.
+ * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+#include "sharedutilities.h"
+#include "sharedrabundvector.h"
+#include "sharedordervector.h"
+
+/**************************************************************************************************/
+
+void SharedUtil::getSharedVectors(vector<string> Groups, vector<SharedRAbundVector*>& lookup, SharedOrderVector* order) {
+ try {
+
+ //delete each sharedrabundvector in lookup
+ for (int j = 0; j < lookup.size(); j++) {
+ delete lookup[j];
+ }
+
+ lookup.clear();
+
+ //create and initialize vector of sharedvectors, one for each group
+ for (int i = 0; i < Groups.size(); i++) {
+ SharedRAbundVector* temp = new SharedRAbundVector(order->getNumBins());
+ temp->setLabel(order->getLabel());
+ temp->setGroup(Groups[i]);
+ lookup.push_back(temp);
+ }
+
+ int numSeqs = order->size();
+ //sample all the members
+ for(int i=0;i<numSeqs;i++){
+ //get first sample
+ individual chosen = order->get(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 SharedUtil class Function getSharedVectors. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+ catch(...) {
+ cout << "An unknown error has occurred in the SharedUtil class function getSharedVectors. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+}
+
+/**************************************************************************************************/
+//need to have mode because different commands require different number of valid groups
+void SharedUtil::setGroups(vector<string>& userGroups, vector<string>& allGroups, string mode) {
+ try {
+ if (userGroups.size() != 0) {
+ if (userGroups[0] != "all") {
+ //check that groups are valid
+ for (int i = 0; i < userGroups.size(); i++) {
+ if (isValidGroup(userGroups[i], allGroups) != true) {
+ cout << userGroups[i] << " is not a valid group, and will be disregarded." << endl;
+ // erase the invalid group from userGroups
+ userGroups.erase(userGroups.begin()+i);
+ i--;
+ }
+ }
+
+ }else{//user has enter "all" and wants the default groups
+ userGroups.clear();
+ for (int i = 0; i < allGroups.size(); i++) {
+ userGroups.push_back(allGroups[i]);
+ }
+ }
+ }else { //the user has not entered groups
+ for (int i = 0; i < allGroups.size(); i++) {
+ userGroups.push_back(allGroups[i]);
+ }
+ }
+
+ if (mode == "venn") {
+ //if the user only entered invalid groups
+ if (userGroups.size() == 0) {
+ if (allGroups.size() > 4) {
+ cout << "When using the groups parameter you must have at least 1 valid group. I will run the command using the first four groups in your groupfile." << endl;
+ for (int i = 0; i < 4; i++) {
+ userGroups.push_back(allGroups[i]);
+ }
+ }else {
+ cout << "When using the groups parameter you must have at least 1 valid group. I will run the command using all the groups in your groupfile." << endl;
+ for (int i = 0; i < allGroups.size(); i++) {
+ userGroups.push_back(allGroups[i]);
+ }
+ }
+ }
+
+ //check to make sure their are only 4 groups
+ if (userGroups.size() > 4) {
+ cout << "You may only use up to 4 groups at a time with this command. I will choose the first four and disregard the rest." << endl;
+ for (int i = 4; i < userGroups.size(); i++) {
+ userGroups.erase(userGroups.begin()+i);
+ }
+ }
+ }else if (mode == "heat") {
+ //if the user only entered invalid groups
+ if (userGroups.size() == 0) {
+ cout << "When using the groups parameter you must have at least 1 valid groups. I will run the command using all the groups in your groupfile." << endl;
+ for (int i = 0; i < allGroups.size(); i++) {
+ userGroups.push_back(allGroups[i]);
+ }
+ }
+ }else if ((mode == "collect") || (mode == "rarefact") || (mode == "summary") || (mode == "treegroup")) {
+ //if the user only entered invalid groups
+ if ((userGroups.size() == 0) || (userGroups.size() == 1)) {
+ cout << "When using the groups parameter you must have at least 2 valid groups. I will run the command using all the groups in your groupfile." << endl;
+ for (int i = 0; i < allGroups.size(); i++) {
+ userGroups.push_back(allGroups[i]);
+ }
+ }
+ }
+
+ }
+ catch(exception& e) {
+ cout << "Standard Error: " << e.what() << " has occurred in the SharedUtil class Function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+ catch(...) {
+ cout << "An unknown error has occurred in the SharedUtil class function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+
+}
+
+/**************************************************************************************/
+//for parsimony and unifrac commands you set pairwise groups as well as an allgroups in calc
+void SharedUtil::setGroups(vector<string>& userGroups, vector<string>& allGroups, string& label, int& numGroups, string mode){ //globaldata->Groups, your tree or group map, allgroups, mode
+ try {
+ numGroups = 0;
+ label = "";
+ //if the user has not entered specific groups to analyze then do them all
+ if (userGroups.size() != 0) {
+ if (userGroups[0] != "all") {
+ //check that groups are valid
+ for (int i = 0; i < userGroups.size(); i++) {
+ if (isValidGroup(userGroups[i], allGroups) != true) {
+ cout << userGroups[i] << " is not a valid group, and will be disregarded." << endl;
+ // erase the invalid group from globaldata->Groups
+ userGroups.erase(userGroups.begin()+i);
+ i--;
+ }
+ }
+ }else { //users wants all groups
+ userGroups.clear();
+ for (int i=0; i < allGroups.size(); i++) {
+ if (allGroups[i] != "xxx") {
+ userGroups.push_back(allGroups[i]);
+ label += allGroups[i] + "-";
+ }
+ }
+ }
+ }else { //the user has not entered groups
+ for (int i=0; i < allGroups.size(); i++) {
+ if (allGroups[i] != "xxx") {
+ label += allGroups[i] + "-";
+ if (mode == "weighted") {
+ userGroups.push_back(allGroups[i]);
+ }else {
+ numGroups = 1;
+ }
+ }
+ }
+ }
+
+
+ if (mode == "weighted") {
+ //if the user only entered invalid groups
+ if (userGroups.size() == 0) {
+ for (int i=0; i < allGroups.size(); i++) {
+ if (allGroups[i] != "xxx") {
+ userGroups.push_back(allGroups[i]);
+ }
+ }
+ cout << "When using the groups parameter you must have at least 2 valid groups. I will run the command using all the groups in your groupfile." << endl;
+ }else if (userGroups.size() == 1) {
+ cout << "When using the groups parameter you must have at least 2 valid groups. I will run the command using all the groups in your groupfile." << endl;
+ userGroups.clear();
+ for (int i=0; i < allGroups.size(); i++) {
+ if (allGroups[i] != "xxx") {
+ userGroups.push_back(allGroups[i]);
+ }
+ }
+ }
+ numGroups = userGroups.size();
+
+ }else if ((mode == "unweighted") || (mode == "parsimony")) {
+ //if the user only entered invalid groups
+ if ((userGroups.size() == 0) && (numGroups == 0)) {
+ cout << "When using the groups parameter you must have at least 1 valid group. I will run the command using all the groups in your groupfile." << endl;
+ for (int i = 0; i < allGroups.size(); i++) {
+ if (allGroups[i] != "xxx") {
+ userGroups.push_back(allGroups[i]);
+ label += allGroups[i] + "-";
+ }
+ }
+ }else {
+ for (int i = 0; i < userGroups.size(); i++) {
+ label += userGroups[i] + "-";
+ }
+ }
+
+ //rip extra - off allgroups
+ label = label.substr(0, label.length()-1);
+
+ if (numGroups != 1) { numGroups = userGroups.size(); }
+
+ }
+ }
+ catch(exception& e) {
+ cout << "Standard Error: " << e.what() << " has occurred in the SharedUtil class Function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+ catch(...) {
+ cout << "An unknown error has occurred in the SharedUtil class function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+}
+/**************************************************************************************/
+void SharedUtil::getCombos(vector<string>& groupComb, vector<string> userGroups, int& numComp) { //groupcomb, globaldata->Groups, numcomb
+ try {
+ //calculate number of comparisons i.e. with groups A,B,C = AB, AC, BC = 3;
+ numComp = 0;
+ for (int i=0; i< userGroups.size(); i++) {
+ numComp += i;
+ for (int l = i+1; l < userGroups.size(); l++) {
+ //set group comparison labels
+ groupComb.push_back(userGroups[i] + "-" + userGroups[l]);
+ }
+ }
+ }
+ catch(exception& e) {
+ cout << "Standard Error: " << e.what() << " has occurred in the SharedUtil class Function getCombos. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+ catch(...) {
+ cout << "An unknown error has occurred in the SharedUtil class function getCombos. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+}
+/**************************************************************************************/
+bool SharedUtil::isValidGroup(string groupname, vector<string> groups) {
+ try {
+ for (int i = 0; i < groups.size(); i++) {
+ if (groupname == groups[i]) { return true; }
+ }
+
+ return false;
+ }
+ catch(exception& e) {
+ cout << "Standard Error: " << e.what() << " has occurred in the SharedUtil class Function isValidGroup. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+ catch(...) {
+ cout << "An unknown error has occurred in the SharedUtil class function isValidGroup. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+}
+
+/**************************************************************************************/
+void SharedUtil::updateGroupIndex(vector<string>& userGroups, map<string, int>& index) {
+ try {
+ index.clear();
+ for (int i = 0; i < userGroups.size(); i++) {
+ index[userGroups[i]] = i;
+ }
+ }
+ catch(exception& e) {
+ cout << "Standard Error: " << e.what() << " has occurred in the SharedUtil class Function updateGroupIndex. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+ catch(...) {
+ cout << "An unknown error has occurred in the SharedUtil class function updateGroupIndex. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+}
--- /dev/null
+#ifndef SHAREDUTIL_H
+#define SHAREDUTIL_H
+/*
+ * sharedutilities.h
+ * Mothur
+ *
+ * Created by Sarah Westcott on 4/9/09.
+ * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+#include "mothur.h"
+
+class SharedRAbundVector;
+class SharedOrderVector;
+
+/**************************************************************************************************/
+
+class SharedUtil {
+ public:
+ SharedUtil() {};
+ ~SharedUtil() {};
+
+ void getSharedVectors(vector<string>, vector<SharedRAbundVector*>&, SharedOrderVector*);
+ void setGroups(vector<string>&, vector<string>&, string); //globaldata->Groups, your tree or group map, mode
+ void setGroups(vector<string>&, vector<string>&, string&, int&, string); //globaldata->Groups, your tree or group map, allgroups, numGroups, mode
+ void getCombos(vector<string>&, vector<string>, int&); //groupcomb, globaldata->Groups, numcomb
+ void updateGroupIndex(vector<string>&, map<string, int>&); //globaldata->Groups, groupmap->groupIndex
+
+ private:
+
+ bool isValidGroup(string, vector<string>);
+};
+
+/**************************************************************************************************/
+
+
+
+#endif
\ No newline at end of file
+#include "mothur.h"
#include "cluster.hpp"
-#include "utilities.hpp"
+
#include "sparsematrix.hpp"
#include "listvector.hpp"
#ifndef SPARSEMATRIX_H
#define SPARSEMATRIX_H
-#include "utilities.hpp"
#include "mothur.h"
openOutputFile(outputFileName, outputFileHandle);
format = globaldata->getFormat();
validCalculator = new ValidCalculators();
+ util = new SharedUtil();
int i;
for (i=0; i<globaldata->Estimators.size(); i++) {
SummarySharedCommand::~SummarySharedCommand(){
delete input;
delete read;
+ delete util;
}
//**********************************************************************************************************************
}
//set users groups
- setGroups();
+ util->setGroups(globaldata->Groups, globaldata->gGroupmap->namesOfGroups, "summary");
//output estimator names as column headers
outputFileHandle << "label" <<'\t' << "comparison" << '\t';
if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(order->getLabel()) == 1){
cout << order->getLabel() << '\t' << count << endl;
- getSharedVectors(); //fills group vectors from order vector.
+ util->getSharedVectors(globaldata->Groups, lookup, order); //fills group vectors from order vector. //fills group vectors from order vector.
//randomize group order
if (globaldata->getJumble() == "1") { random_shuffle(lookup.begin(), lookup.end()); }
int n = 1;
for (int k = 0; k < (lookup.size() - 1); k++) { // pass cdd each set of groups to commpare
for (int l = n; l < lookup.size(); l++) {
- outputFileHandle << order->getLabel() << '\t' << (lookup[k]->getGroup() + lookup[l]->getGroup()) << '\t' << '\t'; //print out label and group
+
outputFileHandle << order->getLabel() << '\t';
//sort groups to be alphanumeric
}
}
-//**********************************************************************************************************************
-
-void SummarySharedCommand::getSharedVectors(){
-try {
- lookup.clear();
- //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]);
- lookup.push_back(temp);
- }
-
- int numSeqs = order->size();
- //sample all the members
- for(int i=0;i<numSeqs;i++){
- //get first sample
- individual chosen = order->get(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 SummarySharedCommand class Function getSharedVectors. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
- exit(1);
- }
- catch(...) {
- cout << "An unknown error has occurred in the SummarySharedCommand class function getSharedVectors. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
- exit(1);
- }
-
-}
-
-//**********************************************************************************************************************
-void SummarySharedCommand::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) || (globaldata->Groups.size() == 1)) {
- cout << "When using the groups parameter you must have at least 2 valid groups. I will run the command using all the 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]);
- }
- }
-
- }
- catch(exception& e) {
- cout << "Standard Error: " << e.what() << " has occurred in the SummarySharedCommand class Function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
- exit(1);
- }
- catch(...) {
- cout << "An unknown error has occurred in the SummarySharedCommand class function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
- exit(1);
- }
-
-}
/***********************************************************/
#include "readmatrix.hpp"
#include "sharedlistvector.h"
#include "validcalculator.h"
+#include "sharedutilities.h"
/*The summary.shared() command
The summary.shared command can only be executed after a successful read.shared command.
int execute();
private:
- void getSharedVectors();
- void setGroups();
-
GlobalData* globaldata;
ReadMatrix* read;
+ SharedUtil* util;
vector<Calculator*> sumCalculators;
InputData* input;
ValidCalculators* validCalculator;
SharedListVector* SharedList;
SharedOrderVector* order;
vector<SharedRAbundVector*> lookup;
- SharedRAbundVector* shared1, shared2;
string outputFileName, format;
ofstream outputFileHandle;
out << ",";
printBranch(tree[node].getRChild());
out << ")";
+ //if there is a branch length then print it
+ if (tree[node].getBranchLength() != -1) {
+ out << ":" << tree[node].getBranchLength();
+ }
}else { //you are a leaf
- out << tree[node].getGroup() << ":" << tree[node].getBranchLength();
+ out << tree[node].getGroup();
+ //if there is a branch length then print it
+ if (tree[node].getBranchLength() != -1) {
+ out << ":" << tree[node].getBranchLength();
+ }
}
}
using namespace std;
#include "mothur.h"
-#include "utilities.hpp"
#include "tree.h"
/* The tree calculator class is the parent class for tree calculators in mothur. */
--- /dev/null
+/*
+ * treegroupscommand.cpp
+ * Mothur
+ *
+ * Created by Sarah Westcott on 4/8/09.
+ * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+#include "treegroupscommand.h"
+#include "sharedjabund.h"
+#include "sharedsorabund.h"
+#include "sharedjclass.h"
+#include "sharedsorclass.h"
+#include "sharedjest.h"
+#include "sharedsorest.h"
+#include "sharedthetayc.h"
+#include "sharedthetan.h"
+#include "sharedmorisitahorn.h"
+
+
+//**********************************************************************************************************************
+
+TreeGroupCommand::TreeGroupCommand(){
+ try {
+ globaldata = GlobalData::getInstance();
+ format = globaldata->getFormat();
+ validCalculator = new ValidCalculators();
+ util = new SharedUtil();
+
+ int i;
+ for (i=0; i<globaldata->Estimators.size(); i++) {
+ if (validCalculator->isValidCalculator("treegroup", globaldata->Estimators[i]) == true) {
+ if (globaldata->Estimators[i] == "sharedjabund") {
+ treeCalculators.push_back(new SharedJAbund());
+ }else if (globaldata->Estimators[i] == "sharedsorensonabund") {
+ treeCalculators.push_back(new SharedSorAbund());
+ }else if (globaldata->Estimators[i] == "sharedjclass") {
+ treeCalculators.push_back(new SharedJclass());
+ }else if (globaldata->Estimators[i] == "sharedsorclass") {
+ treeCalculators.push_back(new SharedSorClass());
+ }else if (globaldata->Estimators[i] == "sharedjest") {
+ treeCalculators.push_back(new SharedJest());
+ }else if (globaldata->Estimators[i] == "sharedsorest") {
+ treeCalculators.push_back(new SharedSorEst());
+ }else if (globaldata->Estimators[i] == "sharedthetayc") {
+ treeCalculators.push_back(new SharedThetaYC());
+ }else if (globaldata->Estimators[i] == "sharedthetan") {
+ treeCalculators.push_back(new SharedThetaN());
+ }else if (globaldata->Estimators[i] == "sharedmorisitahorn") {
+ treeCalculators.push_back(new SharedMorHorn());
+ }
+ }
+ }
+
+ //reset calc for next command
+ globaldata->setCalc("");
+
+ }
+ catch(exception& e) {
+ cout << "Standard Error: " << e.what() << " has occurred in the TreeGroupCommand class Function TreeGroupCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+ catch(...) {
+ cout << "An unknown error has occurred in the TreeGroupCommand class function TreeGroupCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+}
+//**********************************************************************************************************************
+
+TreeGroupCommand::~TreeGroupCommand(){
+ delete input;
+ delete read;
+ delete util;
+}
+
+//**********************************************************************************************************************
+
+int TreeGroupCommand::execute(){
+ try {
+ int count = 1;
+ EstOutput data;
+
+ //if the users entered no valid calculators don't execute command
+ if (treeCalculators.size() == 0) { return 0; }
+
+ if (format == "sharedfile") {
+ read = new ReadPhilFile(globaldata->inputFileName);
+ read->read(&*globaldata);
+
+ input = globaldata->ginput;
+ order = input->getSharedOrderVector();
+ }else {
+ //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();
+ }
+
+ //set users groups
+ util->setGroups(globaldata->Groups, globaldata->gGroupmap->namesOfGroups, "treegroup");
+ numGroups = globaldata->Groups.size();
+ groupNames = "";
+ for (int i = 0; i < numGroups; i++) { groupNames += globaldata->Groups[i]; }
+
+ //clear globaldatas old tree names if any
+ globaldata->Treenames.clear();
+
+ //fills globaldatas tree names
+ globaldata->Treenames = globaldata->Groups;
+
+ //create treemap class from groupmap for tree class to use
+ tmap = new TreeMap();
+ tmap->makeSim(globaldata->gGroupmap);
+ globaldata->gTreemap = tmap;
+
+ while(order != NULL){
+
+ if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(order->getLabel()) == 1){
+
+ cout << order->getLabel() << '\t' << count << endl;
+ util->getSharedVectors(globaldata->Groups, lookup, order); //fills group vectors from order vector.
+
+ //for each calculator
+ for(int i = 0 ; i < treeCalculators.size(); i++) {
+
+ //initialize simMatrix
+ simMatrix.clear();
+ simMatrix.resize(numGroups);
+ for (int m = 0; m < simMatrix.size(); m++) {
+ for (int j = 0; j < simMatrix.size(); j++) {
+ simMatrix[m].push_back(0.0);
+ }
+ }
+
+ //initialize index
+ index.clear();
+ for (int g = 0; g < numGroups; g++) { index[g] = g; }
+
+ //create a new filename
+ outputFile = getRootName(globaldata->inputFileName) + treeCalculators[i]->getName() + "." + order->getLabel() + groupNames + ".tre";
+
+ for (int k = 0; k < lookup.size(); k++) { // pass cdd each set of groups to commpare
+ for (int l = k; l < lookup.size(); l++) {
+ if (k != l) { //we dont need to similiarity of a groups to itself
+ //get estimated similarity between 2 groups
+ data = treeCalculators[i]->getValues(lookup[k], lookup[l]); //saves the calculator outputs
+ //save values in similarity matrix
+ simMatrix[k][l] = data[0];
+ simMatrix[l][k] = data[0];
+ }
+ }
+ }
+
+ //creates tree from similarity matrix and write out file
+ createTree();
+ }
+ }
+
+ //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("");
+
+ return 0;
+ }
+ catch(exception& e) {
+ cout << "Standard Error: " << e.what() << " has occurred in the TreeGroupCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+ catch(...) {
+ cout << "An unknown error has occurred in the TreeGroupCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+}
+//**********************************************************************************************************************
+
+void TreeGroupCommand::createTree(){
+ try {
+ //create tree
+ t = new Tree();
+
+ //do merges and create tree structure by setting parents and children
+ //there are numGroups - 1 merges to do
+ for (int i = 0; i < (numGroups - 1); i++) {
+
+ float largest = 0.0;
+ int row, column;
+ //find largest value in sims matrix by searching lower triangle
+ for (int j = 1; j < simMatrix.size(); j++) {
+ for (int k = 0; k < j; k++) {
+ if (simMatrix[j][k] > largest) { largest = simMatrix[j][k]; row = j; column = k; }
+ }
+ }
+
+ //set non-leaf node info and update leaves to know their parents
+ //non-leaf
+ t->tree[numGroups + i].setChildren(index[row], index[column]);
+
+ //parents
+ t->tree[index[row]].setParent(numGroups + i);
+ t->tree[index[column]].setParent(numGroups + i);
+
+ //blength = distance / 2;
+ float blength = ((1.0 - largest) / 2);
+
+ //branchlengths
+ t->tree[index[row]].setBranchLength(blength - t->tree[index[row]].getLengthToLeaves());
+ t->tree[index[column]].setBranchLength(blength - t->tree[index[column]].getLengthToLeaves());
+
+ //set your length to leaves to your childs length plus branchlength
+ t->tree[numGroups + i].setLengthToLeaves(t->tree[index[row]].getLengthToLeaves() + t->tree[index[row]].getBranchLength());
+
+
+ //update index
+ index[row] = numGroups+i;
+ index[column] = numGroups+i;
+
+ //zero out highest value that caused the merge.
+ simMatrix[row][column] = 0.0;
+ simMatrix[column][row] = 0.0;
+
+ //merge values in simsMatrix
+ for (int n = 0; n < simMatrix.size(); n++) {
+ //row becomes merge of 2 groups
+ simMatrix[row][n] = (simMatrix[row][n] + simMatrix[column][n]) / 2;
+ simMatrix[n][row] = simMatrix[row][n];
+ //delete column
+ simMatrix[column][n] = 0.0;
+ simMatrix[n][column] = 0.0;
+ }
+ }
+
+ //assemble tree
+ t->assembleTree();
+
+ //print newick file
+ t->createNewickFile(outputFile);
+
+ //delete tree
+ delete t;
+
+ }
+ catch(exception& e) {
+ cout << "Standard Error: " << e.what() << " has occurred in the TreeGroupCommand class Function createTree. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+ catch(...) {
+ cout << "An unknown error has occurred in the TreeGroupCommand class function createTree. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+}
+/***********************************************************/
+void TreeGroupCommand::printSims() {
+ try {
+ cout << "simsMatrix" << endl;
+ for (int m = 0; m < simMatrix.size(); m++) {
+ for (int n = 0; n < simMatrix.size(); n++) {
+ cout << simMatrix[m][n] << '\t';
+ }
+ cout << endl;
+ }
+
+ }
+ catch(exception& e) {
+ cout << "Standard Error: " << e.what() << " has occurred in the TreeGroupCommand class Function printSims. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+ catch(...) {
+ cout << "An unknown error has occurred in the TreeGroupCommand class function printSims. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+}
+/***********************************************************/
+
+
--- /dev/null
+#ifndef TREEGROUPCOMMAND_H
+#define TREEGROUPCOMMAND_H
+
+/*
+ * treegroupscommand.h
+ * Mothur
+ *
+ * Created by Sarah Westcott on 4/8/09.
+ * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+#include "command.hpp"
+#include "sharedordervector.h"
+#include "sharedlistvector.h"
+#include "inputdata.h"
+#include "groupmap.h"
+#include "readmatrix.hpp"
+#include "validcalculator.h"
+#include "tree.h"
+#include "treemap.h"
+#include "sharedutilities.h"
+
+
+/* This command create a tree file for each similarity calculator at distance level, using various calculators to find the similiarity between groups.
+ The user can select the lines or labels they wish to use as well as the groups they would like included.
+ They can also use as many or as few calculators as they wish. */
+
+class GlobalData;
+
+class TreeGroupCommand : public Command {
+
+public:
+ TreeGroupCommand();
+ ~TreeGroupCommand();
+ int execute();
+
+private:
+ void createTree();
+ void printSims();
+
+ GlobalData* globaldata;
+ SharedUtil* util;
+ ReadMatrix* read;
+ TreeMap* tmap;
+ Tree* t;
+ vector<Calculator*> treeCalculators;
+ vector< vector<float> > simMatrix;
+ map<int, int> index; //maps row in simMatrix to vector index in the tree
+ InputData* input;
+ ValidCalculators* validCalculator;
+ SharedListVector* SharedList;
+ SharedOrderVector* order;
+ vector<SharedRAbundVector*> lookup;
+ string format, outputFile, groupNames;
+ int numGroups;
+
+};
+
+
+#endif
+
+
}
/************************************************************/
+void TreeMap::makeSim(GroupMap* groupmap) {
+ try {
+ //set names of groups
+ namesOfGroups = groupmap->namesOfGroups;
+
+ //set names of seqs to names of groups
+ namesOfSeqs = groupmap->namesOfGroups;
+
+ // make map where key and value are both the group name since that what the tree.groups command wants
+ for (int i = 0; i < namesOfGroups.size(); i++) {
+ treemap[namesOfGroups[i]].groupname = namesOfGroups[i];
+ seqsPerGroup[namesOfGroups[i]] = 1;
+ }
+
+ numGroups = namesOfGroups.size();
+
+ }
+ catch(exception& e) {
+ cout << "Standard Error: " << e.what() << " has occurred in the TreeMap class Function make. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+ catch(...) {
+ cout << "An unknown error has occurred in the TreeMap class function make. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+}
+/************************************************************/
+
*/
#include "mothur.h"
-#include "utilities.hpp"
+#include "groupmap.h"
/* This class is used by the read.tree command to build the tree container. */
int vectorIndex;
};
-
+class GroupMap;
class TreeMap {
public:
map<string,int> seqsPerGroup; //groupname, number of seqs in that group.
map<string, GroupIndex> treemap; //sequence name and <groupname, vector index>
void print(ostream&);
+ void makeSim(GroupMap*); //takes groupmap info and fills treemap for use by tree.groups command.
private:
parent = -1;
lchild = -1;
rchild = -1;
+ length2leaf = 0.0;
}
/****************************************************************/
/****************************************************************/
void Node::setBranchLength(float l) { branchLength = l; }
/****************************************************************/
+void Node::setLengthToLeaves(float l) { length2leaf = l; }
+/****************************************************************/
void Node::setParent(int p) { parent = p; }
/****************************************************************/
void Node::setIndex(int i) { vectorIndex = i; }
/****************************************************************/
float Node::getBranchLength() { return branchLength; }
/****************************************************************/
+float Node::getLengthToLeaves() { return length2leaf; }
+/****************************************************************/
int Node::getParent() { return parent; }
/****************************************************************/
int Node::getLChild() { return lchild; }
void setParent(int);
void setChildren(int, int); //leftchild, rightchild
void setIndex(int);
+ void setLengthToLeaves(float);
string getName();
string getGroup();
float getBranchLength();
+ float getLengthToLeaves();
int getParent();
int getLChild();
int getRChild();
private:
string name;
string group;
- float branchLength;
+ float branchLength, length2leaf;
int parent;
int lchild;
int rchild;
sumFile = globaldata->getTreeFile() + ".uwsummary";
openOutputFile(sumFile, outSum);
- setGroups(); //sets users groups to analyze
+ util = new SharedUtil();
+ util->setGroups(globaldata->Groups, tmap->namesOfGroups, allGroups, numGroups, "unweighted"); //sets the groups the user wants to analyze
+ util->getCombos(groupComb, globaldata->Groups, numComp);
+ globaldata->setGroups("");
+
+ //ABC
+ if (numComp != 1) {
+ groupComb.push_back(allGroups);
+ numComp++;
+ }
+
+
convert(globaldata->getIters(), iters); //how many random trees to generate
unweighted = new Unweighted(tmap);
UWScoreSig.clear();
}
//reset groups parameter
- globaldata->Groups.clear(); globaldata->setGroups("");
+ globaldata->Groups.clear();
outSum.close();
return 0;
exit(1);
}
}
-/***********************************************************/
-
-void UnifracUnweightedCommand::setGroups() {
- try {
- string allGroups = "";
- numGroups = 0;
- //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 (tmap->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 all the groups in your groupfile." << endl;
- for (int i = 0; i < tmap->namesOfGroups.size(); i++) {
- if (tmap->namesOfGroups[i] != "xxx") {
- globaldata->Groups.push_back(tmap->namesOfGroups[i]);
- numGroups++;
- allGroups += tmap->namesOfGroups[i] + "-";
- }
- }
- allGroups = allGroups.substr(0, allGroups.length()-1);
- }else {
- for (int i = 0; i < globaldata->Groups.size(); i++) {
- allGroups += globaldata->Groups[i] + "-";
- numGroups++;
- }
- allGroups = allGroups.substr(0, allGroups.length()-1);
- }
- }else{//user has enter "all" and wants the default groups
- globaldata->Groups.clear();
- for (int i = 0; i < tmap->namesOfGroups.size(); i++) {
- if (tmap->namesOfGroups[i] != "xxx") {
- globaldata->Groups.push_back(tmap->namesOfGroups[i]);
- numGroups++;
- allGroups += tmap->namesOfGroups[i] + "-";
- }
- }
- allGroups = allGroups.substr(0, allGroups.length()-1);
- globaldata->setGroups("");
- }
- }else {
- for (int i = 0; i < tmap->namesOfGroups.size(); i++) {
- if (tmap->namesOfGroups[i] != "xxx") {
- allGroups += tmap->namesOfGroups[i] + "-";
- }
- }
- allGroups = allGroups.substr(0, allGroups.length()-1);
- numGroups = 1;
- }
-
- //calculate number of comparsions
- numComp = 0;
- for (int r=0; r<numGroups; r++) {
- for (int l = r+1; l < numGroups; l++) {
- groupComb.push_back(globaldata->Groups[r]+ "-" + globaldata->Groups[l]);
- numComp++;
- }
- }
-
- //ABC
- if (numComp != 1) {
- groupComb.push_back(allGroups);
- numComp++;
- }
- }
- catch(exception& e) {
- cout << "Standard Error: " << e.what() << " has occurred in the UnifracUnweightedCommand class Function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
- exit(1);
- }
- catch(...) {
- cout << "An unknown error has occurred in the UnifracUnweightedCommand class function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
- exit(1);
- }
-
-}
/*****************************************************************/
void UnifracUnweightedCommand::initFile(string label){
#include "command.hpp"
#include "unweighted.h"
#include "treemap.h"
+#include "sharedutilities.h"
using namespace std;
public:
UnifracUnweightedCommand();
- ~UnifracUnweightedCommand() { delete unweighted; }
+ ~UnifracUnweightedCommand() { delete unweighted; delete util; }
int execute();
private:
GlobalData* globaldata;
+ SharedUtil* util;
vector<Tree*> T; //user trees
TreeMap* tmap;
Unweighted* unweighted;
- string sumFile, unweightedFile, unweightedFileout;
+ string sumFile, unweightedFile, unweightedFileout, allGroups;
vector<string> groupComb; // AB. AC, BC...
int iters, numGroups, numComp, counter;
EstOutput userData; //unweighted score info for user tree
void printUWSummaryFile();
void printUnweightedFile();
- void setGroups();
void initFile(string);
void output(vector<double>);
void resetFile();
sumFile = globaldata->getTreeFile() + ".wsummary";
openOutputFile(sumFile, outSum);
- setGroups(); //sets the groups the user wants to analyze
+ util = new SharedUtil();
+ string s; //to make work with setgroups
+ util->setGroups(globaldata->Groups, tmap->namesOfGroups, s, numGroups, "weighted"); //sets the groups the user wants to analyze
+ util->getCombos(groupComb, globaldata->Groups, numComp);
+ globaldata->setGroups("");
+
convert(globaldata->getIters(), iters); //how many random trees to generate
weighted = new Weighted(tmap);
counter = 0;
rScores.resize(numComp); //data[0] = weightedscore AB, data[1] = weightedscore AC...
uScores.resize(numComp); //data[0] = weightedscore AB, data[1] = weightedscore AC...
- weightedFile = globaldata->getTreeFile() + toString(i+1) + ".weighted";
- weightedFileout = globaldata->getTreeFile() + "temp." + toString(i+1) + ".weighted";
+ //weightedFile = globaldata->getTreeFile() + toString(i+1) + ".weighted";
+ //weightedFileout = globaldata->getTreeFile() + "temp." + toString(i+1) + ".weighted";
+ output = new ThreeColumnFile2(globaldata->getTreeFile() + toString(i+1) + ".weighted");
userData = weighted->getValues(T[i]); //userData[0] = weightedscore
calculateFreqsCumuls();
printWeightedFile();
+ delete output;
+
//clear data
rScores.clear();
uScores.clear();
void UnifracWeightedCommand::printWeightedFile() {
try {
vector<double> data;
+ vector<string> tags;
+ tags.push_back("Score"); tags.push_back("RandFreq"); tags.push_back("RandCumul");
for(int a = 0; a < numComp; a++) {
- initFile(groupComb[a]);
+ output->initFile(groupComb[a], tags);
//print each line
for (it = validScores.begin(); it != validScores.end(); it++) {
data.push_back(it->first); data.push_back(rScoreFreq[a][it->first]); data.push_back(rCumul[a][it->first]);
- output(data);
+ output->output(data);
data.clear();
}
- resetFile();
+ output->resetFile();
}
- out.close();
- inFile.close();
- remove(weightedFileout.c_str());
+ //out.close();
+ //inFile.close();
+ //remove(weightedFileout.c_str());
}
catch(exception& e) {
}
}
-/***********************************************************/
-void UnifracWeightedCommand::setGroups() {
- try {
- numGroups = 0;
- //if the user has not entered specific groups to analyze then do them all
- if (globaldata->Groups.size() == 0) {
- for (int i=0; i < tmap->getNumGroups(); i++) {
- if (tmap->namesOfGroups[i] != "xxx") {
- globaldata->Groups.push_back(tmap->namesOfGroups[i]);
- numGroups++;
- }
- }
- }else {
- if (globaldata->getGroups() != "all") {
- //check that groups are valid
- for (int i = 0; i < globaldata->Groups.size(); i++) {
- if (tmap->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) {
- for (int i=0; i < tmap->getNumGroups(); i++) {
- if (tmap->namesOfGroups[i] != "xxx") {
- globaldata->Groups.push_back(tmap->namesOfGroups[i]);
- numGroups++;
- }
- }
- cout << "When using the groups parameter you must have at least 2 valid groups. I will run the command using all the groups in your groupfile." << endl;
- }else if (globaldata->Groups.size() == 1) {
- cout << "When using the groups parameter you must have at least 2 valid groups. I will run the command using all the groups in your groupfile." << endl;
- globaldata->Groups.clear();
- for (int i=0; i < tmap->getNumGroups(); i++) {
- if (tmap->namesOfGroups[i] != "xxx") {
- globaldata->Groups.push_back(tmap->namesOfGroups[i]);
- numGroups++;
- }
- }
- }else { numGroups = globaldata->Groups.size(); }
- }else { //users wants all groups
- globaldata->Groups.clear();
- globaldata->setGroups("");
- for (int i=0; i < tmap->getNumGroups(); i++) {
- if (tmap->namesOfGroups[i] != "xxx") {
- globaldata->Groups.push_back(tmap->namesOfGroups[i]);
- numGroups++;
- }
- }
- }
- }
-
- //calculate number of comparisons i.e. with groups A,B,C = AB, AC, BC = 3;
- numComp = 0;
- for (int i=0; i<numGroups; i++) {
- numComp += i;
- for (int l = i+1; l < numGroups; l++) {
- //set group comparison labels
- groupComb.push_back(globaldata->Groups[i] + "-" + globaldata->Groups[l]);
- }
- }
- }
- catch(exception& e) {
- cout << "Standard Error: " << e.what() << " has occurred in the UnifracWeightedCommand class Function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
- exit(1);
- }
- catch(...) {
- cout << "An unknown error has occurred in the UnifracWeightedCommand class function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
- exit(1);
- }
-}
-
/***********************************************************/
void UnifracWeightedCommand::calculateFreqsCumuls() {
}
-/*****************************************************************/
+/*****************************************************************
void UnifracWeightedCommand::initFile(string label){
try {
}
}
-/***********************************************************************/
+/***********************************************************************
void UnifracWeightedCommand::output(vector<double> data){
try {
}
};
-/***********************************************************************/
+/***********************************************************************
void UnifracWeightedCommand::resetFile(){
try {
catch(...) {
cout << "An unknown error has occurred in the UnifracWeightedCommand class function resetFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
exit(1);
- }
+ }
+
+
+
}
+*/
+
+
+
+
#include "weighted.h"
#include "treemap.h"
#include "progress.hpp"
+#include "sharedutilities.h"
+#include "fileoutput.h"
using namespace std;
public:
UnifracWeightedCommand();
- ~UnifracWeightedCommand() { delete weighted; }
+ ~UnifracWeightedCommand() { delete weighted; delete util; }
int execute();
private:
GlobalData* globaldata;
+ SharedUtil* util;
+ FileOutput* output;
vector<Tree*> T; //user trees
vector<double> utreeScores; //user tree unweighted scores
vector<double> WScoreSig; //tree weighted score signifigance when compared to random trees - percentage of random trees with that score or lower.
void printWeightedFile();
//void removeValidScoresDuplicates();
int findIndex(float, int);
- void setGroups();
void calculateFreqsCumuls();
- void initFile(string);
- void output(vector<double>);
- void resetFile();
+ //void initFile(string);
+ //void output(vector<double>);
+ //void resetFile();
};
+++ /dev/null
-#ifndef UTILITIES_H
-#define UTILITIES_H
-
-using namespace std;
-
-#include "mothur.h"
-#include "treemap.h"
-
-typedef unsigned long long ull;
-
-/***********************************************************************/
-
-// snagged from http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.2
-// works for now, but there should be a way to do it without killing the whole program
-
-class BadConversion : public runtime_error {
-public:
- BadConversion(const string& s) : runtime_error(s){ }
-};
-
-//**********************************************************************************************************************
-
-template<typename T>
-inline void convert(const string& s, T& x, bool failIfLeftoverChars = true){
- istringstream i(s);
- char c;
- if (!(i >> x) || (failIfLeftoverChars && i.get(c)))
- throw BadConversion(s);
-}
-//**********************************************************************************************************************
-
-template<typename T>
-inline bool convertTest(const string& s, T& x, bool failIfLeftoverChars = true){
- istringstream i(s);
- char c;
- if (!(i >> x) || (failIfLeftoverChars && i.get(c)))
- {
- cout << "'" << s << "' is unable to be converted into an integer.\n";
- return false;
- }
- return true;
-}
-
-//**********************************************************************************************************************
-
-template<typename T>
-string toString(const T&x){
- stringstream output;
- output << x;
- return output.str();
-}
-
-//**********************************************************************************************************************
-
-template<typename T>
-string toHex(const T&x){
- stringstream output;
-
- output << hex << x;
-
- return output.str();
-}
-
-//**********************************************************************************************************************
-
-template<typename T>
-string toString(const T&x, int i){
- stringstream output;
-
- output.precision(i);
- output << fixed << x;
-
- return output.str();
-}
-
-
-/***********************************************************************/
-
-inline void gobble(istream& f){
-
- char d;
- while(isspace(d=f.get())) {;}
- f.putback(d);
-
-}
-
-/***********************************************************************/
-
-inline float roundDist(float dist, int precision){
-
- return int(dist * precision + 0.5)/float(precision);
-
-}
-
-/***********************************************************************/
-
-inline int getNumNames(string names){
-
- int count = 0;
-
- if(names != ""){
- count = 1;
- for(int i=0;i<names.size();i++){
- if(names[i] == ','){
- count++;
- }
- }
- }
-
- return count;
-
-}
-
-/**************************************************************************************************/
-
-inline vector<vector<double> > binomial(int maxOrder){
-
- vector<vector<double> > binomial(maxOrder+1);
-
- for(int i=0;i<=maxOrder;i++){
- binomial[i].resize(maxOrder+1);
- binomial[i][0]=1;
- binomial[0][i]=0;
- }
- binomial[0][0]=1;
-
- binomial[1][0]=1;
- binomial[1][1]=1;
-
- for(int i=2;i<=maxOrder;i++){
- binomial[1][i]=0;
- }
-
- for(int i=2;i<=maxOrder;i++){
- for(int j=1;j<=maxOrder;j++){
- if(i==j){ binomial[i][j]=1; }
- if(j>i) { binomial[i][j]=0; }
- else { binomial[i][j]=binomial[i-1][j-1]+binomial[i-1][j]; }
- }
- }
-
- return binomial;
-}
-
-/***********************************************************************/
-
-inline string getRootName(string longName){
-
- string rootName = longName;
-
- if(longName.find_last_of(".") != longName.npos){
- int pos = longName.find_last_of('.')+1;
- rootName = longName.substr(0, pos);
- }
-
- return rootName;
-}
-/***********************************************************************/
-
-inline string getSimpleName(string longName){
-
- string simpleName = longName;
-
- if(longName.find_last_of("/") != longName.npos){
- int pos = longName.find_last_of('/')+1;
- simpleName = longName.substr(pos, longName.length());
- }
-
- return simpleName;
-}
-
-/***********************************************************************/
-
-inline string getPathName(string longName){
-
- string rootPathName = longName;
-
- if(longName.find_last_of("/") != longName.npos){
- int pos = longName.find_last_of('/')+1;
- rootPathName = longName.substr(0, pos);
- }
-
- return rootPathName;
-}
-
-/***********************************************************************/
-
-inline int openInputFile(string fileName, ifstream& fileHandle){
-
- fileHandle.open(fileName.c_str());
- if(!fileHandle) {
- cerr << "Error: Could not open " << fileName << endl;
- return 1;
- }
- else {
- return 0;
- }
-
-}
-
-/***********************************************************************/
-
-inline int openOutputFile(string fileName, ofstream& fileHandle){
-
- fileHandle.open(fileName.c_str(), ios::trunc);
- if(!fileHandle) {
- cerr << "Error: Could not open " << fileName << endl;
- return 1;
- }
- else {
- return 0;
- }
-
-}
-
-/***********************************************************************/
-
-//This function parses the estimator options and puts them in a vector
-inline void splitAtDash(string& estim, vector<string>& container) {
- try {
- string individual;
-
- while (estim.find_first_of('-') != -1) {
- individual = estim.substr(0,estim.find_first_of('-'));
- if ((estim.find_first_of('-')+1) <= estim.length()) { //checks to make sure you don't have dash at end of string
- estim = estim.substr(estim.find_first_of('-')+1, estim.length());
- container.push_back(individual);
- }
- }
- //get last one
- container.push_back(estim);
- }
- catch(exception& e) {
- cout << "Standard Error: " << e.what() << " has occurred in the utilities class Function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
- exit(1);
- }
- catch(...) {
- cout << "An unknown error has occurred in the utilities class function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
- exit(1);
- }
-
-}
-
-/***********************************************************************/
-//This function parses the label options and puts them in a set
-inline void splitAtDash(string& estim, set<string>& container) {
- try {
- string individual;
-
- while (estim.find_first_of('-') != -1) {
- individual = estim.substr(0,estim.find_first_of('-'));
- if ((estim.find_first_of('-')+1) <= estim.length()) { //checks to make sure you don't have dash at end of string
- estim = estim.substr(estim.find_first_of('-')+1, estim.length());
- container.insert(individual);
- }
- }
- //get last one
- container.insert(estim);
- }
- catch(exception& e) {
- cout << "Standard Error: " << e.what() << " has occurred in the utilities class Function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
- exit(1);
- }
- catch(...) {
- cout << "An unknown error has occurred in the utilities class function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
- exit(1);
- }
-
-}
-/***********************************************************************/
-//This function parses the line options and puts them in a set
-inline void splitAtDash(string& estim, set<int>& container) {
- try {
- string individual;
- int lineNum;
-
- while (estim.find_first_of('-') != -1) {
- individual = estim.substr(0,estim.find_first_of('-'));
- if ((estim.find_first_of('-')+1) <= estim.length()) { //checks to make sure you don't have dash at end of string
- estim = estim.substr(estim.find_first_of('-')+1, estim.length());
- convert(individual, lineNum); //convert the string to int
- container.insert(lineNum);
- }
- }
- //get last one
- convert(estim, lineNum); //convert the string to int
- container.insert(lineNum);
- }
- catch(exception& e) {
- cout << "Standard Error: " << e.what() << " has occurred in the utilities class Function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
- exit(1);
- }
- catch(...) {
- cout << "An unknown error has occurred in the utilities class function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
- exit(1);
- }
-
-}
-/***********************************************************************/
-//This function parses the a string and puts peices in a vector
-inline void splitAtComma(string& estim, vector<string>& container) {
- try {
- string individual;
-
- while (estim.find_first_of(',') != -1) {
- individual = estim.substr(0,estim.find_first_of(','));
- if ((estim.find_first_of(',')+1) <= estim.length()) { //checks to make sure you don't have comma at end of string
- estim = estim.substr(estim.find_first_of(',')+1, estim.length());
- container.push_back(individual);
- }
- }
- //get last one
- container.push_back(estim);
- }
- catch(exception& e) {
- cout << "Standard Error: " << e.what() << " has occurred in the utilities class Function splitAtComma. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
- exit(1);
- }
- catch(...) {
- cout << "An unknown error has occurred in the utilities class function splitAtComma. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
- exit(1);
- }
-}
-/***********************************************************************/
-
-//This function splits up the various option parameters
-inline void splitAtComma(string& prefix, string& suffix){
- try {
- prefix = suffix.substr(0,suffix.find_first_of(','));
- if ((suffix.find_first_of(',')+2) <= suffix.length()) { //checks to make sure you don't have comma at end of string
- suffix = suffix.substr(suffix.find_first_of(',')+1, suffix.length());
- string space = " ";
- while(suffix.at(0) == ' ')
- suffix = suffix.substr(1, suffix.length());
- }
-
- }
- catch(exception& e) {
- cout << "Standard Error: " << e.what() << " has occurred in the utilities class Function splitAtComma. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
- exit(1);
- }
- catch(...) {
- cout << "An unknown error has occurred in the utilities class function splitAtComma. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
- exit(1);
- }
-
-}
-/***********************************************************************/
-
-//This function separates the key value from the option value i.e. dist=96_...
-inline void splitAtEquals(string& key, string& value){
- try {
- if(value.find_first_of('=') != -1){
- key = value.substr(0,value.find_first_of('='));
- if ((value.find_first_of('=')+1) <= value.length()) {
- value = value.substr(value.find_first_of('=')+1, value.length());
- }
- }else{
- key = value;
- value = 1;
- }
- }
- catch(exception& e) {
- cout << "Standard Error: " << e.what() << " has occurred in the utilities class Function splitAtEquals. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
- exit(1);
- }
- catch(...) {
- cout << "An unknown error has occurred in the utilities class function splitAtEquals. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
- exit(1);
- }
-
-}
-/**************************************************************************************************/
-
-inline bool inUsersGroups(string groupname, vector<string> Groups) {
- try {
- for (int i = 0; i < Groups.size(); i++) {
- if (groupname == Groups[i]) { return true; }
- }
- return false;
- }
- catch(exception& e) {
- cout << "Standard Error: " << e.what() << " has occurred in the utilities class Function inUsersGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
- exit(1);
- }
- catch(...) {
- cout << "An unknown error has occurred in the utilities class function inUsersGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
- exit(1);
- }
-}
-
-#endif
initialSharedSummary();
initialVennSingle();
initialVennShared();
+ initialTreeGroups();
}
catch(exception& e) {
cout << "Standard Error: " << e.what() << " has occurred in the ValidCalculator class Function ValidCalculator. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
}
cout << endl;
return false; }
+ }else if (parameter == "treegroup") {
+ //is it valid
+ if ((treegroup.find(calculator)) != (treegroup.end())) {
+ return true;
+ }else {
+ cout << calculator << " is not a valid estimator for the tree.groups command in shared mode and will be disregarded. Valid estimators are ";
+ for (it = treegroup.begin(); it != treegroup.end(); it++) {
+ cout << it->first << ", ";
+ }
+ cout << endl;
+ return false; }
+
//not a valid parameter
}else { return false; }
}
/********************************************************************/
+void ValidCalculators::initialTreeGroups() {
+ try {
+ treegroup["sharedjabund"] = "sharedjabund";
+ treegroup["sharedsorensonabund"] = "sharedsorensonabund";
+ treegroup["sharedjclass"] = "sharedjclass";
+ treegroup["sharedsorclass"] = "sharedsorclass";
+ treegroup["sharedjest"] = "sharedjest";
+ treegroup["sharedsorest"] = "sharedsorest";
+ treegroup["sharedthetayc"] = "sharedthetayc";
+ treegroup["sharedthetan"] = "sharedthetan";
+ treegroup["sharedmorisitahorn"] = "sharedmorisitahorn";
+ }
+ catch(exception& e) {
+ cout << "Standard Error: " << e.what() << " has occurred in the ValidCalculator class Function initialTreeGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+ catch(...) {
+ cout << "An unknown error has occurred in the ValidCalculator class function initialTreeGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+}
+
+
+/********************************************************************/
+
map<string, string> sharedsummary;
map<string, string> vennsingle;
map<string, string> vennshared;
+ map<string, string> treegroup;
map<string, string>::iterator it;
void initialSingle();
void initialSharedSummary();
void initialVennSingle();
void initialVennShared();
-
+ void initialTreeGroups();
};
#endif
commands["unifrac.weighted"] = "unifrac.weighted";
commands["unifrac.unweighted"] = "unifrac.unweighted";
commands["libshuff"] = "libshuff";
+ commands["tree.groups"] = "tree.groups";
commands["heatmap"] = "heatmap";
commands["venn"] = "venn";
commands["get.group"] = "get.group";
string unifracUnweightedArray[] = {"groups","iters"};
commandParameters["unifrac.unweighted"] = addParameters(unifracUnweightedArray, sizeof(unifracUnweightedArray)/sizeof(string));
- string heatmapArray[] = {"groups","line","label","sorted"};
+ string heatmapArray[] = {"groups","line","label","sorted","scaler"};
commandParameters["heatmap"] = addParameters(heatmapArray, sizeof(heatmapArray)/sizeof(string));
string vennArray[] = {"groups","line","label","calc"};
string getOTURepArray[] = {"fasta","list","line","label","name"};
commandParameters["get.oturep"] = addParameters(getOTURepArray, sizeof(getOTURepArray)/sizeof(string));
+ string treeGroupsArray[] = {"line","label","calc","groups"};
+ commandParameters["tree.groups"] = addParameters(treeGroupsArray, sizeof(treeGroupsArray)/sizeof(string));
+
string quitArray[] = {};
commandParameters["quit"] = addParameters(quitArray, sizeof(quitArray)/sizeof(string));
using namespace std;
#include "mothur.h"
-#include "utilities.hpp"
//This class contains a list of all valid parameters in Mothur.
//It has a function which will tell you if your parameter is valid.
try {
globaldata = GlobalData::getInstance();
format = globaldata->getFormat();
+ util = new SharedUtil();
}
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";
try {
//fills vector of sharedsabunds - lookup
- getSharedVectors(sharedorder);
+ util->getSharedVectors(globaldata->Groups, lookup, sharedorder); //fills group vectors from order vector.
/******************* 1 Group **************************/
if (lookup.size() == 1) {
//make a file for each calculator
for(int i=0;i<vCalcs.size();i++){
- string filenamesvg = globaldata->inputFileName + ".venn." + sharedorder->getLabel() + vCalcs[i]->getName() + "." + groupComb + ".svg";
+ string filenamesvg = getRootName(globaldata->inputFileName) + sharedorder->getLabel() + ".venn." + vCalcs[i]->getName() + ".svg";
openOutputFile(filenamesvg, outsvg);
//in essence you want to run it like a single
outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"700\" height=\"700\"/>";
outsvg << "<text fill=\"black\" class=\"seri\" x=\"265\" y=\"30\">Venn Diagram at distance " + sharedorder->getLabel() + "</text>\n";
outsvg << "<circle fill=\"red\" opacity=\".5\" stroke=\"black\" cx=\"350\" cy=\"200\" r=\"150\"/>";
+ outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)lookup[0]->getGroup().length() / 2)) + "\" y=\"165\">" + lookup[0]->getGroup() + "</text>\n";
outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)toString(data[0]).length() / 2)) + "\" y=\"195\">" + toString(data[0]) + "</text>\n";
if (data.size() == 3) {
//make a file for each calculator
for(int i=0;i<vCalcs.size();i++){
- string filenamesvg = globaldata->inputFileName + ".venn." + sharedorder->getLabel() + vCalcs[i]->getName() + "." + groupComb + ".svg";
+ string filenamesvg = getRootName(globaldata->inputFileName) + sharedorder->getLabel() + ".venn." + vCalcs[i]->getName() + ".svg";
openOutputFile(filenamesvg, outsvg);
//get estimates for sharedAB
outsvg << "<circle fill=\"rgb(0,255,0)\" opacity=\".3\" stroke=\"black\" cx=\"435\" cy=\"200\" r=\"150\"/>";
outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(200 - ((int)toString(numA[0]).length() / 2)) + "\" y=\"195\">" + toString(numA[0] - shared[0]) + "</text>\n";
outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(490 - ((int)toString(numB[0]).length() / 2)) + "\" y=\"195\">" + toString(numB[0] - shared[0]) + "</text>\n";
+ outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(200 - ((int)lookup[0]->getGroup().length() / 2)) + "\" y=\"175\">" + lookup[0]->getGroup() + "</text>\n";
+ outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(490 - ((int)lookup[1]->getGroup().length() / 2)) + "\" y=\"175\">" + lookup[1]->getGroup() + "</text>\n";
outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)toString(shared[0]).length() / 2)) + "\" y=\"195\">" + toString(shared[0]) + "</text>\n";
- outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"460\">The number of species in group " + globaldata->Groups[0] + " is " + toString(numA[0]) + "</text>\n";
- outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"480\">The number of species in group " + globaldata->Groups[1] + " is " + toString(numB[0]) + "</text>\n";
+ outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"460\">The number of species in group " + globaldata->Groups[0] + " is " + toString(numA[0]);
+ if (numA.size() == 3) {
+ outsvg << " the lci is " + toString(numA[1]) + " and the hci is " + toString(numA[2]) + "</text>\n";
+ }else { outsvg << "</text>\n"; }
+
+ outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"480\">The number of species in group " + globaldata->Groups[1] + " is " + toString(numB[0]);
+ if (numB.size() == 3) {
+ outsvg << " the lci is " + toString(numB[1]) + " and the hci is " + toString(numB[2]) + "</text>\n";
+ }else { outsvg << "</text>\n"; }
+
outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"500\">The number of sepecies shared between groups " + globaldata->Groups[0] + " and " + globaldata->Groups[1] + " is " + toString(shared[0]) + "</text>\n";
outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"520\">Percentage of species that are shared in groups " + globaldata->Groups[0] + " and " + globaldata->Groups[1] + " is " + toString((shared[0] / (float)(numA[0] + numB[0] - shared[0]))) + "</text>\n";
+ outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"540\">The total richness for all groups is " + toString((float)(numA[0] + numB[0] - shared[0])) + "</text>\n";
//close file
outsvg << "</g>\n</svg>\n";
//make a file for each calculator
for(int i=0;i<vCalcs.size();i++){
- string filenamesvg = globaldata->inputFileName + ".venn." + sharedorder->getLabel() + vCalcs[i]->getName() + "." + groupComb + ".svg";
+ string filenamesvg = getRootName(globaldata->inputFileName) + sharedorder->getLabel() + ".venn." + vCalcs[i]->getName() + ".svg";
openOutputFile(filenamesvg, outsvg);
//get estimates for sharedAB, sharedAC and sharedBC
outsvg << "<circle fill=\"rgb(0,0,255)\" opacity=\".3\" stroke=\"black\" cx=\"343\" cy=\"400\" r=\"150\"/>";
//place labels within overlaps
- outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(200 - ((int)toString(numA[0]-sharedAwithBC[0]).length() / 2)) + "\" y=\"170\">" + toString(numA[0]-sharedAwithBC[0]) + "</text>\n";
+ outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(200 - ((int)toString(numA[0]-sharedAwithBC[0]).length() / 2)) + "\" y=\"170\">" + toString(numA[0]-sharedAwithBC[0]) + "</text>\n";
+ outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(200 - ((int)lookup[0]->getGroup().length() / 2)) + "\" y=\"150\">" + lookup[0]->getGroup() + "</text>\n";
outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)toString(sharedAB[0] - sharedABC).length() / 2)) + "\" y=\"170\">" + toString(sharedAB[0] - sharedABC) + "</text>\n";
- outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(485 - ((int)toString(numB[0]-sharedBwithAC[0]).length() / 2)) + "\" y=\"170\">" + toString(numB[0]-sharedBwithAC[0]) + "</text>\n";
+ outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(485 - ((int)toString(numB[0]-sharedBwithAC[0]).length() / 2)) + "\" y=\"170\">" + toString(numB[0]-sharedBwithAC[0]) + "</text>\n";
+ outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(485 - ((int)lookup[1]->getGroup().length() / 2)) + "\" y=\"150\">" + lookup[1]->getGroup() + "</text>\n";
outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(268 - ((int)toString(sharedAC[0] - sharedABC).length() / 2)) + "\" y=\"305\">" + toString(sharedAC[0] - sharedABC) + "</text>\n";
- outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)toString(numC[0]-sharedCwithAB[0]).length() / 2)) + "\" y=\"430\">" + toString(numC[0]-sharedCwithAB[0]) + "</text>\n";
+ outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)toString(numC[0]-sharedCwithAB[0]).length() / 2)) + "\" y=\"430\">" + toString(numC[0]-sharedCwithAB[0]) + "</text>\n";
+ outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)lookup[2]->getGroup().length() / 2)) + "\" y=\"410\">" + lookup[2]->getGroup() + "</text>\n";
outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(408 - ((int)toString(sharedBC[0] - sharedABC).length() / 2)) + "\" y=\"305\">" + toString(sharedBC[0] - sharedABC) + "</text>\n";
outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)toString(sharedABC).length() / 2)) + "\" y=\"280\">" + toString(sharedABC) + "</text>\n";
outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"720\">The number of sepecies shared between groups " + globaldata->Groups[0] + " and combined groups " + globaldata->Groups[1] + globaldata->Groups[2] + " is " + toString(sharedAwithBC[0]) + "</text>\n";
outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"740\">The number of sepecies shared between groups " + globaldata->Groups[1] + " and combined groups " + globaldata->Groups[0] + globaldata->Groups[2] + " is " + toString(sharedBwithAC[0]) + "</text>\n";
outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"760\">The number of sepecies shared between groups " + globaldata->Groups[2] + " and combined groups " + globaldata->Groups[0] + globaldata->Groups[1] + " is " + toString(sharedCwithAB[0]) + "</text>\n";
- outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"580\">The number of species in group " + globaldata->Groups[0] + " is " + toString(numA[0]) + "</text>\n";
- outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"600\">The number of species in group " + globaldata->Groups[1] + " is " + toString(numB[0]) + "</text>\n";
- outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"620\">The number of species in group " + globaldata->Groups[2] + " is " + toString(numC[0]) + "</text>\n";
- outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"640\">The total number of species in all groups is " + toString(numA[0] + numB[0] + numC[0] - sharedAB[0] - sharedAC[0] - sharedBC[0] + sharedABC) + "</text>\n";
+ outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"580\">The number of species in group " + globaldata->Groups[0] + " is " + toString(numA[0]);
+ if (numA.size() == 3) {
+ outsvg << " the lci is " + toString(numA[1]) + " and the hci is " + toString(numA[2]) + "</text>\n";
+ }else { outsvg << "</text>\n"; }
+
+ outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"600\">The number of species in group " + globaldata->Groups[1] + " is " + toString(numB[0]);
+ if (numB.size() == 3) {
+ outsvg << " the lci is " + toString(numB[1]) + " and the hci is " + toString(numB[2]) + "</text>\n";
+ }else { outsvg << "</text>\n"; }
+
+ outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"620\">The number of species in group " + globaldata->Groups[2] + " is " + toString(numC[0]);
+ if (numC.size() == 3) {
+ outsvg << " the lci is " + toString(numC[1]) + " and the hci is " + toString(numC[2]) + "</text>\n";
+ }else { outsvg << "</text>\n"; }
+
+ outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"640\">The total richness of all the groups is " + toString(numA[0] + numB[0] + numC[0] - sharedAB[0] - sharedAC[0] - sharedBC[0] + sharedABC) + "</text>\n";
//close file
outsvg << "</g>\n</svg>\n";
if ((lookup[0]->getAbundance(i) != 0) && (lookup[1]->getAbundance(i) != 0) && (lookup[2]->getAbundance(i) != 0) && (lookup[3]->getAbundance(i) != 0)) { sharedABCD++; }
}
- string filenamesvg = globaldata->inputFileName + ".venn." + sharedorder->getLabel() + "." + groupComb + ".svg";
+ string filenamesvg = getRootName(globaldata->inputFileName) + sharedorder->getLabel() + ".venn.SharedSobs.svg";
openOutputFile(filenamesvg, outsvg);
//image window
//A = red, B = green, C = blue, D = yellow
//place labels within overlaps
- outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(460 - ((int)toString(numA).length() / 2)) + "\" y=\"110\">" + toString(numA) + "</text>\n";
+ outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(460 - ((int)toString(numA).length() / 2)) + "\" y=\"110\">" + toString(numA) + "</text>\n";
+ outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(460 - ((int)lookup[0]->getGroup().length() / 2)) + "\" y=\"90\">" + lookup[0]->getGroup() + "</text>\n";
outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(350 - ((int)toString(sharedAB).length() / 2)) + "\" y=\"160\">" + toString(sharedAB) + "</text>\n";
outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(250 - ((int)toString(numB).length() / 2)) + "\" y=\"110\">" + toString(numB) + "</text>\n";
+ outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(250 - ((int)lookup[1]->getGroup().length() / 2)) + "\" y=\"90\">" + lookup[1]->getGroup() + "</text>\n";
outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(490 - ((int)toString(sharedAC).length() / 2)) + "\" y=\"190\">" + toString(sharedAC) + "</text>\n";
outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(550 - ((int)toString(numC).length() / 2)) + "\" y=\"230\">" + toString(numC) + "</text>\n";
+ outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(550 - ((int)lookup[2]->getGroup().length() / 2)) + "\" y=\"210\">" + lookup[2]->getGroup() + "</text>\n";
outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(215 - ((int)toString(sharedBC).length() / 2)) + "\" y=\"190\">" + toString(sharedBC) + "</text>\n";
- outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(150 - ((int)toString(numC).length() / 2)) + "\" y=\"230\">" + toString(numD) + "</text>\n";
+ outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(150 - ((int)toString(numD).length() / 2)) + "\" y=\"230\">" + toString(numD) + "</text>\n";
+ outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(150 - ((int)lookup[3]->getGroup().length() / 2)) + "\" y=\"210\">" + lookup[3]->getGroup() + "</text>\n";
outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(240 - ((int)toString(sharedBC).length() / 2)) + "\" y=\"325\">" + toString(sharedAD) + "</text>\n";
outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(470 - ((int)toString(sharedBC).length() / 2)) + "\" y=\"325\">" + toString(sharedBD) + "</text>\n";
outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(350 - ((int)toString(sharedCD).length() / 2)) + "\" y=\"430\">" + toString(sharedCD) + "</text>\n";
outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(305 - ((int)toString(sharedACD).length() / 2)) + "\" y=\"360\">" + toString(sharedACD) + "</text>\n";
outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(440 - ((int)toString(sharedABC).length() / 2)) + "\" y=\"240\">" + toString(sharedABC) + "</text>\n";
outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(350 - ((int)toString(sharedABCD).length() / 2)) + "\" y=\"320\">" + toString(sharedABCD) + "</text>\n";
+ outsvg << "<text fill=\"black\" class=\"seri\" x=\"250\" y=\"490\">The total richness of all the groups is " + toString((float)(numA + numB + numC + numD + sharedAB + sharedAC + sharedAD + sharedBC + sharedBD + sharedCD + sharedABC + sharedABD + sharedACD + sharedBCD + sharedABCD)) + "</text>\n";
- //outsvg << "<text fill=\"black\" class=\"seri\" x=\"100\" y=\"490\">Percentage of species that are shared in groups " + globaldata->Groups[0] + " and " + globaldata->Groups[1] + " is " + toString(((sharedAB + sharedABD + sharedABC + sharedABCD) / (float)(numA + numB + sharedAB + sharedAC + sharedAD + sharedBC + sharedBD + sharedABC + sharedABD + sharedACD + sharedBCD + sharedABCD))) + "</text>\n";
//outsvg << "<text fill=\"black\" class=\"seri\" x=\"100\" y=\"510\">Percentage of species that are shared in groups " + globaldata->Groups[0] + " and " + globaldata->Groups[2] + " is " + toString(((sharedAC + sharedACD + sharedABC + sharedABCD) / (float)(numA + numC + sharedAB + sharedAC + sharedAD + sharedBC + sharedCD + sharedABC + sharedABD + sharedACD + sharedBCD + sharedABCD))) + "</text>\n";
//outsvg << "<text fill=\"black\" class=\"seri\" x=\"100\" y=\"530\">Percentage of species that are shared in groups " + globaldata->Groups[0] + " and " + globaldata->Groups[3] + " is " + toString(((sharedAD + sharedACD + sharedABD + sharedABCD) / (float)(numA + numD + sharedAB + sharedAC + sharedAD + sharedBD + sharedCD + sharedABC + sharedABD + sharedACD + sharedBCD + sharedABCD))) + "</text>\n";
//outsvg << "<text fill=\"black\" class=\"seri\" x=\"100\" y=\"550\">Percentage of species that are shared in groups " + globaldata->Groups[1] + " and " + globaldata->Groups[2] + " is " + toString(((sharedBC + sharedABC + sharedBCD + sharedABCD) / (float)(numB + numC + sharedAB + sharedAC + sharedCD + sharedBD + sharedBC + sharedABC + sharedABD + sharedACD + sharedBCD + sharedABCD))) + "</text>\n";
outsvg.close();
}
-
-
-
-
}
catch(exception& e) {
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;i<numSeqs;i++){
- //get first sample
- individual chosen = order->get(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);
- }
-}
#include "datavector.hpp"
#include "globaldata.hpp"
#include "calculator.h"
+#include "sharedutilities.h"
/***********************************************************************/
void getPic(SharedOrderVector*, vector<Calculator*>);
private:
- void getSharedVectors(SharedOrderVector*);
-
+ SharedUtil* util;
SAbundVector* sabund;
GlobalData* globaldata;
vector<SharedRAbundVector*> lookup;
#include "ace.h"
#include "sobs.h"
#include "chao1.h"
-#include "jackknife.h"
+//#include "jackknife.h"
#include "sharedsobscollectsummary.h"
#include "sharedchao1.h"
#include "sharedace.h"
globaldata = GlobalData::getInstance();
format = globaldata->getFormat();
validCalculator = new ValidCalculators();
+ util = new SharedUtil();
int i;
if(abund < 5)
abund = 10;
vennCalculators.push_back(new Ace(abund));
- }else if (globaldata->Estimators[i] == "jack") {
- vennCalculators.push_back(new Jackknife());
+ //}else if (globaldata->Estimators[i] == "jack") {
+ //vennCalculators.push_back(new Jackknife());
}
}
}
delete input;
delete read;
delete venn;
+ delete util;
}
//**********************************************************************************************************************
if (format != "list") {
- setGroups();
+ util->setGroups(globaldata->Groups, globaldata->gGroupmap->namesOfGroups, "venn");
+ globaldata->setGroups("");
while(order != NULL){
}
//reset groups parameter
- globaldata->Groups.clear(); globaldata->setGroups("");
+ globaldata->Groups.clear();
}else{
while(ordersingle != NULL){
}
//**********************************************************************************************************************
-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) {
- if (globaldata->gGroupmap->namesOfGroups.size() > 4) {
- cout << "When using the groups parameter you must have at least 1 valid group. I will run the command using the first four groups in your groupfile." << endl;
- for (int i = 0; i < 4; i++) {
- globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]);
- }
- }else {
- cout << "When using the groups parameter you must have at least 1 valid group. I will run the command using all the 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() > 4) {
- cout << "You may only use up to 4 groups at a time with this command. I will choose the first four and disregard the rest." << endl;
- for (int i = 4; 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);
- }
-
-}
-/***********************************************************/
#include "sharedlistvector.h"
#include "venn.h"
#include "validcalculator.h"
+#include "sharedutilities.h"
class GlobalData;
private:
GlobalData* globaldata;
ReadMatrix* read;
+ SharedUtil* util;
InputData* input;
SharedListVector* SharedList;
SharedOrderVector* order;
vector<Calculator*> vennCalculators;
ValidCalculators* validCalculator;
int abund;
-
- void setGroups();
};