]> git.donarmstrong.com Git - mothur.git/commitdiff
you can now use a distance matrix as input for the heatmap.sim command.
authorwestcott <westcott>
Tue, 5 Jan 2010 21:29:35 +0000 (21:29 +0000)
committerwestcott <westcott>
Tue, 5 Jan 2010 21:29:35 +0000 (21:29 +0000)
added distance parameter to unifrac.weighted and unifrac.unweighted commands that allows you to output a distance matrix from the command.
added random parameter to unifrac.weighted and unifrac.unweighted commands that allows you to shut off the comparison to random trees.

14 files changed:
bayesian.cpp
classifyseqscommand.cpp
heatmapsim.cpp
heatmapsim.h
heatmapsimcommand.cpp
heatmapsimcommand.h
pcacommand.cpp
pcacommand.h
phylotree.cpp
phylotree.h
unifracunweightedcommand.cpp
unifracunweightedcommand.h
unifracweightedcommand.cpp
unifracweightedcommand.h

index e6adfc24b863442a58edcd7f348c83f843b10635..e59545a89a04031999885beb932dac5003ab6b8c 100644 (file)
@@ -185,7 +185,7 @@ string Bayesian::bootstrapResults(vector<int> kmers, int tax, int numToSelect) {
                                }
                                
                                if (confidence >= confidenceThreshold) {
-                                       confidenceTax = seqTax.name + "(" + toString(confidence) + ");" + confidenceTax;
+                                       confidenceTax = seqTax.name + "(" + toString(((confidence/(float)iters) * 100)) + ");" + confidenceTax;
                                        simpleTax = seqTax.name + ";" + simpleTax;
                                }
                                
index 7221ac0cc490feb350d351bf303c26789cb417b6..768cb0d4a5bb3041c101752025576cdcf2d11222 100644 (file)
@@ -261,6 +261,7 @@ int ClassifySeqsCommand::execute(){
                remove(tempTaxonomyFile.c_str());
                
                taxaBrowser.assignHeirarchyIDs(0);
+               taxaBrowser.binUnclassified();
                
                ofstream outTaxTree;
                openOutputFile(taxSummary, outTaxTree);
index 1544dc2396c558361a663045278d3757f75aeed6..88a49ed93512369a5c3d0e9d7c17fde7304d5f7f 100644 (file)
@@ -24,7 +24,6 @@ HeatMapSim::HeatMapSim(){
                globaldata = GlobalData::getInstance();
 }
 //**********************************************************************************************************************
-
 void HeatMapSim::getPic(vector<SharedRAbundVector*> lookup, vector<Calculator*> calcs) {
        try {
                EstOutput data;
@@ -101,6 +100,73 @@ void HeatMapSim::getPic(vector<SharedRAbundVector*> lookup, vector<Calculator*>
                exit(1);
        }
 }
+//**********************************************************************************************************************
+void HeatMapSim::getPic(vector< vector<double> > dists, vector<string> groups) {
+       try {
+               
+               vector<double> sims;
+               
+               string filenamesvg = getRootName(globaldata->inputFileName) + "heatmap.sim.svg";
+               openOutputFile(filenamesvg, outsvg);
+                       
+               //svg image
+               outsvg << "<svg xmlns:svg=\"http://www.w3.org/2000/svg\" xmlns=\"http://www.w3.org/2000/svg\" width=\"100%\" height=\"100%\" viewBox=\"0 0 " + toString((dists.size() * 150) + 160) + " " + toString((dists.size() * 150) + 160)  + "\">\n";
+               outsvg << "<g>\n";
+               
+               //white backround
+               outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"" + toString((dists.size() * 150) + 160) + "\" height=\"" + toString((dists.size() * 150) + 160)  + "\"/>"; 
+               outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString((dists.size() * 75) - 40) + "\" y=\"25\">Heatmap for " + globaldata->inputFileName + "</text>\n";
+               
+               //column labels
+               for (int h = 0; h < groups.size(); h++) {
+                       outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(((150 * (h+1)) ) - ((int)groups[h].length() / 2)) + "\" y=\"50\">" + groups[h] + "</text>\n"; 
+                       outsvg << "<text fill=\"black\" class=\"seri\" y=\"" + toString(((150 * (h+1)) ) - ((int)groups[h].length() / 2)) + "\" x=\"50\">" + groups[h] + "</text>\n";
+               }
+                       
+               double biggest = -1;
+               float scaler;
+
+               //get sim for each comparison and save them so you can find the relative similairity
+               for(int i = 0; i < (dists.size()-1); i++){
+                       for(int j = (i+1); j < dists.size(); j++){
+                               
+                               float sim = 1.0 - dists[i][j];
+                               sims.push_back(sim);
+                                       
+                               //save biggest similairity to set relative sim
+                               if (sim > biggest) { biggest = sim; }
+                       }
+               }
+                       
+               //map biggest similairity found to red
+               scaler = 255.0 / biggest;
+                       
+               int count = 0;
+               //output similairites to file
+               for(int i = 0; i < (dists.size()-1); i++){
+                       for(int j = (i+1); j < dists.size(); j++){
+                               
+                                       //find relative color
+                                       int color = scaler * sims[count];                                       
+                                       //draw box
+                                       outsvg << "<rect fill=\"rgb(" + toString(color) + ",0,0)\" stroke=\"rgb(" + toString(color) + ",0,0)\" x=\"" + toString((i*150)+80) + "\" y=\"" + toString((j*150)+75) + "\" width=\"150\" height=\"150\"/>\n";
+                                       count++;
+                       }
+               }
+                       
+               int y = ((dists.size() * 150) + 120);
+               printLegend(y, biggest);
+               
+               outsvg << "</g>\n</svg>\n";
+               outsvg.close();
+               
+       }
+       catch(exception& e) {
+               errorOut(e, "HeatMapSim", "getPic");
+               exit(1);
+       }
+}
+
 //**********************************************************************************************************************
 
 void HeatMapSim::printLegend(int y, float maxSim) {
index c3ec2a79bd773e10db54a1547cf358d3fccd643c..d38683c17a40283a5eafc667dc663fd26e6cab0d 100644 (file)
@@ -24,6 +24,7 @@ class HeatMapSim {
                ~HeatMapSim(){};
        
                void getPic(vector<SharedRAbundVector*>, vector<Calculator*>);
+               void getPic(vector< vector<double> >, vector<string>);
 
        private:
                void printLegend(int, float);
index 3803692be8bf9d0b1b02997d90863fbbba196665..3287e62fd297b440e46971e3c57093799369ff08 100644 (file)
@@ -36,7 +36,7 @@ HeatMapSimCommand::HeatMapSimCommand(string option){
                
                else {
                        //valid paramters for this command
-                       string AlignArray[] =  {"groups","label", "calc"};
+                       string AlignArray[] =  {"groups","label", "calc","phylip","column","name"};
                        vector<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
                        
                        OptionParser parser(option);
@@ -49,43 +49,67 @@ HeatMapSimCommand::HeatMapSimCommand(string option){
                                if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
-                       //make sure the user has already run the read.otu command
-                       if (globaldata->getSharedFile() == "") {
-                                mothurOut("You must read a list and a group, or a shared before you can use the heatmap.sim command."); mothurOutEndLine(); abort = true; 
-                       }
-
-                       //check for optional parameter and set defaults
-                       // ...at some point should added some additional type checking...
-                       label = validParameter.validFile(parameters, "label", false);                   
-                       if (label == "not found") { label = ""; }
-                       else { 
-                               if(label != "all") {  splitAtDash(label, labels);  allLines = 0;  }
-                               else { allLines = 1;  }
-                       }
+                       format = "";
                        
-                       //if the user has not specified any labels use the ones from read.otu
-                       if (label == "") {  
-                               allLines = globaldata->allLines; 
-                               labels = globaldata->labels; 
-                       }
+                       //required parameters
+                       phylipfile = validParameter.validFile(parameters, "phylip", true);
+                       if (phylipfile == "not open") { abort = true; }
+                       else if (phylipfile == "not found") { phylipfile = ""; }        
+                       else {  format = "phylip";      }
                        
-                       calc = validParameter.validFile(parameters, "calc", false);                     
-                       if (calc == "not found") { calc = "jest-thetayc";  }
-                       else { 
-                                if (calc == "default")  {  calc = "jest-thetayc";  }
+                       columnfile = validParameter.validFile(parameters, "column", true);
+                       if (columnfile == "not open") { abort = true; } 
+                       else if (columnfile == "not found") { columnfile = ""; }
+                       else {  format = "column";      }
+                       
+                       namefile = validParameter.validFile(parameters, "name", true);
+                       if (namefile == "not open") { abort = true; }   
+                       else if (namefile == "not found") { namefile = ""; }
+                       
+                       
+                       //error checking on files                       
+                       if ((globaldata->getSharedFile() == "") && ((phylipfile == "") && (columnfile == "")))  { mothurOut("You must run the read.otu command or provide a distance file before running the heatmap.sim command."); mothurOutEndLine(); abort = true; }
+                       else if ((phylipfile != "") && (columnfile != "")) { mothurOut("When running the heatmap.sim command with a distance file you may not use both the column and the phylip parameters."); mothurOutEndLine(); abort = true; }
+                       
+                       if (columnfile != "") {
+                               if (namefile == "") {  mothurOut("You need to provide a namefile if you are going to use the column format."); mothurOutEndLine(); abort = true; }
                        }
-                       splitAtDash(calc, Estimators);
                        
-                       groups = validParameter.validFile(parameters, "groups", false);                 
-                       if (groups == "not found") { groups = ""; }
-                       else { 
-                               splitAtDash(groups, Groups);
-                               globaldata->Groups = Groups;
+                       if (format == "") { format = "shared"; }
+                       
+                       //check for optional parameter and set defaults
+                       // ...at some point should added some additional type checking...
+                       if (format == "shared") {
+                               label = validParameter.validFile(parameters, "label", false);                   
+                               if (label == "not found") { label = ""; }
+                               else { 
+                                       if(label != "all") {  splitAtDash(label, labels);  allLines = 0;  }
+                                       else { allLines = 1;  }
+                               }
+                               
+                               //if the user has not specified any labels use the ones from read.otu
+                               if (label == "") {  
+                                       allLines = globaldata->allLines; 
+                                       labels = globaldata->labels; 
+                               }
+                               
+                               calc = validParameter.validFile(parameters, "calc", false);                     
+                               if (calc == "not found") { calc = "jest-thetayc";  }
+                               else { 
+                                       if (calc == "default")  {  calc = "jest-thetayc";  }
+                               }
+                               splitAtDash(calc, Estimators);
+                               
+                               groups = validParameter.validFile(parameters, "groups", false);                 
+                               if (groups == "not found") { groups = ""; }
+                               else { 
+                                       splitAtDash(groups, Groups);
+                                       globaldata->Groups = Groups;
+                               }
                        }
                        
                        if (abort == false) {
                                validCalculator = new ValidCalculators();
-                               heatmap = new HeatMapSim();
                        
                                int i;
                                for (i=0; i<Estimators.size(); i++) {
@@ -130,8 +154,10 @@ HeatMapSimCommand::HeatMapSimCommand(string option){
 
 void HeatMapSimCommand::help(){
        try {
-               mothurOut("The heatmap.sim command can only be executed after a successful read.otu command.\n");
-               mothurOut("The heatmap.sim command parameters are groups, calc and label.  No parameters are required.\n");
+               mothurOut("The heatmap.sim command can only be executed after a successful read.otu command, or by providing a distance file.\n");
+               mothurOut("The heatmap.sim command parameters are phylip, column, name, groups, calc and label.  No parameters are required.\n");
+               mothurOut("There are two ways to use the heatmap.sim command. The first is with the read.otu command. \n");
+               mothurOut("With the read.otu command you may use the groups, label and calc parameters. \n");
                mothurOut("The groups parameter allows you to specify which of the groups in your groupfile you would like included in your heatmap.\n");
                mothurOut("The group names are separated by dashes. The label parameter allows you to select what distance levels you would like a heatmap created for, and is also separated by dashes.\n");
                mothurOut("The heatmap.sim command should be in the following format: heatmap.sim(groups=yourGroups, calc=yourCalc, label=yourLabels).\n");
@@ -140,6 +166,10 @@ void HeatMapSimCommand::help(){
                validCalculator->printCalc("heat", cout);
                mothurOut("The default value for calc is jclass-thetayc.\n");
                mothurOut("The heatmap.sim command outputs a .svg file for each calculator you choose at each label you specify.\n");
+               mothurOut("The second way to use the heatmap.sim command is with a distance file representing the distance bewteen your groups. \n");
+               mothurOut("Using the command this way, the phylip or column parameter are required, and only one may be used.  If you use a column file the name filename is required. \n");
+               mothurOut("The heatmap.sim command should be in the following format: heatmap.sim(phylip=yourDistanceFile).\n");
+               mothurOut("Example heatmap.sim(phylip=amazonGroups.dist).\n");
                mothurOut("Note: No spaces between parameter labels (i.e. groups), '=' and parameters (i.e.yourGroups).\n\n");
 
        }
@@ -151,14 +181,7 @@ void HeatMapSimCommand::help(){
 
 //**********************************************************************************************************************
 
-HeatMapSimCommand::~HeatMapSimCommand(){
-       if (abort == false) {
-               delete input;  globaldata->ginput = NULL;
-               delete read;
-               delete heatmap;
-               delete validCalculator;
-       }
-}
+HeatMapSimCommand::~HeatMapSimCommand(){}
 
 //**********************************************************************************************************************
 
@@ -167,6 +190,32 @@ int HeatMapSimCommand::execute(){
        
                if (abort == true)  { return 0; }
                
+               heatmap = new HeatMapSim();
+               
+               if (format == "shared") {
+                       runCommandShared();
+               }else if (format == "phylip") {
+                       globaldata->inputFileName = phylipfile;
+                       runCommandDist();
+               }else if (format == "column") {
+                       globaldata->inputFileName = columnfile;
+                       runCommandDist();
+               }
+               
+               delete heatmap;
+               delete validCalculator;
+
+               return 0;
+       }
+       catch(exception& e) {
+               errorOut(e, "HeatMapSimCommand", "execute");
+               exit(1);
+       }
+}
+
+//**********************************************************************************************************************
+int HeatMapSimCommand::runCommandShared() {
+       try {
                //if the users entered no valid calculators don't execute command
                if (heatCalculators.size() == 0) { mothurOut("No valid calculators."); mothurOutEndLine(); return 0; }
                
@@ -248,12 +297,142 @@ int HeatMapSimCommand::execute(){
                //reset groups parameter
                globaldata->Groups.clear();  
                
+               delete input;  globaldata->ginput = NULL;
+               delete read;
+
                return 0;
        }
        catch(exception& e) {
-               errorOut(e, "HeatMapSimCommand", "execute");
+               errorOut(e, "HeatMapSimCommand", "runCommandShared");
                exit(1);
        }
 }
+//**********************************************************************************************************************
+int HeatMapSimCommand::runCommandDist() {
+       try {
+       
+               vector< vector<double> > matrix;
+               vector<string> names;
+               ifstream in;
+               
+               //read distance file and create distance vector and names vector
+               if (format == "phylip") {
+                       //read phylip file
+                       openInputFile(phylipfile, in);
+                       
+                       string name;
+                       int numSeqs;
+                       in >> numSeqs >> name; 
+                       
+                       //save name
+                       names.push_back(name);
+               
+                       //resize the matrix and fill with zeros
+                       matrix.resize(numSeqs); 
+                       for(int i = 0; i < numSeqs; i++) {
+                               matrix[i].resize(numSeqs, 0.0);
+                       }
+                                       
+                       //determine if matrix is square or lower triangle
+                       //if it is square read the distances for the first sequence
+                       char d;
+                       bool square;
+                       while((d=in.get()) != EOF){
+                               
+                               //is d a number meaning its square
+                               if(isalnum(d)){ 
+                                       square = true;
+                                       in.putback(d);
+                                       
+                                       for(int i=0;i<numSeqs;i++){
+                                               in >> matrix[0][i];
+                                       }
+                                       break;
+                               }
+                               
+                               //is d a line return meaning its lower triangle
+                               if(d == '\n'){
+                                       square = false;
+                                       break;
+                               }
+                       }
+                       
+                       //read rest of matrix
+                       if (square == true) { 
+                               for(int i=1;i<numSeqs;i++){
+                                       in >> name;             
+                                       names.push_back(name);
+                                       
+                                       for(int j=0;j<numSeqs;j++) {  in >> matrix[i][j];  }
+                                       gobble(in);
+                               }
+                       }else { 
+                               double dist;
+                               for(int i=1;i<numSeqs;i++){
+                                       in >> name;     
+                                       names.push_back(name);  
+                                       
+                                       for(int j=0;j<i;j++){
+                                               in >> dist;
+                                               matrix[i][j] = dist;  matrix[j][i] = dist;
+                                       }
+                                       gobble(in);
+                               }
+                       }
+                       in.close();
+               }else {
+                       //read names file
+                       NameAssignment* nameMap = new NameAssignment(namefile);
+                       nameMap->readMap();
+                       
+                       //put names in order in vector
+                       for (int i = 0; i < nameMap->size(); i++) {
+                               names.push_back(nameMap->get(i));
+                       }
+                       
+                       //resize matrix
+                       matrix.resize(nameMap->size());
+                       for (int i = 0; i < nameMap->size(); i++) {
+                               matrix[i].resize(nameMap->size(), 0.0);
+                       }
+                       
+                       //read column file
+                       string first, second;
+                       double dist;
+                       openInputFile(columnfile, in);
+                       
+                       while (!in.eof()) {
+                               in >> first >> second >> dist; gobble(in);
+                               
+                               map<string, int>::iterator itA = nameMap->find(first);
+                               map<string, int>::iterator itB = nameMap->find(second);
+                               
+                               if(itA == nameMap->end()){  cerr << "AAError: Sequence '" << first << "' was not found in the names file, please correct\n"; exit(1);  }
+                               if(itB == nameMap->end()){  cerr << "ABError: Sequence '" << second << "' was not found in the names file, please correct\n"; exit(1);  }
+                               
+                               //save distance
+                               matrix[itA->second][itB->second] = dist;
+                               matrix[itB->second][itA->second] = dist;
+                       }
+                       in.close();
+                       
+                       delete nameMap;
+               }
+               
 
+               heatmap->getPic(matrix, names); //vector<vector<double>>, vector<string>
+               
+               return 0;
+       }
+       catch(exception& e) {
+               errorOut(e, "HeatMapSimCommand", "runCommandDist");
+               exit(1);
+       }
+}
 //**********************************************************************************************************************
+
+
+
+
+
+
index 595f918f442352aea7dd94d6e62065b28398c6ca..49924eb9d3fbe1bca2bd6a8650c0eb9586d98e6f 100644 (file)
@@ -39,8 +39,11 @@ private:
        map<string, string>::iterator it;
        bool abort, allLines;
        set<string> labels; //holds labels to be used
-       string format, groups, label, calc;
+       string format, groups, label, calc, phylipfile, columnfile, namefile;
        vector<string> Estimators, Groups;
+       
+       int runCommandShared();
+       int runCommandDist();
 
 
 };
index ef89ae50cd43ad16101b4288931881027d03dcd6..09324c9d3eaf3dd5a525a44cf233abe7df6e7285 100644 (file)
@@ -21,7 +21,7 @@ PCACommand::PCACommand(string option){
                
                else {
                        //valid paramters for this command
-                       string Array[] =  {"phylip","lt"};
+                       string Array[] =  {"phylip"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
                        OptionParser parser(option);
@@ -59,11 +59,11 @@ PCACommand::PCACommand(string option){
                        //      if (namefile == "") {  mothurOut("You need to provide a namefile if you are going to use the column format."); mothurOutEndLine(); abort = true; }
                        //}
                        
-                       string temp = validParameter.validFile(parameters, "lt", false);                                if (temp == "not found") { temp = "false"; }
-                       bool lt = isTrue(temp);
+                       //string temp = validParameter.validFile(parameters, "lt", false);                              if (temp == "not found") { temp = "false"; }
+                       //bool lt = isTrue(temp);
                        
-                       if (lt)         {  matrix = 2;  }
-                       else            {  matrix = 1;  }
+                       //if (lt)               {  matrix = 2;  }
+                       //else          {  matrix = 1;  }
 
 
                }
@@ -108,14 +108,14 @@ int PCACommand::execute(){
                else{
                        fbase += ".";
                }
-               read(filename, matrix, names, D);
+               read(filename, names, D);
        
                double offset = 0.0000;
                vector<double> d;
                vector<double> e;
                vector<vector<double> > G = D;
                vector<vector<double> > copy_G;
-               int rank = D.size();
+               //int rank = D.size();
                
                cout << "\nProcessing...\n";
                
@@ -160,7 +160,7 @@ void PCACommand::get_comment(istream& f, char begin, char end){
 
 /*********************************************************************************************************************************/
 
-void PCACommand::read_mega(istream& f, int square_m, vector<string>& name_list, vector<vector<double> >& d){
+void PCACommand::read_mega(istream& f, vector<string>& name_list, vector<vector<double> >& d){
        try {
                get_comment(f, '#', '\n');
                
@@ -262,23 +262,47 @@ void PCACommand::read_phylip(istream& f, int square_m, vector<string>& name_list
 
 /*********************************************************************************************************************************/
 
-void PCACommand::read(string fname, int m, vector<string>& names, vector<vector<double> >& D){
+void PCACommand::read(string fname, vector<string>& names, vector<vector<double> >& D){
        try {
-               ifstream f(fname.c_str());
-               if(!f) {
-                       cerr << "Error: Could not open " << fname << endl;
-                       exit(1);
-               }
+               ifstream f;
+               openInputFile(fname, f);
+               
                char test = f.peek();
                
                if(test == '#'){
-                       read_mega(f, m, names, D);
+                       read_mega(f, names, D);
                }
                else{
+                       //check whether matrix is square
+                       char d;
+                       int m = 1;
+                       int numSeqs;
+                       string name;
+                       
+                       f >> numSeqs >> name; 
+                       
+                       while((d=f.get()) != EOF){
+                               
+                               //is d a number meaning its square
+                               if(isalnum(d)){ 
+                                       m = 1; 
+                                       break; 
+                               }
+                               
+                               //is d a line return meaning its lower triangle
+                               if(d == '\n'){
+                                       m = 2;
+                                       break;
+                               }
+                       }
+                       f.close();
+                       
+                       //reopen to get back to beginning
+                       openInputFile(fname, f);                        
                        read_phylip(f, m, names, D);
                }
                
-               int rank = D.size();
+               //int rank = D.size();
        }
        catch(exception& e) {
                errorOut(e, "PCACommand", "read");
index 822be3b905b1a808e74c8b3b59272ca2431cf763..143e83dda8efbfb2bbd3548e0c02f47920433f26 100644 (file)
@@ -27,12 +27,11 @@ private:
        bool abort;
        string phylipfile, columnfile, namefile, format, filename, fbase;
        float cutoff, precision;
-       int matrix;
        
        void get_comment(istream&, char, char);
-       void read_mega(istream&, int, vector<string>&, vector<vector<double> >&);
+       void read_mega(istream&, vector<string>&, vector<vector<double> >&);
        void read_phylip(istream&, int, vector<string>&, vector<vector<double> >&);
-       void read(string, int, vector<string>&, vector<vector<double> >&);
+       void read(string, vector<string>&, vector<vector<double> >&);
        double pythag(double, double);
        void matrix_mult(vector<vector<double> >, vector<vector<double> >, vector<vector<double> >&);
        void recenter(double, vector<vector<double> >, vector<vector<double> >&);
index 2a441922cd28ccf1850a6fedbd954f16ebc3ecf3..8d03607820955f6f4474a78f0505fad9de93ad81 100644 (file)
@@ -31,6 +31,7 @@ PhyloTree::PhyloTree(string tfile){
                numSeqs = 0;
                tree.push_back(TaxNode("Root"));
                tree[0].heirarchyID = "0";
+               maxLevel = 0;
                
                ifstream in;
                openInputFile(tfile, in);
@@ -151,6 +152,10 @@ void PhyloTree::assignHeirarchyIDs(int index){
                        tree[it->second].heirarchyID = tree[index].heirarchyID + '.' + toString(counter);
                        counter++;
                        tree[it->second].level = tree[index].level + 1;
+                       
+                       //save maxLevel for binning the unclassified seqs
+                       if (tree[it->second].level > maxLevel) { maxLevel = tree[it->second].level; } 
+                       
                        assignHeirarchyIDs(it->second);
                }
        }
@@ -159,7 +164,60 @@ void PhyloTree::assignHeirarchyIDs(int index){
                exit(1);
        }
 }
-
+/**************************************************************************************************/
+void PhyloTree::binUnclassified(){
+       try {
+               map<string, int>::iterator itBin;
+               map<string, int>::iterator childPointer;
+               
+               //go through the seqs and if a sequence finest taxon is not the same level as the most finely defined taxon then classify it as unclassified where necessary
+               for (itBin = name2Taxonomy.begin(); itBin != name2Taxonomy.end(); itBin++) {
+               
+                       int level = tree[itBin->second].level;
+                       int currentNode = itBin->second;
+                       
+                       //this sequence is unclassified at some levels
+                       while(level != maxLevel){
+                       
+                               level++;
+                       
+                               string taxon = "unclassified";  
+                               
+                               //does the parent have a child names 'unclassified'?
+                               childPointer = tree[currentNode].children.find(taxon);
+                               
+                               if(childPointer != tree[currentNode].children.end()){   //if the node already exists, move on
+                                       currentNode = childPointer->second; //currentNode becomes 'unclassified'
+                                       tree[currentNode].accessions.push_back(itBin->first);  //add this seq
+                                       name2Taxonomy[itBin->first] = currentNode;
+                               }
+                               else{                                                                                   //otherwise, create it
+                                       tree.push_back(TaxNode(taxon));
+                                       numNodes++;
+                                       tree[currentNode].children[taxon] = numNodes-1;
+                                       tree[numNodes-1].parent = currentNode;
+                                                                       
+                                       currentNode = tree[currentNode].children[taxon];
+                                       tree[currentNode].accessions.push_back(itBin->first);
+                                       name2Taxonomy[itBin->first] = currentNode;
+                               }
+                               
+                               if (level == maxLevel) {   uniqueTaxonomies[currentNode] = currentNode; }
+                       }
+               }
+               
+               //clear HeirarchyIDs and reset them
+               for (int i = 1; i < tree.size(); i++) {
+                       tree[i].heirarchyID = "";
+               }
+               assignHeirarchyIDs(0);
+               
+       }
+       catch(exception& e) {
+               errorOut(e, "PhyloTree", "binUnclassified");
+               exit(1);
+       }
+}
 /**************************************************************************************************/
 
 void PhyloTree::print(ofstream& out){
@@ -182,6 +240,8 @@ void PhyloTree::print(int i, ofstream& out){
                        out <<tree[it->second].level << '\t' << tree[it->second].heirarchyID << '\t' << tree[it->second].name << '\t' << tree[it->second].children.size() << '\t' << tree[it->second].accessions.size() << endl;
                        print(it->second, out);
                }
+               
+               
        }
        catch(exception& e) {
                errorOut(e, "PhyloTree", "print");
index f8365d53e7664f9a4ca02cb09dea59cabca11f0b..6e5b58d85c2430807af15e0345a36fece9f0f90e 100644 (file)
@@ -35,7 +35,9 @@ public:
        void addSeqToTree(string, string);
        void assignHeirarchyIDs(int);
        void print(ofstream&);
-       vector<int> getGenusNodes();    
+       vector<int> getGenusNodes();
+       void binUnclassified();
+               
        TaxNode get(int i)                              {       return tree[i]; }
        TaxNode get(string seqName)             {       return tree[name2Taxonomy[seqName]];    }
        int getIndex(string seqName)    {       return name2Taxonomy[seqName];  }
@@ -49,6 +51,7 @@ private:
        void print(int, ofstream&);
        int numNodes;
        int numSeqs;
+       int maxLevel;
 };
 
 /**************************************************************************************************/
index 326e695b20965c451ac17fe5a70bc11b923d6c3e..b551e5f20f7a4ed326dbb1d40b7ce9913826a2b3 100644 (file)
@@ -21,7 +21,7 @@ UnifracUnweightedCommand::UnifracUnweightedCommand(string option) {
                
                else {
                        //valid paramters for this command
-                       string Array[] =  {"groups","iters"};
+                       string Array[] =  {"groups","iters","distance","random"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
                        OptionParser parser(option);
@@ -46,10 +46,24 @@ UnifracUnweightedCommand::UnifracUnweightedCommand(string option) {
                                globaldata->Groups = Groups;
                        }
                                
-                       itersString = validParameter.validFile(parameters, "iters", false);                     if (itersString == "not found") { itersString = "1000"; }
+                       itersString = validParameter.validFile(parameters, "iters", false);                             if (itersString == "not found") { itersString = "1000"; }
                        convert(itersString, iters); 
                        
+                       string temp = validParameter.validFile(parameters, "distance", false);                  if (temp == "not found") { temp = "false"; }
+                       phylip = isTrue(temp);
                        
+                       temp = validParameter.validFile(parameters, "random", false);                                   if (temp == "not found") { temp = "true"; }
+                       random = isTrue(temp);
+                       
+                       if (!random) {  iters = 0;  } //turn off random calcs
+                       
+                       //if user selects distance = true and no groups it won't calc the pairwise
+                       if ((phylip) && (Groups.size() == 0)) {
+                               groups = "all";
+                               splitAtDash(groups, Groups);
+                               globaldata->Groups = Groups;
+                       }
+               
                        if (abort == false) {
                                T = globaldata->gTree;
                                tmap = globaldata->gTreemap;
@@ -80,9 +94,11 @@ UnifracUnweightedCommand::UnifracUnweightedCommand(string option) {
 void UnifracUnweightedCommand::help(){
        try {
                mothurOut("The unifrac.unweighted command can only be executed after a successful read.tree command.\n");
-               mothurOut("The unifrac.unweighted command parameters are groups and iters.  No parameters are required.\n");
+               mothurOut("The unifrac.unweighted command parameters are groups, iters, distance and random.  No parameters are required.\n");
                mothurOut("The groups parameter allows you to specify which of the groups in your groupfile you would like analyzed.  You must enter at least 1 valid group.\n");
                mothurOut("The group names are separated by dashes.  The iters parameter allows you to specify how many random trees you would like compared to your tree.\n");
+               mothurOut("The distance parameter allows you to create a distance file from the results. The default is false.\n");
+               mothurOut("The random parameter allows you to shut off the comparison to random trees. The default is true, meaning compare your trees with randomly generated trees.\n");
                mothurOut("The unifrac.unweighted command should be in the following format: unifrac.unweighted(groups=yourGroups, iters=yourIters).\n");
                mothurOut("Example unifrac.unweighted(groups=A-B-C, iters=500).\n");
                mothurOut("The default value for groups is all the groups in your groupfile, and iters is 1000.\n");
@@ -113,7 +129,7 @@ int UnifracUnweightedCommand::execute() {
                for (int i = 0; i < T.size(); i++) {
                        counter = 0;
                        
-                       output = new ColumnFile(globaldata->getTreeFile()  + toString(i+1) + ".unweighted", itersString);
+                       if (random)  {  output = new ColumnFile(globaldata->getTreeFile()  + toString(i+1) + ".unweighted", itersString);  }
                        
                        //get unweighted for users tree
                        rscoreFreq.resize(numComp);  
@@ -127,7 +143,9 @@ int UnifracUnweightedCommand::execute() {
                        for(int k = 0; k < numComp; k++) {
                                //saves users score
                                utreeScores[k].push_back(userData[k]);
-
+                               
+                               //add users score to validscores
+                               validScores[userData[k]] = userData[k];
                        }
                        
                        //get unweighted scores for random trees
@@ -160,15 +178,16 @@ int UnifracUnweightedCommand::execute() {
                                        if (it2 != rscoreFreq[a].end()) {  rscoreFreq[a][it->first] /= iters; rcumul-= it2->second;  }
                                        else { rscoreFreq[a][it->first] = 0.0000; } //no random trees with that score
                                }
-                               UWScoreSig[a].push_back(rCumul[a][userData[a]]);
+                               
+                               if (random) {   UWScoreSig[a].push_back(rCumul[a][userData[a]]);        }
+                               else            {       UWScoreSig[a].push_back(0.0);                                           }
                        }
                
-               
-               
-                       printUnweightedFile();
+                       //print output files
                        printUWSummaryFile(i);
+                       if (random)  {  printUnweightedFile();  delete output;  }
+                       if (phylip) {   createPhylipFile(i);            }
                        
-                       delete output;
                        rscoreFreq.clear(); 
                        rCumul.clear();  
                        validScores.clear(); 
@@ -193,13 +212,15 @@ void UnifracUnweightedCommand::printUnweightedFile() {
        try {
                vector<double> data;
                vector<string> tags;
-               tags.push_back("Score"); tags.push_back("RandFreq"); tags.push_back("RandCumul");
                
+               tags.push_back("Score");
+               tags.push_back("RandFreq"); tags.push_back("RandCumul");
+                       
                for(int a = 0; a < numComp; a++) {
                        output->initFile(groupComb[a], tags);
                        //print each line
                        for (map<float,float>::iterator 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]); 
+                               data.push_back(it->first);  data.push_back(rscoreFreq[a][it->first]); data.push_back(rCumul[a][it->first]);                                             
                                output->output(data);
                                data.clear();
                        } 
@@ -225,14 +246,20 @@ void UnifracUnweightedCommand::printUWSummaryFile(int i) {
                        outSum << i+1 << '\t';
                        mothurOut(toString(i+1) + "\t");
                        
-                       if (UWScoreSig[a][0] > (1/(float)iters)) {
-                               outSum << setprecision(6) << groupComb[a]  << '\t' << utreeScores[a][0] << '\t' << setprecision(itersString.length()) << UWScoreSig[a][0] << endl;
-                               cout << setprecision(6)  << groupComb[a]  << '\t' << utreeScores[a][0] << '\t' << setprecision(itersString.length()) << UWScoreSig[a][0] << endl; 
-                               mothurOutJustToLog(groupComb[a]  + "\t" + toString(utreeScores[a][0])  + "\t" + toString(UWScoreSig[a][0])); mothurOutEndLine(); 
-                       }else {
-                               outSum << setprecision(6) << groupComb[a]  << '\t' << utreeScores[a][0] << '\t' << setprecision(itersString.length()) << "<" << (1/float(iters)) << endl;
-                               cout << setprecision(6)  << groupComb[a]  << '\t' << utreeScores[a][0] << '\t' << setprecision(itersString.length()) << "<" << (1/float(iters)) << endl; 
-                               mothurOutJustToLog(groupComb[a]  + "\t" + toString(utreeScores[a][0])  + "\t<" + toString((1/float(iters)))); mothurOutEndLine();
+                       if (random) {
+                               if (UWScoreSig[a][0] > (1/(float)iters)) {
+                                       outSum << setprecision(6) << groupComb[a]  << '\t' << utreeScores[a][0] << '\t' << setprecision(itersString.length()) << UWScoreSig[a][0] << endl;
+                                       cout << setprecision(6)  << groupComb[a]  << '\t' << utreeScores[a][0] << '\t' << setprecision(itersString.length()) << UWScoreSig[a][0] << endl; 
+                                       mothurOutJustToLog(groupComb[a]  + "\t" + toString(utreeScores[a][0])  + "\t" + toString(UWScoreSig[a][0])); mothurOutEndLine(); 
+                               }else {
+                                       outSum << setprecision(6) << groupComb[a]  << '\t' << utreeScores[a][0] << '\t' << setprecision(itersString.length()) << "<" << (1/float(iters)) << endl;
+                                       cout << setprecision(6)  << groupComb[a]  << '\t' << utreeScores[a][0] << '\t' << setprecision(itersString.length()) << "<" << (1/float(iters)) << endl; 
+                                       mothurOutJustToLog(groupComb[a]  + "\t" + toString(utreeScores[a][0])  + "\t<" + toString((1/float(iters)))); mothurOutEndLine();
+                               }
+                       }else{
+                               outSum << setprecision(6) << groupComb[a]  << '\t' << utreeScores[a][0] << '\t' << "0.00" << endl;
+                               cout << setprecision(6)  << groupComb[a]  << '\t' << utreeScores[a][0] << '\t' << "0.00" << endl; 
+                               mothurOutJustToLog(groupComb[a]  + "\t" + toString(utreeScores[a][0])  + "\t0.00"); mothurOutEndLine();
                        }
                }
                
@@ -242,7 +269,49 @@ void UnifracUnweightedCommand::printUWSummaryFile(int i) {
                exit(1);
        }
 }
-
 /***********************************************************/
+void UnifracUnweightedCommand::createPhylipFile(int i) {
+       try {
+               string phylipFileName = globaldata->getTreeFile()  + toString(i+1) + ".unweighted.dist";
+               ofstream out;
+               openOutputFile(phylipFileName, out);
+                       
+               //output numSeqs
+               out << globaldata->Groups.size() << endl;
+                       
+               //make matrix with scores in it
+               vector< vector<float> > dists;  dists.resize(globaldata->Groups.size());
+               for (int i = 0; i < globaldata->Groups.size(); i++) {
+                       dists[i].resize(globaldata->Groups.size(), 0.0);
+               }
+               
+               //flip it so you can print it
+               int count = 0;
+               for (int r=0; r<globaldata->Groups.size(); r++) { 
+                       for (int l = r+1; l < globaldata->Groups.size(); l++) {
+                               dists[r][l] = (1.0 - utreeScores[count][0]);
+                               dists[l][r] = (1.0 - utreeScores[count][0]);
+                               count++;
+                       }
+               }
+               
+               //output to file
+               for (int r=0; r<globaldata->Groups.size(); r++) { 
+                       //output name
+                       out << globaldata->Groups[r] << '\t';
+                       
+                       //output distances
+                       for (int l = 0; l < r; l++) {   out  << dists[r][l] << '\t';  }
+                       out << endl;
+               }
+               out.close();
+       }
+       catch(exception& e) {
+               errorOut(e, "UnifracUnweightedCommand", "createPhylipFile");
+               exit(1);
+       }
+}
+/***********************************************************/
+
 
 
index 2fca41a8388e7d3a6f20bbe79536cae9246eb2fb..155fa75d6185d3d1bf10923ca56903a9e3e85aa8 100644 (file)
@@ -45,7 +45,7 @@ class UnifracUnweightedCommand : public Command {
                vector< map<float, float> > rscoreFreq;  //map <unweighted score, number of random trees with that score.> -vector entry for each combination.
                vector< map<float, float> > rCumul;  //map <unweighted score, cumulative percentage of number of random trees with that score or higher.> -vector entry for each combination.
                
-               bool abort;
+               bool abort, phylip, random;
                string groups, itersString;
                vector<string> Groups; //holds groups to be used
 
@@ -54,6 +54,7 @@ class UnifracUnweightedCommand : public Command {
                
                void printUWSummaryFile(int);
                void printUnweightedFile();
+               void createPhylipFile(int);
                 
                
 };
index fb3eb3ca2158d766a57b1f22c3a9c57bfe573370..f9cdd5a86458c6f3039e4392e6e8b27f7d5eaa08 100644 (file)
@@ -21,7 +21,7 @@ UnifracWeightedCommand::UnifracWeightedCommand(string option) {
                
                else {
                        //valid paramters for this command
-                       string Array[] =  {"groups","iters"};
+                       string Array[] =  {"groups","iters","distance","random"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
                        OptionParser parser(option);
@@ -48,7 +48,15 @@ UnifracWeightedCommand::UnifracWeightedCommand(string option) {
                                
                        itersString = validParameter.validFile(parameters, "iters", false);                     if (itersString == "not found") { itersString = "1000"; }
                        convert(itersString, iters); 
+                       
+                       string temp = validParameter.validFile(parameters, "distance", false);                  if (temp == "not found") { temp = "false"; }
+                       phylip = isTrue(temp);
                
+                       temp = validParameter.validFile(parameters, "random", false);                                   if (temp == "not found") { temp = "true"; }
+                       random = isTrue(temp);
+                       
+                       if (!random) {  iters = 0;  } //turn off random calcs
+
                        
                        if (abort == false) {
                                T = globaldata->gTree;
@@ -78,9 +86,11 @@ UnifracWeightedCommand::UnifracWeightedCommand(string option) {
 void UnifracWeightedCommand::help(){
        try {
                mothurOut("The unifrac.weighted command can only be executed after a successful read.tree command.\n");
-               mothurOut("The unifrac.weighted command parameters are groups and iters.  No parameters are required.\n");
+               mothurOut("The unifrac.weighted command parameters are groups, iters, distance and random.  No parameters are required.\n");
                mothurOut("The groups parameter allows you to specify which of the groups in your groupfile you would like analyzed.  You must enter at least 2 valid groups.\n");
                mothurOut("The group names are separated by dashes.  The iters parameter allows you to specify how many random trees you would like compared to your tree.\n");
+               mothurOut("The distance parameter allows you to create a distance file from the results. The default is false.\n");
+               mothurOut("The random parameter allows you to shut off the comparison to random trees. The default is true, meaning compare your trees with randomly generated trees.\n");
                mothurOut("The unifrac.weighted command should be in the following format: unifrac.weighted(groups=yourGroups, iters=yourIters).\n");
                mothurOut("Example unifrac.weighted(groups=A-B-C, iters=500).\n");
                mothurOut("The default value for groups is all the groups in your groupfile, and iters is 1000.\n");
@@ -100,7 +110,7 @@ int UnifracWeightedCommand::execute() {
                if (abort == true) { return 0; }
                
                Progress* reading;
-               reading = new Progress("Comparing to random:", iters);
+               if (random) {   reading = new Progress("Comparing to random:", iters);  }
                
                //get weighted for users tree
                userData.resize(numComp,0);  //data[0] = weightedscore AB, data[1] = weightedscore AC...
@@ -115,7 +125,7 @@ int UnifracWeightedCommand::execute() {
                        rScores.resize(numComp);  //data[0] = weightedscore AB, data[1] = weightedscore AC...
                        uScores.resize(numComp);  //data[0] = weightedscore AB, data[1] = weightedscore AC...
                        
-                       output = new ColumnFile(globaldata->getTreeFile()  + toString(i+1) + ".weighted", itersString);
+                       if (random) {  output = new ColumnFile(globaldata->getTreeFile()  + toString(i+1) + ".weighted", itersString);  } 
 
                        userData = weighted->getValues(T[i]);  //userData[0] = weightedscore
                        
@@ -154,26 +164,28 @@ int UnifracWeightedCommand::execute() {
 
                        //removeValidScoresDuplicates(); 
                        //find the signifigance of the score for summary file
-                       for (int f = 0; f < numComp; f++) {
-                               //sort random scores
-                               sort(rScores[f].begin(), rScores[f].end());
+                       if (random) {
+                               for (int f = 0; f < numComp; f++) {
+                                       //sort random scores
+                                       sort(rScores[f].begin(), rScores[f].end());
+                                       
+                                       //the index of the score higher than yours is returned 
+                                       //so if you have 1000 random trees the index returned is 100 
+                                       //then there are 900 trees with a score greater then you. 
+                                       //giving you a signifigance of 0.900
+                                       int index = findIndex(userData[f], f);    if (index == -1) { mothurOut("error in UnifracWeightedCommand"); mothurOutEndLine(); exit(1); } //error code
+                                       
+                                       //the signifigance is the number of trees with the users score or higher 
+                                       WScoreSig.push_back((iters-index)/(float)iters);
+                               }
                                
-                               //the index of the score higher than yours is returned 
-                               //so if you have 1000 random trees the index returned is 100 
-                               //then there are 900 trees with a score greater then you. 
-                               //giving you a signifigance of 0.900
-                               int index = findIndex(userData[f], f);    if (index == -1) { mothurOut("error in UnifracWeightedCommand"); mothurOutEndLine(); exit(1); } //error code
-                       
-                               //the signifigance is the number of trees with the users score or higher 
-                               WScoreSig.push_back((iters-index)/(float)iters);
+                               //out << "Tree# " << i << endl;
+                               calculateFreqsCumuls();
+                               printWeightedFile();
+                               
+                               delete output;
                        }
                        
-                       //out << "Tree# " << i << endl;
-                       calculateFreqsCumuls();
-                       printWeightedFile();
-                       
-                       delete output;
-                       
                        //clear data
                        rScores.clear();
                        uScores.clear();
@@ -181,11 +193,12 @@ int UnifracWeightedCommand::execute() {
                }
                
                //finish progress bar
-               reading->finish();
-               delete reading;
+               if (random) {   reading->finish();      delete reading;         }
                
                printWSummaryFile();
                
+               if (phylip) {   createPhylipFile();             }
+
                //clear out users groups
                globaldata->Groups.clear();
                
@@ -238,14 +251,20 @@ void UnifracWeightedCommand::printWSummaryFile() {
                int count = 0;
                for (int i = 0; i < T.size(); i++) { 
                        for (int j = 0; j < numComp; j++) {
-                               if (WScoreSig[count] > (1/(float)iters)) {
-                                       outSum << setprecision(6) << i+1 << '\t' << groupComb[j] << '\t' << utreeScores[count] << '\t' << setprecision(itersString.length()) << WScoreSig[count] << endl; 
-                                       cout << setprecision(6) << i+1 << '\t' << groupComb[j] << '\t' << utreeScores[count] << '\t' << setprecision(itersString.length()) << WScoreSig[count] << endl; 
-                                       mothurOutJustToLog(toString(i+1) +"\t" + groupComb[j] +"\t" + toString(utreeScores[count]) +"\t" +  toString(WScoreSig[count])); mothurOutEndLine();  
+                               if (random) {
+                                       if (WScoreSig[count] > (1/(float)iters)) {
+                                               outSum << setprecision(6) << i+1 << '\t' << groupComb[j] << '\t' << utreeScores[count] << '\t' << setprecision(itersString.length()) << WScoreSig[count] << endl; 
+                                               cout << setprecision(6) << i+1 << '\t' << groupComb[j] << '\t' << utreeScores[count] << '\t' << setprecision(itersString.length()) << WScoreSig[count] << endl; 
+                                               mothurOutJustToLog(toString(i+1) +"\t" + groupComb[j] +"\t" + toString(utreeScores[count]) +"\t" +  toString(WScoreSig[count])); mothurOutEndLine();  
+                                       }else{
+                                               outSum << setprecision(6) << i+1 << '\t' << groupComb[j] << '\t' << utreeScores[count] << '\t' << setprecision(itersString.length()) << "<" << (1/float(iters)) << endl; 
+                                               cout << setprecision(6) << i+1 << '\t' << groupComb[j] << '\t' << utreeScores[count] << '\t' << setprecision(itersString.length()) << "<" << (1/float(iters)) << endl; 
+                                               mothurOutJustToLog(toString(i+1) +"\t" + groupComb[j] +"\t" + toString(utreeScores[count]) +"\t<" +  toString((1/float(iters)))); mothurOutEndLine();  
+                                       }
                                }else{
-                                       outSum << setprecision(6) << i+1 << '\t' << groupComb[j] << '\t' << utreeScores[count] << '\t' << setprecision(itersString.length()) << "<" << (1/float(iters)) << endl; 
-                                       cout << setprecision(6) << i+1 << '\t' << groupComb[j] << '\t' << utreeScores[count] << '\t' << setprecision(itersString.length()) << "<" << (1/float(iters)) << endl; 
-                                       mothurOutJustToLog(toString(i+1) +"\t" + groupComb[j] +"\t" + toString(utreeScores[count]) +"\t<" +  toString((1/float(iters)))); mothurOutEndLine();  
+                                       outSum << setprecision(6) << i+1 << '\t' << groupComb[j] << '\t' << utreeScores[count] << '\t' << "0.00" << endl; 
+                                       cout << setprecision(6) << i+1 << '\t' << groupComb[j] << '\t' << utreeScores[count] << '\t' << "0.00" << endl; 
+                                       mothurOutJustToLog(toString(i+1) +"\t" + groupComb[j] +"\t" + toString(utreeScores[count]) +"\t0.00"); mothurOutEndLine(); 
                                }
                                count++;
                        }
@@ -257,7 +276,52 @@ void UnifracWeightedCommand::printWSummaryFile() {
                exit(1);
        }
 }
+/***********************************************************/
+void UnifracWeightedCommand::createPhylipFile() {
+       try {
+               int count = 0;
+               //for each tree
+               for (int i = 0; i < T.size(); i++) { 
+               
+                       string phylipFileName = globaldata->getTreeFile()  + toString(i+1) + ".weighted.dist";
+                       ofstream out;
+                       openOutputFile(phylipFileName, out);
+                       
+                       //output numSeqs
+                       out << globaldata->Groups.size() << endl;
+                       
+                       //make matrix with scores in it
+                       vector< vector<float> > dists;  dists.resize(globaldata->Groups.size());
+                       for (int i = 0; i < globaldata->Groups.size(); i++) {
+                               dists[i].resize(globaldata->Groups.size(), 0.0);
+                       }
+                       
+                       //flip it so you can print it
+                       for (int r=0; r<globaldata->Groups.size(); r++) { 
+                               for (int l = r+1; l < globaldata->Groups.size(); l++) {
+                                       dists[r][l] = (1.0 - utreeScores[count]);
+                                       dists[l][r] = (1.0 - utreeScores[count]);
+                                       count++;
+                               }
+                       }
 
+                       //output to file
+                       for (int r=0; r<globaldata->Groups.size(); r++) { 
+                               //output name
+                               out << globaldata->Groups[r] << '\t';
+                               
+                               //output distances
+                               for (int l = 0; l < r; l++) {   out  << dists[r][l] << '\t';  }
+                               out << endl;
+                       }
+                       out.close();
+               }
+       }
+       catch(exception& e) {
+               errorOut(e, "UnifracWeightedCommand", "createPhylipFile");
+               exit(1);
+       }
+}
 /***********************************************************/
 int UnifracWeightedCommand::findIndex(float score, int index) {
        try{
index 5f55deea98379b5813bed720fe9fad3bd76ac23f..9c0ad9939221f6a94083cac9300344004e2e707d 100644 (file)
@@ -49,7 +49,7 @@ class UnifracWeightedCommand : public Command {
                vector< map<float, float> > rCumul;  //map <weighted score, cumulative percentage of number of random trees with that score or higher.> -vector entry for each c                                                                
                map<float, float>  validScores;  //map contains scores from random
                
-               bool abort;
+               bool abort, phylip, random;
                string groups, itersString;
                vector<string> Groups; //holds groups to be used
 
@@ -58,6 +58,7 @@ class UnifracWeightedCommand : public Command {
                
                void printWSummaryFile();
                void printWeightedFile();  
+               void createPhylipFile();
                //void removeValidScoresDuplicates();
                int findIndex(float, int);
                void calculateFreqsCumuls();