]> git.donarmstrong.com Git - mothur.git/commitdiff
added sort parameter to get.otulist
authorwestcott <westcott>
Wed, 2 Jun 2010 15:23:36 +0000 (15:23 +0000)
committerwestcott <westcott>
Wed, 2 Jun 2010 15:23:36 +0000 (15:23 +0000)
Mothur.xcodeproj/project.pbxproj
binsequencecommand.cpp
getlistcountcommand.cpp
getlistcountcommand.h

index 1736df4d155f138f0fa532e212ba758b0a6d0c3d..ab546df5272e5ed9044d1fb1d8bc053748579e9a 100644 (file)
                                A7DA202B113FECD400BF472F /* command.hpp */,
                                A7DA1FEF113FECD400BF472F /* aligncommand.h */,
                                A7DA1FEE113FECD400BF472F /* aligncommand.cpp */,
-                               A7DA1FFD113FECD400BF472F /* binsequencecommand.cpp */,
                                A7DA1FFE113FECD400BF472F /* binsequencecommand.h */,
+                               A7DA1FFD113FECD400BF472F /* binsequencecommand.cpp */,
                                A7DA2007113FECD400BF472F /* bootstrapsharedcommand.cpp */,
                                A7DA2008113FECD400BF472F /* bootstrapsharedcommand.h */,
                                A7D216061199C47F00F13F13 /* catchallcommand.h */,
                                A7DA205B113FECD400BF472F /* getgroupcommand.h */,
                                A7DA205C113FECD400BF472F /* getlabelcommand.cpp */,
                                A7DA205D113FECD400BF472F /* getlabelcommand.h */,
-                               A7DA205E113FECD400BF472F /* getlistcountcommand.cpp */,
                                A7DA205F113FECD400BF472F /* getlistcountcommand.h */,
+                               A7DA205E113FECD400BF472F /* getlistcountcommand.cpp */,
                                A7DA2061113FECD400BF472F /* getoturepcommand.h */,
                                A7DA2060113FECD400BF472F /* getoturepcommand.cpp */,
                                A7DA2062113FECD400BF472F /* getrabundcommand.cpp */,
index 033cd52e9e323e1707f603f8c20aaf22f50d4ecc..1d4f8c6694c570bbb7075c4150ae5125d29cc18e 100644 (file)
@@ -181,7 +181,6 @@ int BinSeqCommand::execute(){
                        readNamesFile();
                }
                
-               
                //read list file
                read = new ReadOTUFile(globaldata->getListFile());      
                read->read(&*globaldata); 
index 7757122776136ce25edf778709db6c4102a37b9a..43280edd76b1c924ed87572412977f682d3d7b17 100644 (file)
@@ -22,7 +22,7 @@ GetListCountCommand::GetListCountCommand(string option)  {
                
                else {
                        //valid paramters for this command
-                       string AlignArray[] =  {"list","label","outputdir","inputdir"};
+                       string AlignArray[] =  {"list","label","sort","outputdir","inputdir"};
                        vector<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
                        
                        OptionParser parser(option);
@@ -64,6 +64,8 @@ GetListCountCommand::GetListCountCommand(string option)  {
                
                        //check for optional parameter and set defaults
                        // ...at some point should added some additional type checking...
+                       sort = validParameter.validFile(parameters, "sort", false);       if (sort == "not found") { sort = "otu"; }
+                       if ((sort != "otu") && (sort != "name")) { m->mothurOut( sort + " is not a valid sort option. Options are otu and name. I will use otu."); m->mothurOutEndLine(); sort = "otu"; }
                        
                        label = validParameter.validFile(parameters, "label", false);                   
                        if (label == "not found") { label = ""; }
@@ -88,13 +90,16 @@ GetListCountCommand::GetListCountCommand(string option)  {
 
 void GetListCountCommand::help(){
        try {
-               m->mothurOut("The get.listcount command can only be executed after a successful read.otu command of a listfile or providing a list file using the list parameter.\n");
-               m->mothurOut("The get.listcount command parameters are list and label.  No parameters are required.\n");
+               m->mothurOut("The get.otulist command can only be executed after a successful read.otu command of a listfile or providing a list file using the list parameter.\n");
+               m->mothurOut("The get.otulist command parameters are list, sort and label.  No parameters are required.\n");
                m->mothurOut("The label parameter allows you to select what distance levels you would like a output files created for, and are separated by dashes.\n");
-               m->mothurOut("The get.listcount command should be in the following format: get.listcount(list=yourlistFile, label=yourLabels).\n");
-               m->mothurOut("Example get.listcount(list=amazon.fn.list, label=0.10).\n");
+               m->mothurOut("The sort parameter allows you to select how you want the output displayed. Options are otu and name.\n");
+               m->mothurOut("If otu is selected the output will be otu number followed by the list of names in that otu.\n");
+               m->mothurOut("If name is selected the output will be a sequence name followed by its otu number.\n");
+               m->mothurOut("The get.otulist command should be in the following format: get.otulist(list=yourlistFile, label=yourLabels).\n");
+               m->mothurOut("Example get.otulist(list=amazon.fn.list, label=0.10).\n");
                m->mothurOut("The default value for label is all lines in your inputfile.\n");
-               m->mothurOut("The get.listcount command outputs a .otu file for each distance you specify listing the bin number and the names of the sequences in that bin.\n");
+               m->mothurOut("The get.otulist command outputs a .otu file for each distance you specify listing the bin number and the names of the sequences in that bin.\n");
                m->mothurOut("Note: No spaces between parameter labels (i.e. list), '=' and parameters (i.e.yourListFile).\n\n");
        }
        catch(exception& e) {
@@ -239,7 +244,7 @@ int GetListCountCommand::execute(){
 //return 1 if error, 0 otherwise
 void GetListCountCommand::process(ListVector* list) {
        try {
-               string binnames, name, sequence;
+               string binnames;
                if (outputDir == "") { outputDir += hasPath(listfile); }
                string outputFileName = outputDir + getRootName(getSimpleName(listfile)) + list->getLabel() + ".otu";
                openOutputFile(outputFileName, out);
@@ -252,7 +257,17 @@ void GetListCountCommand::process(ListVector* list) {
                        if (m->control_pressed) { break; }
                        
                        binnames = list->get(i);
-                       out << i+1 << '\t' << binnames << endl;
+                       
+                       if (sort == "otu") {
+                               out << i+1 << '\t' << binnames << endl;
+                       }else{ //sort = name
+                               vector<string> names;
+                               splitAtComma(binnames, names);
+                               
+                               for (int j = 0; j < names.size(); j++) {
+                                       out << names[j] << '\t' << i+1 << endl;
+                               }
+                       }
                }
                
                out.close();
index 196d245002498043dd8a32d11de45c5e1eb7c0cb..e238cf5fc8086f5ec29e6f419f6be0ec2c711e18 100644 (file)
@@ -34,7 +34,7 @@ private:
        
        bool abort, allLines;
        set<string> labels; //holds labels to be used
-       string label, listfile, outputDir;
+       string label, listfile, outputDir, sort;
        ofstream out;
        vector<string> outputNames;