375AA1390F9E433D008EF9B8 /* readcolumn.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 375AA1330F9E433D008EF9B8 /* readcolumn.cpp */; };
375AA13A0F9E433D008EF9B8 /* readotu.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 375AA1350F9E433D008EF9B8 /* readotu.cpp */; };
375AA13B0F9E433D008EF9B8 /* readphylip.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 375AA1370F9E433D008EF9B8 /* readphylip.cpp */; };
- 377326650FAF16E0007ABB8B /* concensuscommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 377326630FAF16E0007ABB8B /* concensuscommand.cpp */; };
+ 377326650FAF16E0007ABB8B /* consensuscommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 377326630FAF16E0007ABB8B /* consensuscommand.cpp */; };
378598660FDD497000EF9D03 /* heatmapsimcommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 378598650FDD497000EF9D03 /* heatmapsimcommand.cpp */; };
378598740FDD4C1500EF9D03 /* heatmapsim.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 378598730FDD4C1500EF9D03 /* heatmapsim.cpp */; };
378599100FDD7E8E00EF9D03 /* optionparser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3785990F0FDD7E8E00EF9D03 /* optionparser.cpp */; };
375AA1360F9E433D008EF9B8 /* readotu.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = readotu.h; sourceTree = SOURCE_ROOT; };
375AA1370F9E433D008EF9B8 /* readphylip.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = readphylip.cpp; sourceTree = SOURCE_ROOT; };
375AA1380F9E433D008EF9B8 /* readphylip.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = readphylip.h; sourceTree = SOURCE_ROOT; };
- 377326630FAF16E0007ABB8B /* concensuscommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = concensuscommand.cpp; sourceTree = SOURCE_ROOT; };
- 377326640FAF16E0007ABB8B /* concensuscommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = concensuscommand.h; sourceTree = SOURCE_ROOT; };
+ 377326630FAF16E0007ABB8B /* consensuscommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = consensuscommand.cpp; sourceTree = "<group>"; };
+ 377326640FAF16E0007ABB8B /* consensuscommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = consensuscommand.h; sourceTree = "<group>"; };
378598640FDD497000EF9D03 /* heatmapsimcommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = heatmapsimcommand.h; sourceTree = SOURCE_ROOT; };
378598650FDD497000EF9D03 /* heatmapsimcommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = heatmapsimcommand.cpp; sourceTree = SOURCE_ROOT; };
378598720FDD4C1500EF9D03 /* heatmapsim.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = heatmapsim.h; sourceTree = SOURCE_ROOT; };
37D927C70F21331F001D4494 /* collectcommand.cpp */,
37D927CC0F21331F001D4494 /* collectsharedcommand.h */,
37D927CB0F21331F001D4494 /* collectsharedcommand.cpp */,
- 377326640FAF16E0007ABB8B /* concensuscommand.h */,
- 377326630FAF16E0007ABB8B /* concensuscommand.cpp */,
+ 377326640FAF16E0007ABB8B /* consensuscommand.h */,
+ 377326630FAF16E0007ABB8B /* consensuscommand.cpp */,
37B28F660F27590100808A62 /* deconvolutecommand.h */,
37B28F670F27590100808A62 /* deconvolutecommand.cpp */,
37C753CC0FB3415200DBD02E /* distancecommand.h */,
375AA13B0F9E433D008EF9B8 /* readphylip.cpp in Sources */,
7EC3D4550FA0FFF900338DA5 /* coverage.cpp in Sources */,
7EC3D4560FA0FFF900338DA5 /* whittaker.cpp in Sources */,
- 377326650FAF16E0007ABB8B /* concensuscommand.cpp in Sources */,
+ 377326650FAF16E0007ABB8B /* consensuscommand.cpp in Sources */,
378C1B030FB0644E004D63F5 /* filterseqscommand.cpp in Sources */,
378C1B040FB0644E004D63F5 /* goodscoverage.cpp in Sources */,
378C1B0A0FB0644E004D63F5 /* sequencedb.cpp in Sources */,
//creates tree from similarity matrix and write out file
createTree(out[i], tempTree);
- //save trees for concensus command.
+ //save trees for consensus command.
trees[i].push_back(tempTree);
}
}
globaldata->clear();
- //create concensus trees for each bootstrapped tree set
+ //create consensus trees for each bootstrapped tree set
for (int k = 0; k < trees.size(); k++) {
- mothurOut("Generating concensus tree for " + treeCalculators[k]->getName()); mothurOutEndLine();
+ mothurOut("Generating consensus tree for " + treeCalculators[k]->getName()); mothurOutEndLine();
//set global data to calc trees
globaldata->gTree = trees[k];
string filename = getRootName(globaldata->inputFileName) + treeCalculators[k]->getName() + ".boot" + order->getLabel();
- concensus = new ConcensusCommand(filename);
- concensus->execute();
- delete concensus;
+ consensus = new ConcensusCommand(filename);
+ consensus->execute();
+ delete consensus;
//delete globaldata's tree
for (int m = 0; m < globaldata->gTree.size(); m++) { delete globaldata->gTree[m]; }
#include "tree.h"
#include "treemap.h"
#include "sharedutilities.h"
-#include "concensuscommand.h"
+#include "consensuscommand.h"
class GlobalData;
TreeMap* tmap;
Tree* t;
Tree* tempTree;
- ConcensusCommand* concensus;
+ ConcensusCommand* consensus;
vector< vector<Tree*> > trees; //a vector of trees for each calculator chosen
vector<Calculator*> treeCalculators;
vector<ofstream*> out;
#include "getoturepcommand.h"
#include "treegroupscommand.h"
#include "bootstrapsharedcommand.h"
-//#include "concensuscommand.h"
+//#include "consensuscommand.h"
#include "distancecommand.h"
#include "aligncommand.h"
#include "matrixoutputcommand.h"
commands["get.sabund"] = "get.sabund";
commands["get.rabund"] = "get.rabund";
commands["bootstrap.shared"] = "bootstrap.shared";
- //commands["concensus"] = "concensus";
+ //commands["consensus"] = "consensus";
commands["help"] = "help";
commands["filter.seqs"] = "filter.seqs";
commands["align.seqs"] = "align.seqs";
else if(commandName == "tree.shared") { command = new TreeGroupCommand(optionString); }
else if(commandName == "dist.shared") { command = new MatrixOutputCommand(optionString); }
else if(commandName == "bootstrap.shared") { command = new BootSharedCommand(optionString); }
- //else if(commandName == "concensus") { command = new ConcensusCommand(optionString); }
+ //else if(commandName == "consensus") { command = new ConcensusCommand(optionString); }
else if(commandName == "dist.seqs") { command = new DistanceCommand(optionString); }
else if(commandName == "align.seqs") { command = new AlignCommand(optionString); }
else if(commandName == "summary.seqs") { command = new SeqSummaryCommand(optionString); }
+++ /dev/null
-/*
- * concensuscommand.cpp
- * Mothur
- *
- * Created by Sarah Westcott on 4/29/09.
- * Copyright 2009 Schloss Lab UMASS AMherst. All rights reserved.
- *
- */
-
-#include "concensuscommand.h"
-
-//**********************************************************************************************************************
-
-ConcensusCommand::ConcensusCommand(string fileroot){
- try {
- globaldata = GlobalData::getInstance();
- abort = false;
-
- filename = fileroot;
- //allow user to run help
- //if(option == "help") { help(); abort = true; }
-
- //else {
- //if (option != "") { mothurOut("There are no valid parameters for the concensus command."); mothurOutEndLine(); abort = true; }
-
- // //no trees were read
- // if (globaldata->gTree.size() == 0) { mothurOut("You must execute the read.tree command, before you may use the concensus command."); mothurOutEndLine(); abort = true; }
- //else {
- t = globaldata->gTree;
- // }
- //}
- }
- catch(exception& e) {
- errorOut(e, "ConcensusCommand", "ConcensusCommand");
- exit(1);
- }
-}
-
-//**********************************************************************************************************************
-
-void ConcensusCommand::help(){
- try {
- mothurOut("The concensus command can only be executed after a successful read.tree command.\n");
- mothurOut("The concensus command has no parameters.\n");
- mothurOut("The concensus command should be in the following format: concensus().\n");
- mothurOut("The concensus command output two files: .concensus.tre and .concensuspairs.\n");
- mothurOut("The .concensus.tre file contains the concensus tree of the trees in your input file.\n");
- mothurOut("The branch lengths are the percentage of trees in your input file that had the given pair.\n");
- mothurOut("The .concensuspairs file contains a list of the internal nodes in your tree. For each node, the pair that was used in the concensus tree \n");
- mothurOut("is reported with its percentage, as well as the other pairs that were seen for that node but not used and their percentages.\n\n");
- }
- catch(exception& e) {
- errorOut(e, "ConcensusCommand", "help");
- exit(1);
- }
-}
-
-//**********************************************************************************************************************
-
-ConcensusCommand::~ConcensusCommand(){}
-
-//**********************************************************************************************************************
-
-int ConcensusCommand::execute(){
- try {
-
- if (abort == true) { return 0; }
- else {
- numNodes = t[0]->getNumNodes();
- numLeaves = t[0]->getNumLeaves();
- }
-
- //get the possible pairings
- getSets();
-
- //open file for pairing not included in the tree
- notIncluded = filename + ".concensuspairs";
- openOutputFile(notIncluded, out2);
-
- concensusTree = new Tree();
-
- it2 = nodePairs.find(treeSet);
-
- nodePairsInTree[treeSet] = it2->second;
-
- //erase treeset because you are adding it
- nodePairs.erase(treeSet);
-
- //set count to numLeaves;
- count = numLeaves;
-
- buildConcensusTree(treeSet);
-
- concensusTree->assembleTree();
-
- //output species in order
- out2 << "Species in Order: " << endl << endl;
- for (int i = 0; i < treeSet.size(); i++) { out2 << i+1 << ". " << treeSet[i] << endl; }
-
- vector<string> temp;
- //output sets included
- out2 << endl << "Sets included in the concensus tree:" << endl << endl;
- for (it2 = nodePairsInTree.begin(); it2 != nodePairsInTree.end(); it2++) {
- //only output pairs not leaves
- if (it2->first.size() > 1) {
- temp.clear();
- //initialize temp to all "."
- temp.resize(treeSet.size(), ".");
-
- //set the spot in temp that represents it2->first[i] to a "*"
- for (int i = 0; i < it2->first.size(); i++) {
- //find spot
- int index = findSpot(it2->first[i]);
- temp[index] = "*";
- }
-
- //output temp
- for (int j = 0; j < temp.size(); j++) {
- out2 << temp[j];
- }
- out2 << '\t' << it2->second << endl;
- }
- }
-
- //output sets not included
- out2 << endl << "Sets NOT included in the concensus tree:" << endl << endl;
- for (it2 = nodePairs.begin(); it2 != nodePairs.end(); it2++) {
- temp.clear();
- //initialize temp to all "."
- temp.resize(treeSet.size(), ".");
-
- //set the spot in temp that represents it2->first[i] to a "*"
- for (int i = 0; i < it2->first.size(); i++) {
- //find spot
- int index = findSpot(it2->first[i]);
- temp[index] = "*";
- }
-
- //output temp
- for (int j = 0; j < temp.size(); j++) {
- out2 << temp[j];
- }
- out2 << '\t' << it2->second << endl;
- }
-
- outputFile = filename + ".cons.tre";
- openOutputFile(outputFile, out);
-
- concensusTree->printForBoot(out);
-
- out.close(); out2.close();
-
- delete concensusTree;
-
- return 0;
- }
- catch(exception& e) {
- errorOut(e, "ConcensusCommand", "execute");
- exit(1);
- }
-}
-
-//**********************************************************************************************************************
-int ConcensusCommand::buildConcensusTree(vector<string> nodeSet) {
- try {
- vector<string> leftChildSet;
- vector<string> rightChildSet;
-
- //if you are at a leaf
- if (nodeSet.size() == 1) {
- //return the vector index of the leaf you are at
- return concensusTree->getIndex(nodeSet[0]);
- //terminate recursion
- }else if (count == numNodes) { return 0; }
- else {
- leftChildSet = getNextAvailableSet(nodeSet);
- rightChildSet = getRestSet(nodeSet, leftChildSet);
- int left = buildConcensusTree(leftChildSet);
- int right = buildConcensusTree(rightChildSet);
- concensusTree->tree[count].setChildren(left, right);
- concensusTree->tree[count].setLabel(nodePairsInTree[nodeSet]);
- concensusTree->tree[left].setParent(count);
- concensusTree->tree[right].setParent(count);
- count++;
- return (count-1);
- }
-
- }
- catch(exception& e) {
- errorOut(e, "ConcensusCommand", "buildConcensusTree");
- exit(1);
- }
-}
-
-//**********************************************************************************************************************
-void ConcensusCommand::getSets() {
- try {
- vector<string> temp;
- treeSet.clear();
-
- //for each tree add the possible pairs you find
- for (int i = 0; i < t.size(); i++) {
-
- //for each non-leaf node get descendant info.
- for (int j = numLeaves; j < numNodes; j++) {
- temp.clear();
- //go through pcounts and pull out descendants
- for (it = t[i]->tree[j].pcount.begin(); it != t[i]->tree[j].pcount.end(); it++) {
- temp.push_back(it->first);
- }
-
- //sort temp
- sort(temp.begin(), temp.end());
-
- it2 = nodePairs.find(temp);
- if (it2 != nodePairs.end()) {
- nodePairs[temp]++;
- }else{
- nodePairs[temp] = 1;
- }
- }
- }
-
- //add each leaf to terminate recursion in concensus
- //you want the leaves in there but with insignifigant sightings value so it is added last
- //for each leaf node get descendant info.
- for (int j = 0; j < numLeaves; j++) {
-
- //only need the first one since leaves have no descendants but themselves
- it = t[0]->tree[j].pcount.begin();
- temp.clear(); temp.push_back(it->first);
-
- //fill treeSet
- treeSet.push_back(it->first);
-
- //add leaf to list but with sighting value less then all non leaf pairs
- nodePairs[temp] = 0;
- }
-
- sort(treeSet.begin(), treeSet.end());
- }
- catch(exception& e) {
- errorOut(e, "ConcensusCommand", "getSets");
- exit(1);
- }
-}
-
-//**********************************************************************************************************************
-vector<string> ConcensusCommand::getNextAvailableSet(vector<string> bigset) {
- try {
- vector<string> largest; largest.clear();
- int largestSighting = -1;
-
- //go through the sets
- for (it2 = nodePairs.begin(); it2 != nodePairs.end(); it2++) {
- //are you a subset of bigset
- if (isSubset(bigset, it2->first) == true) {
-
- //are you the largest. if you are the same size as current largest refer to sighting
- if (it2->first.size() > largest.size()) { largest = it2->first; largestSighting = it2->second; }
- else if (it2->first.size() == largest.size()) {
- if (it2->second > largestSighting) { largest = it2->first; largestSighting = it2->second; }
- }
-
- }
- }
-
- //save for printing out later and for branch lengths
- nodePairsInTree[largest] = nodePairs[largest];
-
- //delete whatever set you return because it is no longer available
- nodePairs.erase(largest);
-
- return largest;
-
- }
- catch(exception& e) {
- errorOut(e, "ConcensusCommand", "getNextAvailableSet");
- exit(1);
- }
-}
-
-//**********************************************************************************************************************
-vector<string> ConcensusCommand::getRestSet(vector<string> bigset, vector<string> subset) {
- try {
- vector<string> rest;
-
- for (int i = 0; i < bigset.size(); i++) {
- bool inSubset = false;
- for (int j = 0; j < subset.size(); j++) {
- if (bigset[i] == subset[j]) { inSubset = true; break; }
- }
-
- //its not in the subset so put it in the rest
- if (inSubset == false) { rest.push_back(bigset[i]); }
- }
-
- //save for printing out later and for branch lengths
- nodePairsInTree[rest] = nodePairs[rest];
-
- //delete whatever set you return because it is no longer available
- nodePairs.erase(rest);
-
- return rest;
-
- }
- catch(exception& e) {
- errorOut(e, "ConcensusCommand", "getRestSet");
- exit(1);
- }
-}
-
-//**********************************************************************************************************************
-bool ConcensusCommand::isSubset(vector<string> bigset, vector<string> subset) {
- try {
-
- //check if each guy in suset is also in bigset
- for (int i = 0; i < subset.size(); i++) {
- bool match = false;
- for (int j = 0; j < bigset.size(); j++) {
- if (subset[i] == bigset[j]) { match = true; break; }
- }
-
- //you have a guy in subset that had no match in bigset
- if (match == false) { return false; }
- }
-
- return true;
-
- }
- catch(exception& e) {
- errorOut(e, "ConcensusCommand", "isSubset");
- exit(1);
- }
-}
-//**********************************************************************************************************************
-int ConcensusCommand::findSpot(string node) {
- try {
- int spot;
-
- //check if each guy in suset is also in bigset
- for (int i = 0; i < treeSet.size(); i++) {
- if (treeSet[i] == node) { spot = i; break; }
- }
-
- return spot;
-
- }
- catch(exception& e) {
- errorOut(e, "ConcensusCommand", "findSpot");
- exit(1);
- }
-}
-//**********************************************************************************************************************
-
-
-
-
+++ /dev/null
-#ifndef CONCENSUSCOMMAND_H
-#define CONCENSUSCOMMAND_H
-/*
- * concensuscommand.h
- * Mothur
- *
- * Created by Sarah Westcott on 4/29/09.
- * Copyright 2009 Schloss Lab UMASS AMherst. All rights reserved.
- *
- */
-
-#include "command.hpp"
-#include "tree.h"
-#include "treemap.h"
-#include "sharedutilities.h"
-
-class GlobalData;
-
-class ConcensusCommand : public Command {
-
-public:
- ConcensusCommand(string);
- ~ConcensusCommand();
- int execute();
- void help();
-
-private:
- GlobalData* globaldata;
- SharedUtil* util;
- vector<Tree*> t;
- Tree* concensusTree;
- bool abort;
- vector<string> treeSet; //set containing all members of the tree to start recursion. filled in getSets().
- map< vector<string>, int > nodePairs; //<map of possible combinations these combos are the pcounts or descendants info, to how many times they occured
- // ie. combos FI and EGK would create nodePairs[vector containing F and I] = 1; nodePairs[vector containing E, G and K] = 1
- // if you saw the combo FI again in another tree you would then update nodePairs[vector containing F and I] = 2;
- // requires vectors to be sorted to find key.
- map< vector<string>, int > nodePairsInTree;
- map<string, int>::iterator it;
- map< vector<string>, int>::iterator it2;
- string outputFile, notIncluded, filename;
- ofstream out, out2;
- int numNodes, numLeaves, count; //count is the next available spot in the tree vector
-
- void getSets();
- vector<string> getNextAvailableSet(vector<string>); //gets next largest and highest rated set that is a subset of the set passed in.
- vector<string> getRestSet(vector<string>, vector<string>);
- bool isSubset(vector<string>, vector<string>);
- int findSpot(string);
- int buildConcensusTree(vector<string>);
-
-};
-
-#endif
-
--- /dev/null
+/*
+ * consensuscommand.cpp
+ * Mothur
+ *
+ * Created by Sarah Westcott on 4/29/09.
+ * Copyright 2009 Schloss Lab UMASS AMherst. All rights reserved.
+ *
+ */
+
+#include "consensuscommand.h"
+
+//**********************************************************************************************************************
+
+ConcensusCommand::ConcensusCommand(string fileroot){
+ try {
+ globaldata = GlobalData::getInstance();
+ abort = false;
+
+ filename = fileroot;
+ //allow user to run help
+ //if(option == "help") { help(); abort = true; }
+
+ //else {
+ //if (option != "") { mothurOut("There are no valid parameters for the consensus command."); mothurOutEndLine(); abort = true; }
+
+ // //no trees were read
+ // if (globaldata->gTree.size() == 0) { mothurOut("You must execute the read.tree command, before you may use the consensus command."); mothurOutEndLine(); abort = true; }
+ //else {
+ t = globaldata->gTree;
+ // }
+ //}
+ }
+ catch(exception& e) {
+ errorOut(e, "ConcensusCommand", "ConcensusCommand");
+ exit(1);
+ }
+}
+
+//**********************************************************************************************************************
+
+void ConcensusCommand::help(){
+ try {
+ mothurOut("The consensus command can only be executed after a successful read.tree command.\n");
+ mothurOut("The consensus command has no parameters.\n");
+ mothurOut("The consensus command should be in the following format: consensus().\n");
+ mothurOut("The consensus command output two files: .consensus.tre and .consensuspairs.\n");
+ mothurOut("The .consensus.tre file contains the consensus tree of the trees in your input file.\n");
+ mothurOut("The branch lengths are the percentage of trees in your input file that had the given pair.\n");
+ mothurOut("The .consensuspairs file contains a list of the internal nodes in your tree. For each node, the pair that was used in the consensus tree \n");
+ mothurOut("is reported with its percentage, as well as the other pairs that were seen for that node but not used and their percentages.\n\n");
+ }
+ catch(exception& e) {
+ errorOut(e, "ConcensusCommand", "help");
+ exit(1);
+ }
+}
+
+//**********************************************************************************************************************
+
+ConcensusCommand::~ConcensusCommand(){}
+
+//**********************************************************************************************************************
+
+int ConcensusCommand::execute(){
+ try {
+
+ if (abort == true) { return 0; }
+ else {
+ numNodes = t[0]->getNumNodes();
+ numLeaves = t[0]->getNumLeaves();
+ }
+
+ //get the possible pairings
+ getSets();
+
+ //open file for pairing not included in the tree
+ notIncluded = filename + ".cons.pairs";
+ openOutputFile(notIncluded, out2);
+
+ consensusTree = new Tree();
+
+ it2 = nodePairs.find(treeSet);
+
+ nodePairsInTree[treeSet] = it2->second;
+
+ //erase treeset because you are adding it
+ nodePairs.erase(treeSet);
+
+ //set count to numLeaves;
+ count = numLeaves;
+
+ buildConcensusTree(treeSet);
+
+ consensusTree->assembleTree();
+
+ //output species in order
+ out2 << "Species in Order: " << endl << endl;
+ for (int i = 0; i < treeSet.size(); i++) { out2 << i+1 << ". " << treeSet[i] << endl; }
+
+ vector<string> temp;
+ //output sets included
+ out2 << endl << "Sets included in the consensus tree:" << endl << endl;
+ for (it2 = nodePairsInTree.begin(); it2 != nodePairsInTree.end(); it2++) {
+ //only output pairs not leaves
+ if (it2->first.size() > 1) {
+ temp.clear();
+ //initialize temp to all "."
+ temp.resize(treeSet.size(), ".");
+
+ //set the spot in temp that represents it2->first[i] to a "*"
+ for (int i = 0; i < it2->first.size(); i++) {
+ //find spot
+ int index = findSpot(it2->first[i]);
+ temp[index] = "*";
+ }
+
+ //output temp
+ for (int j = 0; j < temp.size(); j++) {
+ out2 << temp[j];
+ }
+ out2 << '\t' << it2->second << endl;
+ }
+ }
+
+ //output sets not included
+ out2 << endl << "Sets NOT included in the consensus tree:" << endl << endl;
+ for (it2 = nodePairs.begin(); it2 != nodePairs.end(); it2++) {
+ temp.clear();
+ //initialize temp to all "."
+ temp.resize(treeSet.size(), ".");
+
+ //set the spot in temp that represents it2->first[i] to a "*"
+ for (int i = 0; i < it2->first.size(); i++) {
+ //find spot
+ int index = findSpot(it2->first[i]);
+ temp[index] = "*";
+ }
+
+ //output temp
+ for (int j = 0; j < temp.size(); j++) {
+ out2 << temp[j];
+ }
+ out2 << '\t' << it2->second << endl;
+ }
+
+ outputFile = filename + ".cons.tre";
+ openOutputFile(outputFile, out);
+
+ consensusTree->printForBoot(out);
+
+ out.close(); out2.close();
+
+ delete consensusTree;
+
+ return 0;
+ }
+ catch(exception& e) {
+ errorOut(e, "ConcensusCommand", "execute");
+ exit(1);
+ }
+}
+
+//**********************************************************************************************************************
+int ConcensusCommand::buildConcensusTree(vector<string> nodeSet) {
+ try {
+ vector<string> leftChildSet;
+ vector<string> rightChildSet;
+
+ //if you are at a leaf
+ if (nodeSet.size() == 1) {
+ //return the vector index of the leaf you are at
+ return consensusTree->getIndex(nodeSet[0]);
+ //terminate recursion
+ }else if (count == numNodes) { return 0; }
+ else {
+ leftChildSet = getNextAvailableSet(nodeSet);
+ rightChildSet = getRestSet(nodeSet, leftChildSet);
+ int left = buildConcensusTree(leftChildSet);
+ int right = buildConcensusTree(rightChildSet);
+ consensusTree->tree[count].setChildren(left, right);
+ consensusTree->tree[count].setLabel(nodePairsInTree[nodeSet]);
+ consensusTree->tree[left].setParent(count);
+ consensusTree->tree[right].setParent(count);
+ count++;
+ return (count-1);
+ }
+
+ }
+ catch(exception& e) {
+ errorOut(e, "ConcensusCommand", "buildConcensusTree");
+ exit(1);
+ }
+}
+
+//**********************************************************************************************************************
+void ConcensusCommand::getSets() {
+ try {
+ vector<string> temp;
+ treeSet.clear();
+
+ //for each tree add the possible pairs you find
+ for (int i = 0; i < t.size(); i++) {
+
+ //for each non-leaf node get descendant info.
+ for (int j = numLeaves; j < numNodes; j++) {
+ temp.clear();
+ //go through pcounts and pull out descendants
+ for (it = t[i]->tree[j].pcount.begin(); it != t[i]->tree[j].pcount.end(); it++) {
+ temp.push_back(it->first);
+ }
+
+ //sort temp
+ sort(temp.begin(), temp.end());
+
+ it2 = nodePairs.find(temp);
+ if (it2 != nodePairs.end()) {
+ nodePairs[temp]++;
+ }else{
+ nodePairs[temp] = 1;
+ }
+ }
+ }
+
+ //add each leaf to terminate recursion in consensus
+ //you want the leaves in there but with insignifigant sightings value so it is added last
+ //for each leaf node get descendant info.
+ for (int j = 0; j < numLeaves; j++) {
+
+ //only need the first one since leaves have no descendants but themselves
+ it = t[0]->tree[j].pcount.begin();
+ temp.clear(); temp.push_back(it->first);
+
+ //fill treeSet
+ treeSet.push_back(it->first);
+
+ //add leaf to list but with sighting value less then all non leaf pairs
+ nodePairs[temp] = 0;
+ }
+
+ sort(treeSet.begin(), treeSet.end());
+ }
+ catch(exception& e) {
+ errorOut(e, "ConcensusCommand", "getSets");
+ exit(1);
+ }
+}
+
+//**********************************************************************************************************************
+vector<string> ConcensusCommand::getNextAvailableSet(vector<string> bigset) {
+ try {
+ vector<string> largest; largest.clear();
+ int largestSighting = -1;
+
+ //go through the sets
+ for (it2 = nodePairs.begin(); it2 != nodePairs.end(); it2++) {
+ //are you a subset of bigset
+ if (isSubset(bigset, it2->first) == true) {
+
+ //are you the largest. if you are the same size as current largest refer to sighting
+ if (it2->first.size() > largest.size()) { largest = it2->first; largestSighting = it2->second; }
+ else if (it2->first.size() == largest.size()) {
+ if (it2->second > largestSighting) { largest = it2->first; largestSighting = it2->second; }
+ }
+
+ }
+ }
+
+ //save for printing out later and for branch lengths
+ nodePairsInTree[largest] = nodePairs[largest];
+
+ //delete whatever set you return because it is no longer available
+ nodePairs.erase(largest);
+
+ return largest;
+
+ }
+ catch(exception& e) {
+ errorOut(e, "ConcensusCommand", "getNextAvailableSet");
+ exit(1);
+ }
+}
+
+//**********************************************************************************************************************
+vector<string> ConcensusCommand::getRestSet(vector<string> bigset, vector<string> subset) {
+ try {
+ vector<string> rest;
+
+ for (int i = 0; i < bigset.size(); i++) {
+ bool inSubset = false;
+ for (int j = 0; j < subset.size(); j++) {
+ if (bigset[i] == subset[j]) { inSubset = true; break; }
+ }
+
+ //its not in the subset so put it in the rest
+ if (inSubset == false) { rest.push_back(bigset[i]); }
+ }
+
+ //save for printing out later and for branch lengths
+ nodePairsInTree[rest] = nodePairs[rest];
+
+ //delete whatever set you return because it is no longer available
+ nodePairs.erase(rest);
+
+ return rest;
+
+ }
+ catch(exception& e) {
+ errorOut(e, "ConcensusCommand", "getRestSet");
+ exit(1);
+ }
+}
+
+//**********************************************************************************************************************
+bool ConcensusCommand::isSubset(vector<string> bigset, vector<string> subset) {
+ try {
+
+ //check if each guy in suset is also in bigset
+ for (int i = 0; i < subset.size(); i++) {
+ bool match = false;
+ for (int j = 0; j < bigset.size(); j++) {
+ if (subset[i] == bigset[j]) { match = true; break; }
+ }
+
+ //you have a guy in subset that had no match in bigset
+ if (match == false) { return false; }
+ }
+
+ return true;
+
+ }
+ catch(exception& e) {
+ errorOut(e, "ConcensusCommand", "isSubset");
+ exit(1);
+ }
+}
+//**********************************************************************************************************************
+int ConcensusCommand::findSpot(string node) {
+ try {
+ int spot;
+
+ //check if each guy in suset is also in bigset
+ for (int i = 0; i < treeSet.size(); i++) {
+ if (treeSet[i] == node) { spot = i; break; }
+ }
+
+ return spot;
+
+ }
+ catch(exception& e) {
+ errorOut(e, "ConcensusCommand", "findSpot");
+ exit(1);
+ }
+}
+//**********************************************************************************************************************
+
+
+
+
--- /dev/null
+#ifndef CONCENSUSCOMMAND_H
+#define CONCENSUSCOMMAND_H
+/*
+ * consensuscommand.h
+ * Mothur
+ *
+ * Created by Sarah Westcott on 4/29/09.
+ * Copyright 2009 Schloss Lab UMASS AMherst. All rights reserved.
+ *
+ */
+
+#include "command.hpp"
+#include "tree.h"
+#include "treemap.h"
+#include "sharedutilities.h"
+
+class GlobalData;
+
+class ConcensusCommand : public Command {
+
+public:
+ ConcensusCommand(string);
+ ~ConcensusCommand();
+ int execute();
+ void help();
+
+private:
+ GlobalData* globaldata;
+ SharedUtil* util;
+ vector<Tree*> t;
+ Tree* consensusTree;
+ bool abort;
+ vector<string> treeSet; //set containing all members of the tree to start recursion. filled in getSets().
+ map< vector<string>, int > nodePairs; //<map of possible combinations these combos are the pcounts or descendants info, to how many times they occured
+ // ie. combos FI and EGK would create nodePairs[vector containing F and I] = 1; nodePairs[vector containing E, G and K] = 1
+ // if you saw the combo FI again in another tree you would then update nodePairs[vector containing F and I] = 2;
+ // requires vectors to be sorted to find key.
+ map< vector<string>, int > nodePairsInTree;
+ map<string, int>::iterator it;
+ map< vector<string>, int>::iterator it2;
+ string outputFile, notIncluded, filename;
+ ofstream out, out2;
+ int numNodes, numLeaves, count; //count is the next available spot in the tree vector
+
+ void getSets();
+ vector<string> getNextAvailableSet(vector<string>); //gets next largest and highest rated set that is a subset of the set passed in.
+ vector<string> getRestSet(vector<string>, vector<string>);
+ bool isSubset(vector<string>, vector<string>);
+ int findSpot(string);
+ int buildConcensusTree(vector<string>);
+
+};
+
+#endif
+
void GetgroupCommand::help(){
try {
mothurOut("The get.group command can only be executed after a successful read.otu command.\n");
- //mothurOut("The get.group command outputs a .bootGroups file to you can use in addition to the tree file generated by the bootstrap.shared command to run the concensus command.\n");
+ //mothurOut("The get.group command outputs a .bootGroups file to you can use in addition to the tree file generated by the bootstrap.shared command to run the consensus command.\n");
mothurOut("You may not use any parameters with the get.group command.\n");
mothurOut("The get.group command should be in the following format: \n");
mothurOut("get.group()\n");