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;
};
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; }
//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);
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");
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();
}
#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()); }
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;
//***************************************************************************************************************
-Bellerophon::Bellerophon(string name) {
+Bellerophon::Bellerophon(string name, string o) {
try {
fastafile = name;
+ outputDir = o;
}
catch(exception& e) {
errorOut(e, "Bellerophon", "Bellerophon");
//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();
class Bellerophon : public Chimera {
public:
- Bellerophon(string);
+ Bellerophon(string, string);
~Bellerophon() {};
int getChimeras();
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.");
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);
fasta = new FastaMap();
if (groupfile != "") {
groupMap = new GroupMap(groupfile);
- groupMap->readMap();
+
+ int error = groupMap->readMap();
+ if (error == 1) { delete groupMap; abort = true; }
}
}
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();
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;
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);
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; }
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]));
}
//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;
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
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; }
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;
};
#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() {
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);
class ChimeraCheckRDP : public Chimera {
public:
- ChimeraCheckRDP(string, string);
+ ChimeraCheckRDP(string, string, string);
~ChimeraCheckRDP();
int getChimeras();
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 = ""; }
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; }
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; }
//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);
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;
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") {
//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);
//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);
}
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;
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;
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);
}
}
+ //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();
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);
bool abort;
- string method, fileroot, tag;
+ string method, fileroot, tag, outputDir;
double cutoff;
string showabund, timing;
int precision, length;
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);
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; }
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) {
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;
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);
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; }
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;
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;
#include "collectsharedcommand.h"
#include "getgroupcommand.h"
#include "getlabelcommand.h"
-#include "getlinecommand.h"
#include "rarefactcommand.h"
#include "summarycommand.h"
#include "summarysharedcommand.h"
#include "preclustercommand.h"
#include "pcacommand.h"
#include "otuhierarchycommand.h"
+#include "setdircommand.h"
/*******************************************************/
/***********************************************************/
CommandFactory::CommandFactory(){
- _uniqueInstance = 0;
string s = "";
command = new NoCommand(s);
+ outputDir = ""; inputDir = "";
//initialize list of valid commands
commands["read.dist"] = "read.dist";
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";
commands["pre.cluster"] = "pre.cluster";
commands["pca"] = "pca";
commands["otu.hierarchy"] = "otu.hierarchy";
-
+ commands["set.dir"] = "set.dir";
}
/***********************************************************/
/***********************************************************/
CommandFactory::~CommandFactory(){
+ _uniqueInstance = 0;
delete command;
}
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); }
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); }
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;
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
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 = ""; }
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;
void help();
private:
- string inFastaName, oldNameMapFName;
+ string inFastaName, oldNameMapFName, outputDir;
bool abort;
};
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; }
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...
//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){
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
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;
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...
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);
void help();
private:
- string vertical, filter, fastafile, hard;
+ string vertical, filter, fastafile, hard, outputDir;
int alignmentLength;
char trump;
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; }
openInputFile(sharedfile, in);
//open output file
- outputFile = getRootName(sharedfile) + "bootGroups";
+ if (outputDir == "") { outputDir += hasPath(sharedfile); }
+ outputFile = outputDir + getRootName(getSimpleName(sharedfile)) + "bootGroups";
openOutputFile(outputFile, out);
}
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; }
}
+++ /dev/null
-/*
- * 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);
- }
-}
-
-
-
+++ /dev/null
-#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
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; }
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();
bool abort, allLines;
set<string> labels; //holds labels to be used
- string label, listfile;
+ string label, listfile, outputDir;
ofstream out;
void process(ListVector*);
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; }
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 = ""; }
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
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;
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);
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; }
}
if (abort == false) {
- filename = getRootName(globaldata->inputFileName) + "rabund";
+ filename = outputDir + getRootName(getSimpleName(globaldata->inputFileName)) + "rabund";
openOutputFile(filename, out);
}
}
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);
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; }
}
if (abort == false) {
- filename = getRootName(globaldata->inputFileName) + "sabund";
+ filename = outputDir + getRootName(getSimpleName(globaldata->inputFileName)) + "sabund";
openOutputFile(filename, out);
}
}
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; }
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; }
}
}
//**********************************************************************************************************************
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);
//**********************************************************************************************************************
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);
//**********************************************************************************************************************
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);
//**********************************************************************************************************************
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);
//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);
private:
set<string> names;
- string accnosfile, fastafile, namefile, groupfile, alignfile, listfile;
+ string accnosfile, fastafile, namefile, groupfile, alignfile, listfile, outputDir;
bool abort;
void readFasta();
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; }
groups = validParameter.validFile(parameters, "unique", false);
if (groups == "not found") { groups = ""; }
else {
+ userGroups = "unique." + groups;
splitAtDash(groups, Groups);
globaldata->Groups = Groups;
groups = validParameter.validFile(parameters, "shared", false);
if (groups == "not found") { groups = ""; }
else {
+ userGroups = groups;
splitAtDash(groups, Groups);
globaldata->Groups = Groups;
unique = false;
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
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);
}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);
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;
GroupMap::~GroupMap(){}
/************************************************************/
-void GroupMap::readMap() {
+int GroupMap::readMap() {
string seqName, seqGroup;
+ int error = 0;
while(fileHandle){
fileHandle >> seqName; //read from first column
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(); }
GroupMap() {};
GroupMap(string);
~GroupMap();
- void readMap();
+ int readMap();
int getNumGroups();
bool isValidGroup(string); //return true if string is a valid group
string getGroup(string);
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;
}
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; }
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"; }
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;
#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");
}
- 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
}
}
- 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
class HeatMap {
public:
- HeatMap(string, string);
+ HeatMap(string, string, string);
~HeatMap(){};
void getPic(RAbundVector*);
void printLegend(int, float);
GlobalData* globaldata;
- string format, sorted, groupComb, scaler;
+ string format, sorted, groupComb, scaler, outputDir;
ofstream outsvg;
};
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);
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;
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();
}
}
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;
#include "sharedbraycurtis.h"
//**********************************************************************************************************************
-HeatMapSim::HeatMapSim(){
+HeatMapSim::HeatMapSim(string dir) : outputDir(dir) {
globaldata = GlobalData::getInstance();
}
//**********************************************************************************************************************
//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
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
class HeatMapSim {
public:
- HeatMapSim();
+ HeatMapSim(string);
~HeatMapSim(){};
void getPic(vector<SharedRAbundVector*>, vector<Calculator*>);
void printLegend(int, float);
GlobalData* globaldata;
- string format, groupComb;
+ string format, groupComb, outputDir;
ofstream outsvg;
};
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; }
//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 {
if (abort == true) { return 0; }
- heatmap = new HeatMapSim();
+ heatmap = new HeatMapSim(outputDir);
if (format == "shared") {
runCommandShared();
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();
//**********************************************************************************************************************
HelpCommand::HelpCommand(string option){
-
-
- if (option != "") { mothurOut("There are no valid parameters for the help() command."); mothurOutEndLine(); }
validCommands = CommandFactory::getInstance();
}
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);
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;;
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);
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);
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
};
#include "listseqscommand.h"
#include "sequence.hpp"
+#include "listvector.hpp"
//**********************************************************************************************************************
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; }
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; }
}
}
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");
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);
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(){
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();
};
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);
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; }
}
}
- 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();
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
}
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);
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){
}
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();
}
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); }
}
}
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 = ""; }
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;
delete cluster;
}else { //use hcluster to cluster
- tag = "fn";
//get distmatrix and overlap
overlapFile = read->getOverlapFile();
distFile = read->getDistFile();
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;
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;
#include <sstream>
#include <signal.h>
+
//exception
#include <stdexcept>
#include <exception>
//#include <readline/history.h>
#else
#include <conio.h> //allows unbuffered screen capture from stdin
+ #include <direct.h> //get cwd
#endif
using namespace std;
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;
}
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;
+}
/***********************************************************************/
}
/***********************************************************************/
+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 {
/***********************************************************************/
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;
}
/***********************************************************************/
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 {
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...
}
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
private:
bool abort;
set<string> labels; //holds labels to be used
- string label, listFile;
+ string label, listFile, outputDir;
vector<ListVector> getListVectors();
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);
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);
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
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.
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; }
-
-
}
}
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;
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);
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.");
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);
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;
private:
bool abort, allLines;
- string taxonomyFileName, label;
+ string taxonomyFileName, label, outputDir;
set<string> labels; //holds labels to be used
int cutoff;
}
//***************************************************************************************************************
-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() {
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(); }
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";
class Pintail : public Chimera {
public:
- Pintail(string, string);
+ Pintail(string, string, string);
~Pintail();
int getChimeras();
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(); }
}//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();
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
//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; }
}
//**********************************************************************************************************************
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);
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; }
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) {
vector<string> Estimators;
vector<string> inputFileNames;
vector<string> groups;
+ string outputDir;
vector<string> parseSharedFile(string);
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);
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
if (abort == false) {
- string fileNameRoot = getRootName(globaldata->inputFileName);
+ string fileNameRoot = outputDir + getRootName(getSimpleName(globaldata->inputFileName));
// format = globaldata->getFormat();
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;
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; }
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" ) {
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);
FullMatrix* matrix;
GroupMap* groupMap;
string distFileName, format, method;
- string phylipfile, columnfile, namefile, groupfile;
+ string phylipfile, columnfile, namefile, groupfile, outputDir;
NameAssignment* nameMap;
bool abort;
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; }
else {
globaldata->setGroupFile(groupfile);
groupMap = new GroupMap(groupfile);
- groupMap->readMap();
+
+ int error = groupMap->readMap();
+ if (error == 1) { abort = true; }
+
globaldata->gGroupmap = groupMap;
}
if (globaldata->getFormat() == "shared") {
- shared = new SharedCommand();
+ shared = new SharedCommand(outputDir);
int okay = shared->execute();
- delete shared;
//problem with shared
if (okay == 1) {
globaldata->setFormat("sharedfile");
globaldata->setListFile("");
globaldata->setGroupFile("");
- globaldata->setSharedFile(getRootName(filename) + "shared");
}
+ delete shared;
}
return 0;
}
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;
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; }
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; }
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; }
}
}
//**********************************************************************************************************************
void RemoveSeqsCommand::readFasta(){
try {
+ if (outputDir == "") { outputDir += hasPath(fastafile); }
string outputFileName = getRootName(fastafile) + "pick" + getExtension(fastafile);
ofstream out;
openOutputFile(outputFileName, out);
//**********************************************************************************************************************
void RemoveSeqsCommand::readList(){
try {
+ if (outputDir == "") { outputDir += hasPath(listfile); }
string outputFileName = getRootName(listfile) + "pick" + getExtension(listfile);
ofstream out;
openOutputFile(outputFileName, out);
//**********************************************************************************************************************
void RemoveSeqsCommand::readName(){
try {
-
+ if (outputDir == "") { outputDir += hasPath(namefile); }
string outputFileName = getRootName(namefile) + "pick" + getExtension(namefile);
ofstream out;
//**********************************************************************************************************************
void RemoveSeqsCommand::readGroup(){
try {
-
+ if (outputDir == "") { outputDir += hasPath(groupfile); }
string outputFileName = getRootName(groupfile) + "pick" + getExtension(groupfile);
ofstream out;
openOutputFile(outputFileName, out);
//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);
private:
set<string> names;
- string accnosfile, fastafile, namefile, groupfile, alignfile, listfile;
+ string accnosfile, fastafile, namefile, groupfile, alignfile, listfile, outputDir;
bool abort;
void readFasta();
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) {
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()){
private:
bool abort;
- string fasta;
+ string fasta, outputDir;
};
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; }
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;
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);
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);
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);
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);
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);
void screenAlignReport(set<string>);
bool abort;
- string fastafile, namefile, groupfile, alignreport;
+ string fastafile, namefile, groupfile, alignreport, outputDir;
int startPos, endPos, maxAmbig, maxHomoP, minLength, maxLength;
};
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; }
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
+ }
+
}
}
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';
private:
vector<int> structMap;
- string mapfile, fastafile;
+ string mapfile, fastafile, outputDir;
bool abort;
int seqLength;
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) {
int numSeqs = 0;
ofstream outSummary;
- string summaryFile = fastafile + ".summary";
+ string summaryFile = outputDir + getSimpleName(fastafile) + ".summary";
openOutputFile(summaryFile, outSummary);
vector<int> startPosition;
private:
bool abort;
- string fastafile;
+ string fastafile, outputDir;
};
--- /dev/null
+/*
+ * 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);
+ }
+}
+//**********************************************************************************************************************/
--- /dev/null
+#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
+
//**********************************************************************************************************************
-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;
}
//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++) {
//lookup.clear();
string errorOff = "no error";
//errorOff = "";
-
+cout << globaldata->inputFileName << endl;
//read in listfile
read = new ReadOTUFile(globaldata->inputFileName);
read->read(&*globaldata);
delete it3->second;
}
+ globaldata->setSharedFile(filename);
return 0;
}
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; }
class SharedCommand : public Command {
public:
- SharedCommand();
+ SharedCommand(string);
~SharedCommand();
int execute();
void help() {}
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;
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);
//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);
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();
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;
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);
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);
}
}
- outputFileName = ((getRootName(globaldata->inputFileName)) + "shared.summary");
+ outputFileName = outputDir + getRootName(getSimpleName(globaldata->inputFileName)) + "shared.summary";
openOutputFile(outputFileName, outputFileHandle);
mult = false;
}
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*>);
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;
+ }
}
}
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; }
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) {
makeSimsDist();
//create a new filename
- outputFile = getRootName(globaldata->inputFileName) + "tre";
+ outputFile = outputDir + getRootName(getSimpleName(globaldata->inputFileName)) + "tre";
createTree();
mothurOut("Tree complete. "); mothurOutEndLine();
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++) {
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.
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)));
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...
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;
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() == '>'){
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));
}
}
}
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;
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);
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);
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();
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);
/***********************************************************/
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);
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;
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);
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);
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();
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
//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);
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
//**********************************************************************************************************************
-Venn::Venn(){
+Venn::Venn(string o) : outputDir(o) {
try {
globaldata = GlobalData::getInstance();
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);
//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
//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
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") {
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);
class Venn {
public:
- Venn();
+ Venn(string);
~Venn(){};
void getPic(SAbundVector*, vector<Calculator*>);
private:
GlobalData* globaldata;
Calculator* singleCalc;
- string groupComb;
+ string groupComb, outputDir;
ofstream outsvg;
};
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);
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...
}
}
- venn = new Venn();
+ venn = new Venn(outputDir);
}
}
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;