37B28F680F27590100808A62 /* deconvolutecommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37B28F670F27590100808A62 /* deconvolutecommand.cpp */; };
37B73C761004BEFD008C4B41 /* listseqscommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37B73C751004BEFD008C4B41 /* listseqscommand.cpp */; };
37B73CA61004D89A008C4B41 /* getseqscommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37B73CA51004D89A008C4B41 /* getseqscommand.cpp */; };
+ 37B73CC01004EB38008C4B41 /* removeseqscommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37B73CBF1004EB38008C4B41 /* removeseqscommand.cpp */; };
37C1D9730F86506E0059E3F0 /* binsequencecommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37C1D9720F86506E0059E3F0 /* binsequencecommand.cpp */; };
37C753CE0FB3415200DBD02E /* distancecommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37C753CD0FB3415200DBD02E /* distancecommand.cpp */; };
37D928550F21331F001D4494 /* ace.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D927B80F21331F001D4494 /* ace.cpp */; };
37B73C751004BEFD008C4B41 /* listseqscommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = listseqscommand.cpp; sourceTree = "<group>"; };
37B73CA41004D89A008C4B41 /* getseqscommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = getseqscommand.h; sourceTree = "<group>"; };
37B73CA51004D89A008C4B41 /* getseqscommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = getseqscommand.cpp; sourceTree = "<group>"; };
+ 37B73CBE1004EB38008C4B41 /* removeseqscommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = removeseqscommand.h; sourceTree = "<group>"; };
+ 37B73CBF1004EB38008C4B41 /* removeseqscommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = removeseqscommand.cpp; sourceTree = "<group>"; };
37C1D9710F86506E0059E3F0 /* binsequencecommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = binsequencecommand.h; sourceTree = SOURCE_ROOT; };
37C1D9720F86506E0059E3F0 /* binsequencecommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = binsequencecommand.cpp; sourceTree = SOURCE_ROOT; };
37C753CC0FB3415200DBD02E /* distancecommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = distancecommand.h; sourceTree = SOURCE_ROOT; };
372E126F0F26365B0095CF7E /* readotucommand.cpp */,
37E5F4900F2A3DA800F8D827 /* readtreecommand.h */,
37E5F4910F2A3DA800F8D827 /* readtreecommand.cpp */,
+ 37B73CBE1004EB38008C4B41 /* removeseqscommand.h */,
+ 37B73CBF1004EB38008C4B41 /* removeseqscommand.cpp */,
7E09C5120FDA79C5002ECAE5 /* reversecommand.h */,
7E09C5130FDA79C5002ECAE5 /* reversecommand.cpp */,
371B30B30FD7EE67000414CA /* screenseqscommand.h */,
379D3D510FF90E090068C1C0 /* chimeraseqscommand.cpp in Sources */,
37B73C761004BEFD008C4B41 /* listseqscommand.cpp in Sources */,
37B73CA61004D89A008C4B41 /* getseqscommand.cpp in Sources */,
+ 37B73CC01004EB38008C4B41 /* removeseqscommand.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
openInputFile(fastafile, in);
string name;
+ bool wroteSomething = false;
+
while(!in.eof()){
Sequence currSeq(in);
name = currSeq.getName();
//if this name is in the accnos file
if (names.count(name) == 1) {
+ wroteSomething = true;
+
currSeq.printSequence(out);
+
+ names.erase(name);
}
gobble(in);
}
in.close();
- out.close();
+ out.close();
+
+ if (wroteSomething == false) {
+ mothurOut("Your file does not contain any sequence from the .accnos file."); mothurOutEndLine();
+ remove(outputFileName.c_str());
+ }
}
catch(exception& e) {
openInputFile(namefile, in);
string name, firstCol, secondCol;
+ bool wroteSomething = false;
+
while(!in.eof()){
for (int i = 0; i < parsedNames.size(); i++) {
if (names.count(parsedNames[i]) == 1) {
validSecond.push_back(parsedNames[i]);
+ names.erase(parsedNames[i]);
}
}
//if the name in the first column is in the set then print it and any other names in second column also in set
if (names.count(firstCol) == 1) {
+
+ wroteSomething = true;
+
out << firstCol << '\t';
//you know you have at least one valid second since first column is valid
for (int i = 0; i < validSecond.size()-1; i++) { out << validSecond[i] << ','; }
out << validSecond[validSecond.size()-1] << endl;
+
+ names.erase(firstCol);
//make first name in set you come to first column and then add the remaining names to second column
}else {
//you want part of this row
if (validSecond.size() != 0) {
+
+ wroteSomething = true;
+
out << validSecond[0] << '\t';
//you know you have at least one valid second since first column is valid
in.close();
out.close();
+ if (wroteSomething == false) {
+ mothurOut("Your file does not contain any sequence from the .accnos file."); mothurOutEndLine();
+ remove(outputFileName.c_str());
+ }
+
}
catch(exception& e) {
errorOut(e, "GetSeqsCommand", "readName");
openInputFile(groupfile, in);
string name, group;
+ bool wroteSomething = false;
+
while(!in.eof()){
in >> name; //read from first column
//if this name is in the accnos file
if (names.count(name) == 1) {
+ wroteSomething = true;
+
out << name << '\t' << group << endl;
+
+ names.erase(name);
}
gobble(in);
}
in.close();
out.close();
+
+ if (wroteSomething == false) {
+ mothurOut("Your file does not contain any sequence from the .accnos file."); mothurOutEndLine();
+ remove(outputFileName.c_str());
+ }
}
catch(exception& e) {
openInputFile(alignfile, in);
string name, junk;
+ bool wroteSomething = false;
+
//read column headers
for (int i = 0; i < 16; i++) {
if (!in.eof()) { in >> junk; out << junk << '\t'; }
//if this name is in the accnos file
if (names.count(name) == 1) {
-
+ wroteSomething = true;
+
out << name << '\t';
//read rest
}
out << endl;
+ names.erase(name);
+
}else {//still read just don't do anything with it
//read rest
for (int i = 0; i < 15; i++) {
}
in.close();
out.close();
-
+
+ if (wroteSomething == false) {
+ mothurOut("Your file does not contain any sequence from the .accnos file."); mothurOutEndLine();
+ remove(outputFileName.c_str());
+ }
}
catch(exception& e) {
--- /dev/null
+/*
+ * removeseqscommand.cpp
+ * Mothur
+ *
+ * Created by Sarah Westcott on 7/8/09.
+ * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+#include "removeseqscommand.h"
+#include "sequence.hpp"
+
+//**********************************************************************************************************************
+
+RemoveSeqsCommand::RemoveSeqsCommand(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","name", "group", "align", "accnos" };
+ vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+
+ OptionParser parser(option);
+ map<string,string> parameters = parser.getParameters();
+
+ ValidParameters validParameter;
+
+ //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; }
+ }
+
+ //check for required parameters
+ accnosfile = validParameter.validFile(parameters, "accnos", true);
+ if (accnosfile == "not open") { abort = true; }
+ else if (accnosfile == "not found") { accnosfile = ""; mothurOut("You must provide an accnos file."); mothurOutEndLine(); abort = true; }
+
+ fastafile = validParameter.validFile(parameters, "fasta", true);
+ if (fastafile == "not open") { abort = true; }
+ else if (fastafile == "not found") { fastafile = ""; }
+
+ namefile = validParameter.validFile(parameters, "name", true);
+ if (namefile == "not open") { abort = true; }
+ else if (namefile == "not found") { namefile = ""; }
+
+ groupfile = validParameter.validFile(parameters, "group", true);
+ if (groupfile == "not open") { abort = true; }
+ else if (groupfile == "not found") { groupfile = ""; }
+
+ alignfile = validParameter.validFile(parameters, "align", true);
+ if (alignfile == "not open") { abort = true; }
+ else if (alignfile == "not found") { alignfile = ""; }
+
+ if ((fastafile == "") && (namefile == "") && (groupfile == "") && (alignfile == "")) { mothurOut("You must provide one of the following: fasta, name, group, align."); mothurOutEndLine(); abort = true; }
+
+ if (parameters.size() > 2) { mothurOut("You may only enter one of the following: fasta, name, group, align."); mothurOutEndLine(); abort = true; }
+ }
+
+ }
+ catch(exception& e) {
+ errorOut(e, "RemoveSeqsCommand", "RemoveSeqsCommand");
+ exit(1);
+ }
+}
+//**********************************************************************************************************************
+
+void RemoveSeqsCommand::help(){
+ try {
+ mothurOut("The remove.seqs command reads an .accnos file and one of the following file types: fasta, name, group or alignreport file.\n");
+ mothurOut("It outputs a file containing the sequences NOT in the .accnos file.\n");
+ mothurOut("The remove.seqs command parameters are accnos, fasta, name, group and align. You must provide accnos and one of the other parameters.\n");
+ mothurOut("The remove.seqs command should be in the following format: remove.seqs(accnos=yourAccnos, fasta=yourFasta).\n");
+ mothurOut("Example remove.seqs(accnos=amazon.accnos, fasta=amazon.fasta).\n");
+ mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n\n");
+ }
+ catch(exception& e) {
+ errorOut(e, "RemoveSeqsCommand", "help");
+ exit(1);
+ }
+}
+
+//**********************************************************************************************************************
+
+int RemoveSeqsCommand::execute(){
+ try {
+
+ if (abort == true) { return 0; }
+
+ //get names you want to keep
+ readAccnos();
+
+ //read through the correct file and output lines you want to keep
+ if (fastafile != "") { readFasta(); }
+ else if (namefile != "") { readName(); }
+ else if (groupfile != "") { readGroup(); }
+ else if (alignfile != "") { readAlign(); }
+
+ return 0;
+ }
+
+ catch(exception& e) {
+ errorOut(e, "RemoveSeqsCommand", "execute");
+ exit(1);
+ }
+}
+
+//**********************************************************************************************************************
+void RemoveSeqsCommand::readFasta(){
+ try {
+ string outputFileName = getRootName(fastafile) + "pick";
+ ofstream out;
+ openOutputFile(outputFileName, out);
+
+ ifstream in;
+ openInputFile(fastafile, in);
+ string name;
+
+ bool wroteSomething = false;
+
+ while(!in.eof()){
+ Sequence currSeq(in);
+ name = currSeq.getName();
+
+ //if this name is in the accnos file
+ if (names.count(name) == 0) {
+ wroteSomething = true;
+
+ currSeq.printSequence(out);
+ }else { names.erase(name); }
+
+ gobble(in);
+ }
+ in.close();
+ out.close();
+
+ if (wroteSomething == false) {
+ mothurOut("Your file contains only sequences from the .accnos file."); mothurOutEndLine();
+ remove(outputFileName.c_str());
+ }
+
+ }
+ catch(exception& e) {
+ errorOut(e, "RemoveSeqsCommand", "readFasta");
+ exit(1);
+ }
+}
+
+//**********************************************************************************************************************
+void RemoveSeqsCommand::readName(){
+ try {
+
+ string outputFileName = getRootName(namefile) + "pick";
+ ofstream out;
+ openOutputFile(outputFileName, out);
+
+ ifstream in;
+ openInputFile(namefile, in);
+ string name, firstCol, secondCol;
+
+ bool wroteSomething = false;
+
+ while(!in.eof()){
+
+ in >> firstCol;
+ in >> secondCol;
+
+ vector<string> parsedNames;
+ //parse second column saving each name
+ while (secondCol.find_first_of(',') != -1) {
+ name = secondCol.substr(0,secondCol.find_first_of(','));
+ secondCol = secondCol.substr(secondCol.find_first_of(',')+1, secondCol.length());
+ parsedNames.push_back(name);
+ }
+
+ //get name after last ,
+ parsedNames.push_back(secondCol);
+
+ vector<string> validSecond;
+ for (int i = 0; i < parsedNames.size(); i++) {
+ if (names.count(parsedNames[i]) == 0) {
+ validSecond.push_back(parsedNames[i]);
+ }else { names.erase(parsedNames[i]); }
+ }
+
+
+ //if the name in the first column is in the set then print it and any other names in second column also in set
+ if (names.count(firstCol) == 0) {
+
+ wroteSomething = true;
+
+ out << firstCol << '\t';
+
+ //you know you have at least one valid second since first column is valid
+ for (int i = 0; i < validSecond.size()-1; i++) { out << validSecond[i] << ','; }
+ out << validSecond[validSecond.size()-1] << endl;
+
+ //make first name in set you come to first column and then add the remaining names to second column
+ }else {
+ names.erase(firstCol);
+
+ //you want part of this row
+ if (validSecond.size() != 0) {
+
+ wroteSomething = true;
+
+ out << validSecond[0] << '\t';
+
+ //you know you have at least one valid second since first column is valid
+ for (int i = 0; i < validSecond.size()-1; i++) { out << validSecond[i] << ','; }
+ out << validSecond[validSecond.size()-1] << endl;
+ }
+ }
+
+ gobble(in);
+ }
+ in.close();
+ out.close();
+
+ if (wroteSomething == false) {
+ mothurOut("Your file contains only sequences from the .accnos file."); mothurOutEndLine();
+ remove(outputFileName.c_str());
+ }
+
+ }
+ catch(exception& e) {
+ errorOut(e, "RemoveSeqsCommand", "readName");
+ exit(1);
+ }
+}
+
+//**********************************************************************************************************************
+void RemoveSeqsCommand::readGroup(){
+ try {
+
+ string outputFileName = getRootName(groupfile) + "pick";
+ ofstream out;
+ openOutputFile(outputFileName, out);
+
+ ifstream in;
+ openInputFile(groupfile, in);
+ string name, group;
+
+ bool wroteSomething = false;
+
+ while(!in.eof()){
+
+ in >> name; //read from first column
+ in >> group; //read from second column
+
+ //if this name is in the accnos file
+ if (names.count(name) == 0) {
+ wroteSomething = true;
+ out << name << '\t' << group << endl;
+ }else { names.erase(name); }
+
+ gobble(in);
+ }
+ in.close();
+ out.close();
+
+ if (wroteSomething == false) {
+ mothurOut("Your file contains only sequences from the .accnos file."); mothurOutEndLine();
+ remove(outputFileName.c_str());
+ }
+
+ }
+ catch(exception& e) {
+ errorOut(e, "RemoveSeqsCommand", "readGroup");
+ exit(1);
+ }
+}
+
+//**********************************************************************************************************************
+//alignreport file has a column header line then all other lines contain 16 columns. we just want the first column since that contains the name
+void RemoveSeqsCommand::readAlign(){
+ try {
+ string outputFileName = getRootName(alignfile) + "pick";
+ ofstream out;
+ openOutputFile(outputFileName, out);
+
+ ifstream in;
+ openInputFile(alignfile, in);
+ string name, junk;
+
+ bool wroteSomething = false;
+
+ //read column headers
+ for (int i = 0; i < 16; i++) {
+ if (!in.eof()) { in >> junk; out << junk << '\t'; }
+ else { break; }
+ }
+ out << endl;
+
+ while(!in.eof()){
+
+ in >> name; //read from first column
+
+ //if this name is in the accnos file
+ if (names.count(name) == 0) {
+ wroteSomething = true;
+
+ out << name << '\t';
+
+ //read rest
+ for (int i = 0; i < 15; i++) {
+ if (!in.eof()) { in >> junk; out << junk << '\t'; }
+ else { break; }
+ }
+ out << endl;
+
+ }else {//still read just don't do anything with it
+ names.erase(name);
+
+ //read rest
+ for (int i = 0; i < 15; i++) {
+ if (!in.eof()) { in >> junk; }
+ else { break; }
+ }
+ }
+
+ gobble(in);
+ }
+ in.close();
+ out.close();
+
+ if (wroteSomething == false) {
+ mothurOut("Your file contains only sequences from the .accnos file."); mothurOutEndLine();
+ remove(outputFileName.c_str());
+ }
+
+ }
+ catch(exception& e) {
+ errorOut(e, "RemoveSeqsCommand", "readAlign");
+ exit(1);
+ }
+}
+//**********************************************************************************************************************
+void RemoveSeqsCommand::readAccnos(){
+ try {
+
+ ifstream in;
+ openInputFile(accnosfile, in);
+ string name;
+
+ while(!in.eof()){
+ in >> name;
+
+ names.insert(name);
+
+ gobble(in);
+ }
+ in.close();
+
+ }
+ catch(exception& e) {
+ errorOut(e, "RemoveSeqsCommand", "readAccnos");
+ exit(1);
+ }
+}
+
+//**********************************************************************************************************************
+
+