X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=blobdiff_plain;f=listseqscommand.cpp;fp=listseqscommand.cpp;h=0ead54a90cf2ef44205947baddecb39b21e6b8f7;hp=343d4fdc6399f8ca9a91c6cac9b31313d7b76bbb;hb=2ff2d03fbe46ce8cf2738bff4403a52be4f31e2f;hpb=a935b75dd890da5ae7f09e5e6179f90ab2955348 diff --git a/listseqscommand.cpp b/listseqscommand.cpp index 343d4fd..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(){