X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=blobdiff_plain;f=listseqscommand.cpp;h=0ead54a90cf2ef44205947baddecb39b21e6b8f7;hp=8a1effeb7deaf02f6931633f1abfc41f355a9957;hb=cf9987b67aa49777a4c91c2d21f96e58bf17aa82;hpb=1a5c2356c1b955c6ec024b2baf9f46377ee7c72e diff --git a/listseqscommand.cpp b/listseqscommand.cpp index 8a1effe..0ead54a 100644 --- a/listseqscommand.cpp +++ b/listseqscommand.cpp @@ -16,6 +16,7 @@ //********************************************************************************************************************** vector 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); @@ -39,8 +40,8 @@ vector ListSeqsCommand::setParameters(){ 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"; @@ -169,6 +170,14 @@ ListSeqsCommand::ListSeqsCommand(string option) { //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 @@ -205,8 +214,12 @@ ListSeqsCommand::ListSeqsCommand(string option) { 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++; } @@ -230,6 +243,7 @@ int ListSeqsCommand::execute(){ //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(); } @@ -285,6 +299,53 @@ int ListSeqsCommand::execute(){ 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 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(){ @@ -297,7 +358,7 @@ int ListSeqsCommand::readFasta(){ //ofstream out; //string newFastaName = outputDir + m->getRootName(m->getSimpleName(fastafile)) + "numsAdded.fasta"; //m->openOutputFile(newFastaName, out); - //int count = 1; + int count = 1; //string lastName = ""; while(!in.eof()){ @@ -310,7 +371,7 @@ int ListSeqsCommand::readFasta(){ if (name != "") { names.push_back(name); } m->gobble(in); - //count++; + if (m->debug) { count++; cout << "[DEBUG]: count = " + toString(count) + ", name = " + currSeq.getName() + "\n"; } } in.close(); //out.close(); @@ -415,7 +476,7 @@ int ListSeqsCommand::readGroup(){ int ListSeqsCommand::readCount(){ try { CountTable ct; - ct.readTable(countfile); + ct.readTable(countfile, false, false); if (m->control_pressed) { return 0; }