A72B3A63118B37FD004B9F8D /* phylodiversitycommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = phylodiversitycommand.cpp; sourceTree = "<group>"; };
A72B3A7B118B4D1B004B9F8D /* phylodiversity.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = phylodiversity.h; sourceTree = "<group>"; };
A72B3A7C118B4D1B004B9F8D /* phylodiversity.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = phylodiversity.cpp; sourceTree = "<group>"; };
+ A73953DA11987ED100B0B160 /* chopseqscommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = chopseqscommand.h; sourceTree = "<group>"; };
+ A73953DB11987ED100B0B160 /* chopseqscommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = chopseqscommand.cpp; sourceTree = "<group>"; };
A747E79B1163442A00FB9042 /* chimeracheckcommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = chimeracheckcommand.h; sourceTree = "<group>"; };
A747E79C1163442A00FB9042 /* chimeracheckcommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = chimeracheckcommand.cpp; sourceTree = "<group>"; };
A747E81C116365E000FB9042 /* chimeraslayercommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = chimeraslayercommand.h; sourceTree = "<group>"; };
A7DA2007113FECD400BF472F /* bootstrapsharedcommand.cpp */,
A7DA2008113FECD400BF472F /* bootstrapsharedcommand.h */,
A7DA2017113FECD400BF472F /* chimeraseqscommand.cpp */,
+ A78434881162224F00100BE0 /* chimeraccodecommand.h */,
A7DA2018113FECD400BF472F /* chimeraseqscommand.h */,
A7825502116519F70002E2DD /* chimerabellerophoncommand.h */,
A7825503116519F70002E2DD /* chimerabellerophoncommand.cpp */,
A747E79B1163442A00FB9042 /* chimeracheckcommand.h */,
A747E79C1163442A00FB9042 /* chimeracheckcommand.cpp */,
- A78434881162224F00100BE0 /* chimeraccodecommand.h */,
A78434891162224F00100BE0 /* chimeraccodecommand.cpp */,
A78254461164D7790002E2DD /* chimerapintailcommand.h */,
A78254471164D7790002E2DD /* chimerapintailcommand.cpp */,
A747E81C116365E000FB9042 /* chimeraslayercommand.h */,
A747E81D116365E000FB9042 /* chimeraslayercommand.cpp */,
+ A73953DA11987ED100B0B160 /* chopseqscommand.h */,
+ A73953DB11987ED100B0B160 /* chopseqscommand.cpp */,
A7DA201E113FECD400BF472F /* classifyseqscommand.h */,
A7DA201D113FECD400BF472F /* classifyseqscommand.cpp */,
A7DA2021113FECD400BF472F /* clustercommand.cpp */,
--- /dev/null
+/*
+ * chopseqscommand.cpp
+ * Mothur
+ *
+ * Created by westcott on 5/10/10.
+ * Copyright 2010 Schloss Lab. All rights reserved.
+ *
+ */
+
+#include "chopseqscommand.h"
+#include "sequence.hpp"
+
+//**********************************************************************************************************************
+
+ChopSeqsCommand::ChopSeqsCommand(string option) {
+ try {
+ abort = false;
+
+ //allow user to run help
+ if(option == "help") { help(); abort = true; }
+
+ else {
+ //valid paramters for this command
+ string Array[] = {"fasta","end","outputdir","inputdir"};
+ vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+
+ OptionParser parser(option);
+ map<string,string> parameters = parser.getParameters();
+
+ ValidParameters validParameter;
+ map<string,string>::iterator it;
+
+ //check to make sure all parameters are valid for command
+ for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) {
+ if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
+ }
+
+ //if the user changes the output directory command factory will send this info to us in the output parameter
+ outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; }
+
+ //if the user changes the input directory command factory will send this info to us in the output parameter
+ string inputDir = validParameter.validFile(parameters, "inputdir", false);
+ if (inputDir == "not found"){ inputDir = ""; }
+ else {
+ string path;
+ it = parameters.find("fasta");
+ //user has given a template file
+ if(it != parameters.end()){
+ path = hasPath(it->second);
+ //if the user has not given a path then, add inputdir. else leave path alone.
+ if (path == "") { parameters["fasta"] = inputDir + it->second; }
+ }
+ }
+
+ //check for required parameters
+ fastafile = validParameter.validFile(parameters, "fasta", true);
+ if (fastafile == "not open") { abort = true; }
+ else if (fastafile == "not found") { m->mothurOut("You must provide a fasta file."); m->mothurOutEndLine(); abort = true; }
+
+ string temp = validParameter.validFile(parameters, "end", false);
+ if (temp == "not found") { m->mothurOut("You must provide an end for the chops.seqs command."); m->mothurOutEndLine(); abort = true; }
+ else {
+ convert(temp, end);
+ if (end < 0) { m->mothurOut("End must be positive."); m->mothurOutEndLine(); abort = true; }
+ }
+
+ }
+
+ }
+ catch(exception& e) {
+ m->errorOut(e, "ChopSeqsCommand", "ChopSeqsCommand");
+ exit(1);
+ }
+}
+//**********************************************************************************************************************
+
+void ChopSeqsCommand::help(){
+ try {
+ m->mothurOut("The chop.seqs command reads a fasta file and outputs a .chop.fasta with sequences trimmed to the end position.\n");
+ m->mothurOut("The chop.seqs command parameters are fasta and end, both are required.\n");
+ m->mothurOut("The chop.seqs command should be in the following format: chop.seqs(fasta=yourFasta, end=yourEnd).\n");
+ m->mothurOut("Example chop.seqs(fasta=amazon.fasta, end=200).\n");
+ m->mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n\n");
+ }
+ catch(exception& e) {
+ m->errorOut(e, "ChopSeqsCommand", "help");
+ exit(1);
+ }
+}
+
+//**********************************************************************************************************************
+
+int ChopSeqsCommand::execute(){
+ try {
+
+ if (abort == true) { return 0; }
+
+ string outputFileName = outputDir + getRootName(getSimpleName(fastafile)) + "chop.fasta";
+
+ ofstream out;
+ openOutputFile(outputFileName, out);
+
+ ifstream in;
+ openInputFile(fastafile, in);
+
+ while (!in.eof()) {
+
+ Sequence seq(in, "no align");
+
+ if (m->control_pressed) { in.close(); out.close(); remove(outputFileName.c_str()); return 0; }
+
+ if (seq.getName() != "") {
+ string temp = seq.getUnaligned();
+
+ //output sequence name
+ out << ">" << seq.getName() << endl;
+
+ //if needed trim sequence
+ if (temp.length() > end) { temp = temp.substr(0, end); }
+
+ //output trimmed sequence
+ out << temp << endl;
+ }
+ }
+ in.close();
+ out.close();
+
+ m->mothurOutEndLine();
+ m->mothurOut("Output File Name: "); m->mothurOutEndLine();
+ m->mothurOut(outputFileName); m->mothurOutEndLine();
+ m->mothurOutEndLine();
+
+ return 0;
+ }
+
+ catch(exception& e) {
+ m->errorOut(e, "ChopSeqsCommand", "execute");
+ exit(1);
+ }
+}
+
+//**********************************************************************************************************************
+
+
--- /dev/null
+#ifndef CHOPSEQSCOMMAND_H
+#define CHOPSEQSCOMMAND_H
+
+/*
+ * chopseqscommand.h
+ * Mothur
+ *
+ * Created by westcott on 5/10/10.
+ * Copyright 2010 Schloss Lab. All rights reserved.
+ *
+ */
+
+
+#include "command.hpp"
+
+class ChopSeqsCommand : public Command {
+
+ public:
+
+ ChopSeqsCommand(string);
+ ~ChopSeqsCommand(){};
+ int execute();
+ void help();
+
+ private:
+ string fastafile, outputDir;
+ bool abort;
+ int end;
+};
+
+#endif
+
+
#include "setlogfilecommand.h"
#include "phylodiversitycommand.h"
#include "makegroupcommand.h"
+#include "chopseqscommand.h"
/*******************************************************/
commands["set.logfile"] = "set.logfile";
commands["phylo.diversity"] = "phylo.diversity";
commands["make.group"] = "make.group";
+ commands["chop.seqs"] = "chop.seqs";
commands["classify.seqs"] = "MPIEnabled";
commands["dist.seqs"] = "MPIEnabled";
commands["filter.seqs"] = "MPIEnabled";
else if(commandName == "parse.sff") { command = new ParseSFFCommand(optionString); }
else if(commandName == "phylo.diversity") { command = new PhyloDiversityCommand(optionString); }
else if(commandName == "make.group") { command = new MakeGroupCommand(optionString); }
+ else if(commandName == "chop.seqs") { command = new ChopSeqsCommand(optionString); }
else { command = new NoCommand(optionString); }
return command;
int okay = 1;
if (outputDir != "") { okay++; }
+ if (inputDir != "") { okay++; }
if (parameters.size() > okay) { m->mothurOut("You may only enter one file."); m->mothurOutEndLine(); abort = true; }
}
./globaldata.o\\r
./groupmap.o\\r
./helpcommand.o\
- ./makegroupcommand.o\\r
+ ./makegroupcommand.o\
+ ./chopseqscommand.o\\r
./inputdata.o\\r
./jackknife.o\\r
./kmer.o\\r
./globaldata.o\\r
./groupmap.o\\r
./helpcommand.o\
- ./makegroupcommand.o\\r
+ ./makegroupcommand.o\
+ ./chopseqscommand.o\\r
./inputdata.o\\r
./jackknife.o\\r
./kmer.o\\r
./globaldata.o\\r
./groupmap.o\\r
./helpcommand.o\
- ./makegroupcommand.o\\r
+ ./makegroupcommand.o\
+ ./chopseqscommand.o\\r
./inputdata.o\\r
./jackknife.o\\r
./kmer.o\\r
# Item # 201 -- makegroupcommand --\r
./makegroupcommand.o : makegroupcommand.cpp\r
$(CC) $(CC_OPTIONS) makegroupcommand.cpp -c $(INCLUDE) -o ./makegroupcommand.o\r
-\r
+
+# Item # 202 -- chopseqscommand --\r
+./chopseqscommand.o : chopseqscommand.cpp\r
+ $(CC) $(CC_OPTIONS) chopseqscommand.cpp -c $(INCLUDE) -o ./chopseqscommand.o\r
\r
##### END RUN ####\r
for (int i = 0; i < fastaFileNames.size(); i++) {
+ if (m->control_pressed) { out.close(); remove(filename.c_str()); return 0; }
+
ifstream in;
openInputFile(fastaFileNames[i], in);
while (!in.eof()) {
- Sequence seq(in); gobble(in);
+ Sequence seq(in, "no align"); gobble(in);
+
+ if (m->control_pressed) { in.close(); out.close(); remove(filename.c_str()); return 0; }
if (seq.getName() != "") { out << seq.getName() << '\t' << groupsNames[i] << endl; }
}