]> git.donarmstrong.com Git - mothur.git/blob - deconvolutecommand.cpp
added logfile feature
[mothur.git] / deconvolutecommand.cpp
1 /*
2  *  deconvolute.cpp
3  *  Mothur
4  *
5  *  Created by Sarah Westcott on 1/21/09.
6  *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
7  *
8  */
9
10 #include "deconvolutecommand.h"
11
12 /**************************************************************************************/
13 DeconvoluteCommand::DeconvoluteCommand(string option) { 
14         try {
15                 abort = false;
16                 
17                 //allow user to run help
18                 if(option == "help") { help(); abort = true; }
19                 
20                 else {
21                         //valid paramters for this command
22                         string Array[] =  {"fasta", "name"};
23                         vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
24                         
25                         OptionParser parser(option);
26                         map<string,string> parameters = parser.getParameters();
27                         
28                         ValidParameters validParameter;
29                 
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;  }
33                         }
34                         
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 = ""; mothurOut("fasta is a required parameter for the unique.seqs command."); mothurOutEndLine(); abort = true;  }  
39                         
40                         oldNameMapFName = validParameter.validFile(parameters, "name", true);
41                         if (oldNameMapFName == "not open") { abort = true; }
42                         else if (oldNameMapFName == "not found"){       oldNameMapFName = "";   }
43                 }
44
45         }
46         catch(exception& e) {
47                 errorOut(e, "DeconvoluteCommand", "DeconvoluteCommand");
48                 exit(1);
49         }
50 }
51 //**********************************************************************************************************************
52
53 void DeconvoluteCommand::help(){
54         try {
55                 mothurOut("The unique.seqs command reads a fastafile and creates a namesfile.\n");
56                 mothurOut("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");
57                 mothurOut("If the sequence is unique the second column will just contain its name. \n");
58                 mothurOut("The unique.seqs command parameter is fasta and it is required.\n");
59                 mothurOut("The unique.seqs command should be in the following format: \n");
60                 mothurOut("unique.seqs(fasta=yourFastaFile) \n");       
61         }
62         catch(exception& e) {
63                 errorOut(e, "DeconvoluteCommand", "help");
64                 exit(1);
65         }
66 }
67
68 /**************************************************************************************/
69 int DeconvoluteCommand::execute() {     
70         try {
71                 
72                 if (abort == true) { return 0; }
73
74                 //prepare filenames and open files
75                 string outNameFile = (getRootName(inFastaName) + "names");
76                 string outFastaFile = (getRootName(inFastaName) + "unique" + getExtension(inFastaName));
77                 
78                 FastaMap fastamap;
79         
80                 if(oldNameMapFName == "")       {       fastamap.readFastaFile(inFastaName);                                    }
81                 else                                            {       fastamap.readFastaFile(inFastaName, oldNameMapFName);   }
82                 
83                 fastamap.printCondensedFasta(outFastaFile);
84                 fastamap.printNamesFile(outNameFile);
85                 
86                 return 0;
87         }
88         catch(exception& e) {
89                 errorOut(e, "DeconvoluteCommand", "execute");
90                 exit(1);
91         }
92 }
93 /**************************************************************************************/