]> git.donarmstrong.com Git - mothur.git/commitdiff
changes for 1.12.2
authorwestcott <westcott>
Fri, 30 Jul 2010 12:55:01 +0000 (12:55 +0000)
committerwestcott <westcott>
Fri, 30 Jul 2010 12:55:01 +0000 (12:55 +0000)
makefile
mothur.cpp
nast.cpp
phylotree.cpp
sffinfocommand.cpp
summarycommand.cpp
summarycommand.h
taxonomyequalizer.cpp

index d751bb6b310fada520a10a292b3e45f5b8f4b309..3f0893c5ad82d811fb4c5cf05f86f0326b4561c8 100644 (file)
--- a/makefile
+++ b/makefile
@@ -13,7 +13,7 @@
 
 CXXFLAGS += -O3
 
-MOTHUR_FILES = "\"../Release\""
+MOTHUR_FILES = "\"Enter_your_default_path_here\""
 ifeq  ($(strip $(MOTHUR_FILES)),"\"Enter_your_default_path_here\"")
 else
        CXXFLAGS += -DMOTHUR_FILES=${MOTHUR_FILES}
index c413cedeef8dac80a552349a48129dfb54d50a1d..ea3ea3e521cf6f00c48156df3a6c57e70ef97bda 100644 (file)
@@ -98,9 +98,9 @@ int main(int argc, char *argv[]){
                #endif
                
                //header
-               m->mothurOut("mothur v.1.12.1");
+               m->mothurOut("mothur v.1.12.2");
                m->mothurOutEndLine();          
-               m->mothurOut("Last updated: 7/29/2010");
+               m->mothurOut("Last updated: 7/30/2010");
                m->mothurOutEndLine();  
                m->mothurOutEndLine();          
                m->mothurOut("by");
index 9e26b11a7708590389f59b1c82e76ebca72f1bc1..8ed69fa6820cca9003dd8af1a0cb148c85899753 100644 (file)
--- a/nast.cpp
+++ b/nast.cpp
@@ -132,51 +132,56 @@ void Nast::removeExtraGaps(string& candAln, string tempAln, string newTemplateAl
                                        if((i-leftIndex) <= (rightIndex-i)){            //      the left gap is closer - > move stuff left there's
        
                                                if(leftRoom >= insertLength){                   //      enough room to the left to move
+                       //cout << "lr newTemplateAlign = " << newTemplateAlign.length() << '\t' << i << '\t' << i+insertLength << endl;
                                                        string leftTemplateString = newTemplateAlign.substr(0,i);
-                                                       string rightTemplateString = newTemplateAlign.substr(i+insertLength);
+                                                       string rightTemplateString = newTemplateAlign.substr((i+insertLength));
                                                        newTemplateAlign = leftTemplateString + rightTemplateString;
                                                        longAlignmentLength = newTemplateAlign.length();
-                                                       
-                                                       string leftCandidateString = candAln.substr(0,leftIndex-insertLength+1);
-                                                       string rightCandidateString = candAln.substr(leftIndex+1);
+                       //cout << "lr candAln = " << candAln.length() << '\t' << leftIndex-insertLength+1 << '\t' << leftIndex+1 << endl;                               
+                                                       string leftCandidateString = candAln.substr(0,(leftIndex-insertLength+1));
+                                                       string rightCandidateString = candAln.substr((leftIndex+1));
                                                        candAln = leftCandidateString + rightCandidateString;
                
                                                }
                                                else{                                                                   //      not enough room to the left, have to steal some space to
+                                               
+                       //cout << "in else lr newTemplateAlign = " << newTemplateAlign.length() << '\t' << i << '\t' << i+insertLength << endl;
                                                        string leftTemplateString = newTemplateAlign.substr(0,i);       //      the right
-                                                       string rightTemplateString = newTemplateAlign.substr(i+insertLength);
+                                                       string rightTemplateString = newTemplateAlign.substr((i+insertLength));
                                                        newTemplateAlign = leftTemplateString + rightTemplateString;
                                                        longAlignmentLength = newTemplateAlign.length();
-                                                       
-                                                       string leftCandidateString = candAln.substr(0,leftIndex-leftRoom+1);
-                                                       string insertString = candAln.substr(leftIndex+1,rightIndex-leftIndex-1);
-                                                       string rightCandidateString = candAln.substr(rightIndex+(insertLength-leftRoom));
+                       //cout << " in else lr candAln = " << candAln.length() << '\t' << leftIndex-leftRoom+1 << '\t' << rightIndex-leftIndex-1 << '\t' << rightIndex+(insertLength-leftRoom) << endl;                                 
+                                                       string leftCandidateString = candAln.substr(0,(leftIndex-leftRoom+1));
+                                                       string insertString = candAln.substr((leftIndex+1),(rightIndex-leftIndex-1));
+                                                       string rightCandidateString = candAln.substr((rightIndex+(insertLength-leftRoom)));
                                                        candAln = leftCandidateString + insertString + rightCandidateString;
                                
                                                }
                                        }
                                        else{                                                                           //      the right gap is closer - > move stuff right there's
                                                if(rightRoom >= insertLength){                  //      enough room to the right to move
+                       //cout << "rr newTemplateAlign = " << newTemplateAlign.length() << '\t' << i << '\t' << i+insertLength << endl;
                                                        string leftTemplateString = newTemplateAlign.substr(0,i);
-                                                       string rightTemplateString = newTemplateAlign.substr(i+insertLength);
+                                                       string rightTemplateString = newTemplateAlign.substr((i+insertLength));
                                                        newTemplateAlign = leftTemplateString + rightTemplateString;
                                                        longAlignmentLength = newTemplateAlign.length();
-                                                       
+                       //cout << "rr candAln = " << candAln.length() << '\t' << i << '\t' << rightIndex << '\t' << rightIndex+insertLength << endl;                            
                                                        string leftCandidateString = candAln.substr(0,rightIndex);
-                                                       string rightCandidateString = candAln.substr(rightIndex+insertLength);
+                                                       string rightCandidateString = candAln.substr((rightIndex+insertLength));
                                                        candAln = leftCandidateString + rightCandidateString;   
                                                                        
                                                }
                                                else{                                                                   //      not enough room to the right, have to steal some        
                                                        //      space to the left lets move left and then right...
+                                       //cout << "in else rr newTemplateAlign = " << newTemplateAlign.length() << '\t' << i << '\t' << i+insertLength << endl;
                                                        string leftTemplateString = newTemplateAlign.substr(0,i);
-                                                       string rightTemplateString = newTemplateAlign.substr(i+insertLength);
+                                                       string rightTemplateString = newTemplateAlign.substr((i+insertLength));
                                                        newTemplateAlign = leftTemplateString + rightTemplateString;
                                                        longAlignmentLength = newTemplateAlign.length();
-                                                                       
-                                                       string leftCandidateString = candAln.substr(0,leftIndex-(insertLength-rightRoom)+1);
-                                                       string insertString = candAln.substr(leftIndex+1,rightIndex-leftIndex-1);
-                                                       string rightCandidateString = candAln.substr(rightIndex+rightRoom);
+                                       //cout << "in else rr candAln = " << candAln.length() << '\t' << '\t' << (leftIndex-(insertLength-rightRoom)+1) << '\t' <<  (leftIndex+1,rightIndex-leftIndex-1) << '\t' << (rightIndex+rightRoom) << endl;                             
+                                                       string leftCandidateString = candAln.substr(0,(leftIndex-(insertLength-rightRoom)+1));
+                                                       string insertString = candAln.substr((leftIndex+1),(rightIndex-leftIndex-1));
+                                                       string rightCandidateString = candAln.substr((rightIndex+rightRoom));
                                                        candAln = leftCandidateString + insertString + rightCandidateString;    
                                                                        
                                                }
@@ -186,15 +191,16 @@ void Nast::removeExtraGaps(string& candAln, string tempAln, string newTemplateAl
                                }
                                else{
                        //      there could be a case where there isn't enough room in either direction to move stuff
-
+//cout << "in else else newTemplateAlign = " << newTemplateAlign.length() << '\t' << i << '\t' << (i+leftRoom+rightRoom) << endl;
                                        string leftTemplateString = newTemplateAlign.substr(0,i);       
-                                       string rightTemplateString = newTemplateAlign.substr(i+leftRoom+rightRoom);
+                                       string rightTemplateString = newTemplateAlign.substr((i+leftRoom+rightRoom));
                                        newTemplateAlign = leftTemplateString + rightTemplateString;
                                        longAlignmentLength = newTemplateAlign.length();
                                                        
-                                       string leftCandidateString = candAln.substr(0,leftIndex-leftRoom+1);
-                                       string insertString = candAln.substr(leftIndex+1,rightIndex-leftIndex-1);
-                                       string rightCandidateString = candAln.substr(rightIndex+rightRoom);
+               //cout << "in else else newTemplateAlign = " << candAln.length() << '\t' << (leftIndex-leftRoom+1) << '\t' << (leftIndex+1) << '\t' << (rightIndex-leftIndex-1) << '\t' << (rightIndex+rightRoom) << endl;      
+                                       string leftCandidateString = candAln.substr(0,(leftIndex-leftRoom+1));
+                                       string insertString = candAln.substr((leftIndex+1),(rightIndex-leftIndex-1));
+                                       string rightCandidateString = candAln.substr((rightIndex+rightRoom));
                                        candAln = leftCandidateString + insertString + rightCandidateString;
                                        
                                        i -= (leftRoom + rightRoom);
index d085f6c52ce3c733c7666d1c7df28e95a0575647..6b32e27201b5103e077261117f21fe30b69eb31c 100644 (file)
@@ -370,18 +370,18 @@ void PhyloTree::binUnclassified(string file){
                map<string, int>::iterator childPointer;
                
                vector<TaxNode> copy = tree;
-                               
+                       
                //fill out tree
                fillOutTree(0, copy);
-               
-               //get leaf nodes that may need externsion
+       
+               //get leaf nodes that may need extension
                for (int i = 0; i < copy.size(); i++) {  
 
                        if (copy[i].children.size() == 0) {
                                leafNodes[i] = i;
                        }
                }
-               
+       //cout << "maxLevel = " << maxLevel << endl;    
                int copyNodes = copy.size();
                
                //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
@@ -394,7 +394,7 @@ void PhyloTree::binUnclassified(string file){
                        int currentNode = itLeaf->second;
                        
                        //this sequence is unclassified at some levels
-                       while(level <= maxLevel){
+                       while(level < maxLevel){
                
                                level++;
                        
@@ -434,19 +434,21 @@ void PhyloTree::fillOutTree(int index, vector<TaxNode>& copy) {
        try {
                map<string,int>::iterator it;
                
-               it = copy[index].children.find("unclassified");
-               if (it == copy[index].children.end()) { //no unclassified at this level
-                       string taxon = "unclassified";
-                       copy.push_back(TaxNode(taxon));
-                       copy[index].children[taxon] = copy.size()-1;
-                       copy[copy.size()-1].parent = index;
-                       copy[copy.size()-1].level = copy[index].level + 1;
-               }
+               if (copy[index].level < maxLevel) {
+                       it = copy[index].children.find("unclassified");
+                       if (it == copy[index].children.end()) { //no unclassified at this level
+                               string taxon = "unclassified";
+                               copy.push_back(TaxNode(taxon));
+                               copy[index].children[taxon] = copy.size()-1;
+                               copy[copy.size()-1].parent = index;
+                               copy[copy.size()-1].level = copy[index].level + 1;
+                       }
                
-               if (tree[index].level <= maxLevel) {
-                       for(it=tree[index].children.begin();it!=tree[index].children.end();it++){ //check your children
+                       
+                       for(it=copy[index].children.begin();it!=copy[index].children.end();it++){ //check your children
                                fillOutTree(it->second, copy);
                        }
+                       
                }
                
        }
index f8ba25b5fabd1b8485065a548e47911cb0c8c1e3..38322ac86c2a2d440b0dd7f7ac097ef0abb044b2 100644 (file)
@@ -405,7 +405,7 @@ int SffInfoCommand::readHeader(ifstream& in, Header& header){
                        char buffer4 [2];
                        in.read(buffer4, 2);
                        header.clipQualLeft =  be_int2(*(unsigned short *)(&buffer4));
-                       header.clipQualLeft = 5;
+                       header.clipQualLeft = 5; 
                        
                        //read clip qual right
                        char buffer5 [2];
index b086dff619d18046dd0d3cbaabf109a2976421b3..95f42626c9b324a0622c1ff99806384184d42714 100644 (file)
@@ -44,7 +44,7 @@ SummaryCommand::SummaryCommand(string option)  {
                
                else {
                        //valid paramters for this command
-                       string Array[] =  {"label","calc","abund","size","outputdir","inputdir"};
+                       string Array[] =  {"label","calc","abund","size","outputdir","groupmode","inputdir"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
                        OptionParser parser(option);
@@ -94,6 +94,10 @@ SummaryCommand::SummaryCommand(string option)  {
                        
                        temp = validParameter.validFile(parameters, "size", false);                     if (temp == "not found") { temp = "0"; }
                        convert(temp, size); 
+                       
+                       temp = validParameter.validFile(parameters, "groupmode", false);                if (temp == "not found") { temp = "F"; }
+                       groupMode = isTrue(temp);
+                       
        
                }
        }
@@ -108,12 +112,13 @@ void SummaryCommand::help(){
        try {
                m->mothurOut("The summary.single command can only be executed after a successful read.otu WTIH ONE EXECEPTION.\n");
                m->mothurOut("The summary.single command can be executed after a successful cluster command.  It will use the .list file from the output of the cluster.\n");
-               m->mothurOut("The summary.single command parameters are label, calc, abund.  No parameters are required.\n");
+               m->mothurOut("The summary.single command parameters are label, calc, abund and groupmode.  No parameters are required.\n");
                m->mothurOut("The summary.single command should be in the following format: \n");
                m->mothurOut("summary.single(label=yourLabel, calc=yourEstimators).\n");
                m->mothurOut("Example summary.single(label=unique-.01-.03, calc=sobs-chao-ace-jack-bootstrap-shannon-npshannon-simpson).\n");
                validCalculator->printCalc("summary", cout);
                m->mothurOut("The default value calc is sobs-chao-ace-jack-shannon-npshannon-simpson\n");
+               m->mothurOut("If you are running summary.single with a shared file and would like your summary results collated in one file, set groupmode=t. (Default=False).\n");
                m->mothurOut("The label parameter is used to analyze specific labels in your input.\n");
                m->mothurOut("Note: No spaces between parameter labels (i.e. label), '=' and parameters (i.e.yourLabels).\n\n");
        }
@@ -142,8 +147,14 @@ int SummaryCommand::execute(){
                
                if (m->control_pressed) { if (hadShared != "") {  globaldata->setSharedFile(hadShared); globaldata->setFormat("sharedfile");  } return 0; }
                
+               int numLines = 0;
+               int numCols = 0;
+               
                for (int p = 0; p < inputFileNames.size(); p++) {
                        
+                       numLines = 0;
+                       numCols = 0;
+                       
                        string fileNameRoot = outputDir + getRootName(getSimpleName(inputFileNames[p])) + "summary";
                        globaldata->inputFileName = inputFileNames[p];
                        outputNames.push_back(fileNameRoot);
@@ -221,9 +232,11 @@ int SummaryCommand::execute(){
                        for(int i=0;i<sumCalculators.size();i++){
                                if(sumCalculators[i]->getCols() == 1){
                                        outputFileHandle << '\t' << sumCalculators[i]->getName();
+                                       numCols++;
                                }
                                else{
                                        outputFileHandle << '\t' << sumCalculators[i]->getName() << "\t" << sumCalculators[i]->getName() << "_lci\t" << sumCalculators[i]->getName() << "_hci";
+                                       numCols += 3;
                                }
                        }
                        outputFileHandle << endl;
@@ -254,6 +267,7 @@ int SummaryCommand::execute(){
                                                sumCalculators[i]->print(outputFileHandle);
                                        }
                                        outputFileHandle << endl;
+                                       numLines++;
                                }
                                
                                if ((anyLabelsToProcess(sabund->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) {
@@ -276,6 +290,7 @@ int SummaryCommand::execute(){
                                                sumCalculators[i]->print(outputFileHandle);
                                        }
                                        outputFileHandle << endl;
+                                       numLines++;
                                        
                                        //restore real lastlabel to save below
                                        sabund->setLabel(saveLabel);
@@ -318,6 +333,7 @@ int SummaryCommand::execute(){
                                        sumCalculators[i]->print(outputFileHandle);
                                }
                                outputFileHandle << endl;
+                               numLines++;
                                delete sabund;
                        }
                        
@@ -337,6 +353,11 @@ int SummaryCommand::execute(){
                
                if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) {        remove(outputNames[i].c_str());  }  return 0;  }
                
+               //create summary file containing all the groups data for each label - this function just combines the info from the files already created.
+               if ((hadShared != "") && (groupMode)) {   outputNames.push_back(createGroupSummaryFile(numLines, numCols, outputNames));  }
+               
+               if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) {        remove(outputNames[i].c_str());  }  return 0;  }
+               
                m->mothurOutEndLine();
                m->mothurOut("Output File Names: "); m->mothurOutEndLine();
                for (int i = 0; i < outputNames.size(); i++) {  m->mothurOut(outputNames[i]); m->mothurOutEndLine();    }
@@ -409,3 +430,72 @@ vector<string> SummaryCommand::parseSharedFile(string filename) {
        }
 }
 //**********************************************************************************************************************
+string SummaryCommand::createGroupSummaryFile(int numLines, int numCols, vector<string> outputNames) {
+       try {
+               
+               ofstream out;
+               string combineFileName = outputDir + getRootName(getSimpleName(globaldata->inputFileName)) + "groups.summary";
+               
+               //open combined file
+               openOutputFile(combineFileName, out);
+               
+               //open each groups summary file
+               string newLabel = "";
+               ifstream* temp;
+               map<string, ifstream*> filehandles;
+               for (int i=0; i<outputNames.size(); i++) {
+                       temp = new ifstream;
+                       filehandles[outputNames[i]] = temp;
+                       openInputFile(outputNames[i], *(temp));
+                       
+                       //read through first line - labels
+                       string tempLabel;
+                       if (i == 0) { //we want to save the labels to output below
+                               for (int j = 0; j < numCols+1; j++) {  
+                                       *(temp) >> tempLabel; 
+                                       
+                                       if (j == 1) {  newLabel += "group\t" + tempLabel + '\t';
+                                       }else{  newLabel += tempLabel + '\t';   }
+                               }
+                       }else{  for (int j = 0; j < numCols+1; j++) {  *(temp) >> tempLabel;  }  }
+                       
+                       gobble(*(temp));
+               }
+               
+               //output label line to new file
+               out << newLabel << endl;
+               
+               //for each label
+               for (int i = 0; i < numLines; i++) {
+               
+                       //grab summary data for each group
+                       for (int i=0; i<outputNames.size(); i++) {
+                               string tempLabel;
+                               
+                               for (int j = 0; j < numCols+1; j++) {  
+                                       *(filehandles[outputNames[i]]) >> tempLabel; 
+                                       
+                                       //print to combined file
+                                       if (j == 1) { out << groups[i] << '\t' << tempLabel << '\t';    }
+                                       else{  out << tempLabel << '\t';        }
+                               }
+                               
+                               out << endl;
+                               gobble(*(filehandles[outputNames[i]]));
+                       }
+               }       
+               
+               //close each groups summary file
+               for (int i=0; i<outputNames.size(); i++) {  (*(filehandles[outputNames[i]])).close();  }
+               out.close();
+               
+               //return combine file name
+               return combineFileName;
+               
+       }
+       catch(exception& e) {
+               m->errorOut(e, "SummaryCommand", "createGroupSummaryFile");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
index 6f04fc721ad109545aa899b0a85871982bdc3c80..6b3fa69c67e46cd92d44f0064404d2743dd29b7a 100644 (file)
@@ -35,7 +35,7 @@ private:
        SAbundVector* sabund;
        int abund, size;
 
-       bool abort, allLines;
+       bool abort, allLines, groupMode;
        set<string> labels; //holds labels to be used
        string label, calc, outputDir;
        vector<string>  Estimators;
@@ -43,6 +43,7 @@ private:
        vector<string> groups;
        
        vector<string> parseSharedFile(string);
+       string createGroupSummaryFile(int, int, vector<string>);
 
 
 };
index c7e8cb9e4add8388602dc2bfc12cff28673f7db3..1d2832d5fc3a3ba31861d75d93dd202caf82261e 100644 (file)
@@ -88,19 +88,19 @@ int TaxEqualizer::getHighestLevel(ifstream& in) {
                
                        //save sequences level
                        seqLevels[name] = thisLevel;
-               
+       
                        //is this the longest taxonomy?
                        if (thisLevel > level) {  
                                level = thisLevel;  
                                testTax = tax; //testTax is used to figure out if this file has confidences we need to strip out
-                       }  
+                       } 
                }
                
                int pos = testTax.find_first_of('(');
 
                //if there are '(' then there are confidences we need to take out
                if (pos != -1) {  containsConfidence = true;  }
-               
+       
                return level;
                                        
        }