2 * clearcutcommand.cpp
\r
5 * Created by westcott on 5/11/10.
\r
6 * Copyright 2010 Schloss Lab. All rights reserved.
\r
10 #include "clearcutcommand.h"
\r
12 /**************************************************************************************/
\r
13 ClearcutCommand::ClearcutCommand(string option) {
\r
17 //allow user to run help
\r
18 if(option == "help") { help(); abort = true; }
\r
21 //valid paramters for this command
\r
22 string Array[] = {"fasta","phylip","version","verbose","quiet","seed","norandom","shuffle","neighbor","expblen",
\r
23 "expdist","ntrees","matrixout","stdout","kimura","jukes","protein","DNA","stdin","outputdir","inputdir"};
\r
24 vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
\r
26 OptionParser parser(option);
\r
27 map<string,string> parameters = parser.getParameters();
\r
29 ValidParameters validParameter;
\r
30 map<string, string>::iterator it;
\r
32 //check to make sure all parameters are valid for command
\r
33 for (it = parameters.begin(); it != parameters.end(); it++) {
\r
34 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
\r
37 //if the user changes the input directory command factory will send this info to us in the output parameter
\r
38 string inputDir = validParameter.validFile(parameters, "inputdir", false);
\r
39 if (inputDir == "not found"){ inputDir = ""; }
\r
42 it = parameters.find("fasta");
\r
43 //user has given a template file
\r
44 if(it != parameters.end()){
\r
45 path = hasPath(it->second);
\r
46 //if the user has not given a path then, add inputdir. else leave path alone.
\r
47 if (path == "") { parameters["fasta"] = inputDir + it->second; }
\r
50 it = parameters.find("phylip");
\r
51 //user has given a template file
\r
52 if(it != parameters.end()){
\r
53 path = hasPath(it->second);
\r
54 //if the user has not given a path then, add inputdir. else leave path alone.
\r
55 if (path == "") { parameters["phylip"] = inputDir + it->second; }
\r
59 //check for required parameters
\r
60 fastafile = validParameter.validFile(parameters, "fasta", true);
\r
61 if (fastafile == "not open") { fastafile = ""; abort = true; }
\r
62 else if (fastafile == "not found") { fastafile = ""; }
\r
63 else { inputFile = fastafile; }
\r
65 phylipfile = validParameter.validFile(parameters, "phylip", true);
\r
66 if (phylipfile == "not open") { phylipfile = ""; abort = true; }
\r
67 else if (phylipfile == "not found") { phylipfile = ""; }
\r
68 else { inputFile = phylipfile; }
\r
70 if ((phylipfile == "") && (fastafile == "")) { m->mothurOut("You must provide either a phylip formatted distance matrix or an aligned fasta file."); m->mothurOutEndLine(); abort=true; }
\r
71 if ((phylipfile != "") && (fastafile != "")) { m->mothurOut("You must provide either a phylip formatted distance matrix or an aligned fasta file, not BOTH."); m->mothurOutEndLine(); abort=true; }
\r
74 //if the user changes the output directory command factory will send this info to us in the output parameter
\r
75 outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; }
\r
78 temp = validParameter.validFile(parameters, "version", false); if (temp == "not found"){ temp = "F"; }
\r
79 version = isTrue(temp);
\r
81 temp = validParameter.validFile(parameters, "verbose", false); if (temp == "not found"){ temp = "F"; }
\r
82 verbose = isTrue(temp);
\r
84 temp = validParameter.validFile(parameters, "quiet", false); if (temp == "not found"){ temp = "F"; }
\r
85 quiet = isTrue(temp);
\r
87 seed = validParameter.validFile(parameters, "seed", false); if (seed == "not found"){ seed = "*"; }
\r
89 temp = validParameter.validFile(parameters, "norandom", false); if (temp == "not found"){ temp = "F"; }
\r
90 norandom = isTrue(temp);
\r
92 temp = validParameter.validFile(parameters, "shuffle", false); if (temp == "not found"){ temp = "F"; }
\r
93 shuffle = isTrue(temp);
\r
95 temp = validParameter.validFile(parameters, "neighbor", false); if (temp == "not found"){ temp = "F"; }
\r
96 neighbor = isTrue(temp);
\r
98 temp = validParameter.validFile(parameters, "stdin", false); if (temp == "not found"){ temp = "F"; }
\r
99 stdinWanted = isTrue(temp);
\r
101 temp = validParameter.validFile(parameters, "DNA", false); if (temp == "not found"){ temp = "F"; }
\r
102 DNA = isTrue(temp);
\r
104 temp = validParameter.validFile(parameters, "protein", false); if (temp == "not found"){ temp = "F"; }
\r
105 protein = isTrue(temp);
\r
107 temp = validParameter.validFile(parameters, "jukes", false); if (temp == "not found"){ temp = "F"; }
\r
108 jukes = isTrue(temp);
\r
110 temp = validParameter.validFile(parameters, "kimura", false); if (temp == "not found"){ temp = "F"; }
\r
111 kimura = isTrue(temp);
\r
113 temp = validParameter.validFile(parameters, "stdout", false); if (temp == "not found"){ temp = "F"; }
\r
114 stdoutWanted = isTrue(temp);
\r
116 matrixout = validParameter.validFile(parameters, "matrixout", false); if (matrixout == "not found"){ matrixout = ""; }
\r
118 ntrees = validParameter.validFile(parameters, "ntrees", false); if (ntrees == "not found"){ ntrees = "1"; }
\r
120 temp = validParameter.validFile(parameters, "expblen", false); if (temp == "not found"){ temp = "F"; }
\r
121 expblen = isTrue(temp);
\r
123 temp = validParameter.validFile(parameters, "expdist", false); if (temp == "not found"){ temp = "F"; }
\r
124 expdist = isTrue(temp);
\r
126 if ((fastafile != "") && ((!DNA) && (!protein))) { m->mothurOut("You must specify the type of sequences you are using: DNA or protein"); m->mothurOutEndLine(); abort=true; }
\r
130 catch(exception& e) {
\r
131 m->errorOut(e, "ClearcutCommand", "ClearcutCommand");
\r
135 //**********************************************************************************************************************
\r
137 void ClearcutCommand::help(){
\r
139 m->mothurOut("The clearcut command interfaces mothur with the clearcut program written by Initiative for Bioinformatics and Evolutionary Studies (IBEST) at the University of Idaho.\n");
\r
140 m->mothurOut("For more information about clearcut refer to http://bioinformatics.hungry.com/clearcut/ \n");
\r
141 m->mothurOut("The clearcut executable must be in a folder called clearcut in the same folder as your mothur executable, similar to mothur's requirements for using blast. \n");
\r
142 m->mothurOut("The clearcut command parameters are phylip, fasta, version, verbose, quiet, seed, norandom, shuffle, neighbor, expblen, expdist, ntrees, matrixout, stdoutWanted, kimura, jukes, protein, DNA, stdinWanted. \n");
\r
143 m->mothurOut("The phylip parameter allows you to enter your phylip formatted distance matrix. \n");
\r
144 m->mothurOut("The fasta parameter allows you to enter your aligned fasta file, if you enter a fastafile you specify if the sequences are DNA or protein using the DNA or protein parameters. \n");
\r
146 m->mothurOut("The version parameter prints out the version of clearcut you are using, default=F. \n");
\r
147 m->mothurOut("The verbose parameter prints out more output from clearcut, default=F. \n");
\r
148 m->mothurOut("The quiet parameter turns on silent operation mode, default=F. \n");
\r
149 m->mothurOut("The seed parameter allows you to explicitly set the PRNG seed to a specific value. \n");
\r
150 m->mothurOut("The norandom parameter allows you to attempt joins deterministically, default=F. \n");
\r
151 m->mothurOut("The shuffle parameter allows you to randomly shuffle the distance matrix, default=F. \n");
\r
152 m->mothurOut("The neighbor parameter allows you to use traditional Neighbor-Joining algorithm, default=F. \n");
\r
154 m->mothurOut("The stdinWanted parameter reads input from STDIN, default=F. \n");
\r
155 m->mothurOut("The DNA parameter allows you to indicate your fasta file contains DNA sequences, default=F. \n");
\r
156 m->mothurOut("The protein parameter allows you to indicate your fasta file contains protein sequences, default=F. \n");
\r
158 m->mothurOut("The stdoutWanted parameter outputs your tree to STDOUT, default=F. \n");
\r
159 m->mothurOut("The matrixout parameter allows you to specify a filename to output a distance matrix to. \n");
\r
160 m->mothurOut("The ntrees parameter allows you to specify the number of output trees, default=1. \n");
\r
161 m->mothurOut("The expblen parameter allows you to use exponential notation for branch lengths, default=F. \n");
\r
162 m->mothurOut("The expdist parameter allows you to use exponential notation for distance outputs, default=F. \n");
\r
164 m->mothurOut("The clearcut command should be in the following format: \n");
\r
165 m->mothurOut("clearcut(phylip=yourDistanceFile) \n");
\r
166 m->mothurOut("Example: clearcut(phylip=abrecovery.phylip.dist) \n");
\r
169 catch(exception& e) {
\r
170 m->errorOut(e, "ClearcutCommand", "help");
\r
175 /**************************************************************************************/
\r
176 int ClearcutCommand::execute() {
\r
179 if (abort == true) { return 0; }
\r
182 string outputName = outputDir + getRootName(getSimpleName(inputFile)) + "tre";
\r
184 //get location of clearcut
\r
185 GlobalData* globaldata = GlobalData::getInstance();
\r
186 string path = globaldata->argv;
\r
187 path = path.substr(0, (path.find_last_of('m')));
\r
189 string clearcutCommand = "";
\r
190 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
\r
191 clearcutCommand = path + "clearcut/clearcut ";
\r
193 clearcutCommand = path + "clearcut\\clearcut ";
\r
196 //you gave us a distance matrix
\r
197 if (phylipfile != "") { clearcutCommand += "--distance "; }
\r
199 //you gave us a fastafile
\r
200 if (fastafile != "") { clearcutCommand += "--alignment "; }
\r
202 if (version) { clearcutCommand += "--version "; }
\r
203 if (verbose) { clearcutCommand += "--verbose "; }
\r
204 if (quiet) { clearcutCommand += "--quiet "; }
\r
205 if (seed != "*") { clearcutCommand += "--seed=" + seed + " "; }
\r
206 if (norandom) { clearcutCommand += "--norandom "; }
\r
207 if (shuffle) { clearcutCommand += "--shuffle "; }
\r
208 if (neighbor) { clearcutCommand += "--neighbor "; }
\r
210 if (stdinWanted) { clearcutCommand += "--stdin "; }
\r
212 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
\r
213 clearcutCommand += "--in=" + inputFile + " "; }
\r
215 clearcutCommand += "--in=\"" + inputFile + "\" "; }
\r
217 if (stdoutWanted) { clearcutCommand += "--stdout "; }
\r
219 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
\r
220 clearcutCommand += "--out=" + outputName + " "; }
\r
222 clearcutCommand += "--out=\"" + outputName + "\" "; }
\r
225 if (DNA) { clearcutCommand += "--DNA "; }
\r
226 if (protein) { clearcutCommand += "--protein "; }
\r
227 if (jukes) { clearcutCommand += "--jukes "; }
\r
228 if (kimura) { clearcutCommand += "--kimura "; }
\r
229 if (matrixout != "") { clearcutCommand += "--matrixout=" + matrixout + " "; }
\r
230 if (ntrees != "1") { clearcutCommand += "--ntrees=" + ntrees + " "; }
\r
231 if (expblen) { clearcutCommand += "--expblen "; }
\r
232 if (expdist) { clearcutCommand += "--expdist "; }
\r
235 system(clearcutCommand.c_str());
\r
237 if (!stdoutWanted) {
\r
238 m->mothurOutEndLine();
\r
239 m->mothurOut("Output File Names: "); m->mothurOutEndLine();
\r
240 m->mothurOut(outputName); m->mothurOutEndLine();
\r
241 m->mothurOutEndLine();
\r
246 catch(exception& e) {
\r
247 m->errorOut(e, "ClearcutCommand", "execute");
\r
251 /**************************************************************************************/
\r