]> git.donarmstrong.com Git - mothur.git/blob - secondarystructurecommand.cpp
adding more error checking for list and group files. outputs missing.names or missin...
[mothur.git] / secondarystructurecommand.cpp
1 /*
2  *  secondarystructurecommand.cpp
3  *  Mothur
4  *
5  *  Created by westcott on 9/18/09.
6  *  Copyright 2009 Schloss Lab. All rights reserved.
7  *
8  */
9
10 #include "secondarystructurecommand.h"
11 #include "sequence.hpp"
12
13 //**********************************************************************************************************************
14
15 AlignCheckCommand::AlignCheckCommand(string option){
16         try {
17                 abort = false;
18                 
19                 //allow user to run help
20                 if(option == "help") { help(); abort = true; }
21                 
22                 else {
23                         //valid paramters for this command
24                         string Array[] =  {"fasta","map"};
25                         vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
26                         
27                         OptionParser parser(option);
28                         map<string,string> parameters = parser.getParameters();
29                         
30                         ValidParameters validParameter;
31                         
32                         //check to make sure all parameters are valid for command
33                         for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
34                                 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
35                         }
36                         
37                         //check for required parameters
38                         mapfile = validParameter.validFile(parameters, "map", true);
39                         if (mapfile == "not open") { abort = true; }
40                         else if (mapfile == "not found") {  mapfile = "";  mothurOut("You must provide an map file."); mothurOutEndLine(); abort = true; }      
41                         
42                         fastafile = validParameter.validFile(parameters, "fasta", true);
43                         if (fastafile == "not open") { abort = true; }
44                         else if (fastafile == "not found") {  fastafile = "";  mothurOut("You must provide an fasta file."); mothurOutEndLine(); abort = true;  }       
45                         
46                 }
47
48         }
49         catch(exception& e) {
50                 errorOut(e, "AlignCheckCommand", "RemoveSeqsCommand");
51                 exit(1);
52         }
53 }
54 //**********************************************************************************************************************
55
56 void AlignCheckCommand::help(){
57         try {
58                 //mothurOut("The remove.seqs command reads an .accnos file and one of the following file types: fasta, name, group or alignreport file.\n");
59                 //mothurOut("It outputs a file containing the sequences NOT in the .accnos file.\n");
60                 //mothurOut("The remove.seqs command parameters are accnos, fasta, name, group and alignreport.  You must provide accnos and one of the other parameters.\n");
61                 //mothurOut("The remove.seqs command should be in the following format: remove.seqs(accnos=yourAccnos, fasta=yourFasta).\n");
62                 //mothurOut("Example remove.seqs(accnos=amazon.accnos, fasta=amazon.fasta).\n");
63                 //mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n\n");
64         }
65         catch(exception& e) {
66                 errorOut(e, "AlignCheckCommand", "help");
67                 exit(1);
68         }
69 }
70
71 //**********************************************************************************************************************
72
73 int AlignCheckCommand::execute(){
74         try {
75                 
76                 if (abort == true) { return 0; }
77                 
78                 //get secondary structure info.
79                 readMap();
80                 
81         
82                 
83                 return 0;               
84         }
85
86         catch(exception& e) {
87                 errorOut(e, "AlignCheckCommand", "execute");
88                 exit(1);
89         }
90 }
91 //**********************************************************************************************************************
92 void AlignCheckCommand::readMap(){
93         try {
94                         
95                 structMap.resize(1, 0);
96                 ifstream in;
97                 
98                 openInputFile(mapfile, in);
99                 
100                 while(!in.eof()){
101                         int position;
102                         in >> position;
103                         structMap.push_back(position);  
104                         gobble(in);
105                 }
106                 in.close();
107                 
108                 seqLength = structMap.size();
109                 
110                 
111                 //check you make sure is structMap[10] = 380 then structMap[380] = 10.
112                 for(int i=0;i<seqLength;i++){
113                         if(structMap[i] != 0){
114                                 if(structMap[structMap[i]] != i){
115                                         mothurOut("Your map file contains an error:  line " + toString(i) + " does not match line " + toString(structMap[i]) + "."); mothurOutEndLine();
116                                 }
117                         }
118                 }
119                 
120                 
121         }
122         catch(exception& e) {
123                 errorOut(e, "AlignCheckCommand", "readFasta");
124                 exit(1);
125         }
126 }
127
128 //**********************************************************************************************************************