5 * Created by Sarah Westcott on 1/21/09.
6 * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
10 #include "deconvolutecommand.h"
12 /**************************************************************************************/
13 DeconvoluteCommand::DeconvoluteCommand(string option) {
17 //allow user to run help
18 if(option == "help") { help(); abort = true; }
21 //valid paramters for this command
22 string Array[] = {"fasta", "name"};
23 vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
25 OptionParser parser(option);
26 map<string,string> parameters = parser.getParameters();
28 ValidParameters validParameter;
30 //check to make sure all parameters are valid for command
31 for (map<string, string>::iterator it = parameters.begin(); it != parameters.end(); it++) {
32 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
35 //check for required parameters
36 inFastaName = validParameter.validFile(parameters, "fasta", true);
37 if (inFastaName == "not open") { abort = true; }
38 else if (inFastaName == "not found") { inFastaName = ""; cout << "fasta is a required parameter for the unique.seqs command." << endl; abort = true; }
40 oldNameMapFName = validParameter.validFile(parameters, "name", true);
41 if (oldNameMapFName == "not open") { abort = true; }
42 else if (oldNameMapFName == "not found"){ oldNameMapFName = ""; }
47 cout << "Standard Error: " << e.what() << " has occurred in the DeconvoluteCommand class Function DeconvoluteCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
51 cout << "An unknown error has occurred in the DeconvoluteCommand class function DeconvoluteCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
55 //**********************************************************************************************************************
57 void DeconvoluteCommand::help(){
59 cout << "The unique.seqs command reads a fastafile and creates a namesfile." << "\n";
60 cout << "It creates a file where the first column is the groupname and the second column is a list of sequence names who have the same sequence. " << "\n";
61 cout << "If the sequence is unique the second column will just contain its name. " << "\n";
62 cout << "The unique.seqs command parameter is fasta and it is required." << "\n";
63 cout << "The unique.seqs command should be in the following format: " << "\n";
64 cout << "unique.seqs(fasta=yourFastaFile) " << "\n";
67 cout << "Standard Error: " << e.what() << " has occurred in the DeconvoluteCommand class Function help. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
71 cout << "An unknown error has occurred in the DeconvoluteCommand class function help. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
76 /**************************************************************************************/
77 int DeconvoluteCommand::execute() {
80 if (abort == true) { return 0; }
82 //prepare filenames and open files
83 string outNameFile = (getRootName(inFastaName) + "names");
84 string outFastaFile = (getRootName(inFastaName) + "unique" + getExtension(inFastaName));
88 if(oldNameMapFName == "") { fastamap.readFastaFile(inFastaName); }
89 else { fastamap.readFastaFile(inFastaName, oldNameMapFName); }
91 fastamap.printCondensedFasta(outFastaFile);
92 fastamap.printNamesFile(outNameFile);
97 cout << "Standard Error: " << e.what() << " has occurred in the DeconvoluteCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
101 cout << "An unknown error has occurred in the DeconvoluteCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
105 /**************************************************************************************/