]> git.donarmstrong.com Git - mothur.git/commitdiff
added set.dir command and modified commands to redirect input and output, removed...
authorwestcott <westcott>
Tue, 26 Jan 2010 19:36:30 +0000 (19:36 +0000)
committerwestcott <westcott>
Tue, 26 Jan 2010 19:36:30 +0000 (19:36 +0000)
122 files changed:
Mothur.xcodeproj/project.pbxproj
aligncommand.cpp
aligncommand.h
bellerophon.cpp
bellerophon.h
binsequencecommand.cpp
binsequencecommand.h
bootstrapsharedcommand.cpp
bootstrapsharedcommand.h
chimera.h
chimeracheckrdp.cpp
chimeracheckrdp.h
chimeraseqscommand.cpp
chimeraseqscommand.h
classifyseqscommand.cpp
classifyseqscommand.h
clustercommand.cpp
clustercommand.h
collectcommand.cpp
collectcommand.h
collectsharedcommand.cpp
collectsharedcommand.h
commandfactory.cpp
commandfactory.hpp
deconvolutecommand.cpp
deconvolutecommand.h
distancecommand.cpp
distancecommand.h
engine.hpp
filterseqscommand.cpp
filterseqscommand.h
getgroupcommand.cpp
getlabelcommand.cpp
getlinecommand.cpp [deleted file]
getlinecommand.h [deleted file]
getlistcountcommand.cpp
getlistcountcommand.h
getoturepcommand.cpp
getoturepcommand.h
getrabundcommand.cpp
getsabundcommand.cpp
getseqscommand.cpp
getseqscommand.h
getsharedotucommand.cpp
getsharedotucommand.h
groupmap.cpp
groupmap.h
hclustercommand.cpp
hclustercommand.h
heatmap.cpp
heatmap.h
heatmapcommand.cpp
heatmapcommand.h
heatmapsim.cpp
heatmapsim.h
heatmapsimcommand.cpp
heatmapsimcommand.h
helpcommand.cpp
libshuffcommand.cpp
libshuffcommand.h
listseqscommand.cpp
listseqscommand.h
matrixoutputcommand.cpp
matrixoutputcommand.h
mergefilecommand.cpp
mgclustercommand.cpp
mgclustercommand.h
mothur.cpp
mothur.h
otuhierarchycommand.cpp
otuhierarchycommand.h
parsimonycommand.cpp
parsimonycommand.h
pcacommand.cpp
pcacommand.h
phylotypecommand.cpp
phylotypecommand.h
pintail.cpp
pintail.h
preclustercommand.cpp
preclustercommand.h
quitcommand.cpp
rarefactcommand.cpp
rarefactcommand.h
rarefactsharedcommand.cpp
rarefactsharedcommand.h
readdistcommand.cpp
readdistcommand.h
readotucommand.cpp
readotucommand.h
readtreecommand.cpp
removeseqscommand.cpp
removeseqscommand.h
reversecommand.cpp
reversecommand.h
screenseqscommand.cpp
screenseqscommand.h
secondarystructurecommand.cpp
secondarystructurecommand.h
seqsummarycommand.cpp
seqsummarycommand.h
setdircommand.cpp [new file with mode: 0644]
setdircommand.h [new file with mode: 0644]
sharedcommand.cpp
sharedcommand.h
summarycommand.cpp
summarycommand.h
summarysharedcommand.cpp
summarysharedcommand.h
systemcommand.cpp
treegroupscommand.cpp
treegroupscommand.h
trimseqscommand.cpp
trimseqscommand.h
unifracunweightedcommand.cpp
unifracunweightedcommand.h
unifracweightedcommand.cpp
unifracweightedcommand.h
venn.cpp
venn.h
venncommand.cpp
venncommand.h

index a44e1f3d7e3e824a58e4b5c0eaa4d9c960b1deb8..b0db01845e76ddedd0486f3b1906e626f6c88ff7 100644 (file)
                8DD76F6A0486A84900D96B5E /* Mothur.1 in CopyFiles */ = {isa = PBXBuildFile; fileRef = C6859E8B029090EE04C91782 /* Mothur.1 */; };
                A7027F2810DFF86D00BF45FE /* preclustercommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7027F2710DFF86D00BF45FE /* preclustercommand.cpp */; };
                A704E8A31106045D00870157 /* otuhierarchycommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A704E8A21106045D00870157 /* otuhierarchycommand.cpp */; };
+               A70B00C8110885EB002F453A /* setdircommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A70B00C7110885EB002F453A /* setdircommand.cpp */; };
                A70B53AA0F4CD7AD0064797E /* getgroupcommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A70B53A40F4CD7AD0064797E /* getgroupcommand.cpp */; };
                A70B53AB0F4CD7AD0064797E /* getlabelcommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A70B53A60F4CD7AD0064797E /* getlabelcommand.cpp */; };
-               A70B53AC0F4CD7AD0064797E /* getlinecommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A70B53A80F4CD7AD0064797E /* getlinecommand.cpp */; };
                A70DECD91063D8B40057C03C /* secondarystructurecommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A70DECD81063D8B40057C03C /* secondarystructurecommand.cpp */; };
                A727E84A10D14568001A8432 /* readblast.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A727E84910D14568001A8432 /* readblast.cpp */; };
                A7283FF81056CAE100D0CC69 /* chimeracheckrdp.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7283FF71056CAE100D0CC69 /* chimeracheckrdp.cpp */; };
                A7027F2710DFF86D00BF45FE /* preclustercommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = preclustercommand.cpp; sourceTree = SOURCE_ROOT; };
                A704E8A11106045D00870157 /* otuhierarchycommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = otuhierarchycommand.h; sourceTree = SOURCE_ROOT; };
                A704E8A21106045D00870157 /* otuhierarchycommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = otuhierarchycommand.cpp; sourceTree = SOURCE_ROOT; };
+               A70B00C6110885EB002F453A /* setdircommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = setdircommand.h; sourceTree = SOURCE_ROOT; };
+               A70B00C7110885EB002F453A /* setdircommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = setdircommand.cpp; sourceTree = SOURCE_ROOT; };
                A70B53A40F4CD7AD0064797E /* getgroupcommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = getgroupcommand.cpp; sourceTree = SOURCE_ROOT; };
                A70B53A50F4CD7AD0064797E /* getgroupcommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = getgroupcommand.h; sourceTree = SOURCE_ROOT; };
                A70B53A60F4CD7AD0064797E /* getlabelcommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = getlabelcommand.cpp; sourceTree = SOURCE_ROOT; };
                A70B53A70F4CD7AD0064797E /* getlabelcommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = getlabelcommand.h; sourceTree = SOURCE_ROOT; };
-               A70B53A80F4CD7AD0064797E /* getlinecommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = getlinecommand.cpp; sourceTree = SOURCE_ROOT; };
-               A70B53A90F4CD7AD0064797E /* getlinecommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = getlinecommand.h; sourceTree = SOURCE_ROOT; };
                A70DECD71063D8B40057C03C /* secondarystructurecommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = secondarystructurecommand.h; sourceTree = SOURCE_ROOT; };
                A70DECD81063D8B40057C03C /* secondarystructurecommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = secondarystructurecommand.cpp; sourceTree = SOURCE_ROOT; };
                A727E84810D14568001A8432 /* readblast.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = readblast.h; sourceTree = SOURCE_ROOT; };
                                A70B53A40F4CD7AD0064797E /* getgroupcommand.cpp */,
                                A70B53A70F4CD7AD0064797E /* getlabelcommand.h */,
                                A70B53A60F4CD7AD0064797E /* getlabelcommand.cpp */,
-                               A70B53A90F4CD7AD0064797E /* getlinecommand.h */,
-                               A70B53A80F4CD7AD0064797E /* getlinecommand.cpp */,
                                A73329CD1083B3B3003B10C5 /* getlistcountcommand.h */,
                                A73329CE1083B3B3003B10C5 /* getlistcountcommand.cpp */,
                                370B88050F8A4EE4005AB382 /* getoturepcommand.h */,
                                371B30B20FD7EE67000414CA /* screenseqscommand.cpp */,
                                3799A94F0FD6A58C00E33EDE /* seqsummarycommand.h */,
                                3799A94E0FD6A58C00E33EDE /* seqsummarycommand.cpp */,
+                               A70B00C6110885EB002F453A /* setdircommand.h */,
+                               A70B00C7110885EB002F453A /* setdircommand.cpp */,
                                37D928270F21331F001D4494 /* sharedcommand.h */,
                                37D928260F21331F001D4494 /* sharedcommand.cpp */,
                                37D928470F21331F001D4494 /* summarycommand.h */,
                                37AFC71F0F445386005F492D /* sharedsobscollectsummary.cpp in Sources */,
                                A70B53AA0F4CD7AD0064797E /* getgroupcommand.cpp in Sources */,
                                A70B53AB0F4CD7AD0064797E /* getlabelcommand.cpp in Sources */,
-                               A70B53AC0F4CD7AD0064797E /* getlinecommand.cpp in Sources */,
                                EB9303EB0F534D9400E8EF26 /* logsd.cpp in Sources */,
                                EB9303F90F53517300E8EF26 /* geom.cpp in Sources */,
                                EB6E68190F5F1C780044E17B /* qstat.cpp in Sources */,
                                A7D86C7D10FE09AB00865661 /* formatcolumn.cpp in Sources */,
                                A7D86C8C10FE09FE00865661 /* formatphylip.cpp in Sources */,
                                A704E8A31106045D00870157 /* otuhierarchycommand.cpp in Sources */,
+                               A70B00C8110885EB002F453A /* setdircommand.cpp in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
index 3b3afc1795b2d73c709ef4474b07b88acf93e0dc..784155745fa9c0141d6b2db0ba80133b39e3a85f 100644 (file)
@@ -39,27 +39,44 @@ AlignCommand::AlignCommand(string option){
                else {
                        
                        //valid paramters for this command
-                       string AlignArray[] =  {"template","candidate","search","ksize","align","match","mismatch","gapopen","gapextend", "processors","flip","threshold"};
+                       string AlignArray[] =  {"template","candidate","search","ksize","align","match","mismatch","gapopen","gapextend", "processors","flip","threshold","outputdir","inputdir"};
                        vector<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
                        
                        OptionParser parser(option);
                        map<string, string> parameters = parser.getParameters(); 
                        
                        ValidParameters validParameter;
+                       map<string, string>::iterator it;
                        
                        //check to make sure all parameters are valid for command
-                       for (map<string, string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
+                       for (it = parameters.begin(); it != parameters.end(); it++) { 
                                if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
+                       //if the user changes the output directory command factory will send this info to us in the output parameter 
+                       outputDir = validParameter.validFile(parameters, "outputdir", false);           if (outputDir == "not found"){  outputDir = "";         }
+                       
+                       //if the user changes the input directory command factory will send this info to us in the output parameter 
+                       string inputDir = validParameter.validFile(parameters, "inputdir", false);              
+                       if (inputDir == "not found"){   inputDir = "";          }
+                       else {
+                               string path;
+                               it = parameters.find("template");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["template"] = inputDir + it->second;         }
+                               }
+                       }
+                       
                        //check for required parameters
                        templateFileName = validParameter.validFile(parameters, "template", true);
                        if (templateFileName == "not found") { 
                                mothurOut("template is a required parameter for the align.seqs command."); 
                                mothurOutEndLine();
                                abort = true; 
-                       }
-                       else if (templateFileName == "not open") { abort = true; }      
+                       }else if (templateFileName == "not open") { abort = true; }     
                        
                        candidateFileName = validParameter.validFile(parameters, "candidate", false);
                        if (candidateFileName == "not found") { mothurOut("candidate is a required parameter for the align.seqs command."); mothurOutEndLine(); abort = true;  }
@@ -68,6 +85,12 @@ AlignCommand::AlignCommand(string option){
                                
                                //go through files and make sure they are good, if not, then disregard them
                                for (int i = 0; i < candidateFileNames.size(); i++) {
+                                       if (inputDir != "") {
+                                               string path = hasPath(candidateFileNames[i]);
+                                               //if the user has not given a path then, add inputdir. else leave path alone.
+                                               if (path == "") {       candidateFileNames[i] = inputDir + candidateFileNames[i];               }
+                                       }
+
                                        int ableToOpen;
                                        ifstream in;
                                        ableToOpen = openInputFile(candidateFileNames[i], in);
@@ -149,8 +172,8 @@ void AlignCommand::help(){
                mothurOut("The mistmatch parameter allows you to specify the penalty for having different bases.  The default is -1.0.\n");
                mothurOut("The gapopen parameter allows you to specify the penalty for opening a gap in an alignment. The default is -2.0.\n");
                mothurOut("The gapextend parameter allows you to specify the penalty for extending a gap in an alignment.  The default is -1.0.\n");
-               mothurOut("The flip parameter is used to specify whether or not you want mothur to try the reverse compement if a sequence falls below the threshold.  The default is false.\n");
-               mothurOut("The threshold is used to specify a cutoff at which an alignment is deemed 'bad' and the reverse complement may be tried. \n");
+               mothurOut("The flip parameter is used to specify whether or not you want mothur to try the reverse complement if a sequence falls below the threshold.  The default is false.\n");
+               mothurOut("The threshold is used to specify a cutoff at which an alignment is deemed 'bad' and the reverse complement may be tried. The default threshold is 0.50, meaning 50% of the bases are removed in the alignment.\n");
                mothurOut("If the flip parameter is set to true the reverse complement of the sequence is aligned and the better alignment is reported.\n");
                mothurOut("The default for the threshold parameter is 0.50, meaning at least 50% of the bases must remain or the sequence is reported as potentially reversed.\n");
                mothurOut("The align.seqs command should be in the following format: \n");
@@ -187,9 +210,10 @@ int AlignCommand::execute(){
                for (int s = 0; s < candidateFileNames.size(); s++) {
                        mothurOut("Aligning sequences from " + candidateFileNames[s] + " ..." ); mothurOutEndLine();
                        
-                       string alignFileName = candidateFileNames[s].substr(0,candidateFileNames[s].find_last_of(".")+1) + "align";
-                       string reportFileName = candidateFileNames[s].substr(0,candidateFileNames[s].find_last_of(".")+1) + "align.report";
-                       string accnosFileName = candidateFileNames[s].substr(0,candidateFileNames[s].find_last_of(".")+1) + "flip.accnos";
+                       if (outputDir == "") {  outputDir += hasPath(candidateFileNames[s]); }
+                       string alignFileName = outputDir + getRootName(getSimpleName(candidateFileNames[s])) + "align";
+                       string reportFileName = outputDir + getRootName(getSimpleName(candidateFileNames[s])) + "align.report";
+                       string accnosFileName = outputDir + getRootName(getSimpleName(candidateFileNames[s])) + "flip.accnos";
                        
                        int numFastaSeqs = 0;
                        for (int i = 0; i < lines.size(); i++) {  delete lines[i];  }  lines.clear();
@@ -283,13 +307,13 @@ int AlignCommand::execute(){
                        }
 #else
                        ifstream inFASTA;
-                       openInputFile(candidateFileName[s], inFASTA);
+                       openInputFile(candidateFileNames[s], inFASTA);
                        numFastaSeqs=count(istreambuf_iterator<char>(inFASTA),istreambuf_iterator<char>(), '>');
                        inFASTA.close();
                        
                        lines.push_back(new linePair(0, numFastaSeqs));
                        
-                       driver(lines[0], alignFileName, reportFileName, accnosFileName);
+                       driver(lines[0], alignFileName, reportFileName, accnosFileName, candidateFileNames[s]);
                        
                        //delete accnos file if its blank else report to user
                        if (isBlank(accnosFileName)) {  remove(accnosFileName.c_str());  }
index 0a2e7ba618291f99044cfd187f3e616b40a936cd..8042983911c1052e100133b4284f03ddce751031 100644 (file)
@@ -41,7 +41,7 @@ private:
        void appendAlignFiles(string, string); 
        void appendReportFiles(string, string);
        
-       string candidateFileName, templateFileName, distanceFileName, search, align;
+       string candidateFileName, templateFileName, distanceFileName, search, align, outputDir;
        float match, misMatch, gapOpen, gapExtend, threshold;
        int processors, kmerSize;
        vector<string> candidateFileNames;
index a60a838f0139e741c92db8c1b5edafbdb158ca02..7c64d4703a4bd3700e0757052c392639f16aa7eb 100644 (file)
 
 //***************************************************************************************************************
 
-Bellerophon::Bellerophon(string name) {
+Bellerophon::Bellerophon(string name, string o)  {
        try {
                fastafile = name;
+               outputDir = o;
        }
        catch(exception& e) {
                errorOut(e, "Bellerophon", "Bellerophon");
@@ -81,12 +82,16 @@ int Bellerophon::getChimeras() {
                //do soft filter
                if (filter)  {
                        string optionString = "fasta=" + fastafile + ", soft=50";
+                       if (outputDir != "") { optionString += ", outputdir=" + outputDir; }
+                       
                        filterSeqs = new FilterSeqsCommand(optionString);
                        filterSeqs->execute();
                        delete filterSeqs;
                        
                        //reset fastafile to filtered file
-                       fastafile = getRootName(fastafile) + "filter.fasta";
+                       if (outputDir == "") { fastafile = getRootName(fastafile) + "filter.fasta"; }
+                       else                             { fastafile = outputDir + getRootName(getSimpleName(fastafile)) + "filter.fasta"; }
+                       
                }
                
                distCalculator = new eachGapDist();
index 85c555043d207878eed1ccb1466e424cd064629e..aa53f9852f20202ae77841fbf9262a9802356bbe 100644 (file)
@@ -25,7 +25,7 @@ typedef map<int, float> SeqMap;  //maps sequence to all distance for that seqeun
 class Bellerophon : public Chimera {
        
        public:
-               Bellerophon(string);    
+               Bellerophon(string, string);    
                ~Bellerophon() {};
                
                int getChimeras();
index ad90ff45202213fcb88cb222004628a82930ba80..6618eb6e5aa60109cf908786f4b50f7a06b02293 100644 (file)
@@ -22,19 +22,27 @@ BinSeqCommand::BinSeqCommand(string option){
                
                else {
                        //valid paramters for this command
-                       string AlignArray[] =  {"fasta","label","name", "group"};
+                       string AlignArray[] =  {"fasta","label","name", "group","outputdir","inputdir"};
                        vector<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
                        
                        OptionParser parser(option);
                        map<string, string> parameters = parser.getParameters();
                        
                        ValidParameters validParameter;
+                       map<string, string>::iterator it;
                
                        //check to make sure all parameters are valid for command
-                       for (map<string, string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
+                       for (it = parameters.begin(); it != parameters.end(); it++) { 
                                if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
+                       //if the user changes the output directory command factory will send this info to us in the output parameter 
+                       outputDir = validParameter.validFile(parameters, "outputdir", false);           if (outputDir == "not found"){  
+                               outputDir = ""; 
+                               outputDir += hasPath(globaldata->getListFile()); //if user entered a file with a path then preserve it  
+                       }
+
+                       
                        //make sure the user has already run the read.otu command
                        if (globaldata->getListFile() == "") { 
                                mothurOut("You must read a listfile before running the bin.seqs command."); 
@@ -42,6 +50,36 @@ BinSeqCommand::BinSeqCommand(string option){
                                abort = true; 
                        }
                        
+                       //if the user changes the input directory command factory will send this info to us in the output parameter 
+                       string inputDir = validParameter.validFile(parameters, "inputdir", false);              
+                       if (inputDir == "not found"){   inputDir = "";          }
+                       else {
+                               string path;
+                               it = parameters.find("fasta");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["fasta"] = inputDir + it->second;            }
+                               }
+                               
+                               it = parameters.find("name");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["name"] = inputDir + it->second;             }
+                               }
+                               
+                               it = parameters.find("group");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["group"] = inputDir + it->second;            }
+                               }
+                       }
+
                        
                        //check for required parameters
                        fastafile = validParameter.validFile(parameters, "fasta", true);
@@ -77,7 +115,9 @@ BinSeqCommand::BinSeqCommand(string option){
                                fasta = new FastaMap();
                                if (groupfile != "") {
                                        groupMap = new GroupMap(groupfile);
-                                       groupMap->readMap();
+                                       
+                                       int error = groupMap->readMap();
+                                       if (error == 1) { delete groupMap; abort = true; }
                                }
                        }
        
@@ -258,7 +298,8 @@ void BinSeqCommand::readNamesFile() {
 int BinSeqCommand::process(ListVector* list) {
        try {
                                string binnames, name, sequence;
-                               string outputFileName = getRootName(globaldata->getListFile()) + list->getLabel() + ".fasta";
+                               
+                               string outputFileName = outputDir + getRootName(getSimpleName(globaldata->getListFile())) + list->getLabel() + ".fasta";
                                openOutputFile(outputFileName, out);
 
                                mothurOut(list->getLabel()); mothurOutEndLine();
index a183151f3580ab5232a1108c25a58c22a0c540e6..2804235aa67822bf016dcdeb696eca4fbd9d6464 100644 (file)
@@ -38,7 +38,7 @@ private:
        GroupMap* groupMap;
        bool abort, allLines;
        set<string> labels; //holds labels to be used
-       string filename, fastafile, namesfile, groupfile, label;
+       string filename, fastafile, namesfile, groupfile, label, outputDir;
        ofstream out;
        ifstream in, inNames;
        
index 1b682c78e3471fe7b4fef8528e8d74243374cd21..4f4488085a8754b731ca6c742ee43f7b0dc690c4 100644 (file)
@@ -36,7 +36,7 @@ BootSharedCommand::BootSharedCommand(string option){
                
                else {
                        //valid paramters for this command
-                       string Array[] =  {"label","calc","groups","iters"};
+                       string Array[] =  {"label","calc","groups","iters","outputdir","inputdir"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
                        OptionParser parser(option);
@@ -49,6 +49,13 @@ BootSharedCommand::BootSharedCommand(string option){
                                if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
+                       //if the user changes the output directory command factory will send this info to us in the output parameter 
+                       outputDir = validParameter.validFile(parameters, "outputdir", false);           if (outputDir == "not found"){  
+                               outputDir = ""; 
+                               outputDir += hasPath(globaldata->inputFileName); //if user entered a file with a path then preserve it  
+                       }
+
+                       
                        //make sure the user has already run the read.otu command
                        if (globaldata->getSharedFile() == "") {
                                if (globaldata->getListFile() == "") { mothurOut("You must read a list and a group, or a shared before you can use the bootstrap.shared command."); mothurOutEndLine(); abort = true; }
@@ -373,12 +380,11 @@ void BootSharedCommand::process(SharedOrderVector* order) {
        try{
                                EstOutput data;
                                vector<SharedRAbundVector*> subset;
-                               
-                               
+                                                               
                                //open an ostream for each calc to print to
                                for (int z = 0; z < treeCalculators.size(); z++) {
                                        //create a new filename
-                                       outputFile = getRootName(globaldata->inputFileName) + treeCalculators[z]->getName() + ".boot" + order->getLabel() + ".tre";
+                                       outputFile = outputDir + getRootName(getSimpleName(globaldata->inputFileName)) + treeCalculators[z]->getName() + ".boot" + order->getLabel() + ".tre";
                                        openOutputFile(outputFile, *(out[z]));
                                }
                                
@@ -446,7 +452,7 @@ void BootSharedCommand::process(SharedOrderVector* order) {
                                        //set global data to calc trees
                                        globaldata->gTree = trees[k];
                                        
-                                       string filename = getRootName(globaldata->inputFileName) + treeCalculators[k]->getName() + ".boot" + order->getLabel();
+                                       string filename = getRootName(getSimpleName(globaldata->inputFileName)) + treeCalculators[k]->getName() + ".boot" + order->getLabel();
                                        consensus = new ConcensusCommand(filename);
                                        consensus->execute();
                                        delete consensus;
index 794da84001135d9b1ab365fc9014ed021a467d38..6b63233862a661634ab03f47951d683104b125c7 100644 (file)
@@ -56,7 +56,7 @@ private:
 
        bool abort, allLines;
        set<string> labels; //holds labels to be used
-       string outputFile, calc, groups, label;
+       string outputFile, calc, groups, label, outputDir;
        int numGroups, iters;
        vector<string>  Estimators, Groups; //holds estimators to be used
 
index 339f2c6b97c98fe9d0519250370a8c514ba7b700..8b3b0eb713beb96cc391f18a733029298508145a 100644 (file)
--- a/chimera.h
+++ b/chimera.h
@@ -59,8 +59,8 @@ class Chimera {
        public:
        
                Chimera(){};
-               Chimera(string);
                Chimera(string, string);
+               Chimera(string, string, string);
                virtual ~Chimera(){};
                virtual void setFilter(bool f)                  {       filter = f;                     }
                virtual void setCorrection(bool c)              {       correction = c;         }
@@ -97,7 +97,7 @@ class Chimera {
                bool filter, correction, svg, unaligned;
                int processors, window, increment, numWanted, kmerSize, match, misMatch, minSim, parents, iters;
                float divR;
-               string seqMask, quanfile, filterString, name;
+               string seqMask, quanfile, filterString, name, outputDir;
                        
 
 };
index 12785137232677e3a056a43fd31b705f9b618734..04c143fecc50207a682f033567372959bcb831be 100644 (file)
@@ -10,7 +10,7 @@
 #include "chimeracheckrdp.h"
                
 //***************************************************************************************************************
-ChimeraCheckRDP::ChimeraCheckRDP(string filename, string temp) {  fastafile = filename;  templateFile = temp;  }
+ChimeraCheckRDP::ChimeraCheckRDP(string filename, string temp, string o) {  fastafile = filename;  templateFile = temp; outputDir = o;  }
 //***************************************************************************************************************
 
 ChimeraCheckRDP::~ChimeraCheckRDP() {
@@ -338,7 +338,7 @@ void ChimeraCheckRDP::getCutoff() {
 void ChimeraCheckRDP::makeSVGpic(vector<sim> info, int query) {
        try{
                
-               string file = querySeqs[query]->getName() + ".chimeracheck.svg";
+               string file = outputDir + querySeqs[query]->getName() + ".chimeracheck.svg";
                ofstream outsvg;
                openOutputFile(file, outsvg);
                
index e885af5d171d24acd230748ff6a5783aa9952a5b..6193d6d64d47a3dcec90d47844fe62d16ccd6fb7 100644 (file)
@@ -25,7 +25,7 @@
 class ChimeraCheckRDP : public Chimera {
        
        public:
-               ChimeraCheckRDP(string, string);        
+               ChimeraCheckRDP(string, string, string);        
                ~ChimeraCheckRDP();
                
                int getChimeras();
index 9bd13e3a99578ab1374e2367fc73207e89225f50..63d02f5fd6998e61b65c85012d37d8061f6ff433 100644 (file)
@@ -26,24 +26,78 @@ ChimeraSeqsCommand::ChimeraSeqsCommand(string option){
                
                else {
                        //valid paramters for this command
-                       string Array[] =  {"fasta", "filter", "correction", "processors", "method", "window", "increment", "template", "conservation", "quantile", "mask", "numwanted", "ksize", "svg", "name", "match","mismatch", "divergence", "minsim", "parents", "iters" };
+                       string Array[] =  {"fasta", "filter", "correction", "processors", "method", "window", "increment", "template", "conservation", "quantile", "mask", "numwanted", "ksize", "svg", "name", "match","mismatch", "divergence", "minsim", "parents", "iters","outputdir","inputdir" };
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
                        OptionParser parser(option);
                        map<string,string> parameters = parser.getParameters();
                        
                        ValidParameters validParameter;
+                       map<string,string>::iterator it;
                        
                        //check to make sure all parameters are valid for command
-                       for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
+                       for (it = parameters.begin(); it != parameters.end(); it++) { 
                                if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
+                       //if the user changes the input directory command factory will send this info to us in the output parameter 
+                       string inputDir = validParameter.validFile(parameters, "inputdir", false);              
+                       if (inputDir == "not found"){   inputDir = "";          }
+                       else {
+                               string path;
+                               it = parameters.find("fasta");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["fasta"] = inputDir + it->second;            }
+                               }
+                               
+                               it = parameters.find("template");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["template"] = inputDir + it->second;         }
+                               }
+                               
+                               it = parameters.find("conservation");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["conservation"] = inputDir + it->second;             }
+                               }
+                               
+                               it = parameters.find("quantile");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["quantile"] = inputDir + it->second;         }
+                               }
+                               
+                               it = parameters.find("name");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["name"] = inputDir + it->second;             }
+                               }
+                       }
+
+                       
                        //check for required parameters
                        fastafile = validParameter.validFile(parameters, "fasta", true);
                        if (fastafile == "not open") { abort = true; }
                        else if (fastafile == "not found") { fastafile = ""; mothurOut("fasta is a required parameter for the chimera.seqs command."); mothurOutEndLine(); abort = true;  }     
                        
+                       //if the user changes the output directory command factory will send this info to us in the output parameter 
+                       outputDir = validParameter.validFile(parameters, "outputdir", false);           if (outputDir == "not found"){  
+                               outputDir = ""; 
+                               outputDir += hasPath(fastafile); //if user entered a file with a path then preserve it  
+                       }
+
                        templatefile = validParameter.validFile(parameters, "template", true);
                        if (templatefile == "not open") { abort = true; }
                        else if (templatefile == "not found") { templatefile = "";  }   
@@ -63,6 +117,12 @@ ChimeraSeqsCommand::ChimeraSeqsCommand(string option){
                        maskfile = validParameter.validFile(parameters, "mask", false);
                        if (maskfile == "not found") { maskfile = "";  }        
                        else if (maskfile != "default")  { 
+                               if (inputDir != "") {
+                                       string path = hasPath(maskfile);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       maskfile = inputDir + maskfile;         }
+                               }
+
                                ifstream in;
                                int     ableToOpen = openInputFile(maskfile, in);
                                if (ableToOpen == 1) { abort = true; }
@@ -192,10 +252,10 @@ int ChimeraSeqsCommand::execute(){
                
                if (abort == true) { return 0; }
                
-               if (method == "bellerophon")                    {               chimera = new Bellerophon(fastafile);                                           }
-               else if (method == "pintail")                   {               chimera = new Pintail(fastafile, templatefile);                         }
+               if (method == "bellerophon")                    {               chimera = new Bellerophon(fastafile, outputDir);                        }
+               else if (method == "pintail")                   {               chimera = new Pintail(fastafile, templatefile, outputDir);      }
                else if (method == "ccode")                             {               chimera = new Ccode(fastafile, templatefile);                           }
-               else if (method == "chimeracheck")              {               chimera = new ChimeraCheckRDP(fastafile, templatefile);         }
+               else if (method == "chimeracheck")              {               chimera = new ChimeraCheckRDP(fastafile, templatefile, outputDir);      }
                else if (method == "chimeraslayer")             {               chimera = new ChimeraSlayer(fastafile, templatefile);           }
                else { mothurOut("Not a valid method."); mothurOutEndLine(); return 0;          }
                
@@ -231,8 +291,8 @@ int ChimeraSeqsCommand::execute(){
                
                //there was a problem
                if (error == 1) {  return 0;  }
-               
-               string outputFileName = getRootName(fastafile) + method + maskfile + ".chimeras";
+
+               string outputFileName = outputDir + getRootName(getSimpleName(fastafile)) + method + maskfile + ".chimeras";
                ofstream out;
                openOutputFile(outputFileName, out);
                
index f19a79d230642894a8bbb7ab9d459f43368fd5dd..46e2bc88300c7a3e89f8fb985100d6edd50129a1 100644 (file)
@@ -28,7 +28,7 @@ public:
 private:
        
        bool abort;
-       string method, fastafile, templatefile, consfile, quanfile, maskfile, namefile;
+       string method, fastafile, templatefile, consfile, quanfile, maskfile, namefile, outputDir;
        bool filter, correction, svg, printAll;
        int processors, midpoint, averageLeft, averageRight, window, iters, increment, numwanted, ksize, match, mismatch, parents, minSimilarity;
        float divR;
index 473d4d11d78bed00e56a02472afeb4980e19e87e..0d9e797a00c226ba2e2eea219d041fa1143d03fa 100644 (file)
@@ -25,19 +25,45 @@ ClassifySeqsCommand::ClassifySeqsCommand(string option){
                else {
                        
                        //valid paramters for this command
-                       string AlignArray[] =  {"template","fasta","name","search","ksize","method","processors","taxonomy","match","mismatch","gapopen","gapextend","numwanted","cutoff","probs","iters"};
+                       string AlignArray[] =  {"template","fasta","name","search","ksize","method","processors","taxonomy","match","mismatch","gapopen","gapextend","numwanted","cutoff","probs","iters", "outputdir","inputdir"};
                        vector<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
                        
                        OptionParser parser(option);
                        map<string, string> parameters = parser.getParameters(); 
                        
                        ValidParameters validParameter;
+                       map<string, string>::iterator it;
                        
                        //check to make sure all parameters are valid for command
-                       for (map<string, string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
+                       for (it = parameters.begin(); it != parameters.end(); it++) { 
                                if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
+                       //if the user changes the output directory command factory will send this info to us in the output parameter 
+                       outputDir = validParameter.validFile(parameters, "outputdir", false);           if (outputDir == "not found"){  outputDir = "";         }
+                       
+                       //if the user changes the input directory command factory will send this info to us in the output parameter 
+                       string inputDir = validParameter.validFile(parameters, "inputdir", false);              
+                       if (inputDir == "not found"){   inputDir = "";          }
+                       else {
+                               string path;
+                               it = parameters.find("template");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["template"] = inputDir + it->second;         }
+                               }
+                               
+                               it = parameters.find("taxonomy");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["taxonomy"] = inputDir + it->second;         }
+                               }
+                       }
+
                        //check for required parameters
                        templateFileName = validParameter.validFile(parameters, "template", true);
                        if (templateFileName == "not found") { 
@@ -54,6 +80,12 @@ ClassifySeqsCommand::ClassifySeqsCommand(string option){
                                
                                //go through files and make sure they are good, if not, then disregard them
                                for (int i = 0; i < fastaFileNames.size(); i++) {
+                                       if (inputDir != "") {
+                                               string path = hasPath(fastaFileNames[i]);
+                                               //if the user has not given a path then, add inputdir. else leave path alone.
+                                               if (path == "") {       fastaFileNames[i] = inputDir + fastaFileNames[i];               }
+                                       }
+                                       
                                        int ableToOpen;
                                        ifstream in;
                                        ableToOpen = openInputFile(fastaFileNames[i], in);
@@ -88,6 +120,12 @@ ClassifySeqsCommand::ClassifySeqsCommand(string option){
                                
                                //go through files and make sure they are good, if not, then disregard them
                                for (int i = 0; i < namefileNames.size(); i++) {
+                                       if (inputDir != "") {
+                                               string path = hasPath(namefileNames[i]);
+                                               //if the user has not given a path then, add inputdir. else leave path alone.
+                                               if (path == "") {       namefileNames[i] = inputDir + namefileNames[i];         }
+                                       }
+
                                        int ableToOpen;
                                        ifstream in;
                                        ableToOpen = openInputFile(namefileNames[i], in);
@@ -227,9 +265,11 @@ int ClassifySeqsCommand::execute(){
                        }
                
                        mothurOut("Classifying sequences from " + fastaFileNames[s] + " ..." ); mothurOutEndLine();
-                       string newTaxonomyFile = getRootName(fastaFileNames[s]) + getRootName(taxonomyFileName) + "taxonomy";
-                       string tempTaxonomyFile = getRootName(fastaFileNames[s]) + "taxonomy.temp";
-                       string taxSummary = getRootName(fastaFileNames[s]) + getRootName(taxonomyFileName) + "tax.summary";
+                       
+                       if (outputDir == "") { outputDir += hasPath(fastaFileNames[s]); }
+                       string newTaxonomyFile = outputDir + getRootName(getSimpleName(fastaFileNames[s])) + getRootName(getSimpleName(taxonomyFileName)) + "taxonomy";
+                       string tempTaxonomyFile = outputDir + getRootName(getSimpleName(fastaFileNames[s])) + "taxonomy.temp";
+                       string taxSummary = outputDir + getRootName(getSimpleName(fastaFileNames[s])) + getRootName(getSimpleName(taxonomyFileName)) + "tax.summary";
                        
                        int start = time(NULL);
                        int numFastaSeqs = 0;
index 0255bd2409c043abfa1a7d261aa2910c78f9440e..2223593c4e7758ac48844dbf7d5093b20f361b5d 100644 (file)
@@ -48,7 +48,7 @@ private:
        
        Classify* classify;
        
-       string fastaFileName, templateFileName, distanceFileName, namefile, search, method, taxonomyFileName;
+       string fastaFileName, templateFileName, distanceFileName, namefile, search, method, taxonomyFileName, outputDir;
        int processors, kmerSize, numWanted, cutoff, iters;
        float match, misMatch, gapOpen, gapExtend;
        bool abort, probs;
index 93ba1f9b65b8146b666d32debb3df601c046b19a..9d09d2cbe465da6531bbf720f0fd7d89aec08bce 100644 (file)
@@ -21,7 +21,7 @@ ClusterCommand::ClusterCommand(string option){
                
                else {
                        //valid paramters for this command
-                       string Array[] =  {"cutoff","precision","method","showabund","timing"};
+                       string Array[] =  {"cutoff","precision","method","showabund","timing","outputdir","inputdir"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
                        OptionParser parser(option);
@@ -36,6 +36,9 @@ ClusterCommand::ClusterCommand(string option){
                                }
                        }
                        
+                       //if the user changes the output directory command factory will send this info to us in the output parameter 
+                       outputDir = validParameter.validFile(parameters, "outputdir", false);           if (outputDir == "not found"){  outputDir = "";         }
+                       
                        //error checking to make sure they read a distance file
                        if ((globaldata->gSparseMatrix == NULL) || (globaldata->gListVector == NULL)) {
                                mothurOut("Before you use the cluster command, you first need to read in a distance matrix."); mothurOutEndLine();
@@ -85,8 +88,9 @@ ClusterCommand::ClusterCommand(string option){
                                else if(method == "nearest"){   cluster = new SingleLinkage(rabund, list, matrix, cutoff); }
                                else if(method == "average"){   cluster = new AverageLinkage(rabund, list, matrix, cutoff);     }
                                tag = cluster->getTag();
-
-                               fileroot = getRootName(globaldata->inputFileName);
+                               
+                               if (outputDir == "") { outputDir += hasPath(globaldata->inputFileName); }
+                               fileroot = outputDir + getRootName(getSimpleName(globaldata->inputFileName));
                        
                                openOutputFile(fileroot+ tag + ".sabund",       sabundFile);
                                openOutputFile(fileroot+ tag + ".rabund",       rabundFile);
index ad9fe85d9977f4c3ffb74d65bfa58ecc995f710c..5c21efccb279aeeb447a00087c846859c84eae3f 100644 (file)
@@ -45,7 +45,7 @@ private:
 
        bool abort;
 
-       string method, fileroot, tag;
+       string method, fileroot, tag, outputDir;
        double cutoff;
        string showabund, timing;
        int precision, length;
index beb70ebe9c7c82d84ab7c21cd43bc3e7a154eb50..a31883cf3c65aabf3955d12191b91b9ad9fe050c 100644 (file)
@@ -44,7 +44,7 @@ CollectCommand::CollectCommand(string option){
                
                else {
                        //valid paramters for this command
-                       string Array[] =  {"freq","label","calc","abund","size"};
+                       string Array[] =  {"freq","label","calc","abund","size","outputdir","inputdir"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
                        OptionParser parser(option);
@@ -57,6 +57,9 @@ CollectCommand::CollectCommand(string option){
                                if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
+                       //if the user changes the output directory command factory will send this info to us in the output parameter 
+                       outputDir = validParameter.validFile(parameters, "outputdir", false);           if (outputDir == "not found"){  outputDir = "";         }
+                       
                        //make sure the user has already run the read.otu command
                        if ((globaldata->getSharedFile() == "") && (globaldata->getListFile() == "") && (globaldata->getRabundFile() == "") && (globaldata->getSabundFile() == "")) { mothurOut("You must read a list, sabund, rabund or shared file before you can use the collect.single command."); mothurOutEndLine(); abort = true; }
                        
@@ -136,7 +139,8 @@ int CollectCommand::execute(){
                
                for (int p = 0; p < inputFileNames.size(); p++) {
                        
-                       string fileNameRoot = getRootName(inputFileNames[p]);
+                       if (outputDir == "") { outputDir += hasPath(inputFileNames[p]); }
+                       string fileNameRoot = outputDir + getRootName(getSimpleName(inputFileNames[p]));
                        globaldata->inputFileName = inputFileNames[p];
                        
                        if (inputFileNames.size() > 1) {
index 46dd9dc32b339fb2bf95a6e259114cc04d94f12d..0df1bab2315c256d07c98fe38124a213cda88d7e 100644 (file)
@@ -54,7 +54,7 @@ private:
 
        bool abort, allLines;
        set<string> labels; //holds labels to be used
-       string label, calc;
+       string label, calc, outputDir;
        vector<string>  Estimators;
        vector<string> inputFileNames;
        vector<string> groups;
index e68890cec67c253ae78e9400f865b4b66739a07b..a8d5069d7d123277b58df1cfdf1d0ff8b773c4e6 100644 (file)
@@ -50,7 +50,7 @@ CollectSharedCommand::CollectSharedCommand(string option){
                
                else {
                        //valid paramters for this command
-                       string Array[] =  {"freq","label","calc","groups","all"};
+                       string Array[] =  {"freq","label","calc","groups","all","outputdir","inputdir"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
                        OptionParser parser(option);
@@ -63,6 +63,10 @@ CollectSharedCommand::CollectSharedCommand(string option){
                                if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
+                       //if the user changes the output directory command factory will send this info to us in the output parameter 
+                       outputDir = validParameter.validFile(parameters, "outputdir", false);           if (outputDir == "not found"){  outputDir = "";         }
+                       
+                                               
                        //make sure the user has already run the read.otu command
                        if (globaldata->getSharedFile() == "") {
                                if (globaldata->getListFile() == "") { mothurOut("You must read a list and a group, or a shared before you can use the collect.shared command."); mothurOutEndLine(); abort = true; }
@@ -107,8 +111,9 @@ CollectSharedCommand::CollectSharedCommand(string option){
                        all = isTrue(temp);
                                                
                        if (abort == false) {
-                       
-                               string fileNameRoot = getRootName(globaldata->inputFileName);
+                               
+                               if (outputDir == "") { outputDir += hasPath(globaldata->inputFileName); }
+                               string fileNameRoot = outputDir + getRootName(getSimpleName(globaldata->inputFileName));
                                format = globaldata->getFormat();
                                int i;
                                
index 139a0cff7dfb3220db697d582ae037a99a3b0d98..10efcc80077c193694ee7297e40027a35f8bb10a 100644 (file)
@@ -47,7 +47,7 @@ private:
 
        bool abort, allLines, all;
        set<string> labels; //holds labels to be used
-       string label, calc, groups;
+       string label, calc, groups, outputDir;
        vector<string>  Estimators, Groups;
 
 
index 0da5986187ec2a3d4c2920c854cd34d101529528..ddb70290936458fdbc5ca85d550fff1bc1d6ea96 100644 (file)
@@ -16,7 +16,6 @@
 #include "collectsharedcommand.h"
 #include "getgroupcommand.h"
 #include "getlabelcommand.h"
-#include "getlinecommand.h"
 #include "rarefactcommand.h"
 #include "summarycommand.h"
 #include "summarysharedcommand.h"
@@ -64,6 +63,7 @@
 #include "preclustercommand.h"
 #include "pcacommand.h"
 #include "otuhierarchycommand.h"
+#include "setdircommand.h"
 
 /*******************************************************/
 
@@ -78,10 +78,10 @@ CommandFactory* CommandFactory::getInstance() {
 
 /***********************************************************/
 CommandFactory::CommandFactory(){
-       _uniqueInstance = 0;
        string s = "";
        command = new NoCommand(s);
        
+       outputDir = ""; inputDir = "";
        
        //initialize list of valid commands
        commands["read.dist"]                   = "read.dist"; 
@@ -109,7 +109,6 @@ CommandFactory::CommandFactory(){
        commands["venn"]                                = "venn";
        commands["get.group"]           = "get.group";
        commands["get.label"]           = "get.label";
-       commands["get.line"]            = "get.line";
        commands["get.sabund"]          = "get.sabund";
        commands["get.rabund"]          = "get.rabund";
        commands["bootstrap.shared"]    = "bootstrap.shared";
@@ -137,12 +136,13 @@ CommandFactory::CommandFactory(){
        commands["pre.cluster"]                 = "pre.cluster";
        commands["pca"]                                 = "pca";
        commands["otu.hierarchy"]               = "otu.hierarchy";
-
+       commands["set.dir"]                             = "set.dir";
 }
 /***********************************************************/
 
 /***********************************************************/
 CommandFactory::~CommandFactory(){
+       _uniqueInstance = 0;
        delete command;
 }
 
@@ -153,7 +153,14 @@ CommandFactory::~CommandFactory(){
 Command* CommandFactory::getCommand(string commandName, string optionString){
        try {
                delete command;   //delete the old command
+               
+               //user has opted to redirect output from dir where input files are located to some other place
+               if (outputDir != "") { optionString += ", outputdir=" + outputDir; }
+               
+               //user has opted to redirect input from dir where mothur.exe is located to some other place
+               if (inputDir != "") { optionString += ", inputdir=" + inputDir; }
 
+               
                if(commandName == "read.dist")                                  {       command = new ReadDistCommand(optionString);                    }
                else if(commandName == "read.otu")                              {       command = new ReadOtuCommand(optionString);                             }
                else if(commandName == "read.tree")                             {       command = new ReadTreeCommand(optionString);                    }
@@ -172,7 +179,6 @@ Command* CommandFactory::getCommand(string commandName, string optionString){
                else if(commandName == "unifrac.unweighted")    {       command = new UnifracUnweightedCommand(optionString);   }
                else if(commandName == "get.group")             {   command = new GetgroupCommand(optionString);                        }
                else if(commandName == "get.label")             {   command = new GetlabelCommand(optionString);                        }
-               else if(commandName == "get.line")              {   command = new GetlineCommand(optionString);                         }
                else if(commandName == "get.sabund")            {   command = new GetSAbundCommand(optionString);                       }
                else if(commandName == "get.rabund")            {   command = new GetRAbundCommand(optionString);                       }
                else if(commandName == "libshuff")              {   command = new LibShuffCommand(optionString);                        }
@@ -208,6 +214,7 @@ Command* CommandFactory::getCommand(string commandName, string optionString){
                else if(commandName == "pre.cluster")                   {       command = new PreClusterCommand(optionString);                  }
                else if(commandName == "pca")                                   {       command = new PCACommand(optionString);                                 }
                else if(commandName == "otu.hierarchy")                 {       command = new OtuHierarchyCommand(optionString);                }
+               else if(commandName == "set.dir")                               {       command = new SetDirectoryCommand(optionString);        }
                else                                                                                    {       command = new NoCommand(optionString);                                  }
 
                return command;
index 70e263078eee32ad8e706816f15be03a2fb6d369..d84be62a074dde5dc29b8006a636bd7b67b9607d 100644 (file)
@@ -21,11 +21,15 @@ public:
        Command* getCommand();
        bool isValidCommand(string);
        void printCommands(ostream&);
+       void setOutputDirectory(string o)       {       outputDir = o;          }
+       void setInputDirectory(string i)        {       inputDir = i;           }
+       string getOutputDir()                           {       return outputDir;       }
 
 private:
        Command* command;
        map<string, string> commands;
        map<string, string>::iterator it;
+       string outputDir, inputDir;
        
        static CommandFactory* _uniqueInstance;
        CommandFactory( const CommandFactory& ); // Disable copy constructor
index a936c820b56f88609e621894565359892384224a..00c40845484e9ba4eba4e62f7c645135f703e9d2 100644 (file)
@@ -19,24 +19,54 @@ DeconvoluteCommand::DeconvoluteCommand(string option) {
                
                else {
                        //valid paramters for this command
-                       string Array[] =  {"fasta", "name"};
+                       string Array[] =  {"fasta", "name","outputdir","inputdir"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
                        OptionParser parser(option);
                        map<string,string> parameters = parser.getParameters();
                        
                        ValidParameters validParameter;
+                       map<string, string>::iterator it;
                
                        //check to make sure all parameters are valid for command
-                       for (map<string, string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
+                       for (it = parameters.begin(); it != parameters.end(); it++) { 
                                if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
+                       //if the user changes the input directory command factory will send this info to us in the output parameter 
+                       string inputDir = validParameter.validFile(parameters, "inputdir", false);              
+                       if (inputDir == "not found"){   inputDir = "";          }
+                       else {
+                               string path;
+                               it = parameters.find("fasta");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["fasta"] = inputDir + it->second;            }
+                               }
+                               
+                               it = parameters.find("name");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["name"] = inputDir + it->second;             }
+                               }
+                       }
+
+                       
                        //check for required parameters
                        inFastaName = validParameter.validFile(parameters, "fasta", true);
                        if (inFastaName == "not open") { abort = true; }
                        else if (inFastaName == "not found") { inFastaName = ""; mothurOut("fasta is a required parameter for the unique.seqs command."); mothurOutEndLine(); abort = true;  }  
                        
+                       //if the user changes the output directory command factory will send this info to us in the output parameter 
+                       outputDir = validParameter.validFile(parameters, "outputdir", false);           if (outputDir == "not found"){  
+                               outputDir = ""; 
+                               outputDir += hasPath(inFastaName); //if user entered a file with a path then preserve it        
+                       }
+                       
                        oldNameMapFName = validParameter.validFile(parameters, "name", true);
                        if (oldNameMapFName == "not open") { abort = true; }
                        else if (oldNameMapFName == "not found"){       oldNameMapFName = "";   }
@@ -72,8 +102,8 @@ int DeconvoluteCommand::execute() {
                if (abort == true) { return 0; }
 
                //prepare filenames and open files
-               string outNameFile = (getRootName(inFastaName) + "names");
-               string outFastaFile = (getRootName(inFastaName) + "unique" + getExtension(inFastaName));
+               string outNameFile = outputDir + getRootName(getSimpleName(inFastaName)) + "names";
+               string outFastaFile = outputDir + getRootName(getSimpleName(inFastaName)) + "unique" + getExtension(inFastaName);
                
                FastaMap fastamap;
        
index 635e53fe455ab05eacdb2a19e09837b30ef4c955..4cb6aac3e0c9cd23d7b1d11ed40b775d43d4d42d 100644 (file)
@@ -25,7 +25,7 @@ public:
        void help();    
        
 private:
-       string inFastaName, oldNameMapFName;
+       string inFastaName, oldNameMapFName, outputDir;
 
        bool abort;
 };
index 0422532c4b11bb8e64573a6bbc734f42a8b542b2..5364cbfee12cb3bc1813d0112beccb96126528cf 100644 (file)
@@ -26,19 +26,34 @@ DistanceCommand::DistanceCommand(string option){
                
                else {
                        //valid paramters for this command
-                       string Array[] =  {"fasta", "phylip", "calc", "countends", "cutoff", "processors"};
+                       string Array[] =  {"fasta", "phylip", "calc", "countends", "cutoff", "processors", "outputdir","inputdir"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
                        OptionParser parser(option);
                        map<string, string> parameters = parser.getParameters();
                        
                        ValidParameters validParameter;
+                       map<string, string>::iterator it2;
                
                        //check to make sure all parameters are valid for command
-                       for (map<string, string>::iterator it2 = parameters.begin(); it2 != parameters.end(); it2++) { 
+                       for (it2 = parameters.begin(); it2 != parameters.end(); it2++) { 
                                if (validParameter.isValidParameter(it2->first, myArray, it2->second) != true) {  abort = true;  }
                        }
                        
+                       //if the user changes the input directory command factory will send this info to us in the output parameter 
+                       string inputDir = validParameter.validFile(parameters, "inputdir", false);              
+                       if (inputDir == "not found"){   inputDir = "";          }
+                       else {
+                               string path;
+                               it2 = parameters.find("fasta");
+                               //user has given a template file
+                               if(it2 != parameters.end()){ 
+                                       path = hasPath(it2->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["fasta"] = inputDir + it2->second;           }
+                               }
+                       }
+
                        //check for required parameters
                        fastafile = validParameter.validFile(parameters, "fasta", true);
                        if (fastafile == "not found") { mothurOut("fasta is a required parameter for the dist.seqs command."); mothurOutEndLine(); abort = true; }
@@ -49,6 +64,12 @@ DistanceCommand::DistanceCommand(string option){
                                alignDB = SequenceDB(inFASTA); 
                                inFASTA.close();
                        }
+                       
+                       //if the user changes the output directory command factory will send this info to us in the output parameter 
+                       outputDir = validParameter.validFile(parameters, "outputdir", false);           if (outputDir == "not found"){  
+                               outputDir = ""; 
+                               outputDir += hasPath(fastafile); //if user entered a file with a path then preserve it  
+                       }
 
                        //check for optional parameter and set defaults
                        // ...at some point should added some additional type checking...
@@ -146,21 +167,15 @@ int DistanceCommand::execute(){
                
                //doses the user want the phylip formatted file as well
                if (isTrue(phylip) == true) {
-                       outputFile = getRootName(fastafile) + "phylip.dist";
+                       outputFile = outputDir + getRootName(getSimpleName(fastafile)) + "phylip.dist";
                        remove(outputFile.c_str());
                        
                        //output numSeqs to phylip formatted dist file
                }else { //user wants column format
-                       outputFile = getRootName(fastafile) + "dist";
+                       outputFile = outputDir + getRootName(getSimpleName(fastafile)) + "dist";
                        remove(outputFile.c_str());
                }
                                
-               //#     if defined (_WIN32)
-               //figure out how to implement the fork and wait commands in windows
-               //      driver(distCalculator, seqDB, 0, numSeqs, distFile, phylipFile, cutoff);
-               //#     endif
-               
-                               
 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
                //if you don't need to fork anything
                if(processors == 1){
index 542f4283744024e58b297282f83212ad4b5b1292..c7aaf46137a97715baee381d56824482a0e08e80 100644 (file)
@@ -34,7 +34,7 @@ private:
        Dist* distCalculator;
        SequenceDB alignDB;
 
-       string countends, phylip, fastafile, calc;
+       string countends, phylip, fastafile, calc, outputDir;
        int processors;
        float cutoff;
        map<int, int> processIDS;   //end line, processid
index d3f156e533a6a759bab014250dd1d54ad1726c7b..cbcc99aaf2cd8ebc48f6512eb9e88967df8e94b3 100644 (file)
@@ -26,7 +26,8 @@ public:
        virtual ~Engine(){}
        virtual bool getInput() = 0;
        virtual string getCommand();
-       vector<string> getOptions() {   return options;         }
+       virtual string getOutputDir()   {       return cFactory->getOutputDir();  }
+       vector<string> getOptions()             {       return options;         }
 protected:
        vector<string> options;
        CommandFactory* cFactory;
index a689704131d32ae7e8a244babc672695cb432384..8c61ab221d14b27e0f158b93189148817c72b057 100644 (file)
@@ -21,23 +21,52 @@ FilterSeqsCommand::FilterSeqsCommand(string option){
                
                else {
                        //valid paramters for this command
-                       string Array[] =  {"fasta", "trump", "soft", "hard", "vertical"};
+                       string Array[] =  {"fasta", "trump", "soft", "hard", "vertical", "outputdir","inputdir"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
                        OptionParser parser(option);
                        map<string,string> parameters = parser.getParameters();
                        
                        ValidParameters validParameter;
+                       map<string,string>::iterator it;
                        
                        //check to make sure all parameters are valid for command
-                       for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
+                       for (it = parameters.begin(); it != parameters.end(); it++) { 
                                if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
+                       //if the user changes the input directory command factory will send this info to us in the output parameter 
+                       string inputDir = validParameter.validFile(parameters, "inputdir", false);              
+                       if (inputDir == "not found"){   inputDir = "";          }
+                       else {
+                               string path;
+                               it = parameters.find("fasta");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["fasta"] = inputDir + it->second;            }
+                               }
+                               
+                               it = parameters.find("hard");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["hard"] = inputDir + it->second;             }
+                               }
+                       }
+                       
                        //check for required parameters
                        fastafile = validParameter.validFile(parameters, "fasta", true);
                        if (fastafile == "not found") { mothurOut("fasta is a required parameter for the filter.seqs command."); mothurOutEndLine(); abort = true; }
                        else if (fastafile == "not open") { abort = true; }     
+                       
+                       //if the user changes the output directory command factory will send this info to us in the output parameter 
+                       outputDir = validParameter.validFile(parameters, "outputdir", false);           if (outputDir == "not found"){  
+                               outputDir = ""; 
+                               outputDir += hasPath(fastafile); //if user entered a file with a path then preserve it  
+                       }
 
                        //check for optional parameter and set defaults
                        // ...at some point should added some additional type checking...
@@ -140,14 +169,14 @@ int FilterSeqsCommand::execute() {
                filter = F.getFilter();
 
                ofstream outFilter;
-               string filterFile = getRootName(fastafile) + "filter";
+               string filterFile = outputDir + getRootName(getSimpleName(fastafile)) + "filter";
                openOutputFile(filterFile, outFilter);
                outFilter << filter << endl;
                outFilter.close();
                
                ifstream inFasta2;
                openInputFile(fastafile, inFasta2);
-               string filteredFasta = getRootName(fastafile) + "filter.fasta";
+               string filteredFasta = outputDir + getRootName(getSimpleName(fastafile)) + "filter.fasta";
                ofstream outFASTA;
                openOutputFile(filteredFasta, outFASTA);
 
index 611cbbc1b226c13d859273dc0cb356bb3b3d13d5..0946396e3a0fe6623f3501feed5fc6e7b4ba239a 100644 (file)
@@ -23,7 +23,7 @@ public:
        void help();
        
 private:
-       string vertical, filter, fastafile, hard;       
+       string vertical, filter, fastafile, hard, outputDir;    
        int alignmentLength;
 
        char trump;
index 9014031d5a58556493b712282fbf4bfc5535d5e2..c754f8eb1bb2ba79daf77c3a060a0ebf770252dd 100644 (file)
@@ -19,7 +19,21 @@ GetgroupCommand::GetgroupCommand(string option){
                if(option == "help") { help(); abort = true; }
                
                else {
-                       if (option != "") { mothurOut("There are no valid parameters for the get.group command."); mothurOutEndLine(); abort = true; }
+                       //valid paramters for this command
+                       string Array[] =  {"outputdir","inputdir"};
+                       vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+                       
+                       OptionParser parser(option);
+                       map<string,string> parameters = parser.getParameters();
+                       
+                       ValidParameters validParameter;
+                       //check to make sure all parameters are valid for command
+                       for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
+                               if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
+                       }
+                       
+                       //if the user changes the output directory command factory will send this info to us in the output parameter 
+                       string outputDir = validParameter.validFile(parameters, "outputdir", false);            if (outputDir == "not found"){  outputDir = "";         }
                        
                        if ((globaldata->getSharedFile() == "")) { mothurOut("You must use the read.otu command to read a groupfile or a sharedfile before you can use the get.group command."); mothurOutEndLine(); abort = true; }
                                
@@ -29,7 +43,8 @@ GetgroupCommand::GetgroupCommand(string option){
                                openInputFile(sharedfile, in);
                
                                //open output file
-                               outputFile = getRootName(sharedfile) + "bootGroups";
+                               if (outputDir == "") { outputDir += hasPath(sharedfile); }
+                               outputFile = outputDir + getRootName(getSimpleName(sharedfile)) + "bootGroups";
                                openOutputFile(outputFile, out);
 
                        }
index be2a989d7a953be7b68a29ceca1a88c4d514bd20..2ba3054978ecda124017a1e5d5f0f73640d28702 100644 (file)
@@ -20,8 +20,6 @@ GetlabelCommand::GetlabelCommand(string option){
                if(option == "help") { help(); abort = true; }
                
                else {
-                       if (option != "") { mothurOut("There are no valid parameters for the get.label command."); mothurOutEndLine(); abort = true; }
-                       
                        if ((globaldata->getListFile() == "") && (globaldata->getRabundFile() == "") && (globaldata->getSabundFile() == "")) { mothurOut("You must read a list, sabund or rabund before you can use the get.label command."); mothurOutEndLine(); abort = true; }                               
                }
 
diff --git a/getlinecommand.cpp b/getlinecommand.cpp
deleted file mode 100644 (file)
index f1ec55c..0000000
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- *  GetlineCommand.cpp
- *  Mothur
- *
- *  Created by Thomas Ryabin on 1/30/09.
- *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
- *
- */
-
-#include "getlinecommand.h"
-
-//**********************************************************************************************************************
-GetlineCommand::GetlineCommand(string option){
-       try {
-               globaldata = GlobalData::getInstance();
-               abort = false;
-               
-               //allow user to run help
-               if(option == "help") { help(); abort = true; }
-               
-               else {
-                       if (option != "") { mothurOut("There are no valid parameters for the get.line command."); mothurOutEndLine(); abort = true; }
-                       
-                       if ((globaldata->getListFile() == "") && (globaldata->getRabundFile() == "") && (globaldata->getSabundFile() == "")) { mothurOut("You must read a list, sabund or rabund before you can use the get.line command."); mothurOutEndLine(); abort = true; }                                
-               }
-
-       }
-       catch(exception& e) {
-               errorOut(e, "GetlineCommand", "GetlineCommand");
-               exit(1);
-       }
-}
-//**********************************************************************************************************************
-
-void GetlineCommand::help(){
-       try {
-               mothurOut("The get.line command can only be executed after a successful read.otu command.\n");
-               mothurOut("You may not use any parameters with the get.line command.\n");
-               mothurOut("The get.line command should be in the following format: \n");
-               mothurOut("get.line()\n");
-               mothurOut("Example get.line().\n");
-       }
-       catch(exception& e) {
-               errorOut(e, "GetlineCommand", "help");
-               exit(1);
-       }
-}
-
-//**********************************************************************************************************************
-
-GetlineCommand::~GetlineCommand(){
-}
-
-//**********************************************************************************************************************
-
-int GetlineCommand::execute(){
-       try {
-       
-               if (abort == true) { return 0; }
-       
-               ifstream in;
-               openInputFile(globaldata->inputFileName, in);
-               string label;
-               int numBins = 0;
-               int count = -1;
-               int line = 1;
-               while(in.good()) {
-                       if(count > numBins)
-                               count = 0;
-                       if(count == 0) {
-                               mothurOut(toString(line)); mothurOutEndLine();
-                               in >> numBins;
-                               line++;
-                       }
-                       in >> label;
-                       count++;
-               }
-               
-               in.close();
-               return 0;               
-       }
-
-       catch(exception& e) {
-               errorOut(e, "GetlineCommand", "execute");
-               exit(1);
-       }
-}
-
-
-
diff --git a/getlinecommand.h b/getlinecommand.h
deleted file mode 100644 (file)
index 68870b3..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-#ifndef GETLINECOMMAND_H
-#define GETLINECOMMAND_H
-
-/*
- *  getlinecommand.h
- *  Mothur
- *
- *  Created by Thomas Ryabin on 1/30/09.
- *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
- *
- */
-
-#include "command.hpp"
-#include "readmatrix.hpp"
-
-class GlobalData;
-
-class GetlineCommand : public Command {
-public:
-       GetlineCommand(string);
-       ~GetlineCommand();
-       int execute();
-       void help();
-       
-private:
-       GlobalData* globaldata;
-       bool abort;
-};
-
-#endif
index 94437fddfa766efe0bf25233914fe59befd9f204..fcc42ced634b80790d6aa3f5977ea6ef3121f77a 100644 (file)
@@ -22,21 +22,39 @@ GetListCountCommand::GetListCountCommand(string option){
                
                else {
                        //valid paramters for this command
-                       string AlignArray[] =  {"list","label"};
+                       string AlignArray[] =  {"list","label","outputdir","inputdir"};
                        vector<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
                        
                        OptionParser parser(option);
                        map<string, string> parameters = parser.getParameters();
                        
                        ValidParameters validParameter;
-               
+                       map<string, string>::iterator it;
+                       
                        //check to make sure all parameters are valid for command
-                       for (map<string, string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
+                       for (it = parameters.begin(); it != parameters.end(); it++) { 
                                if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
                        string ranRead = globaldata->getListFile();
                        
+                       //if the user changes the input directory command factory will send this info to us in the output parameter 
+                       string inputDir = validParameter.validFile(parameters, "inputdir", false);              
+                       if (inputDir == "not found"){   inputDir = "";          }
+                       else {
+                               string path;
+                               it = parameters.find("list");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["list"] = inputDir + it->second;             }
+                               }
+                       }
+
+                       //if the user changes the output directory command factory will send this info to us in the output parameter 
+                       outputDir = validParameter.validFile(parameters, "outputdir", false);           if (outputDir == "not found"){  outputDir = "";         }
+                       
                        //check for required parameters
                        listfile = validParameter.validFile(parameters, "list", true);
                        if ((listfile == "not found") && (globaldata->getListFile() == ""))  { mothurOut("You must read a listfile before running the get.listcount command.");  mothurOutEndLine(); abort = true; }
@@ -179,7 +197,8 @@ int GetListCountCommand::execute(){
 void GetListCountCommand::process(ListVector* list) {
        try {
                string binnames, name, sequence;
-               string outputFileName = getRootName(listfile) + list->getLabel() + ".otu";
+               if (outputDir == "") { outputDir += hasPath(listfile); }
+               string outputFileName = outputDir + getRootName(getSimpleName(listfile)) + list->getLabel() + ".otu";
                openOutputFile(outputFileName, out);
                
                mothurOut(list->getLabel()); mothurOutEndLine();
index 468ea80ca20308115782bfdf757e8cbd276fe5c9..bd9d20234c6943adba91be63d4e1569e1bdb225e 100644 (file)
@@ -34,7 +34,7 @@ private:
        
        bool abort, allLines;
        set<string> labels; //holds labels to be used
-       string label, listfile;
+       string label, listfile, outputDir;
        ofstream out;
        
        void process(ListVector*);
index d37ee19eb573bba0ade4c91320c9766f1712be69..6b9cee90c40f8f2848a076596d9ed3c88665ffb0 100644 (file)
@@ -48,19 +48,78 @@ GetOTURepCommand::GetOTURepCommand(string option){
                        help(); abort = true;
                } else {
                        //valid paramters for this command
-                       string Array[] =  {"fasta","list","label","name", "group", "sorted", "phylip","column","large","cutoff","precision"};
+                       string Array[] =  {"fasta","list","label","name", "group", "sorted", "phylip","column","large","cutoff","precision","outputdir","inputdir"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
                        OptionParser parser(option);
                        map<string, string> parameters = parser.getParameters();
                        
                        ValidParameters validParameter;
+                       map<string, string>::iterator it;
                
                        //check to make sure all parameters are valid for command
-                       for (map<string, string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
+                       for (it = parameters.begin(); it != parameters.end(); it++) { 
                                if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
+                       //if the user changes the input directory command factory will send this info to us in the output parameter 
+                       string inputDir = validParameter.validFile(parameters, "inputdir", false);              
+                       if (inputDir == "not found"){   inputDir = "";          }
+                       else {
+                               string path;
+                               it = parameters.find("list");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["list"] = inputDir + it->second;             }
+                               }
+                               
+                               it = parameters.find("fasta");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["fasta"] = inputDir + it->second;            }
+                               }
+                               
+                               it = parameters.find("phylip");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["phylip"] = inputDir + it->second;           }
+                               }
+                               
+                               it = parameters.find("column");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["column"] = inputDir + it->second;           }
+                               }
+                               
+                               it = parameters.find("name");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["name"] = inputDir + it->second;             }
+                               }
+                               
+                               it = parameters.find("group");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["group"] = inputDir + it->second;            }
+                               }
+                       }
+
+                       
+                       //if the user changes the output directory command factory will send this info to us in the output parameter 
+                       outputDir = validParameter.validFile(parameters, "outputdir", false);           if (outputDir == "not found"){  outputDir = "";         }
+                       
                        //check for required parameters
                        fastafile = validParameter.validFile(parameters, "fasta", true);
                        if (fastafile == "not found") { mothurOut("fasta is a required parameter for the get.oturep command."); mothurOutEndLine(); abort = true; }
@@ -104,7 +163,8 @@ GetOTURepCommand::GetOTURepCommand(string option){
                        else {
                                //read in group map info.
                                groupMap = new GroupMap(groupfile);
-                               groupMap->readMap();
+                               int error = groupMap->readMap();
+                               if (error == 1) { delete groupMap; abort = true; }
                        }
                        
                        sorted = validParameter.validFile(parameters, "sorted", false);         if (sorted == "not found"){     sorted = "";    }
@@ -490,12 +550,13 @@ int GetOTURepCommand::process(ListVector* processList) {
                string nameRep, name, sequence;
 
                //create output file
-               string outputFileName = getRootName(listfile) + processList->getLabel() + ".rep.fasta";
+               if (outputDir == "") { outputDir += hasPath(listfile); }
+               string outputFileName = outputDir + getRootName(getSimpleName(listfile)) + processList->getLabel() + ".rep.fasta";
                openOutputFile(outputFileName, out);
                vector<repStruct> reps;
                
                ofstream newNamesOutput;
-               string outputNamesFile = getRootName(listfile) + processList->getLabel() + ".rep.names";
+               string outputNamesFile = outputDir + getRootName(getSimpleName(listfile)) + processList->getLabel() + ".rep.names";
                openOutputFile(outputNamesFile, newNamesOutput);
                
                //for each bin in the list vector
index 0e8a121793823677186d67e5d3cd255dd7ec47d1..ceea8988a2bc0963abaa4d18d898729d88c8960a 100644 (file)
@@ -53,7 +53,7 @@ private:
        ReadMatrix* readMatrix;
        FormatMatrix* formatMatrix;
        NameAssignment* nameMap;
-       string filename, fastafile, listfile, namefile, groupfile, label, sorted, phylipfile, columnfile, distFile, format;
+       string filename, fastafile, listfile, namefile, groupfile, label, sorted, phylipfile, columnfile, distFile, format, outputDir;
        ofstream out;
        ifstream in, inNames, inRow;
        bool abort, allLines, groupError, large;
index 2ed5b7be71e13b5369f4cc71aaab72258960d41f..df9754b14219548719305cd53498b5d46b05d42c 100644 (file)
@@ -23,7 +23,7 @@ GetRAbundCommand::GetRAbundCommand(string option){
                
                else {
                        //valid paramters for this command
-                       string Array[] =  {"label","sorted"};
+                       string Array[] =  {"label","sorted","outputdir","inputdir"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
                        OptionParser parser(option);
@@ -36,6 +36,12 @@ GetRAbundCommand::GetRAbundCommand(string option){
                                if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
+                       //if the user changes the output directory command factory will send this info to us in the output parameter 
+                       string outputDir = validParameter.validFile(parameters, "outputdir", false);            if (outputDir == "not found"){  
+                               outputDir = ""; 
+                               outputDir += hasPath(globaldata->inputFileName); //if user entered a file with a path then preserve it  
+                       }
+                       
                        //make sure the user has already run the read.otu command
                        if (globaldata->getListFile() == "") { mothurOut("You must read a listfile before you can use the get.rabund command."); mothurOutEndLine(); abort = true; }
                        
@@ -60,7 +66,7 @@ GetRAbundCommand::GetRAbundCommand(string option){
                        }
                                
                        if (abort == false) {
-                               filename = getRootName(globaldata->inputFileName) + "rabund";
+                               filename = outputDir + getRootName(getSimpleName(globaldata->inputFileName)) + "rabund";
                                openOutputFile(filename, out);
                        }
                }
index 3dd58c117945a299154ebd09cc60b0688ea9f714..10b998e73d78a3af0d41c3106743c52e6235359b 100644 (file)
@@ -23,7 +23,7 @@ GetSAbundCommand::GetSAbundCommand(string option){
                
                else {
                        //valid paramters for this command
-                       string Array[] =  {"label"};
+                       string Array[] =  {"label","outputdir","inputdir"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
                        OptionParser parser(option);
@@ -36,6 +36,12 @@ GetSAbundCommand::GetSAbundCommand(string option){
                                if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
+                       //if the user changes the output directory command factory will send this info to us in the output parameter 
+                       string outputDir = validParameter.validFile(parameters, "outputdir", false);            if (outputDir == "not found"){  
+                               outputDir = ""; 
+                               outputDir += hasPath(globaldata->inputFileName); //if user entered a file with a path then preserve it  
+                       }
+
                        //make sure the user has already run the read.otu command
                        if ((globaldata->getListFile() == "") && (globaldata->getRabundFile() == "")) { mothurOut("You must read a list or rabund before you can use the get.sabund command."); mothurOutEndLine(); abort = true; }
                        
@@ -55,7 +61,7 @@ GetSAbundCommand::GetSAbundCommand(string option){
                        }
                                
                        if (abort == false) {
-                               filename = getRootName(globaldata->inputFileName) + "sabund";
+                               filename = outputDir + getRootName(getSimpleName(globaldata->inputFileName)) + "sabund";
                                openOutputFile(filename, out);
                        }
                }
index 03ccb82f6ef5c9c437942420163ac286fa35c203..d63dc79974ac007f504f7f1928ed8d0f031dcfe3 100644 (file)
@@ -22,19 +22,78 @@ GetSeqsCommand::GetSeqsCommand(string option){
                
                else {
                        //valid paramters for this command
-                       string Array[] =  {"fasta","name", "group", "alignreport", "accnos", "list"};
+                       string Array[] =  {"fasta","name", "group", "alignreport", "accnos", "list","outputdir","inputdir"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
                        OptionParser parser(option);
                        map<string,string> parameters = parser.getParameters();
                        
                        ValidParameters validParameter;
+                       map<string,string>::iterator it;
                        
                        //check to make sure all parameters are valid for command
-                       for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
+                       for (it = parameters.begin(); it != parameters.end(); it++) { 
                                if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
+                       //if the user changes the output directory command factory will send this info to us in the output parameter 
+                       outputDir = validParameter.validFile(parameters, "outputdir", false);           if (outputDir == "not found"){  outputDir = "";         }
+                       
+                       //if the user changes the input directory command factory will send this info to us in the output parameter 
+                       string inputDir = validParameter.validFile(parameters, "inputdir", false);              
+                       if (inputDir == "not found"){   inputDir = "";          }
+                       else {
+                               string path;
+                               it = parameters.find("alignreport");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["alignreport"] = inputDir + it->second;              }
+                               }
+                               
+                               it = parameters.find("fasta");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["fasta"] = inputDir + it->second;            }
+                               }
+                               
+                               it = parameters.find("accnos");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["accnos"] = inputDir + it->second;           }
+                               }
+                               
+                               it = parameters.find("list");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["list"] = inputDir + it->second;             }
+                               }
+                               
+                               it = parameters.find("name");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["name"] = inputDir + it->second;             }
+                               }
+                               
+                               it = parameters.find("group");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["group"] = inputDir + it->second;            }
+                               }
+                       }
+
+                       
                        //check for required parameters
                        accnosfile = validParameter.validFile(parameters, "accnos", true);
                        if (accnosfile == "not open") { abort = true; }
@@ -62,7 +121,10 @@ GetSeqsCommand::GetSeqsCommand(string option){
                        
                        if ((fastafile == "") && (namefile == "") && (groupfile == "") && (alignfile == "") && (listfile == ""))  { mothurOut("You must provide one of the following: fasta, name, group, alignreport or listfile."); mothurOutEndLine(); abort = true; }
                        
-                       if (parameters.size() > 2) { mothurOut("You may only enter one of the following: fasta, name, group, alignreport or listfile."); mothurOutEndLine(); abort = true;  }
+                       int okay = 2;
+                       if (outputDir != "") { okay++; }
+                       
+                       if (parameters.size() > okay) { mothurOut("You may only enter one of the following: fasta, name, group, alignreport or listfile."); mothurOutEndLine(); abort = true;  }
                }
 
        }
@@ -117,7 +179,8 @@ int GetSeqsCommand::execute(){
 //**********************************************************************************************************************
 void GetSeqsCommand::readFasta(){
        try {
-               string outputFileName = getRootName(fastafile) + "pick" +  getExtension(fastafile);
+               if (outputDir == "") { outputDir += hasPath(fastafile); }
+               string outputFileName = outputDir + getRootName(getSimpleName(fastafile)) + "pick" +  getExtension(fastafile);
                ofstream out;
                openOutputFile(outputFileName, out);
                
@@ -160,7 +223,8 @@ void GetSeqsCommand::readFasta(){
 //**********************************************************************************************************************
 void GetSeqsCommand::readList(){
        try {
-               string outputFileName = getRootName(listfile) + "pick" +  getExtension(listfile);
+               if (outputDir == "") { outputDir += hasPath(listfile); }
+               string outputFileName = outputDir + getRootName(getSimpleName(listfile)) + "pick" +  getExtension(listfile);
                ofstream out;
                openOutputFile(outputFileName, out);
                
@@ -224,8 +288,8 @@ void GetSeqsCommand::readList(){
 //**********************************************************************************************************************
 void GetSeqsCommand::readName(){
        try {
-       
-               string outputFileName = getRootName(namefile) + "pick" +  getExtension(namefile);
+               if (outputDir == "") { outputDir += hasPath(namefile); }
+               string outputFileName = outputDir + getRootName(getSimpleName(namefile)) + "pick" +  getExtension(namefile);
                ofstream out;
                openOutputFile(outputFileName, out);
 
@@ -307,8 +371,8 @@ void GetSeqsCommand::readName(){
 //**********************************************************************************************************************
 void GetSeqsCommand::readGroup(){
        try {
-       
-               string outputFileName = getRootName(groupfile) + "pick" + getExtension(groupfile);
+               if (outputDir == "") { outputDir += hasPath(groupfile); }
+               string outputFileName = outputDir + getRootName(getSimpleName(groupfile)) + "pick" + getExtension(groupfile);
                ofstream out;
                openOutputFile(outputFileName, out);
 
@@ -353,7 +417,8 @@ void GetSeqsCommand::readGroup(){
 //alignreport file has a column header line then all other lines contain 16 columns.  we just want the first column since that contains the name
 void GetSeqsCommand::readAlign(){
        try {
-               string outputFileName = getRootName(getRootName(alignfile)) + "pick.align.report";
+               if (outputDir == "") { outputDir += hasPath(alignfile); }
+               string outputFileName = outputDir + getRootName(getSimpleName(alignfile)) + "pick.align.report";
                ofstream out;
                openOutputFile(outputFileName, out);
 
index 8b38a76f4a3c2bdcfbd0855d6a8be0ff3bad1714..24f3968786784965e343f88aef300cad80c54eb4 100644 (file)
@@ -23,7 +23,7 @@ class GetSeqsCommand : public Command {
                
        private:
                set<string> names;
-               string accnosfile, fastafile, namefile, groupfile, alignfile, listfile;
+               string accnosfile, fastafile, namefile, groupfile, alignfile, listfile, outputDir;
                bool abort;
                
                void readFasta();
index f224b479d610b179511ec3bd2b88ca2afe2b210a..7af1ac67349843c59a282338387dc127239a1bcb 100644 (file)
@@ -25,19 +25,54 @@ GetSharedOTUCommand::GetSharedOTUCommand(string option){
                
                else {
                        //valid paramters for this command
-                       string Array[] =  {"label","unique","shared","fasta","list","group","output"};
+                       string Array[] =  {"label","unique","shared","fasta","list","group","output","outputdir","inputdir"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
                        OptionParser parser(option);
                        map<string,string> parameters = parser.getParameters();
                        
                        ValidParameters validParameter;
+                       map<string,string>::iterator it;
                        
                        //check to make sure all parameters are valid for command
-                       for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
+                       for (it = parameters.begin(); it != parameters.end(); it++) { 
                                if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
+                       //if the user changes the output directory command factory will send this info to us in the output parameter 
+                       outputDir = validParameter.validFile(parameters, "outputdir", false);           if (outputDir == "not found"){  outputDir = "";         }
+                       
+                       //if the user changes the input directory command factory will send this info to us in the output parameter 
+                       string inputDir = validParameter.validFile(parameters, "inputdir", false);              
+                       if (inputDir == "not found"){   inputDir = "";          }
+                       else {
+                               string path;
+                               it = parameters.find("fasta");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["fasta"] = inputDir + it->second;            }
+                               }
+                               
+                               it = parameters.find("list");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["list"] = inputDir + it->second;             }
+                               }
+                               
+                               it = parameters.find("group");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["group"] = inputDir + it->second;            }
+                               }
+                       }
+
+                       
                        //check for required parameters
                        listfile = validParameter.validFile(parameters, "list", true);
                        if (listfile == "not open") { abort = true; }
@@ -65,6 +100,7 @@ GetSharedOTUCommand::GetSharedOTUCommand(string option){
                        groups = validParameter.validFile(parameters, "unique", false);                 
                        if (groups == "not found") { groups = ""; }
                        else { 
+                               userGroups = "unique." + groups;
                                splitAtDash(groups, Groups);
                                globaldata->Groups = Groups;
                                
@@ -73,6 +109,7 @@ GetSharedOTUCommand::GetSharedOTUCommand(string option){
                        groups = validParameter.validFile(parameters, "shared", false);                 
                        if (groups == "not found") { groups = "";  }
                        else { 
+                               userGroups = groups;
                                splitAtDash(groups, Groups);
                                globaldata->Groups = Groups;
                                unique = false;
@@ -128,11 +165,18 @@ int GetSharedOTUCommand::execute(){
                if (abort == true) { return 0; }
                
                groupMap = new GroupMap(groupfile);
-               groupMap->readMap();
+               int error = groupMap->readMap();
+               if (error == 1) { delete groupMap; return 0; }
+               
                globaldata->gGroupmap = groupMap;
                
                if (Groups.size() == 0) {
                        Groups = groupMap->namesOfGroups;
+                       
+                       //make string for outputfile name
+                       userGroups = "unique.";
+                       for(int i = 0; i < Groups.size(); i++) {  userGroups += Groups[i] + "-";  }
+                       userGroups = userGroups.substr(0, userGroups.length()-1);
                }
        
                //put groups in map to find easier
@@ -238,10 +282,12 @@ void GetSharedOTUCommand::process(ListVector* shared) {
                
                ofstream outNames;
                string outputFileNames;
+               
+               if (outputDir == "") { outputDir += hasPath(listfile); }
                if (output != "accnos") {
-                       outputFileNames = getRootName(listfile) + shared->getLabel() + ".shared.seqs";
+                       outputFileNames = outputDir + getRootName(getSimpleName(listfile)) + shared->getLabel() + userGroups + ".shared.seqs";
                }else {
-                       outputFileNames = getRootName(listfile) + shared->getLabel() + ".accnos";
+                       outputFileNames = outputDir + getRootName(getSimpleName(listfile)) + shared->getLabel() + userGroups + ".accnos";
                }
                openOutputFile(outputFileNames, outNames);
                
@@ -340,8 +386,9 @@ void GetSharedOTUCommand::process(ListVector* shared) {
                }else { mothurOut("\t" + toString(num)); mothurOutEndLine(); }
                
                //if fasta file provided output new fasta file
-               if ((fastafile != "") && wroteSomething) {      
-                       string outputFileFasta = getRootName(fastafile) + shared->getLabel() + ".shared.fasta";
+               if ((fastafile != "") && wroteSomething) {
+                       if (outputDir == "") { outputDir += hasPath(fastafile); }
+                       string outputFileFasta = outputDir + getRootName(getSimpleName(fastafile)) + shared->getLabel() + userGroups + ".shared.fasta";
                        ofstream outFasta;
                        openOutputFile(outputFileFasta, outFasta);
                        
index 3b14b39bb70e8939641dea69c2e53bcb98a82ffa..5b5516c3a3d6850aa36cce33b104c888872b9137 100644 (file)
@@ -33,7 +33,7 @@ class GetSharedOTUCommand : public Command {
                GroupMap* groupMap;
                
                set<string> labels;
-               string fastafile, label, groups, listfile, groupfile, output;
+               string fastafile, label, groups, listfile, groupfile, output, userGroups, outputDir;
                bool abort, allLines, unique;
                vector<string> Groups;
                map<string, string> groupFinder;
index b627a6bda6e3fa63de073a4b3f6c20bee7a2a680..598e301648978ab642274edb69ffa41bbea6f205 100644 (file)
@@ -21,8 +21,9 @@
  GroupMap::~GroupMap(){}
 
 /************************************************************/
-void GroupMap::readMap() {
+int GroupMap::readMap() {
                string seqName, seqGroup;
+               int error = 0;
        
                while(fileHandle){
                        fileHandle >> seqName;                  //read from first column
@@ -30,12 +31,17 @@ void GroupMap::readMap() {
                        
                        setNamesOfGroups(seqGroup);
                        
-                       groupmap[seqName] = seqGroup;   //store data in map
-                       seqsPerGroup[seqGroup]++;  //increment number of seqs in that group
-               
+                       it = groupmap.find(seqName);
+                       
+                       if (it != groupmap.end()) { error = 1; mothurOut("Your groupfile contains more than 1 sequence named " + seqName + ", sequence names must be unique. Please correct."); mothurOutEndLine();  }
+                       else {
+                               groupmap[seqName] = seqGroup;   //store data in map
+                               seqsPerGroup[seqGroup]++;  //increment number of seqs in that group
+                       }
                        gobble(fileHandle);
                }
                fileHandle.close();
+               return error;
 }
 /************************************************************/
 int GroupMap::getNumGroups() { return namesOfGroups.size();    }
index fd6c14605065ea3fd1f12613d89b6bca9a1e0861..a99ad119db44c2fd3bb6f78b696fc2d9ddf170af 100644 (file)
@@ -19,7 +19,7 @@ public:
        GroupMap() {};
        GroupMap(string);
        ~GroupMap();
-       void readMap();
+       int readMap();
        int getNumGroups();
        bool isValidGroup(string);  //return true if string is a valid group
        string getGroup(string);
index c39b002ccfc0096197cd59ced3f4bb7fa21cce6b..365c80ee7956045fec1c1d82e848183f3138fe70 100644 (file)
@@ -21,16 +21,17 @@ HClusterCommand::HClusterCommand(string option){
                
                else {
                        //valid paramters for this command
-                       string Array[] =  {"cutoff","precision","method","phylip","column","name","sorted","showabund","timing"};
+                       string Array[] =  {"cutoff","precision","method","phylip","column","name","sorted","showabund","timing","outputdir","inputdir"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
                        OptionParser parser(option);
                        map<string,string> parameters = parser.getParameters();
                        
                        ValidParameters validParameter;
+                       map<string,string>::iterator it;
                
                        //check to make sure all parameters are valid for command
-                       for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
+                       for (it = parameters.begin(); it != parameters.end(); it++) { 
                                if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {
                                        abort = true;
                                }
@@ -38,6 +39,39 @@ HClusterCommand::HClusterCommand(string option){
                        
                        globaldata->newRead();
                        
+                       //if the user changes the input directory command factory will send this info to us in the output parameter 
+                       string inputDir = validParameter.validFile(parameters, "inputdir", false);              
+                       if (inputDir == "not found"){   inputDir = "";          }
+                       else {
+                               string path;
+                               it = parameters.find("phylip");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["phylip"] = inputDir + it->second;           }
+                               }
+                               
+                               it = parameters.find("column");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["column"] = inputDir + it->second;           }
+                               }
+                               
+                               it = parameters.find("name");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["name"] = inputDir + it->second;             }
+                               }
+                       }
+
+                       //if the user changes the output directory command factory will send this info to us in the output parameter 
+                       outputDir = validParameter.validFile(parameters, "outputdir", false);           if (outputDir == "not found"){  outputDir = "";         }
+                       
                        //check for required parameters
                        phylipfile = validParameter.validFile(parameters, "phylip", true);
                        if (phylipfile == "not open") { abort = true; }
@@ -93,8 +127,9 @@ HClusterCommand::HClusterCommand(string option){
                        
                                
                        if (abort == false) {
-                                                                                       
-                               fileroot = getRootName(distfile);
+                               
+                               if (outputDir == "") {  outputDir += hasPath(distfile); }
+                               fileroot = outputDir + getRootName(getSimpleName(distfile));
                                
                                if (method == "furthest")               { tag = "fn";  }
                                else if (method == "nearest")   { tag = "nn";  }
index 4c8fa9c9aa7811d31dc52e3b050ac0c1d5305184..443d8709bb7dd9294841e2dfc24584569e78e7c0 100644 (file)
@@ -47,7 +47,7 @@ private:
        ReadCluster* read;
        
        bool abort, sorted, print_start;
-       string method, fileroot, tag, distfile, format, phylipfile, columnfile, namefile, sort, showabund, timing;
+       string method, fileroot, tag, distfile, format, phylipfile, columnfile, namefile, sort, showabund, timing, outputDir;
        double cutoff;
        int precision, length;
        ofstream sabundFile, rabundFile, listFile;
index e4e947ef6970787a5c05d340006f595dfe3830c5..2bd020e0c3cf8337c0671c1db515954e51177dd0 100644 (file)
 #include "heatmap.h"
 
 //**********************************************************************************************************************
-HeatMap::HeatMap(string sort, string scale){
+HeatMap::HeatMap(string sort, string scale, string dir){
        try {
                globaldata = GlobalData::getInstance();
 //             format = globaldata->getFormat();
                sorted = sort;
                scaler = scale;
+               outputDir = dir;
        }
        catch(exception& e) {
                errorOut(e, "HeatMap", "HeatMap");
@@ -57,7 +58,7 @@ void HeatMap::getPic(RAbundVector* rabund) {
                }
                
                
-               string filenamesvg = getRootName(globaldata->inputFileName) + rabund->getLabel() + ".heatmap.bin.svg";
+               string filenamesvg = outputDir + getRootName(getSimpleName(globaldata->inputFileName)) + rabund->getLabel() + ".heatmap.bin.svg";
                openOutputFile(filenamesvg, outsvg);
                
                //svg image
@@ -133,7 +134,7 @@ void HeatMap::getPic(vector<SharedRAbundVector*> lookup) {
                        }
                }
 
-               string filenamesvg = getRootName(globaldata->inputFileName) + lookup[0]->getLabel() + ".heatmap.bin.svg";
+               string filenamesvg = outputDir + getRootName(getSimpleName(globaldata->inputFileName)) + lookup[0]->getLabel() + ".heatmap.bin.svg";
                openOutputFile(filenamesvg, outsvg);
                
                //svg image
index 56a56e4e841b4f258f5ab4f183db96acd7d6f268..438d84bbb69335d9825fa3b34acf96c05ceb59a4 100644 (file)
--- a/heatmap.h
+++ b/heatmap.h
@@ -19,7 +19,7 @@
 class HeatMap {
        
        public:
-               HeatMap(string, string);
+               HeatMap(string, string, string);
                ~HeatMap(){};
        
                void getPic(RAbundVector*);
@@ -30,7 +30,7 @@ class HeatMap {
                void printLegend(int, float);
 
                GlobalData* globaldata;
-               string format, sorted, groupComb, scaler;
+               string format, sorted, groupComb, scaler, outputDir;
                ofstream outsvg;
                        
 };
index 1992ce593a7e65c2638f7d5ac0c5f39e4f50b5f9..04f12456a49b623a82bf3e009929d7a31870da35 100644 (file)
@@ -24,7 +24,7 @@ HeatMapCommand::HeatMapCommand(string option){
                
                else {
                        //valid paramters for this command
-                       string AlignArray[] =  {"groups","label","sorted","scale"};
+                       string AlignArray[] =  {"groups","label","sorted","scale","outputdir","inputdir"};
                        vector<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
                        
                        OptionParser parser(option);
@@ -37,6 +37,12 @@ HeatMapCommand::HeatMapCommand(string option){
                                if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
+                       //if the user changes the output directory command factory will send this info to us in the output parameter 
+                       outputDir = validParameter.validFile(parameters, "outputdir", false);           if (outputDir == "not found"){  
+                               outputDir = ""; 
+                               outputDir += hasPath(globaldata->inputFileName); //if user entered a file with a path then preserve it  
+                       }
+                       
                        //make sure the user has already run the read.otu command
                        if ((globaldata->getListFile() == "") && (globaldata->getRabundFile() == "") && (globaldata->getSabundFile() == "") && (globaldata->getSharedFile() == "")) {
                                 mothurOut("You must read a list, rabund, sabund, or a list and a group, or a shared before you can use the heatmap.bin command."); mothurOutEndLine(); abort = true; 
@@ -69,7 +75,7 @@ HeatMapCommand::HeatMapCommand(string option){
                        scale = validParameter.validFile(parameters, "scale", false);                           if (scale == "not found") { scale = "log10"; }
                        
                        if (abort == false) {
-                               heatmap = new HeatMap(sorted, scale);
+                               heatmap = new HeatMap(sorted, scale, outputDir);
                                format = globaldata->getFormat();
                        }
                }
index 5c00b284061dd279db4ee52aaa891ef700d0cc61..83f6c0f21f4aefeb209056bdad3002e5449762be 100644 (file)
@@ -39,7 +39,7 @@ private:
 
        bool abort, allLines;
        set<string> labels; //holds labels to be used
-       string format, groups, sorted, scale, label;
+       string format, groups, sorted, scale, label, outputDir;
        vector<string> Groups;
 
 
index c68d0cc413855650efc86f2370ad7ab82508e6b7..b29e98b68c4af0824d4effbffa753ede522309c7 100644 (file)
@@ -20,7 +20,7 @@
 #include "sharedbraycurtis.h"
 
 //**********************************************************************************************************************
-HeatMapSim::HeatMapSim(){
+HeatMapSim::HeatMapSim(string dir) : outputDir(dir) {
                globaldata = GlobalData::getInstance();
 }
 //**********************************************************************************************************************
@@ -32,7 +32,7 @@ void HeatMapSim::getPic(vector<SharedRAbundVector*> lookup, vector<Calculator*>
                //make file for each calculator selected
                for (int m = 0; m < calcs.size(); m++) {
                        
-                       string filenamesvg = getRootName(globaldata->inputFileName) + lookup[0]->getLabel() + calcs[m]->getName() + ".heatmap.sim.svg";
+                       string filenamesvg = outputDir + getRootName(getSimpleName(globaldata->inputFileName)) + lookup[0]->getLabel() + calcs[m]->getName() + ".heatmap.sim.svg";
                        openOutputFile(filenamesvg, outsvg);
                        
                        //svg image
@@ -107,7 +107,7 @@ void HeatMapSim::getPic(vector< vector<double> > dists, vector<string> groups) {
                
                vector<double> sims;
                
-               string filenamesvg = getRootName(globaldata->inputFileName) + "heatmap.sim.svg";
+               string filenamesvg = outputDir + getRootName(getSimpleName(globaldata->inputFileName)) + "heatmap.sim.svg";
                openOutputFile(filenamesvg, outsvg);
                        
                //svg image
index d38683c17a40283a5eafc667dc663fd26e6cab0d..ffafb7d3f96ac5d72695371af4b3e850c3fc80ad 100644 (file)
@@ -20,7 +20,7 @@
 class HeatMapSim {
        
        public:
-               HeatMapSim();
+               HeatMapSim(string);
                ~HeatMapSim(){};
        
                void getPic(vector<SharedRAbundVector*>, vector<Calculator*>);
@@ -30,7 +30,7 @@ class HeatMapSim {
                void printLegend(int, float);
 
                GlobalData* globaldata;
-               string format, groupComb;
+               string format, groupComb, outputDir;
                ofstream outsvg;
                        
 };
index 3287e62fd297b440e46971e3c57093799369ff08..cef790633454b7d8136556d6441a684f0e45e3de 100644 (file)
@@ -36,31 +36,64 @@ HeatMapSimCommand::HeatMapSimCommand(string option){
                
                else {
                        //valid paramters for this command
-                       string AlignArray[] =  {"groups","label", "calc","phylip","column","name"};
+                       string AlignArray[] =  {"groups","label", "calc","phylip","column","name","outputdir","inputdir"};
                        vector<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
                        
                        OptionParser parser(option);
                        map<string,string> parameters = parser.getParameters();
                        
                        ValidParameters validParameter;
+                       map<string,string>::iterator it;
                        
                        //check to make sure all parameters are valid for command
-                       for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
+                       for (it = parameters.begin(); it != parameters.end(); it++) { 
                                if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
                        format = "";
+                       //if the user changes the output directory command factory will send this info to us in the output parameter 
+                       outputDir = validParameter.validFile(parameters, "outputdir", false);           if (outputDir == "not found"){  outputDir = "";         }
                        
+                       //if the user changes the input directory command factory will send this info to us in the output parameter 
+                       string inputDir = validParameter.validFile(parameters, "inputdir", false);              
+                       if (inputDir == "not found"){   inputDir = "";          }
+                       else {
+                               string path;
+                               it = parameters.find("phylip");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["phylip"] = inputDir + it->second;           }
+                               }
+                               
+                               it = parameters.find("column");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["column"] = inputDir + it->second;           }
+                               }
+                               
+                               it = parameters.find("name");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["name"] = inputDir + it->second;             }
+                               }
+                       }
+
                        //required parameters
                        phylipfile = validParameter.validFile(parameters, "phylip", true);
                        if (phylipfile == "not open") { abort = true; }
                        else if (phylipfile == "not found") { phylipfile = ""; }        
-                       else {  format = "phylip";      }
+                       else {  format = "phylip";      if (outputDir == "") { outputDir += hasPath(phylipfile); }  }
                        
                        columnfile = validParameter.validFile(parameters, "column", true);
                        if (columnfile == "not open") { abort = true; } 
                        else if (columnfile == "not found") { columnfile = ""; }
-                       else {  format = "column";      }
+                       else {  format = "column";      if (outputDir == "") { outputDir += hasPath(columnfile); } }
                        
                        namefile = validParameter.validFile(parameters, "name", true);
                        if (namefile == "not open") { abort = true; }   
@@ -80,6 +113,8 @@ HeatMapSimCommand::HeatMapSimCommand(string option){
                        //check for optional parameter and set defaults
                        // ...at some point should added some additional type checking...
                        if (format == "shared") {
+                               if (outputDir == "") { outputDir += hasPath(globaldata->getSharedFile()); }
+                               
                                label = validParameter.validFile(parameters, "label", false);                   
                                if (label == "not found") { label = ""; }
                                else { 
@@ -190,7 +225,7 @@ int HeatMapSimCommand::execute(){
        
                if (abort == true)  { return 0; }
                
-               heatmap = new HeatMapSim();
+               heatmap = new HeatMapSim(outputDir);
                
                if (format == "shared") {
                        runCommandShared();
index 49924eb9d3fbe1bca2bd6a8650c0eb9586d98e6f..838babdbe388b69b57d56f01fa3d1e508e18faae 100644 (file)
@@ -39,7 +39,7 @@ private:
        map<string, string>::iterator it;
        bool abort, allLines;
        set<string> labels; //holds labels to be used
-       string format, groups, label, calc, phylipfile, columnfile, namefile;
+       string format, groups, label, calc, phylipfile, columnfile, namefile, outputDir;
        vector<string> Estimators, Groups;
        
        int runCommandShared();
index e0ef2a3ebdf20de0d8a7e3ede3ad4a5f14857da1..948c31760a6ace11e2eba806c46d44e9f89f6719 100644 (file)
@@ -12,9 +12,6 @@
 //**********************************************************************************************************************
 
 HelpCommand::HelpCommand(string option){
-
-       
-       if (option != "") { mothurOut("There are no valid parameters for the help() command."); mothurOutEndLine();  }
        
        validCommands = CommandFactory::getInstance();
 }
index 74acd841b676acc429df6df4e303210d82ae92ba..cfccdf6514297fe16af59234d94cdfd758b94c43 100644 (file)
@@ -32,7 +32,7 @@ LibShuffCommand::LibShuffCommand(string option){
                
                else {
                        //valid paramters for this command
-                       string Array[] =  {"iters","groups","step","form","cutoff"};
+                       string Array[] =  {"iters","groups","step","form","cutoff","outputdir","inputdir"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
                        OptionParser parser(option);
@@ -45,6 +45,12 @@ LibShuffCommand::LibShuffCommand(string option){
                                if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
+                       //if the user changes the output directory command factory will send this info to us in the output parameter 
+                       outputDir = validParameter.validFile(parameters, "outputdir", false);           if (outputDir == "not found"){  
+                               outputDir = ""; 
+                               outputDir += hasPath(globaldata->getPhylipFile()); //if user entered a file with a path then preserve it        
+                       }
+                       
                        //make sure the user has already run the read.dist command
                        if ((globaldata->gMatrix == NULL) || (globaldata->gGroupmap == NULL)) {
                                mothurOut("You must read in a matrix and groupfile using the read.dist command, before you use the libshuff command. "); mothurOutEndLine(); abort = true;; 
@@ -186,7 +192,7 @@ void LibShuffCommand::printCoverageFile() {
        try {
 
                ofstream outCov;
-               summaryFile = getRootName(globaldata->getPhylipFile()) + "libshuff.coverage";
+               summaryFile = outputDir + getRootName(getSimpleName(globaldata->getPhylipFile())) + "libshuff.coverage";
                openOutputFile(summaryFile, outCov);
                outCov.setf(ios::fixed, ios::floatfield); outCov.setf(ios::showpoint);
                //cout.setf(ios::fixed, ios::floatfield); cout.setf(ios::showpoint);
@@ -273,7 +279,7 @@ void LibShuffCommand::printSummaryFile() {
        try {
 
                ofstream outSum;
-               summaryFile = getRootName(globaldata->getPhylipFile()) + "libshuff.summary";
+               summaryFile = outputDir + getRootName(getSimpleName(globaldata->getPhylipFile())) + "libshuff.summary";
                openOutputFile(summaryFile, outSum);
 
                outSum.setf(ios::fixed, ios::floatfield); outSum.setf(ios::showpoint);
index 1e5726dd770f928b62ca8ef07fa3c24150c0a8b5..da5f9e8c1d3d06cd7ad3812578ec83bf6bff5774 100644 (file)
@@ -43,7 +43,7 @@ private:
        vector<vector<vector<double> > > savedMinValues;
 
        bool abort;
-       string outputFile, groups, userform, savegroups;
+       string outputFile, groups, userform, savegroups, outputDir;
        vector<string> Groups; //holds groups to be used
 };
 
index 3087b48fd9669d13b5460f032f911b8f32049dce..d0b00bd3061d2a14365ee43ef96db1bc04ac1cb0 100644 (file)
@@ -9,6 +9,7 @@
 
 #include "listseqscommand.h"
 #include "sequence.hpp"
+#include "listvector.hpp"
 
 //**********************************************************************************************************************
 
@@ -21,19 +22,69 @@ ListSeqsCommand::ListSeqsCommand(string option){
                
                else {
                        //valid paramters for this command
-                       string Array[] =  {"fasta","name", "group", "alignreport" };
+                       string Array[] =  {"fasta","name", "group", "alignreport","list","outputdir","inputdir"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
                        OptionParser parser(option);
                        map<string,string> parameters = parser.getParameters();
                        
                        ValidParameters validParameter;
+                       map<string,string>::iterator it;
                        
                        //check to make sure all parameters are valid for command
                        for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
                                if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
+                       //if the user changes the output directory command factory will send this info to us in the output parameter 
+                       outputDir = validParameter.validFile(parameters, "outputdir", false);           if (outputDir == "not found"){  outputDir = "";         }
+                       
+                       //if the user changes the input directory command factory will send this info to us in the output parameter 
+                       string inputDir = validParameter.validFile(parameters, "inputdir", false);              
+                       if (inputDir == "not found"){   inputDir = "";          }
+                       else {
+                               string path;
+                               it = parameters.find("alignreport");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["alignreport"] = inputDir + it->second;              }
+                               }
+                               
+                               it = parameters.find("fasta");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["fasta"] = inputDir + it->second;            }
+                               }
+                               
+                               it = parameters.find("list");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["list"] = inputDir + it->second;             }
+                               }
+                               
+                               it = parameters.find("name");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["name"] = inputDir + it->second;             }
+                               }
+                               
+                               it = parameters.find("group");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["group"] = inputDir + it->second;            }
+                               }
+                       }
+
                        //check for required parameters
                        fastafile = validParameter.validFile(parameters, "fasta", true);
                        if (fastafile == "not open") { abort = true; }
@@ -51,9 +102,17 @@ ListSeqsCommand::ListSeqsCommand(string option){
                        if (alignfile == "not open") { abort = true; }
                        else if (alignfile == "not found") {  alignfile = "";  }
                        
-                       if ((fastafile == "") && (namefile == "") && (groupfile == "") && (alignfile == ""))  { mothurOut("You must provide a file."); mothurOutEndLine(); abort = true; }
+                       listfile = validParameter.validFile(parameters, "list", true);
+                       if (listfile == "not open") { abort = true; }
+                       else if (listfile == "not found") {  listfile = "";  }
+
+                       
+                       if ((fastafile == "") && (namefile == "") && (listfile == "") && (groupfile == "") && (alignfile == ""))  { mothurOut("You must provide a file."); mothurOutEndLine(); abort = true; }
+                       
+                       int okay = 1;
+                       if (outputDir != "") { okay++; }
                        
-                       if (parameters.size() > 1) { mothurOut("You may only enter one file."); mothurOutEndLine(); abort = true;  }
+                       if (parameters.size() > okay) { mothurOut("You may only enter one file."); mothurOutEndLine(); abort = true;  }
                }
 
        }
@@ -66,7 +125,7 @@ ListSeqsCommand::ListSeqsCommand(string option){
 
 void ListSeqsCommand::help(){
        try {
-               mothurOut("The list.seqs command reads a fasta, name, group or alignreport file and outputs a .accnos file containing sequence names.\n");
+               mothurOut("The list.seqs command reads a fasta, name, group, list or alignreport file and outputs a .accnos file containing sequence names.\n");
                mothurOut("The list.seqs command parameters are fasta, name, group and alignreport.  You must provide one of these parameters.\n");
                mothurOut("The list.seqs command should be in the following format: list.seqs(fasta=yourFasta).\n");
                mothurOut("Example list.seqs(fasta=amazon.fasta).\n");
@@ -90,11 +149,15 @@ int ListSeqsCommand::execute(){
                else if (namefile != "")        {       inputFileName = namefile;       readName();             }
                else if (groupfile != "")       {       inputFileName = groupfile;      readGroup();    }
                else if (alignfile != "")       {       inputFileName = alignfile;      readAlign();    }
+               else if (listfile != "")        {       inputFileName = listfile;       readList();             }
                
                //sort in alphabetical order
                sort(names.begin(), names.end());
                
-               string outputFileName = getRootName(inputFileName) + "accnos";
+               if (outputDir == "") {  outputDir += hasPath(inputFileName);  }
+               
+               string outputFileName = outputDir + getRootName(getSimpleName(inputFileName)) + "accnos";
+
                ofstream out;
                openOutputFile(outputFileName, out);
                
@@ -137,6 +200,37 @@ void ListSeqsCommand::readFasta(){
                exit(1);
        }
 }
+//**********************************************************************************************************************
+void ListSeqsCommand::readList(){
+       try {
+               ifstream in;
+               openInputFile(listfile, in);
+               
+               if(!in.eof()){
+                       //read in list vector
+                       ListVector list(in);
+                       
+                       //for each bin
+                       for (int i = 0; i < list.getNumBins(); i++) {
+                               string binnames = list.get(i);
+                               
+                               while (binnames.find_first_of(',') != -1) { 
+                                       string name = binnames.substr(0,binnames.find_first_of(','));
+                                       binnames = binnames.substr(binnames.find_first_of(',')+1, binnames.length());
+                                       names.push_back(name);
+                               }
+                       
+                               names.push_back(binnames);
+                       }
+               }
+               in.close();     
+               
+       }
+       catch(exception& e) {
+               errorOut(e, "ListSeqsCommand", "readList");
+               exit(1);
+       }
+}
 
 //**********************************************************************************************************************
 void ListSeqsCommand::readName(){
index 4e0febd9c6dc84a7b49589e614c076493638c913..04d9e1da99ae079bd9b10d2ba3e30d5b0ba2f01c 100644 (file)
@@ -23,13 +23,14 @@ class ListSeqsCommand : public Command {
                
        private:
                vector<string> names;
-               string fastafile, namefile, groupfile, alignfile, inputFileName;
+               string fastafile, namefile, groupfile, alignfile, inputFileName, outputDir, listfile;
                bool abort;
                
                void readFasta();
                void readName();
                void readGroup();
                void readAlign();
+               void readList();
                
 };
 
index 5069e0f07684391033c7c1e2b7595dca9b18e30f..fb74875159a0aabe98e8ea79a540802d25ca2f21 100644 (file)
@@ -36,7 +36,7 @@ MatrixOutputCommand::MatrixOutputCommand(string option){
                
                else {
                        //valid paramters for this command
-                       string Array[] =  {"label","calc","groups"};
+                       string Array[] =  {"label","calc","groups","outputdir","inputdir"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
                        OptionParser parser(option);
@@ -49,6 +49,12 @@ MatrixOutputCommand::MatrixOutputCommand(string option){
                                if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
+                       //if the user changes the output directory command factory will send this info to us in the output parameter 
+                       outputDir = validParameter.validFile(parameters, "outputdir", false);           if (outputDir == "not found"){  
+                               outputDir = ""; 
+                               outputDir += hasPath(globaldata->inputFileName); //if user entered a file with a path then preserve it  
+                       }
+                       
                        //make sure the user has already run the read.otu command
                        if (globaldata->getSharedFile() == "") {
                                if (globaldata->getListFile() == "") { mothurOut("You must read a list and a group, or a shared before you can use the dist.shared command."); mothurOutEndLine(); abort = true; }
@@ -309,7 +315,7 @@ void MatrixOutputCommand::process(vector<SharedRAbundVector*> thisLookup){
                                                }
                                        }
                                        
-                                       exportFileName = getRootName(globaldata->inputFileName) + matrixCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + ".dist";
+                                       exportFileName = outputDir + getRootName(getSimpleName(globaldata->inputFileName)) + matrixCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + ".dist";
                                        openOutputFile(exportFileName, out);
                                        printSims(out);
                                        out.close();
index 02e8fe6b4cb75351fadfc5a503b78ed6bd589a7d..6c1ce895ac0459b2b1e0358814bc0e30d8bfe51c 100644 (file)
@@ -48,7 +48,7 @@ private:
 
        bool abort, allLines;
        set<string> labels; //holds labels to be used
-       string outputFile, calc, groups, label;
+       string outputFile, calc, groups, label, outputDir;
        vector<string>  Estimators, Groups; //holds estimators to be used
        
 
index fcf63895b960fa8293df03dcff7c1e5bce28c914..d5973394e5a097e879bf1526689d137266a417c1 100644 (file)
@@ -21,7 +21,7 @@ MergeFileCommand::MergeFileCommand(string option){
                }
                else {
                        //valid paramters for this command
-                       string Array[] =  {"input", "output"};
+                       string Array[] =  {"input", "output","outputdir","inputdir"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
                        OptionParser parser(option);
@@ -34,10 +34,18 @@ MergeFileCommand::MergeFileCommand(string option){
                                if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
+                       //if the user changes the input directory command factory will send this info to us in the output parameter 
+                       string inputDir = validParameter.validFile(parameters, "inputdir", false);              
+                       if (inputDir == "not found"){   inputDir = "";          }
+                       
                        string fileList = validParameter.validFile(parameters, "input", false);                 
                        if(fileList == "not found") { mothurOut("you must enter two or more file names"); mothurOutEndLine();  abort=true;  }
                        else{   splitAtDash(fileList, fileNames);       }
                        
+                       //if the user changes the output directory command factory will send this info to us in the output parameter 
+                       string outputDir = validParameter.validFile(parameters, "outputdir", false);            if (outputDir == "not found")   {       outputDir = "";         }
+                       
+                       
                        numInputFiles = fileNames.size();
                        ifstream testFile;
                        if(numInputFiles == 0){
@@ -46,6 +54,12 @@ MergeFileCommand::MergeFileCommand(string option){
                        }
                        else{
                                for(int i=0;i<numInputFiles;i++){
+                                       if (inputDir != "") {
+                                               string path = hasPath(fileNames[i]);
+                                               //if the user has not given a path then, add inputdir. else leave path alone.
+                                               if (path == "") {       fileNames[i] = inputDir + fileNames[i];         }
+                                       }
+                                       
                                        if(openInputFile(fileNames[i], testFile)){      abort = true;   }
                                        testFile.close();
                                }
@@ -53,6 +67,7 @@ MergeFileCommand::MergeFileCommand(string option){
                        
                        outputFileName = validParameter.validFile(parameters, "output", false);                 
                        if (outputFileName == "not found") { mothurOut("you must enter an output file name"); mothurOutEndLine();  abort=true;  }
+                       else if (outputDir != "") { outputFileName = outputDir + getSimpleName(outputFileName); }
                }
                        
        }
index 81e80ccaf6ee82a0bbed8cd5a757a4502fd5449d..07c51479f35ff00db1694dcef2bc135df32976da 100644 (file)
@@ -20,24 +20,54 @@ MGClusterCommand::MGClusterCommand(string option){
                
                else {
                        //valid paramters for this command
-                       string Array[] =  {"blast", "method", "name", "cutoff", "precision", "length", "min", "penalty", "hcluster","merge"};
+                       string Array[] =  {"blast", "method", "name", "cutoff", "precision", "length", "min", "penalty", "hcluster","merge","outputdir","inputdir"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
                        OptionParser parser(option);
                        map<string, string> parameters = parser.getParameters();
                        
                        ValidParameters validParameter;
+                       map<string,string>::iterator it;
                
                        //check to make sure all parameters are valid for command
-                       for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
+                       for (it = parameters.begin(); it != parameters.end(); it++) { 
                                if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
+                       //if the user changes the input directory command factory will send this info to us in the output parameter 
+                       string inputDir = validParameter.validFile(parameters, "inputdir", false);              
+                       if (inputDir == "not found"){   inputDir = "";          }
+                       else {
+                               string path;
+                               it = parameters.find("blast");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["blast"] = inputDir + it->second;            }
+                               }
+                               
+                               it = parameters.find("name");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["name"] = inputDir + it->second;             }
+                               }
+                       }
+
+                       
                        //check for required parameters
                        blastfile = validParameter.validFile(parameters, "blast", true);
                        if (blastfile == "not open") { abort = true; }  
                        else if (blastfile == "not found") { blastfile = ""; }
                        
+                       //if the user changes the output directory command factory will send this info to us in the output parameter 
+                       outputDir = validParameter.validFile(parameters, "outputdir", false);           if (outputDir == "not found"){  
+                               outputDir = ""; 
+                               outputDir += hasPath(blastfile); //if user entered a file with a path then preserve it  
+                       }
+                       
                        namefile = validParameter.validFile(parameters, "name", true);
                        if (namefile == "not open") { abort = true; }   
                        else if (namefile == "not found") { namefile = ""; }
@@ -120,7 +150,7 @@ int MGClusterCommand::execute(){
                        nameMap->readMap();
                }else{ nameMap= new NameAssignment(); }
                
-               string fileroot = getRootName(blastfile);
+               string fileroot = outputDir + getRootName(getSimpleName(blastfile));
                string tag = "";
                time_t start;
                float previousDist = 0.00000;
@@ -210,7 +240,6 @@ int MGClusterCommand::execute(){
                        delete cluster;
                        
                }else { //use hcluster to cluster
-                       tag = "fn";
                        //get distmatrix and overlap
                        overlapFile = read->getOverlapFile();
                        distFile = read->getDistFile(); 
index 2ac80c91dd65fa7cf56f71331e4c4486c68c8b87..89b72fceb2ad6c57cf0cde5ae531bf985bf3468f 100644 (file)
@@ -38,7 +38,7 @@ private:
        ListVector oldList;
        vector<seqDist> overlapMatrix;
        
-       string blastfile, method, namefile, overlapFile, distFile;
+       string blastfile, method, namefile, overlapFile, distFile, outputDir;
        ofstream sabundFile, rabundFile, listFile;
        float cutoff, penalty;
        int precision, length, precisionLength;
index ab4fea0e09482b3c8c988ade3e244fa4c8504750..d4177e3368be8d836374e935b9e884d6ff26c5f4 100644 (file)
@@ -99,14 +99,10 @@ int main(int argc, char *argv[]){
                        mothur = new InteractEngine(argv[0]);   
                }
                
-               //used to intercept the terminate signal, so instead of terminating mothur it will end a command
-               //void (*prev_fn)(int);
-               //prev_fn = signal(SIGTERM, mothur->terminateCommand(0));
-               
-               //if (prev_fn==SIG_IGN) signal (SIGTERM,SIG_IGN);
-
-               
                while(bail == 0)                {       bail = mothur->getInput();                      }
+               
+               string outputDir = mothur->getOutputDir();
+               logFileName = outputDir + logFileName;
        
                delete mothur;
                
index 8bd8d7f155ea7aaa28dc1b0d8b5bea2e9e4b43d6..6381e51d626246244b5ce077b9b077337cfc42d8 100644 (file)
--- a/mothur.h
+++ b/mothur.h
@@ -23,6 +23,7 @@
 #include <sstream>
 #include <signal.h>
 
+
 //exception
 #include <stdexcept>
 #include <exception>
@@ -61,6 +62,7 @@
        //#include <readline/history.h>
 #else
        #include <conio.h> //allows unbuffered screen capture from stdin
+       #include <direct.h> //get cwd
 #endif
 
 using namespace std;
@@ -391,11 +393,18 @@ inline string getSimpleName(string longName){
  
        string simpleName = longName;
        
-       if(longName.find_last_of("/") != longName.npos){
-               int pos = longName.find_last_of('/')+1;
-               simpleName = longName.substr(pos, longName.length());
-       }
+       size_t found;
+       found=longName.find_last_of("/\\");
 
+       if(found != longName.npos){
+               simpleName = longName.substr(found+1);
+       }
+       
+               //if(longName.find_last_of("/") != longName.npos){
+               //      int pos = longName.find_last_of('/')+1;
+               //      simpleName = longName.substr(pos, longName.length());
+               //}
+       
        return simpleName;
 }
 
@@ -428,9 +437,24 @@ inline string getPathName(string longName){
                int pos = longName.find_last_of('/')+1;
                rootPathName = longName.substr(0, pos);
        }
-
+       
        return rootPathName;
 }
+/***********************************************************************/
+
+inline string hasPath(string longName){
+       
+       string path = "";
+       
+       size_t found;
+       found=longName.find_last_of("/\\");
+
+       if(found != longName.npos){
+               path = longName.substr(0, found+1);
+       }
+       
+       return path;
+}
 
 /***********************************************************************/
 
@@ -462,11 +486,114 @@ inline bool isBlank(string fileName){
 }
 /***********************************************************************/
 
+inline string getFullPathName(string fileName){
+       
+       string path = hasPath(fileName);
+       string newFileName = getSimpleName(fileName);
+       int pos;
+       
+       if (path == "") { return fileName; } //its a simple name
+       else { //we need to complete the pathname
+               // ex. ../../../filename 
+               // cwd = /user/work/desktop
+                               
+               string cwd;
+               //get current working directory 
+               #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)   
+                       if (path.rfind("./") == -1) { return fileName; } //already complete name
+                       
+                       char* cwdpath;
+                       size_t size;
+                       cwdpath=getcwd(cwdpath,size);
+                       cwd = cwdpath;
+               
+                       //rip off first '/'
+                       string simpleCWD;
+                       if (cwd.length() > 0) { simpleCWD = cwd.substr(1); }
+                       
+                       //break apart the current working directory
+                       vector<string> dirs;
+                       while (simpleCWD.find_first_of('/') != -1) {
+                               string dir = simpleCWD.substr(0,simpleCWD.find_first_of('/'));
+                               simpleCWD = simpleCWD.substr(simpleCWD.find_first_of('/')+1, simpleCWD.length());
+                               dirs.push_back(dir);
+                       }
+                       //get last one              // ex. ../../../filename = /user/work/desktop/filename
+                       dirs.push_back(simpleCWD);  //ex. dirs[0] = user, dirs[1] = work, dirs[2] = desktop
+                               
+                       int index = dirs.size()-1;
+                               
+                       while((pos = path.rfind("./")) != -1) { //while you don't have a complete path
+                               if (path[(pos-1)] == '.') { //you want your parent directory ../
+                                       path = path.substr(0, pos-1);
+                                       index--;
+                                       if (index == 0) {  break; }
+                               }else if (path[(pos-1)] == '/') { //you want the current working dir ./
+                                       path = path.substr(0, pos);
+                               }else if (pos == 1) { break; 
+                               }else {  mothurOut("cannot resolve path for " + fileName); mothurOutEndLine(); return fileName; }
+                       }
+               
+                       for (int i = index; i >= 0; i--) {
+                               newFileName = dirs[i] +  "/" + newFileName;             
+                       }
+                       
+                       newFileName =  "/" +  newFileName;
+                       return newFileName;
+                               
+               #else
+                       if (path.rfind(".\\") == -1) { return fileName; } //already complete name
+                                               
+                       char *cwdpath = NULL;
+                       cwdpath = getcwd(NULL, 0); // or _getcwd
+                       if ( cwdpath != NULL) { cwd = cwdpath; }
+                       else { cwd = "";  }
+                       
+                       //break apart the current working directory
+                       vector<string> dirs;
+                       while (cwd.find_first_of('\\') != -1) {
+                               string dir = cwd.substr(0,cwd.find_first_of('\\'));
+                               cwd = cwd.substr(cwd.find_first_of('\\')+1, cwd.length());
+                               dirs.push_back(dir);
+       
+                       }
+                       //get last one
+                       dirs.push_back(cwd);  //ex. dirs[0] = user, dirs[1] = work, dirs[2] = desktop
+                               
+                       int index = dirs.size()-1;
+                               
+                       while((pos = path.rfind(".\\")) != -1) { //while you don't have a complete path
+                               if (path[(pos-1)] == '.') { //you want your parent directory ../
+                                       path = path.substr(0, pos-1);
+                                       index--;
+                                       if (index == 0) {  break; }
+                               }else if (path[(pos-1)] == '\\') { //you want the current working dir ./
+                                       path = path.substr(0, pos);
+                               }else if (pos == 1) { break; 
+                               }else {  mothurOut("cannot resolve path for " + fileName); mothurOutEndLine(); return fileName; }
+                       }
+               
+                       for (int i = index; i >= 0; i--) {
+                               newFileName = dirs[i] +  "\\" + newFileName;            
+                       }
+                       
+                       return newFileName;
+                       
+               #endif
+       }
+       
+}
+/***********************************************************************/
+
 inline int openInputFile(string fileName, ifstream& fileHandle, string m){
+       
+       //get full path name
+       string completeFileName = getFullPathName(fileName);
+       //string completeFileName = fileName;
 
-       fileHandle.open(fileName.c_str());
+       fileHandle.open(completeFileName.c_str());
        if(!fileHandle) {
-               mothurOut("Error: Could not open " + fileName);  mothurOutEndLine();
+               mothurOut("Error: Could not open " + completeFileName);  mothurOutEndLine();
                return 1;
        }
        else {
@@ -479,16 +606,18 @@ inline int openInputFile(string fileName, ifstream& fileHandle, string m){
 /***********************************************************************/
 
 inline int openInputFile(string fileName, ifstream& fileHandle){
-
-       fileHandle.open(fileName.c_str());
+       //get full path name
+       string completeFileName = getFullPathName(fileName);
+       
+       fileHandle.open(completeFileName.c_str());
        if(!fileHandle) {
-               mothurOut("Error: Could not open " + fileName);  mothurOutEndLine();
+               mothurOut("Error: Could not open " + completeFileName);  mothurOutEndLine();
                return 1;
        }
        else {
                //check for blank file
                gobble(fileHandle);
-               if (fileHandle.eof()) { mothurOut(fileName + " is blank. Please correct."); mothurOutEndLine();  return 1;  }
+               if (fileHandle.eof()) { mothurOut(completeFileName + " is blank. Please correct."); mothurOutEndLine();  return 1;  }
                
                return 0;
        }
@@ -498,10 +627,12 @@ inline int openInputFile(string fileName, ifstream& fileHandle){
 /***********************************************************************/
 
 inline int openOutputFile(string fileName, ofstream& fileHandle){
+
+       string completeFileName = getFullPathName(fileName);
        
-       fileHandle.open(fileName.c_str(), ios::trunc);
+       fileHandle.open(completeFileName.c_str(), ios::trunc);
        if(!fileHandle) {
-               mothurOut("Error: Could not open " + fileName);  mothurOutEndLine();
+               mothurOut("Error: Could not open " + completeFileName);  mothurOutEndLine();
                return 1;
        }
        else {
index d0951387dc5e70dbe4e86eee3a8d8a777a4296e8..bc87211e0bde9a4581119a91592683e34262d006 100644 (file)
@@ -18,23 +18,43 @@ OtuHierarchyCommand::OtuHierarchyCommand(string option){
                
                else {
                        //valid paramters for this command
-                       string Array[] =  {"list","label"};
+                       string Array[] =  {"list","label","outputdir","inputdir"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
                        OptionParser parser(option);
                        map<string,string> parameters = parser.getParameters();
                        
                        ValidParameters validParameter;
+                       map<string,string>::iterator it;
                
                        //check to make sure all parameters are valid for command
-                       for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
+                       for (it = parameters.begin(); it != parameters.end(); it++) { 
                                if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
+                       //if the user changes the input directory command factory will send this info to us in the output parameter 
+                       string inputDir = validParameter.validFile(parameters, "inputdir", false);              
+                       if (inputDir == "not found"){   inputDir = "";          }
+                       else {
+                               string path;
+                               it = parameters.find("list");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["list"] = inputDir + it->second;             }
+                               }
+                       }
+
                        listFile = validParameter.validFile(parameters, "list", true);
                        if (listFile == "not found") { mothurOut("list is a required parameter for the otu.hierarchy command."); mothurOutEndLine(); abort = true; }
                        else if (listFile == "not open") { abort = true; }      
-
+                       
+                       //if the user changes the output directory command factory will send this info to us in the output parameter 
+                       outputDir = validParameter.validFile(parameters, "outputdir", false);           if (outputDir == "not found"){  
+                               outputDir = ""; 
+                               outputDir += hasPath(listFile); //if user entered a file with a path then preserve it   
+                       }
                        
                        //check for optional parameter and set defaults
                        // ...at some point should added some additional type checking...
@@ -111,7 +131,7 @@ int OtuHierarchyCommand::execute(){
                }
                
                ofstream out;
-               string outputFileName = getRootName(listFile) + lists[0].getLabel() + "-" + lists[1].getLabel() + ".otu.hierarchy";
+               string outputFileName = outputDir + getRootName(getSimpleName(listFile)) + lists[0].getLabel() + "-" + lists[1].getLabel() + ".otu.hierarchy";
                openOutputFile(outputFileName, out);
                
                //go through each bin in "big" otu and output the bins in "little" otu which created it
index 39795dc3055e1a1f8a057d3335b265c4d5ce4209..c6749ef3841800971f82f5a01c54d76de713b096 100644 (file)
@@ -25,7 +25,7 @@ public:
 private:
        bool abort;
        set<string> labels; //holds labels to be used
-       string label, listFile;
+       string label, listFile, outputDir;
        
        vector<ListVector> getListVectors();
                
index 6ffb30b3caf18a695604c69c5556b2b7c5c2b50a..da997c13b0c150369e15d94ccabb95f8dc3b8d26 100644 (file)
@@ -21,7 +21,7 @@ ParsimonyCommand::ParsimonyCommand(string option) {
                
                else {
                        //valid paramters for this command
-                       string Array[] =  {"random","groups","iters"};
+                       string Array[] =  {"random","groups","iters","outputdir","inputdir"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
                        OptionParser parser(option);
@@ -41,7 +41,10 @@ ParsimonyCommand::ParsimonyCommand(string option) {
                                if (globaldata->gTree.size() == 0) {
                                        mothurOut("You must read a treefile and a groupfile or set the randomtree parameter to the output filename you wish, before you may execute the parsimony command."); mothurOutEndLine(); abort = true;  }
                        }
-                                               
+                       
+                       //if the user changes the output directory command factory will send this info to us in the output parameter 
+                       string outputDir = validParameter.validFile(parameters, "outputdir", false);            if (outputDir == "not found"){  outputDir = ""; }
+                       
                        //check for optional parameter and set defaults
                        // ...at some point should added some additional type checking...
                        groups = validParameter.validFile(parameters, "groups", false);                 
@@ -60,13 +63,18 @@ ParsimonyCommand::ParsimonyCommand(string option) {
                                if (randomtree == "") { 
                                        T = globaldata->gTree;
                                        tmap = globaldata->gTreemap;
-                                       output = new ColumnFile(globaldata->getTreeFile()  +  ".parsimony", itersString);
-                                       sumFile = globaldata->getTreeFile() + ".psummary";
+                                       
+                                       if(outputDir == "") { outputDir += hasPath(globaldata->getTreeFile()); }
+                                       output = new ColumnFile(outputDir + getSimpleName(globaldata->getTreeFile())  +  ".parsimony", itersString);
+                                       
+                                       sumFile = outputDir + getSimpleName(globaldata->getTreeFile()) + ".psummary";
                                        openOutputFile(sumFile, outSum);
                                }else { //user wants random distribution
                                        savetmap = globaldata->gTreemap;
                                        getUserInput();
-                                       output = new ColumnFile(randomtree, itersString);
+                                       
+                                       if(outputDir == "") { outputDir += hasPath(randomtree); }
+                                       output = new ColumnFile(outputDir+ getSimpleName(randomtree), itersString);
                                }
                                
                                //set users groups to analyze
index 0f12d421ab291e176df2415c70b2ee27365a92ad..f855d86497fa0447cb4ef5b17e454bbe0a116628 100644 (file)
@@ -38,7 +38,7 @@ private:
        TreeMap* savetmap;
        Parsimony* pars;
        vector<string> groupComb; // AB. AC, BC...
-       string sumFile, randomtree, allGroups;
+       string sumFile, randomtree, allGroups, outputDir;
        int iters, numGroups, numComp, counter;
        vector<int> numEachGroup; //vector containing the number of sequences in each group the users wants for random distrib.
        vector< vector<float> > userTreeScores; //scores for users trees for each comb.
index 09324c9d3eaf3dd5a525a44cf233abe7df6e7285..77b16e82d58a427634f6bcd5c58fafdd2fe9a1f5 100644 (file)
@@ -21,51 +21,47 @@ PCACommand::PCACommand(string option){
                
                else {
                        //valid paramters for this command
-                       string Array[] =  {"phylip"};
+                       string Array[] =  {"phylip","outputdir", "inputdir"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
                        OptionParser parser(option);
                        map<string, string> parameters = parser. getParameters();
                        
                        ValidParameters validParameter;
+                       map<string, string>::iterator it;
                
                        //check to make sure all parameters are valid for command
-                       for (map<string, string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
+                       for (it = parameters.begin(); it != parameters.end(); it++) { 
                                if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
-                       
+                       //if the user changes the input directory command factory will send this info to us in the output parameter 
+                       string inputDir = validParameter.validFile(parameters, "inputdir", false);              
+                       if (inputDir == "not found"){   inputDir = "";          }
+                       else {
+                               string path;
+                               it = parameters.find("phylip");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["phylip"] = inputDir + it->second;           }
+                               }
+                       }
+
                        //required parameters
                        phylipfile = validParameter.validFile(parameters, "phylip", true);
                        if (phylipfile == "not open") { abort = true; }
                        else if (phylipfile == "not found") { phylipfile = ""; abort = true; }  
                        else {  filename = phylipfile;  }
                        
-                       //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 = ""; }
-                       
+                       //if the user changes the output directory command factory will send this info to us in the output parameter 
+                       outputDir = validParameter.validFile(parameters, "outputdir", false);           if (outputDir == "not found"){  
+                               outputDir = ""; 
+                               outputDir += hasPath(phylipfile); //if user entered a file with a path then preserve it 
+                       }
                        
                        //error checking on files       
                        if (phylipfile == "")   { mothurOut("You must provide a distance file before running the pca command."); mothurOutEndLine(); abort = true; }            
-                       //if ((phylipfile == "") && (columnfile == "")) { mothurOut("You must provide a distance file before running the pca command."); mothurOutEndLine(); abort = true; }
-                       //else if ((phylipfile != "") && (columnfile != "")) { mothurOut("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; }
-                       //}
-                       
-                       //string temp = validParameter.validFile(parameters, "lt", false);                              if (temp == "not found") { temp = "false"; }
-                       //bool lt = isTrue(temp);
-                       
-                       //if (lt)               {  matrix = 2;  }
-                       //else          {  matrix = 1;  }
-
-
                }
 
        }
@@ -101,13 +97,16 @@ int PCACommand::execute(){
                vector<string> names;
                vector<vector<double> > D;
        
-               fbase = filename;
-               if(fbase.find_last_of(".")!=string::npos){
-                       fbase.erase(fbase.find_last_of(".")+1); 
-               }
-               else{
-                       fbase += ".";
-               }
+               //fbase = filename;
+               //if(fbase.find_last_of(".")!=string::npos){
+               //      fbase.erase(fbase.find_last_of(".")+1); 
+               //}
+               //else{
+               //      fbase += ".";
+               //}
+               
+               fbase = outputDir + getRootName(getSimpleName(filename));
+               
                read(filename, names, D);
        
                double offset = 0.0000;
index 143e83dda8efbfb2bbd3548e0c02f47920433f26..a447ffced3040086a2c91a7f6014a79cf50b58b8 100644 (file)
@@ -25,7 +25,7 @@ public:
 private:
 
        bool abort;
-       string phylipfile, columnfile, namefile, format, filename, fbase;
+       string phylipfile, columnfile, namefile, format, filename, fbase, outputDir;
        float cutoff, precision;
        
        void get_comment(istream&, char, char);
index 8ba0a091ee7b77ff8f1abe37ae30117b64cec597..2dbd53a5dad36477279961d76d547fff3d8e83d3 100644 (file)
@@ -24,19 +24,34 @@ PhylotypeCommand::PhylotypeCommand(string option){
                else {
                        
                        //valid paramters for this command
-                       string AlignArray[] =  {"taxonomy","cutoff","label"};
+                       string AlignArray[] =  {"taxonomy","cutoff","label","outputdir","inputdir"};
                        vector<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
                        
                        OptionParser parser(option);
                        map<string, string> parameters = parser.getParameters(); 
                        
                        ValidParameters validParameter;
+                       map<string, string>::iterator it;
                        
                        //check to make sure all parameters are valid for command
-                       for (map<string, string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
+                       for (it = parameters.begin(); it != parameters.end(); it++) { 
                                if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
+                       //if the user changes the input directory command factory will send this info to us in the output parameter 
+                       string inputDir = validParameter.validFile(parameters, "inputdir", false);              
+                       if (inputDir == "not found"){   inputDir = "";          }
+                       else {
+                               string path;
+                               it = parameters.find("taxonomy");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["taxonomy"] = inputDir + it->second;         }
+                               }
+                       }
+
                        taxonomyFileName = validParameter.validFile(parameters, "taxonomy", true);
                        if (taxonomyFileName == "not found") { 
                                mothurOut("taxonomy is a required parameter for the phylotype command."); 
@@ -44,6 +59,12 @@ PhylotypeCommand::PhylotypeCommand(string option){
                                abort = true; 
                        }else if (taxonomyFileName == "not open") { abort = true; }     
                        
+                       //if the user changes the output directory command factory will send this info to us in the output parameter 
+                       outputDir = validParameter.validFile(parameters, "outputdir", false);           if (outputDir == "not found"){  
+                               outputDir = ""; 
+                               outputDir += hasPath(taxonomyFileName); //if user entered a file with a path then preserve it   
+                       }
+                       
                        string temp = validParameter.validFile(parameters, "cutoff", false);
                        if (temp == "not found") { temp = "-1"; }
                        convert(temp, cutoff); 
@@ -112,14 +133,16 @@ int PhylotypeCommand::execute(){
                bool done = false;
                if (tree->get(leaves[0]).parent == -1) {  mothurOut("Empty Tree"); mothurOutEndLine();  done = true;    }
                
+               string fileroot = outputDir + getRootName(getSimpleName(taxonomyFileName));
+               
                ofstream outList;
-               string outputListFile = getRootName(taxonomyFileName) + "tx.list";
+               string outputListFile = fileroot + "tx.list";
                openOutputFile(outputListFile, outList);
                ofstream outSabund;
-               string outputSabundFile = getRootName(taxonomyFileName) + "tx.sabund";
+               string outputSabundFile = fileroot + "tx.sabund";
                openOutputFile(outputSabundFile, outSabund);
                ofstream outRabund;
-               string outputRabundFile = getRootName(taxonomyFileName) + "tx.rabund";
+               string outputRabundFile = fileroot + "tx.rabund";
                openOutputFile(outputRabundFile, outRabund);
                
                int count = 1;          
index 0322daf423ab716022e2146b6d4f352911fed693..b61c03939492fe4147225fadb159e00b9a0ef71e 100644 (file)
@@ -26,7 +26,7 @@ public:
        
 private:
        bool abort, allLines;
-       string taxonomyFileName, label;
+       string taxonomyFileName, label, outputDir;
        set<string> labels; //holds labels to be used
        int cutoff;
        
index 2698fe48b278fff835ec9c1a5c40dfe8dc76a9f3..6adfdf91ebeaf30847bee05d90f2c9b22d3c5946 100644 (file)
@@ -18,7 +18,7 @@ inline bool compareQuanMembers(quanMember left, quanMember right){
 } 
 //***************************************************************************************************************
 
-Pintail::Pintail(string filename, string temp) {  fastafile = filename;  templateFile = temp;  }
+Pintail::Pintail(string filename, string temp, string o) {  fastafile = filename;  templateFile = temp; outputDir = o; }
 //***************************************************************************************************************
 
 Pintail::~Pintail() {
@@ -161,7 +161,7 @@ int Pintail::getChimeras() {
                mothurOut("Getting conservation... "); cout.flush();
                if (consfile == "") { 
                        mothurOut("Calculating probability of conservation for your template sequences.  This can take a while...  I will output the frequency of the highest base in each position to a .freq file so that you can input them using the conservation parameter next time you run this command.  Providing the .freq file will improve speed.    "); cout.flush();
-                       probabilityProfile = decalc->calcFreq(templateSeqs, templateFile); 
+                       probabilityProfile = decalc->calcFreq(templateSeqs, outputDir + getSimpleName(templateFile)); 
                        mothurOut("Done."); mothurOutEndLine();
                }else                           {   probabilityProfile = readFreq();                      }
 
@@ -281,13 +281,13 @@ int Pintail::getChimeras() {
                        string noOutliers, outliers;
                        
                        if ((!filter) && (seqMask == "")) {
-                               noOutliers = getRootName(templateFile) + "pintail.quan";
+                               noOutliers = outputDir + getRootName(getSimpleName(templateFile)) + "pintail.quan";
                        }else if ((filter) && (seqMask == "")) { 
-                               noOutliers = getRootName(templateFile) + "pintail.filtered.quan";
+                               noOutliers = outputDir + getRootName(getSimpleName(templateFile)) + "pintail.filtered.quan";
                        }else if ((!filter) && (seqMask != "")) { 
-                               noOutliers = getRootName(templateFile) + "pintail.masked.quan";
+                               noOutliers = outputDir + getRootName(getSimpleName(templateFile)) + "pintail.masked.quan";
                        }else if ((filter) && (seqMask != "")) { 
-                               noOutliers = getRootName(templateFile) + "pintail.filtered.masked.quan";
+                               noOutliers = outputDir + getRootName(getSimpleName(templateFile)) + "pintail.filtered.masked.quan";
                        }
 
                        //outliers = getRootName(templateFile) + "pintail.quanYESOUTLIERS";
index 516c682da3d9123cc07f9e6e143dd7fdc7d519c4..26154b2403176e14691fd86248a9edc4ac03a085 100644 (file)
--- a/pintail.h
+++ b/pintail.h
@@ -24,7 +24,7 @@
 class Pintail : public Chimera {
        
        public:
-               Pintail(string, string);        
+               Pintail(string, string, string);        
                ~Pintail();
                
                int getChimeras();
index 89e6cbfb9e2560e4860cae8dd6a0ee4632a687da..d638bd2240a46ab20a7b5253e15be5a056a41aa4 100644 (file)
@@ -22,28 +22,56 @@ PreClusterCommand::PreClusterCommand(string option){
                
                else {
                        //valid paramters for this command
-                       string Array[] =  {"fasta", "name", "diffs"};
+                       string Array[] =  {"fasta", "name", "diffs", "outputdir","inputdir"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
                        OptionParser parser(option);
                        map<string, string> parameters = parser.getParameters();
                        
                        ValidParameters validParameter;
+                       map<string, string>::iterator it;
                
                        //check to make sure all parameters are valid for command
                        for (map<string, string>::iterator it2 = parameters.begin(); it2 != parameters.end(); it2++) { 
                                if (validParameter.isValidParameter(it2->first, myArray, it2->second) != true) {  abort = true;  }
                        }
                        
+                       //if the user changes the input directory command factory will send this info to us in the output parameter 
+                       string inputDir = validParameter.validFile(parameters, "inputdir", false);              
+                       if (inputDir == "not found"){   inputDir = "";          }
+                       else {
+                               string path;
+                               it = parameters.find("fasta");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["fasta"] = inputDir + it->second;            }
+                               }
+                               
+                               it = parameters.find("name");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["name"] = inputDir + it->second;             }
+                               }
+                       }
+
                        //check for required parameters
                        fastafile = validParameter.validFile(parameters, "fasta", true);
                        if (fastafile == "not found") { mothurOut("fasta is a required parameter for the pre.cluster command."); mothurOutEndLine(); abort = true; }
                        else if (fastafile == "not open") { abort = true; }     
                        
+                       //if the user changes the output directory command factory will send this info to us in the output parameter 
+                       outputDir = validParameter.validFile(parameters, "outputdir", false);           if (outputDir == "not found"){  
+                               outputDir = ""; 
+                               outputDir += hasPath(fastafile); //if user entered a file with a path then preserve it  
+                       }
+
                        //check for optional parameter and set defaults
                        // ...at some point should added some additional type checking...
                        namefile = validParameter.validFile(parameters, "name", true);
-
                        if (namefile == "not found") { namefile =  "";  }
                        else if (namefile == "not open") { abort = true; }      
 //                     else {  readNameFile();  }
@@ -132,9 +160,11 @@ int PreClusterCommand::execute(){
                        }//end if active i
                        if(i % 100 == 0)        { cout << i << '\t' << numSeqs - count << '\t' << count << endl;        }
                }
-       
-               string newFastaFile = getRootName(fastafile) + "precluster" + getExtension(fastafile);
-               string newNamesFile = getRootName(fastafile) + "precluster.names";
+               
+               string fileroot = outputDir + getRootName(getSimpleName(fastafile));
+               
+               string newFastaFile = fileroot + "precluster" + getExtension(fastafile);
+               string newNamesFile = fileroot + "precluster.names";
                
                
                mothurOut("Total number of sequences before precluster was " + toString(alignSeqs.size()) + "."); mothurOutEndLine();
index 5113fa44e0e5b848a22d52c6c8c03f29a646ffd0..3a1157d1979935e990f45e1f3202d4fe74525574 100644 (file)
@@ -38,7 +38,7 @@ public:
 private:
        int diffs, length;
        bool abort;
-       string fastafile, namefile;
+       string fastafile, namefile, outputDir;
        vector<seqPNode> alignSeqs; //maps the number of identical seqs to a sequence
 //     map<string, string> names; //represents the names file first column maps to second column
 //     map<string, int> sizes;  //this map a seq name to the number of identical seqs in the names file
index 99dc46be30ca9c282d82474e5021bdf4fc7f3c33..05e2758a2778505858283a450dbfb0b270cf77ca 100644 (file)
@@ -16,8 +16,6 @@ QuitCommand::QuitCommand(string option){
                
                //allow user to run help
                if(option == "help") { help(); abort = true; }
-               
-               else if (option != "") { mothurOut("There are no valid parameters for the quit command."); mothurOutEndLine();  abort = true;  }
 
 }
 //**********************************************************************************************************************
index f2de77bbeed121a53d670e99ff203b5336cd1d9c..97d633278f4d43dc8b30a5e95298d2897bdabca7 100644 (file)
@@ -35,7 +35,7 @@ RareFactCommand::RareFactCommand(string option){
                
                else {
                        //valid paramters for this command
-                       string Array[] =  {"iters","freq","label","calc","abund"};
+                       string Array[] =  {"iters","freq","label","calc","abund","outputdir","inputdir"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
                        OptionParser parser(option);
@@ -48,6 +48,12 @@ RareFactCommand::RareFactCommand(string option){
                                if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
+                       //if the user changes the output directory command factory will send this info to us in the output parameter 
+                       outputDir = validParameter.validFile(parameters, "outputdir", false);           if (outputDir == "not found"){  
+                               outputDir = ""; 
+                               outputDir += hasPath(globaldata->inputFileName); //if user entered a file with a path then preserve it  
+                       }
+
                        //make sure the user has already run the read.otu command
                        if ((globaldata->getSharedFile() == "") && (globaldata->getListFile() == "") && (globaldata->getRabundFile() == "") && (globaldata->getSabundFile() == "")) { mothurOut("You must read a list, sabund, rabund or shared file before you can use the rarefact.single command."); mothurOutEndLine(); abort = true; }
                        
@@ -127,7 +133,7 @@ int RareFactCommand::execute(){
                
                for (int p = 0; p < inputFileNames.size(); p++) {
                        
-                       string fileNameRoot = getRootName(inputFileNames[p]);
+                       string fileNameRoot = outputDir + getRootName(getSimpleName(inputFileNames[p]));
                        globaldata->inputFileName = inputFileNames[p];
                        
                        if (inputFileNames.size() > 1) {
index 3213af4d6b8ea66fd9c50bbfa7ce0d7efcf85327..dce1a0d4862190c01bb2082f8506d3a505bad899 100644 (file)
@@ -44,6 +44,7 @@ private:
        vector<string>  Estimators;
        vector<string> inputFileNames;
        vector<string> groups;
+       string outputDir;
        
        vector<string> parseSharedFile(string);
 
index 83fb35ed883fbb748d8cb5a6191aa136c692ae06..1d13a569c2026fd800283ad3b8bfc3dd5cd48a93 100644 (file)
@@ -28,7 +28,7 @@ RareFactSharedCommand::RareFactSharedCommand(string option){
                
                else {
                        //valid paramters for this command
-                       string Array[] =  {"iters","label","calc","groups", "jumble"};
+                       string Array[] =  {"iters","label","calc","groups", "jumble","outputdir","inputdir"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
                        OptionParser parser(option);
@@ -46,6 +46,12 @@ RareFactSharedCommand::RareFactSharedCommand(string option){
                                if (globaldata->getListFile() == "") { mothurOut("You must read a list and a group, or a shared before you can use the collect.shared command."); mothurOutEndLine(); abort = true; }
                                else if (globaldata->getGroupFile() == "") { mothurOut("You must read a list and a group, or a shared before you can use the collect.shared command."); mothurOutEndLine(); abort = true; }
                        }
+                       
+                       //if the user changes the output directory command factory will send this info to us in the output parameter 
+                       outputDir = validParameter.validFile(parameters, "outputdir", false);           if (outputDir == "not found"){  
+                               outputDir = ""; 
+                               outputDir += hasPath(globaldata->inputFileName); //if user entered a file with a path then preserve it  
+                       }
 
                        
                        //check for optional parameter and set defaults
@@ -88,7 +94,7 @@ RareFactSharedCommand::RareFactSharedCommand(string option){
                        
                        if (abort == false) {
                        
-                               string fileNameRoot = getRootName(globaldata->inputFileName);
+                               string fileNameRoot = outputDir + getRootName(getSimpleName(globaldata->inputFileName));
 //                             format = globaldata->getFormat();
 
                                
index a141988e51c90989515a5ec868319a94015a6e2d..aa321e84e7d7115c7a000403da3bcd39959dbab2 100644 (file)
@@ -39,7 +39,7 @@ private:
 
        bool abort, allLines, jumble;
        set<string> labels; //holds labels to be used
-       string label, calc, groups;
+       string label, calc, groups, outputDir;
        vector<string>  Estimators, Groups;
 
 
index 9d38e76b10935e2ea7fe9f485e53eab662fc982e..9cb2046139ba7d275aa31cb1e9024bf9a729cbf2 100644 (file)
@@ -22,21 +22,63 @@ ReadDistCommand::ReadDistCommand(string option){
                
                else {
                        //valid paramters for this command
-                       string Array[] =  {"phylip", "column", "name", "cutoff", "precision", "group"};
+                       string Array[] =  {"phylip", "column", "name", "cutoff", "precision", "group","outputdir","inputdir"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
                        OptionParser parser(option);
                        map<string, string> parameters = parser.getParameters();
                        
                        ValidParameters validParameter;
+                       map<string,string>::iterator it;
                
                        //check to make sure all parameters are valid for command
-                       for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
+                       for (it = parameters.begin(); it != parameters.end(); it++) { 
                                if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
                        globaldata->newRead();
                        
+                       //if the user changes the input directory command factory will send this info to us in the output parameter 
+                       string inputDir = validParameter.validFile(parameters, "inputdir", false);              
+                       if (inputDir == "not found"){   inputDir = "";          }
+                       else {
+                               string path;
+                               it = parameters.find("phylip");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["phylip"] = inputDir + it->second;           }
+                               }
+                               
+                               it = parameters.find("column");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["column"] = inputDir + it->second;           }
+                               }
+                               
+                               it = parameters.find("name");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["name"] = inputDir + it->second;             }
+                               }
+                               
+                               it = parameters.find("group");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["group"] = inputDir + it->second;            }
+                               }
+                       }
+
+                       //if the user changes the output directory command factory will send this info to us in the output parameter 
+                       outputDir = validParameter.validFile(parameters, "outputdir", false);           if (outputDir == "not found"){  outputDir = ""; }
+
                        //check for required parameters
                        phylipfile = validParameter.validFile(parameters, "phylip", true);
                        if (phylipfile == "not open") { abort = true; }
@@ -92,10 +134,12 @@ ReadDistCommand::ReadDistCommand(string option){
                                else if (format == "phylip") { read = new ReadPhylipMatrix(distFileName); }
                                else if (format == "matrix") { 
                                        groupMap = new GroupMap(groupfile);
-                                       groupMap->readMap();
-       
-                                       if (globaldata->gGroupmap != NULL) { delete globaldata->gGroupmap;  }
-                                       globaldata->gGroupmap = groupMap;
+                                       int error = groupMap->readMap();
+                                       if (error == 1) { delete groupMap; abort = true; }
+                                       else {
+                                               if (globaldata->gGroupmap != NULL) { delete globaldata->gGroupmap;  }
+                                               globaldata->gGroupmap = groupMap;
+                                       }
                                }
                
                                if (format != "matrix" ) {
@@ -169,7 +213,9 @@ int ReadDistCommand::execute(){
                        if (matrix->getNumSeqs() < groupMap->getNumSeqs()) {  
                                mothurOut("Your distance file contains " + toString(matrix->getNumSeqs()) + " sequences, and your group file contains " + toString(groupMap->getNumSeqs()) + " sequences.");  mothurOutEndLine();                               
                                //create new group file
-                               string newGroupFile = getRootName(groupfile) + "editted.groups";
+                               if(outputDir == "") { outputDir += hasPath(groupfile); }
+                               
+                               string newGroupFile = outputDir + getRootName(getSimpleName(groupfile)) + "editted.groups";
                                ofstream outGroups;
                                openOutputFile(newGroupFile, outGroups);
                                
index 868d72e6bd5184b11253dc5c9aacded459f0ee3d..1f852be88e84223a3f07b9847f71e57ee8160442 100644 (file)
@@ -39,7 +39,7 @@ private:
        FullMatrix* matrix;
        GroupMap* groupMap;
        string distFileName, format, method;
-       string phylipfile, columnfile, namefile, groupfile;
+       string phylipfile, columnfile, namefile, groupfile, outputDir;
        NameAssignment* nameMap;
 
        bool abort;
index b58dc607ec20891dd760360d74402ffa90bc9ea0..e55e9805af42cf37728fad27cc4f8b60f36fc882 100644 (file)
@@ -21,21 +21,81 @@ ReadOtuCommand::ReadOtuCommand(string option){
                
                else {
                        //valid paramters for this command
-                       string Array[] =  {"list","order","shared", "label","group","sabund", "rabund","groups"};
+                       string Array[] =  {"list","order","shared", "label","group","sabund", "rabund","groups","outputdir","inputdir"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
                        OptionParser parser(option);
                        map<string, string> parameters = parser.getParameters();
                        
                        ValidParameters validParameter;
+                       map<string, string>::iterator it;
                
                        //check to make sure all parameters are valid for command
-                       for (map<string, string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
+                       for (it = parameters.begin(); it != parameters.end(); it++) { 
                                if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
                        globaldata->newRead();
                        
+                       //if the user changes the input directory command factory will send this info to us in the output parameter 
+                       string inputDir = validParameter.validFile(parameters, "inputdir", false);              
+                       if (inputDir == "not found"){   inputDir = "";          }
+                       else {
+                               string path;
+                               it = parameters.find("list");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["list"] = inputDir + it->second;             }
+                               }
+                               
+                               it = parameters.find("order");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["order"] = inputDir + it->second;            }
+                               }
+                               
+                               it = parameters.find("shared");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["shared"] = inputDir + it->second;           }
+                               }
+                               
+                               it = parameters.find("group");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["group"] = inputDir + it->second;            }
+                               }
+                               
+                               it = parameters.find("sabund");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["sabund"] = inputDir + it->second;           }
+                               }
+                               
+                               it = parameters.find("rabund");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["rabund"] = inputDir + it->second;           }
+                               }
+
+                       }
+
+                       
+                       //if the user changes the output directory command factory will send this info to us in the output parameter 
+                       outputDir = validParameter.validFile(parameters, "outputdir", false);           if (outputDir == "not found"){  outputDir = ""; }
+
                        //check for required parameters
                        listfile = validParameter.validFile(parameters, "list", true);
                        if (listfile == "not open") { abort = true; }
@@ -63,7 +123,10 @@ ReadOtuCommand::ReadOtuCommand(string option){
                        else {  
                                globaldata->setGroupFile(groupfile); 
                                groupMap = new GroupMap(groupfile);
-                               groupMap->readMap();
+                               
+                               int error = groupMap->readMap();
+                               if (error == 1) { abort = true; }
+                               
                                globaldata->gGroupmap = groupMap;
                        }
                        
@@ -154,9 +217,8 @@ int ReadOtuCommand::execute(){
                
                if (globaldata->getFormat() == "shared") {
                        
-                       shared = new SharedCommand();
+                       shared = new SharedCommand(outputDir);
                        int okay = shared->execute();
-                       delete shared;
                        
                        //problem with shared
                        if (okay == 1) {
@@ -169,8 +231,8 @@ int ReadOtuCommand::execute(){
                                globaldata->setFormat("sharedfile");
                                globaldata->setListFile("");
                                globaldata->setGroupFile("");
-                               globaldata->setSharedFile(getRootName(filename) + "shared");
                        }
+                       delete shared;
                }
                return 0;
        }
index 543642b66b4bd4b889fd54c8d19776fc71b17b8d..beb2f4bcbfe31ed89bdb2f9c393585a4ffae3667 100644 (file)
@@ -29,7 +29,7 @@ private:
        InputData* input;
        Command* shared;
        GroupMap* groupMap;
-       string filename, listfile, orderfile, sharedfile, label, groupfile, sabundfile, rabundfile, format, groups;
+       string filename, listfile, orderfile, sharedfile, label, groupfile, sabundfile, rabundfile, format, groups, outputDir;
        vector<string> Groups;
 
        bool abort, allLines;
index 0f07ac2f6d66bb1e68c322f74ddfc326b9d3f47e..5b371f51acc0eeec74e2b52c5c9a63319a74b892 100644 (file)
@@ -20,21 +20,45 @@ ReadTreeCommand::ReadTreeCommand(string option){
                
                else {
                        //valid paramters for this command
-                       string Array[] =  {"tree","group"};
+                       string Array[] =  {"tree","group","outputdir","inputdir"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
                        OptionParser parser(option);
                        map<string, string> parameters = parser.getParameters();
                        
                        ValidParameters validParameter;
+                       map<string, string>::iterator it;
                
                        //check to make sure all parameters are valid for command
-                       for (map<string, string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
+                       for (it = parameters.begin(); it != parameters.end(); it++) { 
                                if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
                        globaldata->newRead();
                        
+                       //if the user changes the input directory command factory will send this info to us in the output parameter 
+                       string inputDir = validParameter.validFile(parameters, "inputdir", false);              
+                       if (inputDir == "not found"){   inputDir = "";          }
+                       else {
+                               string path;
+                               it = parameters.find("tree");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["tree"] = inputDir + it->second;             }
+                               }
+                               
+                               it = parameters.find("group");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["group"] = inputDir + it->second;            }
+                               }
+                       }
+
+                       
                        //check for required parameters
                        treefile = validParameter.validFile(parameters, "tree", true);
                        if (treefile == "not open") { abort = true; }
index 790cf79f43505ac56e52681ff86a572ab3453e79..a8f03e06b29c505d219a8a4f5770999586e182ae 100644 (file)
@@ -22,19 +22,78 @@ RemoveSeqsCommand::RemoveSeqsCommand(string option){
                
                else {
                        //valid paramters for this command
-                       string Array[] =  {"fasta","name", "group", "alignreport", "accnos", "list" };
+                       string Array[] =  {"fasta","name", "group", "alignreport", "accnos", "list","outputdir","inputdir" };
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
                        OptionParser parser(option);
                        map<string,string> parameters = parser.getParameters();
                        
                        ValidParameters validParameter;
+                       map<string,string>::iterator it;
                        
                        //check to make sure all parameters are valid for command
-                       for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
+                       for (it = parameters.begin(); it != parameters.end(); it++) { 
                                if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
+                       //if the user changes the output directory command factory will send this info to us in the output parameter 
+                       outputDir = validParameter.validFile(parameters, "outputdir", false);           if (outputDir == "not found"){  outputDir = "";         }
+                       
+                       //if the user changes the input directory command factory will send this info to us in the output parameter 
+                       string inputDir = validParameter.validFile(parameters, "inputdir", false);              
+                       if (inputDir == "not found"){   inputDir = "";          }
+                       else {
+                               string path;
+                               it = parameters.find("alignreport");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["alignreport"] = inputDir + it->second;              }
+                               }
+                               
+                               it = parameters.find("fasta");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["fasta"] = inputDir + it->second;            }
+                               }
+                               
+                               it = parameters.find("accnos");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["accnos"] = inputDir + it->second;           }
+                               }
+                               
+                               it = parameters.find("list");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["list"] = inputDir + it->second;             }
+                               }
+                               
+                               it = parameters.find("name");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["name"] = inputDir + it->second;             }
+                               }
+                               
+                               it = parameters.find("group");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["group"] = inputDir + it->second;            }
+                               }
+                       }
+
+                       
                        //check for required parameters
                        accnosfile = validParameter.validFile(parameters, "accnos", true);
                        if (accnosfile == "not open") { abort = true; }
@@ -62,7 +121,10 @@ RemoveSeqsCommand::RemoveSeqsCommand(string option){
                        
                        if ((fastafile == "") && (namefile == "") && (groupfile == "") && (alignfile == "") && (listfile == ""))  { mothurOut("You must provide one of the following: fasta, name, group, alignreport or list."); mothurOutEndLine(); abort = true; }
                        
-                       if (parameters.size() > 2) { mothurOut("You may only enter one of the following: fasta, name, group, alignreport, or list."); mothurOutEndLine(); abort = true;  }
+                       int okay = 2;
+                       if (outputDir != "") { okay++; }
+                       
+                       if (parameters.size() > okay) { mothurOut("You may only enter one of the following: fasta, name, group, alignreport, or list."); mothurOutEndLine(); abort = true;  }
                }
 
        }
@@ -117,6 +179,7 @@ int RemoveSeqsCommand::execute(){
 //**********************************************************************************************************************
 void RemoveSeqsCommand::readFasta(){
        try {
+               if (outputDir == "") {  outputDir += hasPath(fastafile);  }
                string outputFileName = getRootName(fastafile) + "pick" + getExtension(fastafile);
                ofstream out;
                openOutputFile(outputFileName, out);
@@ -158,6 +221,7 @@ void RemoveSeqsCommand::readFasta(){
 //**********************************************************************************************************************
 void RemoveSeqsCommand::readList(){
        try {
+               if (outputDir == "") {  outputDir += hasPath(listfile);  }
                string outputFileName = getRootName(listfile) + "pick" +  getExtension(listfile);
                ofstream out;
                openOutputFile(outputFileName, out);
@@ -222,7 +286,7 @@ void RemoveSeqsCommand::readList(){
 //**********************************************************************************************************************
 void RemoveSeqsCommand::readName(){
        try {
-       
+               if (outputDir == "") {  outputDir += hasPath(namefile);  }
                string outputFileName = getRootName(namefile) + "pick" + getExtension(namefile);
 
                ofstream out;
@@ -305,7 +369,7 @@ void RemoveSeqsCommand::readName(){
 //**********************************************************************************************************************
 void RemoveSeqsCommand::readGroup(){
        try {
-       
+               if (outputDir == "") {  outputDir += hasPath(groupfile);  }
                string outputFileName = getRootName(groupfile) + "pick" + getExtension(groupfile);
                ofstream out;
                openOutputFile(outputFileName, out);
@@ -348,6 +412,7 @@ void RemoveSeqsCommand::readGroup(){
 //alignreport file has a column header line then all other lines contain 16 columns.  we just want the first column since that contains the name
 void RemoveSeqsCommand::readAlign(){
        try {
+               if (outputDir == "") {  outputDir += hasPath(alignfile);  }
                string outputFileName = getRootName(getRootName(alignfile)) + "pick.align.report";
                ofstream out;
                openOutputFile(outputFileName, out);
index 1ad1eee835e4ba0bf48e1be44b7c89631367f22e..1dcb0fceab5ed3800d2b604d2ba32ff632cfec8c 100644 (file)
@@ -23,7 +23,7 @@ class RemoveSeqsCommand : public Command {
                
        private:
                set<string> names;
-               string accnosfile, fastafile, namefile, groupfile, alignfile, listfile;
+               string accnosfile, fastafile, namefile, groupfile, alignfile, listfile, outputDir;
                bool abort;
                
                void readFasta();
index 37e95685430184760cd0919c18a1cfeea2ec4c42..274240158068655fcbbc501d81e335238966edfa 100644 (file)
@@ -22,24 +22,45 @@ ReverseSeqsCommand::ReverseSeqsCommand(string option){
                
                else {
                        //valid paramters for this command
-                       string Array[] =  {"fasta"};
+                       string Array[] =  {"fasta", "outputdir","inputdir"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
                        OptionParser parser(option);
                        map<string,string> parameters = parser.getParameters();
                        
                        ValidParameters validParameter;
-               
+                       map<string,string>::iterator it;
+                       
                        //check to make sure all parameters are valid for command
-                       for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
+                       for (it = parameters.begin(); it != parameters.end(); it++) { 
                                if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
+                       //if the user changes the input directory command factory will send this info to us in the output parameter 
+                       string inputDir = validParameter.validFile(parameters, "inputdir", false);              
+                       if (inputDir == "not found"){   inputDir = "";          }
+                       else {
+                               string path;
+                               it = parameters.find("fasta");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["fasta"] = inputDir + it->second;            }
+                               }
+                       }
+
                        //check for required parameters
                        fasta = validParameter.validFile(parameters, "fasta", true);
                        if (fasta == "not open") { abort = true; }
                        else if (fasta == "not found") { fasta = ""; mothurOut("fasta is a required parameter for the reverse.seqs command."); mothurOutEndLine(); abort = true;  }     
                        
+                       //if the user changes the output directory command factory will send this info to us in the output parameter 
+                       outputDir = validParameter.validFile(parameters, "outputdir", false);           if (outputDir == "not found"){  
+                               outputDir = ""; 
+                               outputDir += hasPath(fasta); //if user entered a file with a path then preserve it      
+                       }
+
                }
        }
        catch(exception& e) {
@@ -78,7 +99,7 @@ int ReverseSeqsCommand::execute(){
                openInputFile(fasta, inFASTA);
                
                ofstream outFASTA;
-               string reverseFile = getRootName(fasta) + "rc" + getExtension(fasta);
+               string reverseFile = outputDir + getRootName(getSimpleName(fasta)) + "rc" + getExtension(fasta);
                openOutputFile(reverseFile, outFASTA);
                
                while(!inFASTA.eof()){
index b47ee3a51d614c84f746a1f231894809059bcad3..aad454313b6668699ea8626cfdf883b8b2d4902e 100644 (file)
@@ -23,7 +23,7 @@ public:
 private:
 
        bool abort;
-       string fasta;
+       string fasta, outputDir;
        
 };
 
index 32426f3092d17468aa2f2599528f915423954376..48bf17119c98d832b0176dcab78675a94ecf80e8 100644 (file)
@@ -22,19 +22,58 @@ ScreenSeqsCommand::ScreenSeqsCommand(string option){
                else {
                        //valid paramters for this command
                        string AlignArray[] =  {"fasta", "start", "end", "maxambig", "maxhomop", "minlength", "maxlength",
-                                                                       "name", "group", "alignreport"};
+                                                                       "name", "group", "alignreport","outputdir","inputdir"};
                        vector<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
                        
                        OptionParser parser(option);
                        map<string,string> parameters = parser.getParameters();
                        
                        ValidParameters validParameter;
+                       map<string,string>::iterator it;
                        
                        //check to make sure all parameters are valid for command
-                       for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
+                       for (it = parameters.begin(); it != parameters.end(); it++) { 
                                if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
+                       //if the user changes the input directory command factory will send this info to us in the output parameter 
+                       string inputDir = validParameter.validFile(parameters, "inputdir", false);              
+                       if (inputDir == "not found"){   inputDir = "";          }
+                       else {
+                               string path;
+                               it = parameters.find("fasta");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["fasta"] = inputDir + it->second;            }
+                               }
+                               
+                               it = parameters.find("group");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["group"] = inputDir + it->second;            }
+                               }
+                               
+                               it = parameters.find("name");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["name"] = inputDir + it->second;             }
+                               }
+                               
+                               it = parameters.find("alignreport");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["alignreport"] = inputDir + it->second;              }
+                               }
+                       }
+
                        //check for required parameters
                        fastafile = validParameter.validFile(parameters, "fasta", true);
                        if (fastafile == "not found") { mothurOut("fasta is a required parameter for the screen.seqs command."); mothurOutEndLine(); abort = true; }
@@ -52,6 +91,12 @@ ScreenSeqsCommand::ScreenSeqsCommand(string option){
                        if (alignreport == "not open") { abort = true; }
                        else if (alignreport == "not found") { alignreport = ""; }      
                        
+                       //if the user changes the output directory command factory will send this info to us in the output parameter 
+                       outputDir = validParameter.validFile(parameters, "outputdir", false);           if (outputDir == "not found"){  
+                               outputDir = ""; 
+                               outputDir += hasPath(fastafile); //if user entered a file with a path then preserve it  
+                       }
+
                        //check for optional parameter and set defaults
                        // ...at some point should added some additional type checking...
                        string temp;
@@ -123,8 +168,8 @@ int ScreenSeqsCommand::execute(){
                
                set<string> badSeqNames;
                
-               string goodSeqFile = getRootName(fastafile) + "good" + getExtension(fastafile);
-               string badSeqFile = getRootName(fastafile) + "bad" + getExtension(fastafile);
+               string goodSeqFile = outputDir + getRootName(getSimpleName(fastafile)) + "good" + getExtension(fastafile);
+               string badSeqFile =  outputDir + getRootName(getSimpleName(fastafile)) + "bad" + getExtension(fastafile);
                
                ofstream goodSeqOut;    openOutputFile(goodSeqFile, goodSeqOut);
                ofstream badSeqOut;             openOutputFile(badSeqFile, badSeqOut);          
@@ -176,8 +221,8 @@ void ScreenSeqsCommand::screenNameGroupFile(set<string> badSeqNames){
        string seqName, seqList, group;
        set<string>::iterator it;
 
-       string goodNameFile = getRootName(namefile) + "good" + getExtension(namefile);
-       string badNameFile = getRootName(namefile) + "bad" + getExtension(namefile);
+       string goodNameFile = outputDir + getRootName(getSimpleName(namefile)) + "good" + getExtension(namefile);
+       string badNameFile = outputDir + getRootName(getSimpleName(namefile)) + "bad" + getExtension(namefile);
        
        ofstream goodNameOut;   openOutputFile(goodNameFile, goodNameOut);
        ofstream badNameOut;    openOutputFile(badNameFile, badNameOut);                
@@ -222,8 +267,8 @@ void ScreenSeqsCommand::screenNameGroupFile(set<string> badSeqNames){
                ifstream inputGroups;
                openInputFile(groupfile, inputGroups);
 
-               string goodGroupFile = getRootName(groupfile) + "good" + getExtension(groupfile);
-               string badGroupFile = getRootName(groupfile) + "bad" + getExtension(groupfile);
+               string goodGroupFile = outputDir + getRootName(getSimpleName(groupfile)) + "good" + getExtension(groupfile);
+               string badGroupFile = outputDir + getRootName(getSimpleName(groupfile)) + "bad" + getExtension(groupfile);
                
                ofstream goodGroupOut;  openOutputFile(goodGroupFile, goodGroupOut);
                ofstream badGroupOut;   openOutputFile(badGroupFile, badGroupOut);              
@@ -265,8 +310,8 @@ void ScreenSeqsCommand::screenGroupFile(set<string> badSeqNames){
        string seqName, group;
        set<string>::iterator it;
        
-       string goodGroupFile = getRootName(groupfile) + "good" + getExtension(groupfile);
-       string badGroupFile = getRootName(groupfile) + "bad" + getExtension(groupfile);
+       string goodGroupFile = outputDir + getRootName(getSimpleName(groupfile)) + "good" + getExtension(groupfile);
+       string badGroupFile = outputDir + getRootName(getSimpleName(groupfile)) + "bad" + getExtension(groupfile);
        
        ofstream goodGroupOut;  openOutputFile(goodGroupFile, goodGroupOut);
        ofstream badGroupOut;   openOutputFile(badGroupFile, badGroupOut);              
@@ -308,8 +353,8 @@ void ScreenSeqsCommand::screenAlignReport(set<string> badSeqNames){
        string seqName, group;
        set<string>::iterator it;
        
-       string goodAlignReportFile = getRootName(alignreport) + "good" + getExtension(alignreport);
-       string badAlignReportFile = getRootName(alignreport) + "bad" + getExtension(alignreport);
+       string goodAlignReportFile = outputDir + getRootName(getSimpleName(alignreport)) + "good" + getExtension(alignreport);
+       string badAlignReportFile = outputDir + getRootName(getSimpleName(alignreport)) + "bad" + getExtension(alignreport);
        
        ofstream goodAlignReportOut;    openOutputFile(goodAlignReportFile, goodAlignReportOut);
        ofstream badAlignReportOut;             openOutputFile(badAlignReportFile, badAlignReportOut);          
index 269275d38409c251ef3f9b0b1c2552602367f348..5b44091dbd07d044f0de288490ff0d4633495008 100644 (file)
@@ -26,7 +26,7 @@ private:
        void screenAlignReport(set<string>);
        
        bool abort;
-       string fastafile, namefile, groupfile, alignreport;
+       string fastafile, namefile, groupfile, alignreport, outputDir;
        int startPos, endPos, maxAmbig, maxHomoP, minLength, maxLength;
 };
 
index c2c104e71b1f535cd2a818afe268e5d7e1ed4c24..e2302d38bf02f5c58daae759713deb28a1a75b6b 100644 (file)
@@ -21,19 +21,42 @@ AlignCheckCommand::AlignCheckCommand(string option){
                
                else {
                        //valid paramters for this command
-                       string Array[] =  {"fasta","map"};
+                       string Array[] =  {"fasta","map", "outputdir","inputdir"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
                        OptionParser parser(option);
                        map<string,string> parameters = parser.getParameters();
                        
                        ValidParameters validParameter;
+                       map<string,string>::iterator it;
                        
                        //check to make sure all parameters are valid for command
-                       for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
+                       for (it = parameters.begin(); it != parameters.end(); it++) { 
                                if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
+                       //if the user changes the input directory command factory will send this info to us in the output parameter 
+                       string inputDir = validParameter.validFile(parameters, "inputdir", false);              
+                       if (inputDir == "not found"){   inputDir = "";          }
+                       else {
+                               string path;
+                               it = parameters.find("fasta");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["fasta"] = inputDir + it->second;            }
+                               }
+                               
+                               it = parameters.find("map");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["map"] = inputDir + it->second;              }
+                               }
+                       }
+
                        //check for required parameters
                        mapfile = validParameter.validFile(parameters, "map", true);
                        if (mapfile == "not open") { abort = true; }
@@ -43,6 +66,12 @@ AlignCheckCommand::AlignCheckCommand(string option){
                        if (fastafile == "not open") { abort = true; }
                        else if (fastafile == "not found") {  fastafile = "";  mothurOut("You must provide an fasta file."); mothurOutEndLine(); abort = true;  }       
                        
+                       //if the user changes the output directory command factory will send this info to us in the output parameter 
+                       outputDir = validParameter.validFile(parameters, "outputdir", false);           if (outputDir == "not found"){  
+                               outputDir = ""; 
+                               outputDir += hasPath(fastafile); //if user entered a file with a path then preserve it  
+                       }
+
                }
 
        }
@@ -82,7 +111,7 @@ int AlignCheckCommand::execute(){
                openInputFile(fastafile, in);
                
                ofstream out;
-               string outfile = getRootName(fastafile) + "align.check";
+               string outfile = outputDir + getRootName(getSimpleName(fastafile)) + "align.check";
                openOutputFile(outfile, out);
                
                out << "name" << '\t' << "pound" << '\t' << "dash" << '\t' << "plus" << '\t' << "equal" << '\t';
index a82cf4e5edd89a5536cfbecafb5def8f6a7e3ed4..dffb4cbd980ff504307465ae64a0f6645fe5e6a5 100644 (file)
@@ -39,7 +39,7 @@ class AlignCheckCommand : public Command {
                
        private:
                vector<int> structMap;
-               string mapfile, fastafile;
+               string mapfile, fastafile, outputDir;
                bool abort;
                int seqLength;
                
index 9ab27f9cbd439fe55ed1856c6940f0e42e6ee7e0..8b07b857c73930bb24265c58da93b7702dccf42d 100644 (file)
@@ -21,24 +21,45 @@ SeqSummaryCommand::SeqSummaryCommand(string option){
                
                else {
                        //valid paramters for this command
-                       string Array[] =  {"fasta"};
+                       string Array[] =  {"fasta","outputdir","inputdir"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
                        OptionParser parser(option);
                        map<string,string> parameters = parser.getParameters();
                        
                        ValidParameters validParameter;
+                       map<string,string>::iterator it;
                        
                        //check to make sure all parameters are valid for command
-                       for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
+                       for (it = parameters.begin(); it != parameters.end(); it++) { 
                                if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
+                       //if the user changes the input directory command factory will send this info to us in the output parameter 
+                       string inputDir = validParameter.validFile(parameters, "inputdir", false);              
+                       if (inputDir == "not found"){   inputDir = "";          }
+                       else {
+                               string path;
+                               it = parameters.find("fasta");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["fasta"] = inputDir + it->second;            }
+                               }
+                       }
+                       
                        //check for required parameters
                        fastafile = validParameter.validFile(parameters, "fasta", true);
                        if (fastafile == "not open") { abort = true; }
                        else if (fastafile == "not found") { fastafile = ""; mothurOut("fasta is a required parameter for the summary.seqs command."); mothurOutEndLine(); abort = true;  }     
                        
+                       //if the user changes the output directory command factory will send this info to us in the output parameter 
+                       outputDir = validParameter.validFile(parameters, "outputdir", false);           if (outputDir == "not found"){  
+                               outputDir = ""; 
+                               outputDir += hasPath(fastafile); //if user entered a file with a path then preserve it  
+                       }
+
                }
        }
        catch(exception& e) {
@@ -78,7 +99,7 @@ int SeqSummaryCommand::execute(){
                int numSeqs = 0;
 
                ofstream outSummary;
-               string summaryFile = fastafile + ".summary";
+               string summaryFile = outputDir + getSimpleName(fastafile) + ".summary";
                openOutputFile(summaryFile, outSummary);
                
                vector<int> startPosition;
index 6d48284baeffe974a2c13ddbb16dfaf95704df90..e6b3b879b8f25e72d2151ae69fae8a75f211909d 100644 (file)
@@ -22,7 +22,7 @@ public:
        
 private:
        bool abort;
-       string fastafile;
+       string fastafile, outputDir;
 
 };
 
diff --git a/setdircommand.cpp b/setdircommand.cpp
new file mode 100644 (file)
index 0000000..a23b61d
--- /dev/null
@@ -0,0 +1,140 @@
+/*
+ *  setoutdircommand.cpp
+ *  Mothur
+ *
+ *  Created by westcott on 1/21/10.
+ *  Copyright 2010 Schloss Lab. All rights reserved.
+ *
+ */
+
+#include "setdircommand.h"
+
+//**********************************************************************************************************************
+
+SetDirectoryCommand::SetDirectoryCommand(string option){
+       try {
+               abort = false;
+               
+               //allow user to run help
+               if(option == "help") { help(); abort = true; }
+               
+               else {
+                       //valid paramters for this command
+                       string Array[] =  {"output","input","outputdir","inputdir"};
+                       vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+                       
+                       OptionParser parser(option);
+                       map<string, string> parameters = parser.getParameters();
+                       
+                       ValidParameters validParameter;
+                       //check to make sure all parameters are valid for command
+                       for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
+                               if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
+                       }
+               
+                       output = validParameter.validFile(parameters, "output", false);                 
+                       if (output == "not found") {  output = "";  } 
+                       
+                       input = validParameter.validFile(parameters, "input", false);                   
+                       if (input == "not found") {  input = "";  }
+                               
+                       if ((input == "") && (output == "")) {  
+                               mothurOut("You must provide either an input or output for the set.outdir command."); mothurOutEndLine(); abort = true;
+                       }
+               }
+       }
+       catch(exception& e) {
+               errorOut(e, "SetDirectoryCommand", "SetDirectoryCommand");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+
+void SetDirectoryCommand::help(){
+       try {
+               mothurOut("The set.dir command can be used to direct the output files generated by mothur to a specific place, the directory must exist.\n");
+               mothurOut("The set.dir command can also be used to specify the directory where your input files are located, the directory must exist.\n");
+               mothurOut("The set.dir command parameter is output and is required.\n");
+               mothurOut("To return the output to the same directory as the input files you may enter: output=clear.\n");
+               mothurOut("To return the input to the same directory as the mothur.exe you may enter: input=clear.\n");
+               mothurOut("The set.dir command should be in the following format: set.dir(output=yourOutputDirectory, input=yourInputDirectory).\n");
+               mothurOut("Example set.outdir(output=/Users/lab/desktop/outputs, input=/Users/lab/desktop/inputs).\n");
+               mothurOut("Note: No spaces between parameter labels (i.e. output), '=' and parameters (i.e.yourOutputDirectory).\n\n");
+       }
+       catch(exception& e) {
+               errorOut(e, "SetDirectoryCommand", "help");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+
+SetDirectoryCommand::~SetDirectoryCommand(){}
+
+//**********************************************************************************************************************
+
+int SetDirectoryCommand::execute(){
+       try {
+               
+               if (abort == true) { return 0; }
+               
+               commandFactory = CommandFactory::getInstance();
+               
+               
+               //redirect output
+               if ((output == "clear") || (output == "")) {  output = "";  commandFactory->setOutputDirectory(output);  }
+               else {
+                       //add / to name if needed
+                       string lastChar = output.substr(output.length()-1);
+                       #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
+                               if (lastChar != "/") { output += "/"; }
+                       #else
+                               if (lastChar != "\\") { output += "\\"; }       
+                       #endif
+                       
+                       //test to make sure directory exists
+                       output = getFullPathName(output);
+                       string outTemp = output + "temp";
+                       ofstream out;
+                       out.open(outTemp.c_str(), ios::trunc);
+                       if(!out) {
+                               mothurOut(output + " directory does not exist or is not writable."); mothurOutEndLine(); 
+                       }else{
+                               remove(outTemp.c_str());
+                               mothurOut("Changing output directory to " + output); mothurOutEndLine();  
+                               commandFactory->setOutputDirectory(output);
+                       }
+               }
+               
+               //redirect input
+               if ((input == "clear") || (input == "")) {  input = "";  commandFactory->setInputDirectory(input);  }
+               else {
+                       //add / to name if needed
+                       string lastChar = input.substr(input.length()-1);
+                       #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
+                               if (lastChar != "/") { input += "/"; }
+                       #else
+                               if (lastChar != "\\") { input += "\\"; }        
+                       #endif
+                       
+                       //test to make sure directory exists
+                       input = getFullPathName(input);
+                       string inTemp = input + "temp";
+                       ofstream in;
+                       in.open(inTemp.c_str(), ios::trunc);
+                       if(!in) {
+                               mothurOut(input + " directory does not exist or is not writable."); mothurOutEndLine(); 
+                       }else{
+                               remove(inTemp.c_str());
+                               mothurOut("Changing input directory to " + input); mothurOutEndLine();  
+                               commandFactory->setInputDirectory(input); 
+                       }
+               }
+
+               return 0;
+       }
+       catch(exception& e) {
+               errorOut(e, "SetDirectoryCommand", "SetDirectoryCommand");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************/
diff --git a/setdircommand.h b/setdircommand.h
new file mode 100644 (file)
index 0000000..6634965
--- /dev/null
@@ -0,0 +1,36 @@
+#ifndef SETDIRCOMMAND_H
+#define SETDIRCOMMAND_H
+
+/*
+ *  setoutdircommand.h
+ *  Mothur
+ *
+ *  Created by westcott on 1/21/10.
+ *  Copyright 2010 Schloss Lab. All rights reserved.
+ *
+ */
+
+#include "command.hpp"
+#include "commandfactory.hpp"
+
+/**********************************************************/
+
+class SetDirectoryCommand : public Command {
+       
+public:
+       SetDirectoryCommand(string);
+       ~SetDirectoryCommand();
+       int execute();
+       void help();
+       
+private:
+       CommandFactory* commandFactory;
+       string output, input;
+       bool abort;
+               
+};
+
+/**********************************************************/
+#endif
+
index 89f57eb5ca1aa80bf0d72d5aa47fcdabca6d8ef2..efc45c191482cc191fa204e526758a81af4bf910 100644 (file)
 
 //**********************************************************************************************************************
 
-SharedCommand::SharedCommand(){
+SharedCommand::SharedCommand(string o) : outputDir(o) {
        try {
                globaldata = GlobalData::getInstance();
                
                //getting output filename
                filename = globaldata->inputFileName;
-               filename = getRootName(filename);
+               if (outputDir == "") { outputDir += hasPath(filename); }
+               
+               filename = outputDir + getRootName(getSimpleName(filename));
                filename = filename + "shared";
+               
                openOutputFile(filename, out);
                pickedGroups = false;
                
@@ -41,7 +44,7 @@ SharedCommand::SharedCommand(){
                }
                
                //set fileroot
-               fileroot = getRootName(globaldata->getListFile());
+               fileroot = outputDir + getRootName(getSimpleName(globaldata->getListFile()));
                
                //clears file before we start to write to it below
                for (int i=0; i<groups.size(); i++) {
@@ -62,7 +65,7 @@ int SharedCommand::execute(){
                //lookup.clear();
                string errorOff = "no error";
                //errorOff = "";
-                       
+cout << globaldata->inputFileName << endl;                     
                //read in listfile
                read = new ReadOTUFile(globaldata->inputFileName);      
                read->read(&*globaldata); 
@@ -196,6 +199,7 @@ int SharedCommand::execute(){
                        delete it3->second;
                }
 
+               globaldata->setSharedFile(filename);
                
                return 0;
        }
@@ -288,10 +292,10 @@ void SharedCommand::createMisMatchFile() {
                                        string name = names.substr(0,names.find_first_of(','));
                                        names = names.substr(names.find_first_of(',')+1, names.length());
                                        string group = groupMap->getGroup(name);
-       cout << name << endl;                           
+                               
                                        if(group == "not found") {      outMisMatch << name << endl;  }
                                }
-       cout << names << endl;                  
+                       
                                //get last name
                                string group = groupMap->getGroup(names);
                                if(group == "not found") {      outMisMatch << names << endl;  }                                
index 5b922b6d6255eb993f8607fedc9696d4054f7caa..3d39b8b7a54ba348966f80d41cf1cea3b9bc9283 100644 (file)
@@ -26,7 +26,7 @@ class GlobalData;
 class SharedCommand : public Command {
        
 public:
-       SharedCommand();        
+       SharedCommand(string);  
        ~SharedCommand();
        int execute();  
        void help() {}
@@ -44,7 +44,7 @@ private:
        GroupMap* groupMap;
        vector<string> groups;
        ofstream out;
-       string filename, fileroot;
+       string filename, fileroot, outputDir;
        bool firsttime, pickedGroups;
        map<string, ofstream*> filehandles;
        map<string, ofstream*>::iterator it3;
index afb4758a29b3831cd7958583344aa223fec3e223..032282411f60905990f59dc0275259266e86d7e7 100644 (file)
@@ -44,7 +44,7 @@ SummaryCommand::SummaryCommand(string option){
                
                else {
                        //valid paramters for this command
-                       string Array[] =  {"label","calc","abund","size"};
+                       string Array[] =  {"label","calc","abund","size","outputdir","inputdir"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
                        OptionParser parser(option);
@@ -59,7 +59,13 @@ SummaryCommand::SummaryCommand(string option){
                        
                        //make sure the user has already run the read.otu command
                        if ((globaldata->getSharedFile() == "") && (globaldata->getListFile() == "") && (globaldata->getRabundFile() == "") && (globaldata->getSabundFile() == "")) { mothurOut("You must read a list, sabund, rabund or shared file before you can use the summary.single command."); mothurOutEndLine(); abort = true; }
-       
+                       
+                       //if the user changes the output directory command factory will send this info to us in the output parameter 
+                       outputDir = validParameter.validFile(parameters, "outputdir", false);           if (outputDir == "not found"){  
+                               outputDir = ""; 
+                               outputDir += hasPath(globaldata->inputFileName); //if user entered a file with a path then preserve it  
+                       }
+
                        //check for optional parameter and set defaults
                        // ...at some point should added some additional type checking...
                        label = validParameter.validFile(parameters, "label", false);                   
@@ -133,13 +139,14 @@ int SummaryCommand::execute(){
                
                for (int p = 0; p < inputFileNames.size(); p++) {
                        
-                       string fileNameRoot = getRootName(inputFileNames[p]) + "summary";
+                       string fileNameRoot = outputDir + getRootName(getSimpleName(inputFileNames[p])) + "summary";
                        globaldata->inputFileName = inputFileNames[p];
                        
                        if (inputFileNames.size() > 1) {
                                mothurOutEndLine(); mothurOut("Processing group " + groups[p]); mothurOutEndLine(); mothurOutEndLine();
                        }
                        
+                       sumCalculators.clear();
                        
                        validCalculator = new ValidCalculators();
                        
index 1258c650179a73afd9bcc85e56bfee92dca1d996..6f04fc721ad109545aa899b0a85871982bdc3c80 100644 (file)
@@ -37,7 +37,7 @@ private:
 
        bool abort, allLines;
        set<string> labels; //holds labels to be used
-       string label, calc;
+       string label, calc, outputDir;
        vector<string>  Estimators;
        vector<string> inputFileNames;
        vector<string> groups;
index e39d70bee58e1374774453d81d70dcf843c53be2..081f5ef027dc04c30da1eba77647d67288bbfb44 100644 (file)
@@ -48,7 +48,7 @@ SummarySharedCommand::SummarySharedCommand(string option){
                
                else {
                        //valid paramters for this command
-                       string Array[] =  {"label","calc","groups","all"};
+                       string Array[] =  {"label","calc","groups","all","outputdir","inputdir"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
                        OptionParser parser(option);
@@ -66,6 +66,12 @@ SummarySharedCommand::SummarySharedCommand(string option){
                                 mothurOut("You must read a list and a group, or a shared before you can use the summary.shared command."); mothurOutEndLine(); abort = true; 
                        }
                        
+                       //if the user changes the output directory command factory will send this info to us in the output parameter 
+                       outputDir = validParameter.validFile(parameters, "outputdir", false);           if (outputDir == "not found"){  
+                               outputDir = ""; 
+                               outputDir += hasPath(globaldata->getSharedFile()); //if user entered a file with a path then preserve it        
+                       }
+
                        //check for optional parameter and set defaults
                        // ...at some point should added some additional type checking...
                        label = validParameter.validFile(parameters, "label", false);                   
@@ -151,7 +157,7 @@ SummarySharedCommand::SummarySharedCommand(string option){
                                        }
                                }
                                
-                               outputFileName = ((getRootName(globaldata->inputFileName)) + "shared.summary");
+                               outputFileName = outputDir + getRootName(getSimpleName(globaldata->inputFileName)) + "shared.summary";
                                openOutputFile(outputFileName, outputFileHandle);
                                mult = false;
                        }
index 090c9f4ef9ed40287040bec733f0e5d8802ff23d..351b1352b7e865d8c0741ffb56875407070db344 100644 (file)
@@ -39,7 +39,7 @@ private:
        string label, calc, groups;
        vector<string>  Estimators, Groups;
        vector<SharedRAbundVector*> lookup;
-       string outputFileName, format, outAllFileName;
+       string outputFileName, format, outAllFileName, outputDir;
        ofstream outputFileHandle, outAll;
        void process(vector<SharedRAbundVector*>);
 
index f341d0a03e3d35177895ab49696f7fb4f1f7ad20..489a2f11f7c3a13df14bedf42a05339e86fcaeb2 100644 (file)
@@ -20,7 +20,17 @@ SystemCommand::SystemCommand(string option){
                
                else {
                        if (option == "") { mothurOut("You must enter a command to run."); mothurOutEndLine(); abort = true; }
-                       else { command = option; }
+                       else { 
+                               //check for outputdir and inputdir parameters
+                               int commaPos = option.find_first_of(',');
+                               
+                               //if there is a comma then grab string up to that pos
+                               if (commaPos != option.npos) {
+                                       option = option.substr(0, commaPos);
+                               }
+                       
+                               command = option;
+                       }
                }       
 
        }
index c115c54ce1bcb39786ec7c54fcd4ba11df3115ab..e8f68e7f34c52258e480bd8e6f369a200734df1f 100644 (file)
@@ -36,37 +36,68 @@ TreeGroupCommand::TreeGroupCommand(string option){
                
                else {
                        //valid paramters for this command
-                       string Array[] =  {"label","calc","groups", "phylip", "column", "name", "precision","cutoff"};
+                       string Array[] =  {"label","calc","groups", "phylip", "column", "name", "precision","cutoff","outputdir","inputdir"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
                        OptionParser parser(option);
                        map<string, string> parameters = parser. getParameters();
                        
                        ValidParameters validParameter;
+                       map<string, string>::iterator it;
                
                        //check to make sure all parameters are valid for command
-                       for (map<string, string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
+                       for (it = parameters.begin(); it != parameters.end(); it++) { 
                                if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
+                       //if the user changes the input directory command factory will send this info to us in the output parameter 
+                       string inputDir = validParameter.validFile(parameters, "inputdir", false);              
+                       if (inputDir == "not found"){   inputDir = "";          }
+                       else {
+                               string path;
+                               it = parameters.find("phylip");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["phylip"] = inputDir + it->second;           }
+                               }
+                               
+                               it = parameters.find("column");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["column"] = inputDir + it->second;           }
+                               }
+                               
+                               it = parameters.find("name");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["name"] = inputDir + it->second;             }
+                               }
+                       }
+                       
+                       format = globaldata->getFormat();
+                       
                        //required parameters
                        phylipfile = validParameter.validFile(parameters, "phylip", true);
                        if (phylipfile == "not open") { abort = true; }
                        else if (phylipfile == "not found") { phylipfile = ""; }        
-                       else {  format = "phylip";      }
+                       else {  format = "phylip";  globaldata->setPhylipFile(phylipfile);      }
                        
                        columnfile = validParameter.validFile(parameters, "column", true);
                        if (columnfile == "not open") { abort = true; } 
                        else if (columnfile == "not found") { columnfile = ""; }
-                       else {  format = "column";      }
+                       else {  format = "column"; globaldata->setColumnFile(columnfile);       }
                        
                        namefile = validParameter.validFile(parameters, "name", true);
                        if (namefile == "not open") { abort = true; }   
                        else if (namefile == "not found") { namefile = ""; }
                        else {  globaldata->setNameFile(namefile);      }
                        
-                       format = globaldata->getFormat();
-                       
                        //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 tree.shared command."); mothurOutEndLine(); abort = true; }
                        else if ((phylipfile != "") && (columnfile != "")) { mothurOut("When running the tree.shared command with a distance file you may not use both the column and the phylip parameters."); mothurOutEndLine(); abort = true; }
@@ -111,6 +142,12 @@ TreeGroupCommand::TreeGroupCommand(string option){
                        temp = validParameter.validFile(parameters, "cutoff", false);                   if (temp == "not found") { temp = "10"; }
                        convert(temp, cutoff); 
                        cutoff += (5 / (precision * 10.0));
+                       
+                       //if the user changes the output directory command factory will send this info to us in the output parameter 
+                       outputDir = validParameter.validFile(parameters, "outputdir", false);           if (outputDir == "not found"){  
+                               outputDir = ""; 
+                               outputDir += hasPath(globaldata->inputFileName); //if user entered a file with a path then preserve it  
+                       }
 
                                
                        if (abort == false) {
@@ -262,7 +299,7 @@ int TreeGroupCommand::execute(){
                        makeSimsDist();
 
                        //create a new filename
-                       outputFile = getRootName(globaldata->inputFileName) + "tre";    
+                       outputFile = outputDir + getRootName(getSimpleName(globaldata->inputFileName)) + "tre"; 
                                
                        createTree();
                        mothurOut("Tree complete. "); mothurOutEndLine();
@@ -519,7 +556,7 @@ void TreeGroupCommand::process(vector<SharedRAbundVector*> thisLookup) {
                                        for (int g = 0; g < numGroups; g++) {   index[g] = g;   }
                
                                        //create a new filename
-                                       outputFile = getRootName(globaldata->inputFileName) + treeCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + ".tre";                         
+                                       outputFile = outputDir + getRootName(getSimpleName(globaldata->inputFileName)) + treeCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + ".tre";                              
                                                                                                
                                        for (int k = 0; k < thisLookup.size(); k++) { 
                                                for (int l = k; l < thisLookup.size(); l++) {
index 3f2822cfae2abe2929b8ac8f2b94b0e5b9236503..e23dc777689f80806a8d81e458c9acda7f3ba4aa 100644 (file)
@@ -67,7 +67,7 @@ private:
 
        bool abort, allLines;
        set<string> labels; //holds labels to be used
-       string phylipfile, columnfile, namefile, calc, groups, label;
+       string phylipfile, columnfile, namefile, calc, groups, label, outputDir;
        vector<string>  Estimators, Groups; //holds estimators to be used
        
        //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
index b185da0905321c7980f2237a9d938bd260d9397d..4dc07a7afa207f80b026077b7abfbbb27bb498c2 100644 (file)
@@ -21,7 +21,8 @@ TrimSeqsCommand::TrimSeqsCommand(string option){
                
                else {
                        //valid paramters for this command
-                       string AlignArray[] =  {"fasta", "flip", "oligos", "maxambig", "maxhomop", "minlength", "maxlength", "qfile", "qthreshold", "qaverage", "allfiles", "qtrim"};
+                       string AlignArray[] =  {"fasta", "flip", "oligos", "maxambig", "maxhomop", "minlength", "maxlength", "qfile", 
+                                                                       "qthreshold", "qaverage", "allfiles", "qtrim", "outputdir","inputdir"};
                        
                        vector<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
                        
@@ -29,17 +30,54 @@ TrimSeqsCommand::TrimSeqsCommand(string option){
                        map<string,string> parameters = parser.getParameters();
                        
                        ValidParameters validParameter;
+                       map<string,string>::iterator it;
                        
                        //check to make sure all parameters are valid for command
-                       for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
+                       for (it = parameters.begin(); it != parameters.end(); it++) { 
                                if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
+                       //if the user changes the input directory command factory will send this info to us in the output parameter 
+                       string inputDir = validParameter.validFile(parameters, "inputdir", false);              
+                       if (inputDir == "not found"){   inputDir = "";          }
+                       else {
+                               string path;
+                               it = parameters.find("fasta");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["fasta"] = inputDir + it->second;            }
+                               }
+                               
+                               it = parameters.find("oligos");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["oligos"] = inputDir + it->second;           }
+                               }
+                               
+                               it = parameters.find("qfile");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["qfile"] = inputDir + it->second;            }
+                               }
+                       }
+
+                       
                        //check for required parameters
                        fastaFile = validParameter.validFile(parameters, "fasta", true);
                        if (fastaFile == "not found") { mothurOut("fasta is a required parameter for the screen.seqs command."); mothurOutEndLine(); abort = true; }
                        else if (fastaFile == "not open") { abort = true; }     
-               
+                       
+                       //if the user changes the output directory command factory will send this info to us in the output parameter 
+                       outputDir = validParameter.validFile(parameters, "outputdir", false);           if (outputDir == "not found"){  
+                               outputDir = ""; 
+                               outputDir += hasPath(fastaFile); //if user entered a file with a path then preserve it  
+                       }
                
                        //check for optional parameter and set defaults
                        // ...at some point should added some additional type checking...
@@ -150,19 +188,19 @@ int TrimSeqsCommand::execute(){
                openInputFile(fastaFile, inFASTA);
                
                ofstream outFASTA;
-               string trimSeqFile = getRootName(fastaFile) + "trim.fasta";
+               string trimSeqFile = outputDir + getRootName(getSimpleName(fastaFile)) + "trim.fasta";
                openOutputFile(trimSeqFile, outFASTA);
                
                ofstream outGroups;
                vector<ofstream*> fastaFileNames;
                if(oligoFile != ""){
-                       string groupFile = getRootName(fastaFile) + "groups"; 
+                       string groupFile = outputDir + getRootName(getSimpleName(fastaFile)) + "groups"; 
                        openOutputFile(groupFile, outGroups);
                        getOligos(fastaFileNames);
                }
                
                ofstream scrapFASTA;
-               string scrapSeqFile = getRootName(fastaFile) + "scrap.fasta";
+               string scrapSeqFile = outputDir + getRootName(getSimpleName(fastaFile)) + "scrap.fasta";
                openOutputFile(scrapSeqFile, scrapFASTA);
                
                ifstream qFile;
@@ -249,7 +287,7 @@ int TrimSeqsCommand::execute(){
                        string seqName;
                        openInputFile(getRootName(fastaFile) + groupVector[i] + ".fasta", inFASTA);
                        ofstream outGroups;
-                       openOutputFile(getRootName(fastaFile) + groupVector[i] + ".groups", outGroups);
+                       openOutputFile(outputDir + getRootName(getSimpleName(fastaFile)) + groupVector[i] + ".groups", outGroups);
                        
                        while(!inFASTA.eof()){
                                if(inFASTA.get() == '>'){
@@ -311,7 +349,7 @@ void TrimSeqsCommand::getOligos(vector<ofstream*>& outFASTAVec){
                                        groupVector.push_back(group);
                                        
                                        if(allFiles){
-                                               outFASTAVec.push_back(new ofstream((getRootName(fastaFile) + group + ".fasta").c_str(), ios::ate));
+                                               outFASTAVec.push_back(new ofstream((outputDir + getRootName(getSimpleName(fastaFile)) + group + ".fasta").c_str(), ios::ate));
                                        }
                                }
                        }
index ca029616870f97a31482a40497c645e240ae72db..9b02be9ef5ec0f5a50d0563ab87a7f7d053bdadc 100644 (file)
@@ -34,7 +34,7 @@ private:
        bool compareDNASeq(string, string);
 
        bool abort;
-       string fastaFile, oligoFile, qFileName;
+       string fastaFile, oligoFile, qFileName, outputDir;
        
        bool flip, allFiles, qtrim;
        int numFPrimers, numRPrimers, maxAmbig, maxHomoP, minLength, maxLength, qThreshold, qAverage;
index 1512284544b0e7d4cb7ba6ddac4663bf60d6d777..957a4aaab458d5f65256d8f9bf43579ad383d493 100644 (file)
@@ -21,7 +21,7 @@ UnifracUnweightedCommand::UnifracUnweightedCommand(string option) {
                
                else {
                        //valid paramters for this command
-                       string Array[] =  {"groups","iters","distance","random"};
+                       string Array[] =  {"groups","iters","distance","random", "outputdir","inputdir"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
                        OptionParser parser(option);
@@ -36,7 +36,13 @@ UnifracUnweightedCommand::UnifracUnweightedCommand(string option) {
                        
                        if (globaldata->gTree.size() == 0) {//no trees were read
                                mothurOut("You must execute the read.tree command, before you may execute the unifrac.unweighted command."); mothurOutEndLine(); abort = true;  }
-                                                                               
+                       
+                       //if the user changes the output directory command factory will send this info to us in the output parameter 
+                       outputDir = validParameter.validFile(parameters, "outputdir", false);           if (outputDir == "not found"){  
+                               outputDir = ""; 
+                               outputDir += hasPath(globaldata->inputFileName); //if user entered a file with a path then preserve it  
+                       }
+                                                       
                        //check for optional parameter and set defaults
                        // ...at some point should added some additional type checking...
                        groups = validParameter.validFile(parameters, "groups", false);                 
@@ -67,7 +73,7 @@ UnifracUnweightedCommand::UnifracUnweightedCommand(string option) {
                        if (abort == false) {
                                T = globaldata->gTree;
                                tmap = globaldata->gTreemap;
-                               sumFile = globaldata->getTreeFile() + ".uwsummary";
+                               sumFile = outputDir + getSimpleName(globaldata->getTreeFile()) + ".uwsummary";
                                openOutputFile(sumFile, outSum);
                                
                                util = new SharedUtil();
@@ -129,7 +135,7 @@ int UnifracUnweightedCommand::execute() {
                for (int i = 0; i < T.size(); i++) {
                        counter = 0;
                        
-                       if (random)  {  output = new ColumnFile(globaldata->getTreeFile()  + toString(i+1) + ".unweighted", itersString);  }
+                       if (random)  {  output = new ColumnFile(outputDir + getSimpleName(globaldata->getTreeFile())  + toString(i+1) + ".unweighted", itersString);  }
                        
                        //get unweighted for users tree
                        rscoreFreq.resize(numComp);  
@@ -272,7 +278,7 @@ void UnifracUnweightedCommand::printUWSummaryFile(int i) {
 /***********************************************************/
 void UnifracUnweightedCommand::createPhylipFile(int i) {
        try {
-               string phylipFileName = globaldata->getTreeFile()  + toString(i+1) + ".unweighted.dist";
+               string phylipFileName = outputDir + getSimpleName(globaldata->getTreeFile())  + toString(i+1) + ".unweighted.dist";
                ofstream out;
                openOutputFile(phylipFileName, out);
                        
index 155fa75d6185d3d1bf10923ca56903a9e3e85aa8..c98abc48d748be4dcbb8928283d808b118db29b8 100644 (file)
@@ -46,7 +46,7 @@ class UnifracUnweightedCommand : public Command {
                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, phylip, random;
-               string groups, itersString;
+               string groups, itersString, outputDir;
                vector<string> Groups; //holds groups to be used
 
                ofstream outSum, out;
index ea79475038dc3abf2cbbc5be8eaaa750e3489bc1..a9f9570e771b7c45c95f96e9a162ddc9ec8dfdb8 100644 (file)
@@ -21,7 +21,7 @@ UnifracWeightedCommand::UnifracWeightedCommand(string option) {
                
                else {
                        //valid paramters for this command
-                       string Array[] =  {"groups","iters","distance","random"};
+                       string Array[] =  {"groups","iters","distance","random","outputdir","inputdir"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
                        OptionParser parser(option);
@@ -36,7 +36,13 @@ UnifracWeightedCommand::UnifracWeightedCommand(string option) {
                        
                        if (globaldata->gTree.size() == 0) {//no trees were read
                                mothurOut("You must execute the read.tree command, before you may execute the unifrac.weighted command."); mothurOutEndLine(); abort = true;  }
-                                                                               
+                       
+                       //if the user changes the output directory command factory will send this info to us in the output parameter 
+                       outputDir = validParameter.validFile(parameters, "outputdir", false);           if (outputDir == "not found"){  
+                               outputDir = ""; 
+                               outputDir += hasPath(globaldata->inputFileName); //if user entered a file with a path then preserve it  
+                       }
+                                                                                                                                       
                        //check for optional parameter and set defaults
                        // ...at some point should added some additional type checking...
                        groups = validParameter.validFile(parameters, "groups", false);                 
@@ -61,7 +67,7 @@ UnifracWeightedCommand::UnifracWeightedCommand(string option) {
                        if (abort == false) {
                                T = globaldata->gTree;
                                tmap = globaldata->gTreemap;
-                               sumFile = globaldata->getTreeFile() + ".wsummary";
+                               sumFile = outputDir + getSimpleName(globaldata->getTreeFile()) + ".wsummary";
                                openOutputFile(sumFile, outSum);
                                
                                util = new SharedUtil();
@@ -125,7 +131,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...
                        
-                       if (random) {  output = new ColumnFile(globaldata->getTreeFile()  + toString(i+1) + ".weighted", itersString);  } 
+                       if (random) {  output = new ColumnFile(outputDir + getSimpleName(globaldata->getTreeFile())  + toString(i+1) + ".weighted", itersString);  } 
 
                        userData = weighted->getValues(T[i]);  //userData[0] = weightedscore
                        
@@ -283,7 +289,7 @@ void UnifracWeightedCommand::createPhylipFile() {
                //for each tree
                for (int i = 0; i < T.size(); i++) { 
                
-                       string phylipFileName = globaldata->getTreeFile()  + toString(i+1) + ".weighted.dist";
+                       string phylipFileName = outputDir + getSimpleName(globaldata->getTreeFile())  + toString(i+1) + ".weighted.dist";
                        ofstream out;
                        openOutputFile(phylipFileName, out);
                        
index 9c0ad9939221f6a94083cac9300344004e2e707d..c36152d107d894c4e26c857ce3508e4780ae06ef 100644 (file)
@@ -39,7 +39,7 @@ class UnifracWeightedCommand : public Command {
                Tree* randT;  //random tree
                TreeMap* tmap;
                Weighted* weighted;
-               string sumFile;
+               string sumFile, outputDir;
                int iters, numGroups, numComp, counter;
                EstOutput userData;                     //weighted score info for user tree
                EstOutput randomData;           //weighted score info for random trees
index 8370701f9e4910fac97ff3849cd8a1c89ed28d0a..986c68db1f4942e8242aef7514f78441ef0e37e0 100644 (file)
--- a/venn.cpp
+++ b/venn.cpp
@@ -16,7 +16,7 @@
 
 
 //**********************************************************************************************************************
-Venn::Venn(){
+Venn::Venn(string o) : outputDir(o) {
        try {
                globaldata = GlobalData::getInstance();
 
@@ -31,7 +31,7 @@ void Venn::getPic(SAbundVector* sabund, vector<Calculator*> vCalcs) {
        try {
                                
                for(int i=0;i<vCalcs.size();i++){
-                       string filenamesvg = globaldata->inputFileName + ".venn." + sabund->getLabel() + vCalcs[i]->getName() + ".svg";
+                       string filenamesvg = outputDir + getSimpleName(globaldata->inputFileName) + ".venn." + sabund->getLabel() + vCalcs[i]->getName() + ".svg";
                        openOutputFile(filenamesvg, outsvg);
 
                        vector<double> data = vCalcs[i]->getValues(sabund);
@@ -73,7 +73,7 @@ void Venn::getPic(vector<SharedRAbundVector*> lookup, vector<Calculator*> vCalcs
                        
                        //make a file for each calculator
                        for(int i=0;i<vCalcs.size();i++){
-                               string filenamesvg = getRootName(globaldata->inputFileName) + lookup[0]->getLabel() + ".venn." + vCalcs[i]->getName() + ".svg";
+                               string filenamesvg = outputDir + getSimpleName(globaldata->inputFileName) + lookup[0]->getLabel() + ".venn." + vCalcs[i]->getName() + ".svg";
                                openOutputFile(filenamesvg, outsvg);
                        
                                //in essence you want to run it like a single 
@@ -122,7 +122,7 @@ void Venn::getPic(vector<SharedRAbundVector*> lookup, vector<Calculator*> vCalcs
                        
                        //make a file for each calculator
                        for(int i=0;i<vCalcs.size();i++){
-                               string filenamesvg = getRootName(globaldata->inputFileName) + lookup[0]->getLabel() + ".venn." + vCalcs[i]->getName() + ".svg";
+                               string filenamesvg = outputDir + getSimpleName(globaldata->inputFileName) + lookup[0]->getLabel() + ".venn." + vCalcs[i]->getName() + ".svg";
                                openOutputFile(filenamesvg, outsvg);
                                
                                //get estimates for sharedAB
@@ -191,7 +191,7 @@ void Venn::getPic(vector<SharedRAbundVector*> lookup, vector<Calculator*> vCalcs
                        for(int i=0;i<vCalcs.size();i++){
                        
                                                                                                
-                               string filenamesvg = getRootName(globaldata->inputFileName) + lookup[0]->getLabel() + ".venn." + vCalcs[i]->getName() + ".svg";
+                               string filenamesvg = outputDir + getSimpleName(globaldata->inputFileName) + lookup[0]->getLabel() + ".venn." + vCalcs[i]->getName() + ".svg";
                                openOutputFile(filenamesvg, outsvg);
                                
                                if (vCalcs[i]->getName() == "sharedace") {
@@ -446,7 +446,7 @@ void Venn::getPic(vector<SharedRAbundVector*> lookup, vector<Calculator*> vCalcs
                                
                                if ((vCalcs[i]->getName() != "sharedsobs") && (vCalcs[i]->getName() != "sharedchao")) { mothurOut(vCalcs[i]->getName() + " is not a valid calculator with four groups.  It will be disregarded. "); mothurOutEndLine(); }
                                else{
-                                       string filenamesvg = getRootName(globaldata->inputFileName) + lookup[0]->getLabel() + ".venn." + vCalcs[i]->getName() + ".svg";
+                                       string filenamesvg = outputDir + getSimpleName(globaldata->inputFileName) + lookup[0]->getLabel() + ".venn." + vCalcs[i]->getName() + ".svg";
                                        openOutputFile(filenamesvg, outsvg);
 
                                
diff --git a/venn.h b/venn.h
index 8902cf4c9298dfe7df40b6739445cc494ebce3eb..cf6a5ee332fbe2d70e3b5d1c2066c59db5ebb107 100644 (file)
--- a/venn.h
+++ b/venn.h
@@ -20,7 +20,7 @@
 
 class Venn {
 public:
-       Venn();
+       Venn(string);
        ~Venn(){};
 
        void getPic(SAbundVector*, vector<Calculator*>);
@@ -29,7 +29,7 @@ public:
 private:
        GlobalData* globaldata;
        Calculator* singleCalc;
-       string groupComb;
+       string groupComb, outputDir;
        ofstream outsvg;
 };
 
index e26dbcc5f6e926be9531dd7c719fcf79abfd13a3..437f044e841783059421a121a2d89bc079207c54 100644 (file)
@@ -31,7 +31,7 @@ VennCommand::VennCommand(string option){
                
                else {
                        //valid paramters for this command
-                       string AlignArray[] =  {"groups","label","calc", "abund"};
+                       string AlignArray[] =  {"groups","label","calc", "abund","outputdir","inputdir"};
                        vector<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
                        
                        OptionParser parser(option);
@@ -48,6 +48,12 @@ VennCommand::VennCommand(string option){
                        if ((globaldata->getListFile() == "") && (globaldata->getSharedFile() == "")) {
                                mothurOut("You must read a list, or a list and a group, or a shared before you can use the venn command."); mothurOutEndLine(); abort = true; 
                        }
+                       
+                       //if the user changes the output directory command factory will send this info to us in the output parameter 
+                       outputDir = validParameter.validFile(parameters, "outputdir", false);           if (outputDir == "not found"){  
+                               outputDir = ""; 
+                               outputDir += hasPath(globaldata->inputFileName); //if user entered a file with a path then preserve it  
+                       }
 
                        //check for optional parameter and set defaults
                        // ...at some point should added some additional type checking...
@@ -122,7 +128,7 @@ VennCommand::VennCommand(string option){
                                        }
                                }
                                
-                               venn = new Venn();
+                               venn = new Venn(outputDir);
                        }
                }
 
index cc6b333d12f7eba65d9837e167220e34d6b3327d..aa1e8562343f899fcaf1e1d60295c47799b533c1 100644 (file)
@@ -42,7 +42,7 @@ private:
        
        bool abort, allLines;
        set<string> labels; //holds labels to be used
-       string format, groups, calc, label;
+       string format, groups, calc, label, outputDir;
        vector<string> Estimators, Groups;