optionString = input.substr((openParen+1), (closeParen-openParen-1)); //optionString contains everything between "(" and ")".
}
else if (openParen == -1) { m->mothurOut("[ERROR]: You are missing ("); m->mothurOutEndLine(); }
- else if (closeParen == -1) { m->mothurOut("[ERROR]:You are missing )"); m->mothurOutEndLine(); }
+ else if (closeParen == -1) { m->mothurOut("[ERROR]: You are missing )"); m->mothurOutEndLine(); }
}
catch(exception& e) {
m->errorOut(e, "CommandOptionParser", "CommandOptionParser");
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 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";
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(){
private:
set<string> names;
vector<string> outputNames;
- string accnosfile, accnosfile2, fastafile, namefile, countfile, groupfile, alignfile, listfile, taxfile, qualfile, outputDir;
+ string accnosfile, accnosfile2, fastafile, fastqfile, namefile, countfile, groupfile, alignfile, listfile, taxfile, qualfile, outputDir;
bool abort, dups;
map<string, string> uniqueMap;
//for debug
map<string, set<string> > sanity; //maps file type to names chosen for file. something like "fasta" -> vector<string>. If running in debug mode this is filled and we check to make sure all the files have the same names. If they don't we output the differences for the user.
int readFasta();
+ int readFastq();
int readName();
int readGroup();
int readCount();
//**********************************************************************************************************************
vector<string> ListSeqsCommand::setParameters(){
try {
+ CommandParameter pfastq("fastq", "InputTypes", "", "", "FNGLT", "FNGLT", "none","accnos",false,false,true); parameters.push_back(pfastq);
CommandParameter pfasta("fasta", "InputTypes", "", "", "FNGLT", "FNGLT", "none","accnos",false,false,true); parameters.push_back(pfasta);
CommandParameter pname("name", "InputTypes", "", "", "FNGLT", "FNGLT", "none","accnos",false,false,true); parameters.push_back(pname);
CommandParameter pcount("count", "InputTypes", "", "", "FNGLT", "FNGLT", "none","accnos",false,false,true); parameters.push_back(pcount);
string ListSeqsCommand::getHelpString(){
try {
string helpString = "";
- helpString += "The list.seqs command reads a fasta, name, group, count, list, taxonomy or alignreport file and outputs a .accnos file containing sequence names.\n";
- helpString += "The list.seqs command parameters are fasta, name, group, count, list, taxonomy and alignreport. You must provide one of these parameters.\n";
+ helpString += "The list.seqs command reads a fasta, name, group, count, list, taxonomy, fastq or alignreport file and outputs a .accnos file containing sequence names.\n";
+ helpString += "The list.seqs command parameters are fasta, name, group, count, list, taxonomy, fastq and alignreport. You must provide one of these parameters.\n";
helpString += "The list.seqs command should be in the following format: list.seqs(fasta=yourFasta).\n";
helpString += "Example list.seqs(fasta=amazon.fasta).\n";
helpString += "Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n";
//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; }
+ }
}
//check for required parameters
if (countfile == "not open") { abort = true; }
else if (countfile == "not found") { countfile = ""; }
else { m->setCountTableFile(countfile); }
+
+ fastqfile = validParameter.validFile(parameters, "fastq", true);
+ if (fastqfile == "not open") { abort = true; }
+ else if (fastqfile == "not found") { fastqfile = ""; }
- if ((countfile == "") && (fastafile == "") && (namefile == "") && (listfile == "") && (groupfile == "") && (alignfile == "") && (taxfile == "")) { m->mothurOut("You must provide a file."); m->mothurOutEndLine(); abort = true; }
+ if ((fastqfile == "") && (countfile == "") && (fastafile == "") && (namefile == "") && (listfile == "") && (groupfile == "") && (alignfile == "") && (taxfile == "")) { m->mothurOut("You must provide a file."); m->mothurOutEndLine(); abort = true; }
int okay = 1;
if (outputDir != "") { okay++; }
//read functions fill names vector
if (fastafile != "") { inputFileName = fastafile; readFasta(); }
+ else if (fastqfile != "") { inputFileName = fastqfile; readFastq(); }
else if (namefile != "") { inputFileName = namefile; readName(); }
else if (groupfile != "") { inputFileName = groupfile; readGroup(); }
else if (alignfile != "") { inputFileName = alignfile; readAlign(); }
exit(1);
}
}
+//**********************************************************************************************************************
+int ListSeqsCommand::readFastq(){
+ try {
+
+ ifstream in;
+ m->openInputFile(fastqfile, in);
+ string name;
+
+ //ofstream out;
+ //string newFastaName = outputDir + m->getRootName(m->getSimpleName(fastafile)) + "numsAdded.fasta";
+ //m->openOutputFile(newFastaName, out);
+ int count = 1;
+ //string lastName = "";
+
+ while(!in.eof()){
+
+ if (m->control_pressed) { in.close(); return 0; }
+
+ //read sequence name
+ string name = m->getline(in); m->gobble(in);
+
+ if (name[0] == '@') {
+ vector<string> splits = m->splitWhiteSpace(name);
+ name = splits[0];
+ name = name.substr(1);
+ m->checkName(name);
+ names.push_back(name);
+ //get rest of lines
+ name = m->getline(in); m->gobble(in);
+ name = m->getline(in); m->gobble(in);
+ name = m->getline(in); m->gobble(in);
+ }
+
+ m->gobble(in);
+ if (m->debug) { count++; cout << "[DEBUG]: count = " + toString(count) + ", name = " + name + "\n"; }
+ }
+ in.close();
+ //out.close();
+
+ return 0;
+
+ }
+ catch(exception& e) {
+ m->errorOut(e, "ListSeqsCommand", "readFastq");
+ exit(1);
+ }
+}
//**********************************************************************************************************************
int ListSeqsCommand::readFasta(){
private:
vector<string> names, outputNames;
- string fastafile, namefile, groupfile, countfile, alignfile, inputFileName, outputDir, listfile, taxfile;
+ string fastafile, namefile, groupfile, countfile, alignfile, inputFileName, outputDir, listfile, taxfile, fastqfile;
bool abort;
int readFasta();
int readList();
int readTax();
int readCount();
-
+ int readFastq();
};
#endif
}
}
/***********************************************************************/
+bool MothurOut::checkLocations(string& filename, string inputDir){
+ try {
+ filename = getFullPathName(filename);
+
+ int ableToOpen;
+ ifstream in;
+ ableToOpen = openInputFile(filename, in, "noerror");
+ in.close();
+
+ //if you can't open it, try input location
+ if (ableToOpen == 1) {
+ if (inputDir != "") { //default path is set
+ string tryPath = inputDir + getSimpleName(filename);
+ mothurOut("Unable to open " + filename + ". Trying input directory " + tryPath); mothurOutEndLine();
+ ifstream in2;
+ ableToOpen = openInputFile(tryPath, in2, "noerror");
+ in2.close();
+ filename = tryPath;
+ }
+ }
+
+ //if you can't open it, try default location
+ if (ableToOpen == 1) {
+ if (getDefaultPath() != "") { //default path is set
+ string tryPath = getDefaultPath() + getSimpleName(filename);
+ mothurOut("Unable to open " + filename + ". Trying default " + tryPath); mothurOutEndLine();
+ ifstream in2;
+ ableToOpen = openInputFile(tryPath, in2, "noerror");
+ in2.close();
+ filename = tryPath;
+ }
+ }
+
+ //if you can't open it its not in current working directory or inputDir, try mothur excutable location
+ if (ableToOpen == 1) {
+ string exepath = argv;
+ string tempPath = exepath;
+ for (int i = 0; i < exepath.length(); i++) { tempPath[i] = tolower(exepath[i]); }
+ exepath = exepath.substr(0, (tempPath.find_last_of('m')));
+
+ string tryPath = getFullPathName(exepath) + getSimpleName(filename);
+ mothurOut("Unable to open " + filename + ". Trying mothur's executable location " + tryPath); mothurOutEndLine();
+ ifstream in2;
+ ableToOpen = openInputFile(tryPath, in2, "noerror");
+ in2.close();
+ filename = tryPath;
+ }
+
+ if (ableToOpen == 1) { mothurOut("Unable to open " + filename + "."); mothurOutEndLine(); return false; }
+
+ return true;
+ }
+ catch(exception& e) {
+ errorOut(e, "MothurOut", "checkLocations");
+ exit(1);
+ }
+}
+/***********************************************************************/
//This function parses the estimator options and puts them in a vector
void MothurOut::splitAtChar(string& estim, vector<string>& container, char symbol) {
int openOutputFileAppend(string, ofstream&);
int openOutputFileBinaryAppend(string, ofstream&);
int openInputFile(string, ifstream&);
- int openInputFile(string, ifstream&, string); //no error given
+ int openInputFile(string, ifstream&, string); //no error given
+
+ bool checkLocations(string&, string); //filename, inputDir. checks for file in ./, inputdir, default and mothur's exe location. Returns false if cant be found. If found completes name with location
string getline(ifstream&);
string getline(istringstream&);
void gobble(istream&);
//**********************************************************************************************************************
vector<string> RemoveSeqsCommand::setParameters(){
try {
+ 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);
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 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]"; }
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(); }
}
}
//**********************************************************************************************************************
+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;
private:
set<string> names;
- string accnosfile, fastafile, namefile, groupfile, countfile, alignfile, listfile, taxfile, qualfile, outputDir;
+ string accnosfile, fastafile, fastqfile, namefile, groupfile, countfile, alignfile, listfile, taxfile, qualfile, outputDir;
bool abort, dups;
vector<string> outputNames;
map<string, string> uniqueMap;
int readFasta();
+ int readFastq();
int readName();
int readGroup();
int readCount();
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);
+ inputDir = validParameter.validFile(parameters, "inputdir", false);
if (inputDir == "not found"){ inputDir = ""; }
else {
string path;
path += "lookupFiles\\";
#endif
lookupFileName = m->getFullPathName(path) + "LookUp_Titanium.pat";
-
- int ableToOpen;
- ifstream in;
- ableToOpen = m->openInputFile(lookupFileName, in, "noerror");
- in.close();
-
- //if you can't open it, try input location
- if (ableToOpen == 1) {
- if (inputDir != "") { //default path is set
- string tryPath = inputDir + m->getSimpleName(lookupFileName);
- m->mothurOut("Unable to open " + lookupFileName + ". Trying input directory " + tryPath); m->mothurOutEndLine();
- ifstream in2;
- ableToOpen = m->openInputFile(tryPath, in2, "noerror");
- in2.close();
- lookupFileName = tryPath;
- }
- }
-
- //if you can't open it, try default location
- if (ableToOpen == 1) {
- if (m->getDefaultPath() != "") { //default path is set
- string tryPath = m->getDefaultPath() + m->getSimpleName(lookupFileName);
- m->mothurOut("Unable to open " + lookupFileName + ". Trying default " + tryPath); m->mothurOutEndLine();
- ifstream in2;
- ableToOpen = m->openInputFile(tryPath, in2, "noerror");
- in2.close();
- lookupFileName = tryPath;
- }
- }
-
- //if you can't open it its not in current working directory or inputDir, try mothur excutable location
- if (ableToOpen == 1) {
- string exepath = m->argv;
- string tempPath = exepath;
- for (int i = 0; i < exepath.length(); i++) { tempPath[i] = tolower(exepath[i]); }
- exepath = exepath.substr(0, (tempPath.find_last_of('m')));
-
- string tryPath = m->getFullPathName(exepath) + m->getSimpleName(lookupFileName);
- m->mothurOut("Unable to open " + lookupFileName + ". Trying mothur's executable location " + tryPath); m->mothurOutEndLine();
- ifstream in2;
- ableToOpen = m->openInputFile(tryPath, in2, "noerror");
- in2.close();
- lookupFileName = tryPath;
- }
-
- if (ableToOpen == 1) { m->mothurOut("Unable to open " + lookupFileName + "."); m->mothurOutEndLine(); abort=true; }
- }
- else if(temp == "not open") {
+ bool ableToOpen = m->checkLocations(lookupFileName, inputDir);
+ if (!ableToOpen) { abort=true; }
+ }else if(temp == "not open") {
lookupFileName = validParameter.validFile(parameters, "lookup", false);
vector<string> sffFiles, oligosFiles;
readFile(sffFiles, oligosFiles);
- outputDir = m->hasPath(filename);
- string fileroot = outputDir + m->getRootName(m->getSimpleName(filename));
+ string thisOutputDir = outputDir;
+ if (thisOutputDir == "") { thisOutputDir = m->hasPath(filename); }
+ string fileroot = thisOutputDir + m->getRootName(m->getSimpleName(filename));
map<string, string> variables;
variables["[filename]"] = fileroot;
string fasta = getOutputFileName("fasta",variables);
if (makeGroup) { outputNames.push_back(group); outputTypes["group"].push_back(group); m->setGroupFile(group); }
}
+ m->setProcessors(toString(processors));
+
//report output filenames
m->mothurOutEndLine();
m->mothurOut("Output File Names: "); m->mothurOutEndLine();
in >> sff;
- sff = m->getFullPathName(sff);
-
//ignore file pairing
if(sff[0] == '#'){ while (!in.eof()) { char c = in.get(); if (c == 10 || c == 13){ break; } } m->gobble(in); }
else { //check for oligos file
+ bool ableToOpenSff = m->checkLocations(sff, inputDir);
+
oligos = "";
// get rest of line in case there is a oligos filename
if (c == 10 || c == 13 || c == -1){ break; }
else if (c == 32 || c == 9){;} //space or tab
else { oligos += c; }
- }
- sffFiles.push_back(sff);
- if (oligos != "") { oligos = m->getFullPathName(oligos); allBlank = false; }
- if (oligos == "") { allFull = false; }
- oligosFiles.push_back(oligos); //will push a blank if there is not an oligos for this sff file
+ }
+
+ if (ableToOpenSff) {
+ sffFiles.push_back(sff);
+ if (oligos != "") {
+ bool ableToOpenOligos = m->checkLocations(oligos, inputDir);
+ if (ableToOpenOligos) { allBlank = false; }
+ else { m->mothurOut("Can not find " + oligos + ". Ignoring.\n"); oligos = ""; }
+ }
+ if (oligos == "") { allFull = false; }
+ oligosFiles.push_back(oligos); //will push a blank if there is not an oligos for this sff file
+ }else { m->mothurOut("Can not find " + sff + ". Ignoring.\n"); }
}
m->gobble(in);
}
m->mothurOut("\n>>>>>\tProcessing " + sff + " (file " + toString(s+1) + " of " + toString(sffFiles.size()) + ")\t<<<<<\n");
//run sff.info
+ string redirects = "";
+ if (inputDir != "") { redirects += ", inputdir=" + inputDir; }
+ if (outputDir != "") { redirects += ", outputdir=" + outputDir; }
string inputString = "sff=" + sff + ", flow=T";
if (trim) { inputString += ", trim=T"; }
+ if (redirects != "") { inputString += redirects; }
m->mothurOut("/******************************************/"); m->mothurOutEndLine();
m->mothurOut("Running command: sffinfo(" + inputString + ")"); m->mothurOutEndLine();
m->mothurCalling = true;
m->mothurCalling = false;
m->mothurOutEndLine();
+ redirects = "";
+ if (outputDir != "") { redirects += ", outputdir=" + outputDir; }
+
//run summary.seqs on the fasta file
string fastaFile = "";
map<string, vector<string> >::iterator it = filenames.find("fasta");
else { m->mothurOut("[ERROR]: sffinfo did not create a fasta file, quitting.\n"); m->control_pressed = true; break; }
inputString = "fasta=" + fastaFile + ", processors=1";
+ if (redirects != "") { inputString += redirects; }
m->mothurOutEndLine();
m->mothurOut("Running command: summary.seqs(" + inputString + ")"); m->mothurOutEndLine();
m->mothurCalling = true;
inputString += ", maxhomop=" + toString(maxHomoP) + ", maxflows=" + toString(maxFlows) + ", minflows=" + toString(minFlows);
inputString += ", pdiffs=" + toString(pdiffs) + ", bdiffs=" + toString(bdiffs) + ", ldiffs=" + toString(ldiffs) + ", sdiffs=" + toString(sdiffs);
inputString += ", tdiffs=" + toString(tdiffs) + ", signal=" + toString(signal) + ", noise=" + toString(noise) + ", order=" + flowOrder + ", processors=1";
-
+ if (redirects != "") { inputString += redirects; }
m->mothurOutEndLine();
m->mothurOut("Running command: trim.flows(" + inputString + ")"); m->mothurOutEndLine();
m->mothurCalling = true;
inputString += ", sigma=" +toString(sigma);
inputString += ", mindelta=" + toString(minDelta);
inputString += ", order=" + flowOrder + ", processors=1";
-
+ if (redirects != "") { inputString += redirects; }
//run shhh.flows
m->mothurOutEndLine();
m->mothurOut("Running command: shhh.flows(" + inputString + ")"); m->mothurOutEndLine();
if (keepFirst != 0) { inputString += ", keepfirst=" + toString(keepFirst); }
if (removeLast != 0) { inputString += ", removelast=" + toString(removeLast); }
inputString += ", processors=1";
-
+ if (redirects != "") { inputString += redirects; }
//run trim.seqs
m->mothurOutEndLine();
m->mothurOut("Running command: trim.seqs(" + inputString + ")"); m->mothurOutEndLine();
}
inputString = "fasta=" + fastaFile + ", processors=1, name=" + nameFile;
+ if (redirects != "") { inputString += redirects; }
m->mothurOutEndLine();
m->mothurOut("Running command: summary.seqs(" + inputString + ")"); m->mothurOutEndLine();
m->mothurCalling = true;
m->appendFiles(nameFile, name);
if (makeGroup) { m->appendFiles(groupFile, group); }
}
- count++;
+
for (it = filenames.begin(); it != filenames.end(); it++) {
for (int i = 0; i < (it->second).size(); i++) {
outputNames.push_back((it->second)[i]); outputTypes[it->first].push_back((it->second)[i]);
}
}
+ count++;
}
return count;
int end;
linePair(int i, int j) : start(i), end(j) {}
};
-
+
+ string inputDir;
string filename, outputDir, flowOrder, lookupFileName, minDelta;
vector<string> outputNames;
bool abort, trim, large, flip, allFiles, keepforward, append, makeGroup;
if (vCalcs[i]->getName() == "sharedsobs") {
singleCalc = new Sobs();
if (sharedOtus && (labels.size() != 0)) {
- string filenameShared = outputDir + m->getRootName(m->getSimpleName(inputfile)) + lookup[0]->getLabel() + "." + vCalcs[i]->getName() + ".sharedotus";
+ string groupsTag = "";
+ for (int h = 0; h < lookup.size()-1; h++) { groupsTag += lookup[h]->getGroup() + "-"; } groupsTag += lookup[lookup.size()-1]->getGroup();
+ string filenameShared = outputDir + m->getRootName(m->getSimpleName(inputfile)) + lookup[0]->getLabel() + "." + vCalcs[i]->getName() + "." + groupsTag + ".sharedotus";
outputNames.push_back(filenameShared);
ofstream outShared;
ofstream outShared;
if (sharedOtus && (vCalcs[i]->getName() == "sharedsobs")) {
- string filenameShared = outputDir + m->getRootName(m->getSimpleName(inputfile)) + lookup[0]->getLabel() + "." + vCalcs[i]->getName() + ".sharedotus";
+ string groupsTag = "";
+ for (int h = 0; h < lookup.size()-1; h++) { groupsTag += lookup[h]->getGroup() + "-"; } groupsTag += lookup[lookup.size()-1]->getGroup();
+ string filenameShared = outputDir + m->getRootName(m->getSimpleName(inputfile)) + lookup[0]->getLabel() + "." + vCalcs[i]->getName() + "." + groupsTag + ".sharedotus";
outputNames.push_back(filenameShared);
ofstream outShared;
if (sharedOtus && (vCalcs[i]->getName() == "sharedsobs")) {
- string filenameShared = outputDir + m->getRootName(m->getSimpleName(inputfile)) + lookup[0]->getLabel() + "." + vCalcs[i]->getName() + ".sharedotus";
+ string groupsTag = "";
+ for (int h = 0; h < lookup.size()-1; h++) { groupsTag += lookup[h]->getGroup() + "-"; } groupsTag += lookup[lookup.size()-1]->getGroup();
+ string filenameShared = outputDir + m->getRootName(m->getSimpleName(inputfile)) + lookup[0]->getLabel() + "." + vCalcs[i]->getName() + "." + groupsTag + ".sharedotus";
outputNames.push_back(filenameShared);