]> git.donarmstrong.com Git - mothur.git/commitdiff
changed rarefaction.single output
authorwestcott <westcott>
Fri, 23 Dec 2011 16:24:19 +0000 (16:24 +0000)
committerwestcott <westcott>
Fri, 23 Dec 2011 16:24:19 +0000 (16:24 +0000)
getgroupscommand.cpp
mothurout.cpp
mothurout.h
rarefactcommand.cpp
rarefactcommand.h
removegroupscommand.cpp

index e533bc47defa9467b345a0a58cc8b80b59710275..0c42b7dad8281b1d9edd49550c3df95ae773c7e8 100644 (file)
@@ -190,13 +190,9 @@ GetGroupsCommand::GetGroupsCommand(string option)  {
                        else { m->setNameFile(namefile); }
                        
                        groupfile = validParameter.validFile(parameters, "group", true);
-                       if (groupfile == "not open") { abort = true; }
-                       else if (groupfile == "not found") {  
-                               //if there is a current group file, use it
-                               groupfile = m->getGroupFile(); 
-                               if (groupfile != "") { m->mothurOut("Using " + groupfile + " as input file for the group parameter."); m->mothurOutEndLine(); }
-                               else {  m->mothurOut("You have no current groupfile and the group parameter is required."); m->mothurOutEndLine(); abort = true; }
-                       }else { m->setGroupFile(groupfile); }   
+                       if (groupfile == "not open") { groupfile = ""; abort = true; }
+                       else if (groupfile == "not found") {  groupfile = "";                   }
+                       else { m->setGroupFile(groupfile); }    
                        
                        listfile = validParameter.validFile(parameters, "list", true);
                        if (listfile == "not open") { abort = true; }
index 001e8c48a8932374d7266b4e6097036c5b2ed9ac..c58e634500270cce359470ebc56f7244ef994c8c 100644 (file)
@@ -1477,6 +1477,26 @@ int MothurOut::getNumNames(string names){
 }
 /***********************************************************************/
 
+int MothurOut::getNumChar(string line, char c){
+       try {
+               int count = 0;
+               
+               if(line != ""){
+                       for(int i=0;i<line.size();i++){
+                               if(line[i] == c){
+                                       count++;
+                               }
+                       }
+               }
+               
+               return count;
+       }
+       catch(exception& e) {
+               errorOut(e, "MothurOut", "getNumChar");
+               exit(1);
+       }
+}
+/***********************************************************************/
 int MothurOut::mothurRemove(string filename){
        try {
                filename = getFullPathName(filename);
index e61490267270680e6800cfa31a68b47cb1bbbbc3..5ba3d083677a35f4ef0004506bf63f25facb481f 100644 (file)
@@ -94,6 +94,7 @@ class MothurOut {
                void getNumSeqs(ifstream&, int&);
                int getNumSeqs(ifstream&);
                int getNumNames(string);
+               int getNumChar(string, char);
                bool isTrue(string);
                bool isContainingOnlyDigits(string);
        
index bc27d6a3fe00b8dafaba29ce05844c6652459a77..8d1cfc864d35d12d2127672f68af60802cd8b02d 100644 (file)
@@ -287,6 +287,7 @@ int RareFactCommand::execute(){
                                
                if (m->control_pressed) { return 0; }
                
+               map<string, string> nameMap;
                for (int p = 0; p < inputFileNames.size(); p++) {
                        
                        string fileNameRoot = outputDir + m->getRootName(m->getSimpleName(inputFileNames[p]));
@@ -295,6 +296,7 @@ int RareFactCommand::execute(){
                        
                        if (inputFileNames.size() > 1) {
                                m->mothurOutEndLine(); m->mothurOut("Processing group " + groups[p]); m->mothurOutEndLine(); m->mothurOutEndLine();
+                               nameMap[fileNameRoot] = groups[p];
                        }
                        int i;
                        ValidCalculators validCalculator;
@@ -448,7 +450,7 @@ int RareFactCommand::execute(){
                if (m->control_pressed) {  for (int i = 0; i < outputNames.size(); i++) {       m->mothurRemove(outputNames[i]); } 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 ((sharedfile != "") && (groupMode)) {   outputNames = createGroupFile(outputNames);  }
+               if ((sharedfile != "") && (groupMode)) {   outputNames = createGroupFile(outputNames, nameMap);  }
 
                if (m->control_pressed) {  for (int i = 0; i < outputNames.size(); i++) {       m->mothurRemove(outputNames[i]); } return 0; }
 
@@ -465,7 +467,7 @@ int RareFactCommand::execute(){
        }
 }
 //**********************************************************************************************************************
-vector<string> RareFactCommand::createGroupFile(vector<string>& outputNames) {
+vector<string> RareFactCommand::createGroupFile(vector<string>& outputNames, map<string, string> nameMap) {
        try {
                
                vector<string> newFileNames;
@@ -496,6 +498,7 @@ vector<string> RareFactCommand::createGroupFile(vector<string>& outputNames) {
                }
                
                //for each type create a combo file
+               map<int, int> lineToNumber; 
                for (map<string, vector<string> >::iterator it = typesFiles.begin(); it != typesFiles.end(); it++) {
                        
                        ofstream out;
@@ -508,6 +511,7 @@ vector<string> RareFactCommand::createGroupFile(vector<string>& outputNames) {
                        //open each type summary file
                        map<string, vector<string> > files; //maps file name to lines in file
                        int maxLines = 0;
+                       int numColumns = 0;
                        for (int i=0; i<thisTypesFiles.size(); i++) {
                                                                
                                ifstream temp;
@@ -517,15 +521,29 @@ vector<string> RareFactCommand::createGroupFile(vector<string>& outputNames) {
                                m->getline(temp);       m->gobble(temp);
                                
                                vector<string> thisFilesLines;
-                               string group = m->getRootName(thisTypesFiles[i]);
-                               group = group.substr(0, group.length()-1);
-                               group = group.substr(group.find_last_of('.')+1);
+                               string fileNameRoot = m->getRootName(thisTypesFiles[i]);
+                               map<string, string>::iterator itName = nameMap.find(fileNameRoot);
+                               string group = "";
+                               if (itName != nameMap.end()) {
+                                       group = itName->second;
+                               }else {
+                                       group = "not found" + i;
+                                       m->mothurOut("[ERROR]: can't parse filename."); m->mothurOutEndLine();
+                               }
                                
                                thisFilesLines.push_back(group);
+                               int count = 1;
                                while (!temp.eof()){
                                
                                        string thisLine = m->getline(temp);
-                                                                               
+                                       
+                                       string numSampled = thisLine.substr(0, thisLine.find_first_of('\t'));
+                                       int num = 0;
+                                       convert(numSampled, num);
+                                       numColumns = m->getNumChar(thisLine, '\t');
+                                       lineToNumber[count] = num;
+                                       count++;
+                                                                       
                                        thisFilesLines.push_back(thisLine);
                                        
                                        m->gobble(temp);
@@ -547,15 +565,21 @@ vector<string> RareFactCommand::createGroupFile(vector<string>& outputNames) {
                                //grab data for each group
                                for (int i=0; i<thisTypesFiles.size(); i++) {
                                        
-                                       string output = "NA\t";
-                                       if (k < files[thisTypesFiles[i]].size()) {
-                                               string line = files[thisTypesFiles[i]][k];
-                                               output = line.substr(0, line.find_first_of('\t'));
-                                               output += '\t' + files[thisTypesFiles[i]][0] + '\t' + line.substr(line.find_first_of('\t'));
-                                       }else{
-                                               output += '\t' + files[thisTypesFiles[i]][0] + '\t';
-                                       }
-                                       out << output << endl;
+                                       map<int, int>::iterator itLine = lineToNumber.find(k);
+                                       if (itLine != lineToNumber.end()) {
+                                               string output = toString(itLine->second);
+                                               if (k < files[thisTypesFiles[i]].size()) {
+                                                       string line = files[thisTypesFiles[i]][k];
+                                                       output = line.substr(0, line.find_first_of('\t'));
+                                                       output += '\t' + files[thisTypesFiles[i]][0] + '\t' + line.substr(line.find_first_of('\t'));
+                                               }else{
+                                                       output += '\t' + files[thisTypesFiles[i]][0] + '\t';
+                                                       for (int h = 0; h < numColumns; h++) {
+                                                               output += "NA\t";
+                                                       }
+                                               }
+                                               out << output << endl;
+                                       }else { m->mothurOut("[ERROR]: parsing results, cant find " + toString(k)); m->mothurOutEndLine(); }
                                }
                        }       
                        
index 36288927ac2d5bb575378329c9c0a6b66f1db5c4..72d24151193076eea753f5b17d97e135da7d42d0 100644 (file)
@@ -51,7 +51,7 @@ private:
        string outputDir;
        
        vector<string> parseSharedFile(string);
-       vector<string> createGroupFile(vector<string>&);
+       vector<string> createGroupFile(vector<string>&, map<string, string>);
 };
 
 #endif
index 6ec0fcd34e61500633ecdec6e921ae987fe19e31..e5a3bb2edc7fc97dacb89393ef3a2968b64247b4 100644 (file)
@@ -191,13 +191,9 @@ RemoveGroupsCommand::RemoveGroupsCommand(string option)  {
                        else { m->setNameFile(namefile); }
                        
                        groupfile = validParameter.validFile(parameters, "group", true);
-                       if (groupfile == "not open") { abort = true; }
-                       else if (groupfile == "not found") {            
-                               //if there is a current group file, use it
-                               groupfile = m->getGroupFile(); 
-                               if (groupfile != "") { m->mothurOut("Using " + groupfile + " as input file for the group parameter."); m->mothurOutEndLine(); }
-                               else {  m->mothurOut("You have no current groupfile and the group parameter is required."); m->mothurOutEndLine(); abort = true; }
-                       }else { m->setGroupFile(groupfile); }   
+                       if (groupfile == "not open") { groupfile = "";  abort = true; }
+                       else if (groupfile == "not found") {    groupfile = "";         }
+                       else { m->setGroupFile(groupfile); }    
                        
                        listfile = validParameter.validFile(parameters, "list", true);
                        if (listfile == "not open") { listfile = ""; abort = true; }