]> git.donarmstrong.com Git - mothur.git/blob - makegroupcommand.cpp
modified trim.seqs to account for primers of different lengths
[mothur.git] / makegroupcommand.cpp
1 /*
2  *  makegroupcommand.cpp
3  *  Mothur
4  *
5  *  Created by westcott on 5/7/10.
6  *  Copyright 2010 Schloss Lab. All rights reserved.
7  *
8  */
9
10 #include "makegroupcommand.h"
11
12 //**********************************************************************************************************************
13
14 MakeGroupCommand::MakeGroupCommand(string option)  {
15         try {
16                 
17                 abort = false;
18         
19                 //allow user to run help
20                 if(option == "help") { help(); abort = true; }
21                 
22                 else {
23                         
24                         //valid paramters for this command
25                         string AlignArray[] =  {"fasta","groups","outputdir","inputdir"};
26                         vector<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
27                         
28                         OptionParser parser(option);
29                         map<string, string> parameters = parser.getParameters(); 
30                         
31                         ValidParameters validParameter;
32                         map<string, string>::iterator it;
33                         
34                         //check to make sure all parameters are valid for command
35                         for (it = parameters.begin(); it != parameters.end(); it++) { 
36                                 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
37                         }
38
39                         //if the user changes the output directory command factory will send this info to us in the output parameter 
40                         outputDir = validParameter.validFile(parameters, "outputdir", false);           if (outputDir == "not found"){  outputDir = "";         }
41                         
42
43                         //if the user changes the input directory command factory will send this info to us in the output parameter 
44                         string inputDir = validParameter.validFile(parameters, "inputdir", false);              
45                         if (inputDir == "not found"){   inputDir = "";          }
46                         
47
48                         fastaFileName = validParameter.validFile(parameters, "fasta", false);
49                         if (fastaFileName == "not found") { m->mothurOut("fasta is a required parameter for the make.group command."); m->mothurOutEndLine(); abort = true;  }
50                         else { 
51                                 splitAtDash(fastaFileName, fastaFileNames);
52                                 
53                                 //go through files and make sure they are good, if not, then disregard them
54                                 for (int i = 0; i < fastaFileNames.size(); i++) {
55                                         if (inputDir != "") {
56                                                 string path = hasPath(fastaFileNames[i]);
57                                                 //if the user has not given a path then, add inputdir. else leave path alone.
58                                                 if (path == "") {       fastaFileNames[i] = inputDir + fastaFileNames[i];               }
59                                         }
60         
61                                         int ableToOpen;
62                                         ifstream in;
63                                         
64                                         ableToOpen = openInputFile(fastaFileNames[i], in);
65                                         in.close();
66
67                                         if (ableToOpen == 1) { 
68                                                 m->mothurOut(fastaFileNames[i] + " will be disregarded."); m->mothurOutEndLine(); 
69                                                 //erase from file list
70                                                 fastaFileNames.erase(fastaFileNames.begin()+i);
71                                                 i--;
72                                         }
73                                         
74                                 }
75                                 
76                                 //make sure there is at least one valid file left
77                                 if (fastaFileNames.size() == 0) { m->mothurOut("no valid files."); m->mothurOutEndLine(); abort = true; }
78                         }
79                 
80                 }
81                 
82         }
83         catch(exception& e) {
84                 m->errorOut(e, "MakeGroupCommand", "MakeGroupCommand");
85                 exit(1);
86         }
87 }
88
89 //**********************************************************************************************************************
90
91 MakeGroupCommand::~MakeGroupCommand(){  }
92
93 //**********************************************************************************************************************
94
95 void MakeGroupCommand::help(){
96         try {
97                 m->mothurOut("The align.seqs command reads a file containing sequences and creates an alignment file and a report file.\n");
98                 m->mothurOut("The align.seqs command parameters are template, candidate, search, ksize, align, match, mismatch, gapopen and gapextend.\n");
99                 m->mothurOut("The template and candidate parameters are required. You may enter multiple fasta files by separating their names with dashes. ie. fasta=abrecovery.fasta-amzon.fasta \n");
100                 m->mothurOut("The search parameter allows you to specify the method to find most similar template.  Your options are: suffix, kmer and blast. The default is kmer.\n");
101                 m->mothurOut("The align parameter allows you to specify the alignment method to use.  Your options are: gotoh, needleman, blast and noalign. The default is needleman.\n");
102                 m->mothurOut("The ksize parameter allows you to specify the kmer size for finding most similar template to candidate.  The default is 8.\n");
103                 m->mothurOut("The match parameter allows you to specify the bonus for having the same base. The default is 1.0.\n");
104                 m->mothurOut("The mistmatch parameter allows you to specify the penalty for having different bases.  The default is -1.0.\n");
105                 m->mothurOut("The gapopen parameter allows you to specify the penalty for opening a gap in an alignment. The default is -2.0.\n");
106                 m->mothurOut("The gapextend parameter allows you to specify the penalty for extending a gap in an alignment.  The default is -1.0.\n");
107                 m->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");
108                 m->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");
109                 m->mothurOut("If the flip parameter is set to true the reverse complement of the sequence is aligned and the better alignment is reported.\n");
110                 m->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");
111                 m->mothurOut("The align.seqs command should be in the following format: \n");
112                 m->mothurOut("align.seqs(template=yourTemplateFile, candidate=yourCandidateFile, align=yourAlignmentMethod, search=yourSearchmethod, ksize=yourKmerSize, match=yourMatchBonus, mismatch=yourMismatchpenalty, gapopen=yourGapopenPenalty, gapextend=yourGapExtendPenalty) \n");
113                 m->mothurOut("Example align.seqs(candidate=candidate.fasta, template=core.filtered, align=kmer, search=gotoh, ksize=8, match=2.0, mismatch=3.0, gapopen=-2.0, gapextend=-1.0)\n");
114                 m->mothurOut("Note: No spaces between parameter labels (i.e. candidate), '=' and parameters (i.e.yourFastaFile).\n\n");
115         }
116         catch(exception& e) {
117                 m->errorOut(e, "MakeGroupCommand", "help");
118                 exit(1);
119         }
120 }
121
122
123 //**********************************************************************************************************************
124
125 int MakeGroupCommand::execute(){
126         try {
127                 if (abort == true) {    return 0;       }
128                 
129                 
130                 m->mothurOutEndLine();
131                 m->mothurOut("Output File Names: "); m->mothurOutEndLine();
132                 //for (int i = 0; i < outputNames.size(); i++) {        m->mothurOut(outputNames[i]); m->mothurOutEndLine();    }
133                 m->mothurOutEndLine();
134
135                 return 0;
136         }
137         catch(exception& e) {
138                 m->errorOut(e, "MakeGroupCommand", "execute");
139                 exit(1);
140         }
141 }
142