//**********************************************************************************************************************
vector<string> RemoveSeqsCommand::setParameters(){
try {
- CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(pfasta);
- CommandParameter pname("name", "InputTypes", "", "", "NameCount", "FNGLT", "none",false,false); parameters.push_back(pname);
- CommandParameter pcount("count", "InputTypes", "", "", "NameCount-CountGroup", "FNGLT", "none",false,false); parameters.push_back(pcount);
- CommandParameter pgroup("group", "InputTypes", "", "", "CountGroup", "FNGLT", "none",false,false); parameters.push_back(pgroup);
- CommandParameter plist("list", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(plist);
- CommandParameter ptaxonomy("taxonomy", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(ptaxonomy);
- CommandParameter palignreport("alignreport", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(palignreport);
- CommandParameter pqfile("qfile", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(pqfile);
- CommandParameter paccnos("accnos", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(paccnos);
- CommandParameter pdups("dups", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(pdups);
- CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir);
- CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir);
+ CommandParameter pfastq("fastq", "InputTypes", "", "", "none", "FNGLT", "none","fastq",false,false,true); parameters.push_back(pfastq);
+ CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "FNGLT", "none","fasta",false,false,true); parameters.push_back(pfasta);
+ CommandParameter pname("name", "InputTypes", "", "", "NameCount", "FNGLT", "none","name",false,false,true); parameters.push_back(pname);
+ CommandParameter pcount("count", "InputTypes", "", "", "NameCount-CountGroup", "FNGLT", "none","count",false,false,true); parameters.push_back(pcount);
+ CommandParameter pgroup("group", "InputTypes", "", "", "CountGroup", "FNGLT", "none","group",false,false,true); parameters.push_back(pgroup);
+ CommandParameter plist("list", "InputTypes", "", "", "none", "FNGLT", "none","list",false,false,true); parameters.push_back(plist);
+ CommandParameter ptaxonomy("taxonomy", "InputTypes", "", "", "none", "FNGLT", "none","taxonomy",false,false,true); parameters.push_back(ptaxonomy);
+ CommandParameter palignreport("alignreport", "InputTypes", "", "", "none", "FNGLT", "none","alignreport",false,false); parameters.push_back(palignreport);
+ CommandParameter pqfile("qfile", "InputTypes", "", "", "none", "FNGLT", "none","qfile",false,false); parameters.push_back(pqfile);
+ CommandParameter paccnos("accnos", "InputTypes", "", "", "none", "none", "none","",false,true,true); parameters.push_back(paccnos);
+ CommandParameter pdups("dups", "Boolean", "", "T", "", "", "","",false,false); parameters.push_back(pdups);
+ CommandParameter pinputdir("inputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(pinputdir);
+ CommandParameter poutputdir("outputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(poutputdir);
vector<string> myArray;
for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); }
string RemoveSeqsCommand::getHelpString(){
try {
string helpString = "";
- helpString += "The remove.seqs command reads an .accnos file and at least one of the following file types: fasta, name, group, count, list, taxonomy, quality or alignreport file.\n";
+ helpString += "The remove.seqs command reads an .accnos file and at least one of the following file types: fasta, name, group, count, list, taxonomy, quality, fastq or alignreport file.\n";
helpString += "It outputs a file containing the sequences NOT in the .accnos file.\n";
- helpString += "The remove.seqs command parameters are accnos, fasta, name, group, count, list, taxonomy, qfile, alignreport and dups. You must provide accnos and at least one of the file parameters.\n";
+ helpString += "The remove.seqs command parameters are accnos, fasta, name, group, count, list, taxonomy, qfile, alignreport, fastq and dups. You must provide accnos and at least one of the file parameters.\n";
helpString += "The dups parameter allows you to remove the entire line from a name file if you remove any name from the line. default=true. \n";
helpString += "The remove.seqs command should be in the following format: remove.seqs(accnos=yourAccnos, fasta=yourFasta).\n";
helpString += "Example remove.seqs(accnos=amazon.accnos, fasta=amazon.fasta).\n";
}
}
//**********************************************************************************************************************
-string RemoveSeqsCommand::getOutputFileNameTag(string type, string inputName=""){
- try {
- string outputFileName = "";
- map<string, vector<string> >::iterator it;
+string RemoveSeqsCommand::getOutputPattern(string type) {
+ try {
+ string pattern = "";
- //is this a type this command creates
- it = outputTypes.find(type);
- if (it == outputTypes.end()) { m->mothurOut("[ERROR]: this command doesn't create a " + type + " output file.\n"); }
- else {
- if (type == "fasta") { outputFileName = "pick" + m->getExtension(inputName); }
- else if (type == "taxonomy") { outputFileName = "pick" + m->getExtension(inputName); }
- else if (type == "name") { outputFileName = "pick" + m->getExtension(inputName); }
- else if (type == "group") { outputFileName = "pick" + m->getExtension(inputName); }
- else if (type == "list") { outputFileName = "pick" + m->getExtension(inputName); }
- else if (type == "qfile") { outputFileName = "pick" + m->getExtension(inputName); }
- else if (type == "alignreport") { outputFileName = "pick.align.report"; }
- else if (type == "count") { outputFileName = "pick.count_table"; }
- else { m->mothurOut("[ERROR]: No definition for type " + type + " output file tag.\n"); m->control_pressed = true; }
- }
- return outputFileName;
- }
- catch(exception& e) {
- m->errorOut(e, "RemoveSeqsCommand", "getOutputFileNameTag");
- exit(1);
- }
+ if (type == "fasta") { pattern = "[filename],pick,[extension]"; }
+ else if (type == "fastq") { pattern = "[filename],pick,[extension]"; }
+ else if (type == "taxonomy") { pattern = "[filename],pick,[extension]"; }
+ else if (type == "name") { pattern = "[filename],pick,[extension]"; }
+ else if (type == "group") { pattern = "[filename],pick,[extension]"; }
+ else if (type == "count") { pattern = "[filename],pick,[extension]"; }
+ else if (type == "list") { pattern = "[filename],[distance],pick,[extension]"; }
+ else if (type == "qfile") { pattern = "[filename],pick,[extension]"; }
+ else if (type == "alignreport") { pattern = "[filename],pick.align.report"; }
+ else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; }
+
+ return pattern;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "GetSeqsCommand", "getOutputPattern");
+ exit(1);
+ }
}
-
//**********************************************************************************************************************
RemoveSeqsCommand::RemoveSeqsCommand(){
try {
setParameters();
vector<string> tempOutNames;
outputTypes["fasta"] = tempOutNames;
+ outputTypes["fastq"] = tempOutNames;
outputTypes["taxonomy"] = tempOutNames;
outputTypes["name"] = tempOutNames;
outputTypes["group"] = tempOutNames;
//initialize outputTypes
vector<string> tempOutNames;
outputTypes["fasta"] = tempOutNames;
+ outputTypes["fastq"] = tempOutNames;
outputTypes["taxonomy"] = tempOutNames;
outputTypes["name"] = tempOutNames;
outputTypes["group"] = tempOutNames;
//if the user has not given a path then, add inputdir. else leave path alone.
if (path == "") { parameters["count"] = inputDir + it->second; }
}
+
+ it = parameters.find("fastq");
+ //user has given a template file
+ if(it != parameters.end()){
+ path = m->hasPath(it->second);
+ //if the user has not given a path then, add inputdir. else leave path alone.
+ if (path == "") { parameters["fastq"] = inputDir + it->second; }
+ }
}
if (qualfile == "not open") { abort = true; }
else if (qualfile == "not found") { qualfile = ""; }
else { m->setQualFile(qualfile); }
+
+ fastqfile = validParameter.validFile(parameters, "fastq", true);
+ if (fastqfile == "not open") { abort = true; }
+ else if (fastqfile == "not found") { fastqfile = ""; }
string usedDups = "true";
string temp = validParameter.validFile(parameters, "dups", false);
m->mothurOut("[ERROR]: you may only use one of the following: group or count."); m->mothurOutEndLine(); abort=true;
}
- if ((countfile == "") && (fastafile == "") && (namefile == "") && (groupfile == "") && (alignfile == "") && (listfile == "") && (taxfile == "") && (qualfile == "")) { m->mothurOut("You must provide at least one of the following: fasta, name, group, taxonomy, quality, alignreport or list."); m->mothurOutEndLine(); abort = true; }
+ if ((fastqfile == "") && (countfile == "") && (fastafile == "") && (namefile == "") && (groupfile == "") && (alignfile == "") && (listfile == "") && (taxfile == "") && (qualfile == "")) { m->mothurOut("You must provide at least one of the following: fasta, name, group, taxonomy, quality, alignreport, fastq or list."); m->mothurOutEndLine(); abort = true; }
if (countfile == "") {
if ((fastafile != "") && (namefile == "")) {
//read through the correct file and output lines you want to keep
if (namefile != "") { readName(); }
if (fastafile != "") { readFasta(); }
+ if (fastqfile != "") { readFastq(); }
if (groupfile != "") { readGroup(); }
if (alignfile != "") { readAlign(); }
if (listfile != "") { readList(); }
try {
string thisOutputDir = outputDir;
if (outputDir == "") { thisOutputDir += m->hasPath(fastafile); }
- string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(fastafile)) + getOutputFileNameTag("fasta", fastafile);
+ map<string, string> variables;
+ variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(fastafile));
+ variables["[extension]"] = m->getExtension(fastafile);
+ string outputFileName = getOutputFileName("fasta", variables);
ofstream out;
m->openOutputFile(outputFileName, out);
}
}
//**********************************************************************************************************************
+int RemoveSeqsCommand::readFastq(){
+ try {
+ bool wroteSomething = false;
+ int removedCount = 0;
+
+ ifstream in;
+ m->openInputFile(fastqfile, in);
+
+ string thisOutputDir = outputDir;
+ if (outputDir == "") { thisOutputDir += m->hasPath(fastqfile); }
+ map<string, string> variables;
+ variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(fastqfile));
+ variables["[extension]"] = m->getExtension(fastqfile);
+ string outputFileName = getOutputFileName("fastq", variables);
+ ofstream out;
+ m->openOutputFile(outputFileName, out);
+
+
+ while(!in.eof()){
+
+ if (m->control_pressed) { in.close(); out.close(); m->mothurRemove(outputFileName); return 0; }
+
+ //read sequence name
+ string input = m->getline(in); m->gobble(in);
+
+ string outputString = input + "\n";
+
+ if (input[0] == '@') {
+ //get rest of lines
+ outputString += m->getline(in) + "\n"; m->gobble(in);
+ outputString += m->getline(in) + "\n"; m->gobble(in);
+ outputString += m->getline(in) + "\n"; m->gobble(in);
+
+ vector<string> splits = m->splitWhiteSpace(input);
+ string name = splits[0];
+ name = name.substr(1);
+ m->checkName(name);
+
+ if (names.count(name) == 0) {
+ wroteSomething = true;
+ out << outputString;
+ }else { removedCount++; }
+ }
+
+ m->gobble(in);
+ }
+ in.close();
+ out.close();
+
+
+ if (wroteSomething == false) { m->mothurOut("Your file contains only sequences from the .accnos file."); m->mothurOutEndLine(); }
+ outputTypes["fasta"].push_back(outputFileName); outputNames.push_back(outputFileName);
+
+ m->mothurOut("Removed " + toString(removedCount) + " sequences from your fastq file."); m->mothurOutEndLine();
+
+
+ return 0;
+
+ }
+ catch(exception& e) {
+ m->errorOut(e, "RemoveSeqsCommand", "readFastq");
+ exit(1);
+ }
+}
+//**********************************************************************************************************************
int RemoveSeqsCommand::readQual(){
try {
string thisOutputDir = outputDir;
if (outputDir == "") { thisOutputDir += m->hasPath(qualfile); }
- string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(qualfile)) + getOutputFileNameTag("qfile", qualfile);
+ map<string, string> variables;
+ variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(qualfile));
+ variables["[extension]"] = m->getExtension(qualfile);
+ string outputFileName = getOutputFileName("qfile", variables);
ofstream out;
m->openOutputFile(outputFileName, out);
saveName = name.substr(1);
while (!in.eof()) {
char c = in.get();
- if (c == 10 || c == 13){ break; }
+ if (c == 10 || c == 13 || c == -1){ break; }
else { name += c; }
}
m->gobble(in);
string thisOutputDir = outputDir;
if (outputDir == "") { thisOutputDir += m->hasPath(countfile); }
- string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(countfile)) + getOutputFileNameTag("count", countfile);
+ map<string, string> variables;
+ variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(countfile));
+ variables["[extension]"] = m->getExtension(countfile);
+ string outputFileName = getOutputFileName("count", variables);
ofstream out;
m->openOutputFile(outputFileName, out);
//check for groups that have been eliminated
CountTable ct;
if (ct.testGroups(outputFileName)) {
- ct.readTable(outputFileName);
+ ct.readTable(outputFileName, true, false);
ct.printTable(outputFileName);
}
try {
string thisOutputDir = outputDir;
if (outputDir == "") { thisOutputDir += m->hasPath(listfile); }
- string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(listfile)) + getOutputFileNameTag("list", listfile);
- ofstream out;
- m->openOutputFile(outputFileName, out);
-
+ map<string, string> variables;
+ variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(listfile));
+ variables["[extension]"] = m->getExtension(listfile);
+
ifstream in;
m->openInputFile(listfile, in);
//make a new list vector
ListVector newList;
newList.setLabel(list.getLabel());
+
+ variables["[distance]"] = list.getLabel();
+ string outputFileName = getOutputFileName("list", variables);
+ ofstream out;
+ m->openOutputFile(outputFileName, out);
+ outputTypes["list"].push_back(outputFileName); outputNames.push_back(outputFileName);
+
+ vector<string> binLabels = list.getLabels();
+ vector<string> newBinLabels;
+
+ if (m->control_pressed) { in.close(); out.close(); return 0; }
+
//for each bin
for (int i = 0; i < list.getNumBins(); i++) {
if (m->control_pressed) { in.close(); out.close(); m->mothurRemove(outputFileName); return 0; }
//parse out names that are in accnos file
- string binnames = list.get(i);
+ string bin = list.get(i);
+ vector<string> bnames;
+ m->splitAtComma(bin, bnames);
string newNames = "";
- while (binnames.find_first_of(',') != -1) {
- string name = binnames.substr(0,binnames.find_first_of(','));
- binnames = binnames.substr(binnames.find_first_of(',')+1, binnames.length());
-
- //if that name is in the .accnos file, add it
+ for (int j = 0; j < bnames.size(); j++) {
+ string name = bnames[j];
+ //if that name is in the .accnos file, add it
if (names.count(name) == 0) { newNames += name + ","; }
else { removedCount++; }
- }
-
- //get last name
- if (names.count(binnames) == 0) { newNames += binnames + ","; }
- else { removedCount++; }
+ }
//if there are names in this bin add to new list
if (newNames != "") {
newNames = newNames.substr(0, newNames.length()-1); //rip off extra comma
- newList.push_back(newNames);
+ newList.push_back(newNames);
+ newBinLabels.push_back(binLabels[i]);
}
}
//print new listvector
if (newList.getNumBins() != 0) {
wroteSomething = true;
+ newList.setLabels(newBinLabels);
+ newList.printHeaders(out);
newList.print(out);
+
}
m->gobble(in);
+ out.close();
}
in.close();
- out.close();
+
if (wroteSomething == false) { m->mothurOut("Your file contains only sequences from the .accnos file."); m->mothurOutEndLine(); }
- outputTypes["list"].push_back(outputFileName); outputNames.push_back(outputFileName);
m->mothurOut("Removed " + toString(removedCount) + " sequences from your list file."); m->mothurOutEndLine();
try {
string thisOutputDir = outputDir;
if (outputDir == "") { thisOutputDir += m->hasPath(namefile); }
- string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(namefile)) + getOutputFileNameTag("name", namefile);
+ map<string, string> variables;
+ variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(namefile));
+ variables["[extension]"] = m->getExtension(namefile);
+ string outputFileName = getOutputFileName("name", variables);
ofstream out;
m->openOutputFile(outputFileName, out);
try {
string thisOutputDir = outputDir;
if (outputDir == "") { thisOutputDir += m->hasPath(groupfile); }
- string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(groupfile)) + getOutputFileNameTag("group", groupfile);
+ map<string, string> variables;
+ variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(groupfile));
+ variables["[extension]"] = m->getExtension(groupfile);
+ string outputFileName = getOutputFileName("group", variables);
ofstream out;
m->openOutputFile(outputFileName, out);
try {
string thisOutputDir = outputDir;
if (outputDir == "") { thisOutputDir += m->hasPath(taxfile); }
- string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(taxfile)) + getOutputFileNameTag("taxonomy", taxfile);
+ map<string, string> variables;
+ variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(taxfile));
+ variables["[extension]"] = m->getExtension(taxfile);
+ string outputFileName = getOutputFileName("taxonomy", variables);
ofstream out;
m->openOutputFile(outputFileName, out);
while(!in.eof()){
if (m->control_pressed) { in.close(); out.close(); m->mothurRemove(outputFileName); return 0; }
- in >> name; //read from first column
+ in >> name; m->gobble(in); //read from first column
in >> tax; //read from second column
if (!dups) {//adjust name if needed
try {
string thisOutputDir = outputDir;
if (outputDir == "") { thisOutputDir += m->hasPath(alignfile); }
- string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(alignfile)) + getOutputFileNameTag("alignreport");
+ map<string, string> variables;
+ variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(alignfile));
+ string outputFileName = getOutputFileName("alignreport", variables);
ofstream out;
m->openOutputFile(outputFileName, out);