vector<string> GetSeqsCommand::setParameters(){
try {
CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "FNGLT", "none","fasta",false,false,true); parameters.push_back(pfasta);
+ CommandParameter pfastq("fastq", "InputTypes", "", "", "none", "FNGLT", "none","fastq",false,false,true); parameters.push_back(pfastq);
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);
string GetSeqsCommand::getHelpString(){
try {
string helpString = "";
- helpString += "The get.seqs command reads an .accnos file and any of the following file types: fasta, name, group, count, list, taxonomy, quality or alignreport file.\n";
+ helpString += "The get.seqs command reads an .accnos file and any of the following file types: fasta, name, group, count, list, taxonomy, quality, fastq or alignreport file.\n";
helpString += "It outputs a file containing only the sequences in the .accnos file.\n";
- helpString += "The get.seqs command parameters are accnos, fasta, name, group, list, taxonomy, qfile, alignreport and dups. You must provide accnos unless you have a valid current accnos file, and at least one of the other parameters.\n";
- helpString += "The dups parameter allows you to add the entire line from a name file if you add any name from the line. default=false. \n";
+ helpString += "The get.seqs command parameters are accnos, fasta, name, group, list, taxonomy, qfile, alignreport, fastq and dups. You must provide accnos unless you have a valid current accnos file, and at least one of the other parameters.\n";
+ helpString += "The dups parameter allows you to add the entire line from a name file if you add any name from the line. default=true. \n";
helpString += "The get.seqs command should be in the following format: get.seqs(accnos=yourAccnos, fasta=yourFasta).\n";
helpString += "Example get.seqs(accnos=amazon.accnos, fasta=amazon.fasta).\n";
helpString += "Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n";
setParameters();
vector<string> tempOutNames;
outputTypes["fasta"] = tempOutNames;
+ outputTypes["fastq"] = tempOutNames;
outputTypes["taxonomy"] = tempOutNames;
outputTypes["name"] = tempOutNames;
outputTypes["group"] = tempOutNames;
string pattern = "";
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]"; }
//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 = ""; }
accnosfile2 = validParameter.validFile(parameters, "accnos2", true);
if (accnosfile2 == "not open") { abort = true; }
string temp = validParameter.validFile(parameters, "dups", false); if (temp == "not found") { temp = "true"; usedDups = ""; }
dups = m->isTrue(temp);
- if ((fastafile == "") && (namefile == "") && (groupfile == "") && (alignfile == "") && (listfile == "") && (taxfile == "") && (qualfile == "") && (accnosfile2 == "") && (countfile == "")) { m->mothurOut("You must provide one of the following: fasta, name, group, count, alignreport, taxonomy, quality or listfile."); m->mothurOutEndLine(); abort = true; }
+ if ((fastqfile == "") && (fastafile == "") && (namefile == "") && (groupfile == "") && (alignfile == "") && (listfile == "") && (taxfile == "") && (qualfile == "") && (accnosfile2 == "") && (countfile == "")) { m->mothurOut("You must provide one of the following: fasta, name, group, count, alignreport, taxonomy, quality, fastq or listfile."); m->mothurOutEndLine(); abort = true; }
if (countfile == "") {
if ((namefile == "") && ((fastafile != "") || (taxfile != ""))){
//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 (countfile != "") { readCount(); }
if (alignfile != "") { readAlign(); }
exit(1);
}
}
+//**********************************************************************************************************************
+int GetSeqsCommand::readFastq(){
+ try {
+ bool wroteSomething = false;
+ int selectedCount = 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;
+ selectedCount++;
+ out << outputString;
+ }
+ }
+
+ m->gobble(in);
+ }
+ in.close();
+ out.close();
+
+
+ if (wroteSomething == false) { m->mothurOut("Your file does not contain any sequence from the .accnos file."); m->mothurOutEndLine(); }
+ outputNames.push_back(outputFileName); outputTypes["fastq"].push_back(outputFileName);
+
+ m->mothurOut("Selected " + toString(selectedCount) + " sequences from your fastq file."); m->mothurOutEndLine();
+
+ return 0;
+
+ }
+ catch(exception& e) {
+ m->errorOut(e, "GetSeqsCommand", "readFastq");
+ exit(1);
+ }
+}
//**********************************************************************************************************************
int GetSeqsCommand::readFasta(){
Sequence currSeq(in);
name = currSeq.getName();
+
+ if (!dups) {//adjust name if needed
+ map<string, string>::iterator it = uniqueMap.find(name);
+ if (it != uniqueMap.end()) { currSeq.setName(it->second); }
+ }
+ name = currSeq.getName();
+
if (name != "") {
//if this name is in the accnos file
if (names.count(name) != 0) {
string name = "";
string scores = "";
- in >> name;
+ in >> name;
+
+ if (!dups) {//adjust name if needed
+ map<string, string>::iterator it = uniqueMap.find(name);
+ if (it != uniqueMap.end()) { name = it->second; }
+ }
if (name.length() != 0) {
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);
//check for groups that have been eliminated
CountTable ct;
if (ct.testGroups(outputFileName)) {
- ct.readTable(outputFileName);
+ ct.readTable(outputFileName, true, false);
ct.printTable(outputFileName);
}
if (m->control_pressed) { in.close(); out.close(); m->mothurRemove(outputFileName); return 0; }
- in >> firstCol;
+ in >> firstCol; m->gobble(in);
in >> secondCol;
string hold = "";
selectedCount += parsedNames.size();
if (m->debug) { sanity["name"].insert(firstCol); }
}else {
+
selectedCount += validSecond.size();
//if the name in the first column is in the set then print it and any other names in second column also in set
//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';
+ //we are changing the unique name in the fasta file
+ uniqueMap[firstCol] = validSecond[0];
//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] << ','; }
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) {
in >> name; //read from first column
in >> tax; //read from second column
+
+ if (!dups) {//adjust name if needed
+ map<string, string>::iterator it = uniqueMap.find(name);
+ if (it != uniqueMap.end()) { name = it->second; }
+ }
//if this name is in the accnos file
if (names.count(name) != 0) {
in >> name; //read from first column
+
+ if (!dups) {//adjust name if needed
+ map<string, string>::iterator it = uniqueMap.find(name);
+ if (it != uniqueMap.end()) { name = it->second; }
+ }
//if this name is in the accnos file
if (names.count(name) != 0) {