]> git.donarmstrong.com Git - mothur.git/blobdiff - splitabundcommand.cpp
added oldfasta and column parameter to dist.seqs so you can append distances to an...
[mothur.git] / splitabundcommand.cpp
index f86891bde47d6817a3d65651b989f24c7533ea30..891fb979e3aa533a53453628f2701e790161fbcc 100644 (file)
@@ -20,7 +20,7 @@ SplitAbundCommand::SplitAbundCommand(string option)  {
                
                else {
                        //valid paramters for this command
-                       string Array[] =  {"name","group","label","accnos","groups","fasta","cutoff","outputdir","inputdir"}; //"list",
+                       string Array[] =  {"name","group","list","label","accnos","groups","fasta","cutoff","outputdir","inputdir"}; //
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
                        OptionParser parser(option);
@@ -146,7 +146,7 @@ SplitAbundCommand::SplitAbundCommand(string option)  {
 void SplitAbundCommand::help(){
        try {
                m->mothurOut("The split.abund command reads a fasta file and a list or a names file splits the sequences into rare and abundant groups. \n");
-               m->mothurOut("The split.abund command parameters are list, name, cutoff, group, label, groups and accnos.\n");
+               m->mothurOut("The split.abund command parameters are fasta, list, name, cutoff, group, label, groups, cutoff and accnos.\n");
                m->mothurOut("The fasta and a list or name parameter are required, and you must provide a cutoff value.\n");
                m->mothurOut("The cutoff parameter is used to qualify what is abundant and rare.\n");
                m->mothurOut("The group parameter allows you to parse a group file into rare and abundant groups.\n");
@@ -155,8 +155,8 @@ void SplitAbundCommand::help(){
                m->mothurOut("The groups parameter allows you to parse the files into rare and abundant files by group.  \n");
                m->mothurOut("For example if you set groups=A-B-C, you will get a .A.abund, .A.rare, .B.abund, .B.rare, .C.abund, .C.rare files.  \n");
                m->mothurOut("If you want .abund and .rare files for all groups, set groups=all.  \n");
-               m->mothurOut("The split.abund command should be used in the following format: split.abund(list=yourListFile, group=yourGroupFile, label=yourLabels, cutoff=yourCutoff).\n");
-               m->mothurOut("Example: split.abundt(list=abrecovery.fn.list, group=abrecovery.groups, label=0.03, cutoff=2).\n");
+               m->mothurOut("The split.abund command should be used in the following format: split.abund(fasta=yourFasta, list=yourListFile, group=yourGroupFile, label=yourLabels, cutoff=yourCutoff).\n");
+               m->mothurOut("Example: split.abund(fasta=abrecovery.fasta, list=abrecovery.fn.list, group=abrecovery.groups, label=0.03, cutoff=2).\n");
                m->mothurOut("Note: No spaces between parameter labels (i.e. list), '=' and parameters (i.e.yourListfile).\n\n");
 
        }
@@ -176,6 +176,7 @@ int SplitAbundCommand::execute(){
                if (abort == true) {    return 0;       }
                
                if (listfile != "") { //you are using a listfile to determine abundance
+                       if (outputDir == "") { outputDir = hasPath(listfile); }
                
                        //remove old files so you can append later....
                        string fileroot = outputDir + getRootName(getSimpleName(listfile));
@@ -278,6 +279,9 @@ int SplitAbundCommand::execute(){
                        
                        for (map<string, bool>::iterator itBool = wroteListFile.begin(); itBool != wroteListFile.end(); itBool++) {
                                string filename = fileroot + itBool->first;
+                               if ((itBool->first == "rare") || (itBool->first == "abund")) {
+                                       filename = fileroot + itBool->first + ".list";
+                               }
                                if (itBool->second) { //we wrote to this file
                                        outputNames.push_back(filename);
                                }else{
@@ -289,7 +293,8 @@ int SplitAbundCommand::execute(){
 
                                                                        
                }else { //you are using the namefile to determine abundance
-
+                       if (outputDir == "") { outputDir = hasPath(namefile); }
+                       
                        splitNames(); 
                        writeNames();
                        
@@ -373,17 +378,17 @@ int SplitAbundCommand::writeList(ListVector* thisList) {
                        ofstream rout;
                        
                        if (rareNames.size() != 0) {
-                               string rare = outputDir + getRootName(getSimpleName(listfile))  + ".rare.list";
+                               string rare = outputDir + getRootName(getSimpleName(listfile))  + "rare.list";
                                wroteListFile["rare"] = true;
                                openOutputFileAppend(rare, rout);
                                rout << thisList->getLabel() << '\t' << numRareBins << '\t';
                        }
                        
                        if (abundNames.size() != 0) {
-                               string abund = outputDir + getRootName(getSimpleName(listfile))  + ".abund.list";
+                               string abund = outputDir + getRootName(getSimpleName(listfile))  + "abund.list";
                                wroteListFile["abund"] = true;
                                openOutputFileAppend(abund, aout);
-                               rout << thisList->getLabel() << '\t' << numAbundBins << '\t';
+                               aout << thisList->getLabel() << '\t' << numAbundBins << '\t';
                        }
 
                        for (int i = 0; i < thisList->getNumBins(); i++) {
@@ -799,7 +804,7 @@ int SplitAbundCommand::parseGroup(string tag) { //namefile
                                                if (rareNames.count(itName->first) != 0) { //you are a rare name
                                                        rout << names[i] << '\t' << group << endl;
                                                }else{ //you are a abund name
-                                                       rout << names[i] << '\t' << group << endl;
+                                                       aout << names[i] << '\t' << group << endl;
                                                }
                                        }
                                }