X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=sffinfocommand.cpp;h=66409e88f9013abd8deb9fd2ba78f6bfdf249a38;hb=3e2465c16d187247ce3befd29811c2d5dfc15ee8;hp=a691a405ddb31fb022ebf37c98b40deb8e54c6a5;hpb=260ae19c36cb11a53ddc5a75b5e507f8dd8b31d6;p=mothur.git diff --git a/sffinfocommand.cpp b/sffinfocommand.cpp index a691a40..66409e8 100644 --- a/sffinfocommand.cpp +++ b/sffinfocommand.cpp @@ -10,6 +10,57 @@ #include "sffinfocommand.h" #include "endiannessmacros.h" +//********************************************************************************************************************** +vector SffInfoCommand::getValidParameters(){ + try { + string Array[] = {"sff","qfile","fasta","flow","trim","accnos","sfftxt","outputdir","inputdir", "outputdir"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "SffInfoCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +SffInfoCommand::SffInfoCommand(){ + try { + abort = true; + //initialize outputTypes + vector tempOutNames; + outputTypes["fasta"] = tempOutNames; + outputTypes["flow"] = tempOutNames; + outputTypes["sfftxt"] = tempOutNames; + outputTypes["qual"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "SffInfoCommand", "SffInfoCommand"); + exit(1); + } +} +//********************************************************************************************************************** +vector SffInfoCommand::getRequiredParameters(){ + try { + string Array[] = {"sff"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "SffInfoCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector SffInfoCommand::getRequiredFiles(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "SffInfoCommand", "getRequiredFiles"); + exit(1); + } +} //********************************************************************************************************************** SffInfoCommand::SffInfoCommand(string option) { @@ -34,6 +85,13 @@ SffInfoCommand::SffInfoCommand(string option) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } + //initialize outputTypes + vector tempOutNames; + outputTypes["fasta"] = tempOutNames; + outputTypes["flow"] = tempOutNames; + outputTypes["sfftxt"] = tempOutNames; + outputTypes["qual"] = tempOutNames; + //if the user changes the output directory command factory will send this info to us in the output parameter outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; } @@ -61,10 +119,25 @@ SffInfoCommand::SffInfoCommand(string option) { if (m->getDefaultPath() != "") { //default path is set string tryPath = m->getDefaultPath() + m->getSimpleName(filenames[i]); m->mothurOut("Unable to open " + filenames[i] + ". Trying default " + tryPath); m->mothurOutEndLine(); - ableToOpen = m->openInputFile(tryPath, in, "noerror"); + ifstream in2; + ableToOpen = m->openInputFile(tryPath, in2, "noerror"); + in2.close(); filenames[i] = tryPath; } } + + //if you can't open it, try default location + if (ableToOpen == 1) { + if (m->getOutputDir() != "") { //default path is set + string tryPath = m->getOutputDir() + m->getSimpleName(filenames[i]); + m->mothurOut("Unable to open " + filenames[i] + ". Trying output directory " + tryPath); m->mothurOutEndLine(); + ifstream in2; + ableToOpen = m->openInputFile(tryPath, in2, "noerror"); + in2.close(); + filenames[i] = tryPath; + } + } + in.close(); if (ableToOpen == 1) { @@ -101,7 +174,20 @@ SffInfoCommand::SffInfoCommand(string option) { if (m->getDefaultPath() != "") { //default path is set string tryPath = m->getDefaultPath() + m->getSimpleName(accnosFileNames[i]); m->mothurOut("Unable to open " + accnosFileNames[i] + ". Trying default " + tryPath); m->mothurOutEndLine(); - ableToOpen = m->openInputFile(tryPath, in, "noerror"); + ifstream in2; + ableToOpen = m->openInputFile(tryPath, in2, "noerror"); + in2.close(); + accnosFileNames[i] = tryPath; + } + } + //if you can't open it, try default location + if (ableToOpen == 1) { + if (m->getOutputDir() != "") { //default path is set + string tryPath = m->getOutputDir() + m->getSimpleName(accnosFileNames[i]); + m->mothurOut("Unable to open " + accnosFileNames[i] + ". Trying output directory " + tryPath); m->mothurOutEndLine(); + ifstream in2; + ableToOpen = m->openInputFile(tryPath, in2, "noerror"); + in2.close(); accnosFileNames[i] = tryPath; } } @@ -227,10 +313,10 @@ int SffInfoCommand::extractSffInfo(string input, string accnos){ outQualFileName = outputDir + m->getRootName(m->getSimpleName(input)) + "raw.qual"; } - if (sfftxt) { m->openOutputFile(sfftxtFileName, outSfftxt); outSfftxt.setf(ios::fixed, ios::floatfield); outSfftxt.setf(ios::showpoint); outputNames.push_back(sfftxtFileName); } - if (fasta) { m->openOutputFile(outFastaFileName, outFasta); outputNames.push_back(outFastaFileName); } - if (qual) { m->openOutputFile(outQualFileName, outQual); outputNames.push_back(outQualFileName); } - if (flow) { m->openOutputFile(outFlowFileName, outFlow); outputNames.push_back(outFlowFileName); } + if (sfftxt) { m->openOutputFile(sfftxtFileName, outSfftxt); outSfftxt.setf(ios::fixed, ios::floatfield); outSfftxt.setf(ios::showpoint); outputNames.push_back(sfftxtFileName); outputTypes["sfftxt"].push_back(sfftxtFileName); } + if (fasta) { m->openOutputFile(outFastaFileName, outFasta); outputNames.push_back(outFastaFileName); outputTypes["fasta"].push_back(outFastaFileName); } + if (qual) { m->openOutputFile(outQualFileName, outQual); outputNames.push_back(outQualFileName); outputTypes["qual"].push_back(outQualFileName); } + if (flow) { m->openOutputFile(outFlowFileName, outFlow); outputNames.push_back(outFlowFileName); outputTypes["flow"].push_back(outFlowFileName); } ifstream in; in.open(input.c_str(), ios::binary); @@ -429,6 +515,9 @@ int SffInfoCommand::readHeader(ifstream& in, Header& header){ if (header.name.length() > header.nameLength) { header.name = header.name.substr(0, header.nameLength); } delete[] tempBuffer; + //extract info from name + decodeName(header.timestamp, header.region, header.xy, header.name); + /* Pad to 8 chars */ unsigned long int spotInFile = in.tellg(); unsigned long int spot = (spotInFile + 7)& ~7; @@ -499,6 +588,43 @@ int SffInfoCommand::readSeqData(ifstream& in, seqRead& read, int numFlowReads, i } } //********************************************************************************************************************** +int SffInfoCommand::decodeName(string& timestamp, string& region, string& xy, string name) { + try { + + string time = name.substr(0, 6); + unsigned int timeNum = m->fromBase36(time); + + int q1 = timeNum / 60; + int sec = timeNum - 60 * q1; + int q2 = q1 / 60; + int minute = q1 - 60 * q2; + int q3 = q2 / 24; + int hr = q2 - 24 * q3; + int q4 = q3 / 32; + int day = q3 - 32 * q4; + int q5 = q4 / 13; + int mon = q4 - 13 * q5; + int year = 2000 + q5; + + timestamp = toString(year) + "_" + toString(mon) + "_" + toString(day) + "_" + toString(hr) + "_" + toString(minute) + "_" + toString(sec); + + region = name.substr(7, 2); + + string xyNum = name.substr(9); + unsigned int myXy = m->fromBase36(xyNum); + int x = myXy >> 12; + int y = myXy & 4095; + + xy = toString(x) + "_" + toString(y); + + return 0; + } + catch(exception& e) { + m->errorOut(e, "SffInfoCommand", "decodeName"); + exit(1); + } +} +//********************************************************************************************************************** int SffInfoCommand::printCommonHeader(ofstream& out, CommonHeader& header) { try { @@ -526,9 +652,9 @@ int SffInfoCommand::printHeader(ofstream& out, Header& header) { try { out << ">" << header.name << endl; - out << "Run Prefix: " << endl; - out << "Region #: " << endl; - out << "XY Location: " << endl << endl; + out << "Run Prefix: " << header.timestamp << endl; + out << "Region #: " << header.region << endl; + out << "XY Location: " << header.xy << endl << endl; out << "Run Name: " << endl; out << "Analysis Name: " << endl; @@ -607,7 +733,7 @@ int SffInfoCommand::printFastaSeqData(ofstream& out, seqRead& read, Header& head } } - out << ">" << header.name << endl; + out << ">" << header.name << " xy=" << header.xy << endl; out << seq << endl; return 0; @@ -627,15 +753,15 @@ int SffInfoCommand::printQualSeqData(ofstream& out, seqRead& read, Header& heade out << "0\t0\t0\t0"; } else if((header.clipQualRight != 0) && ((header.clipQualRight-header.clipQualLeft) >= 0)){ - out << ">" << header.name << " length=" << (header.clipQualRight-header.clipQualLeft) << endl; + out << ">" << header.name << " xy=" << header.xy << " length=" << (header.clipQualRight-header.clipQualLeft) << endl; for (int i = (header.clipQualLeft-1); i < (header.clipQualRight-1); i++) { out << read.qualScores[i] << '\t'; } } else{ - out << ">" << header.name << " length=" << (header.clipQualRight-header.clipQualLeft) << endl; + out << ">" << header.name << " xy=" << header.xy << " length=" << (header.clipQualRight-header.clipQualLeft) << endl; for (int i = (header.clipQualLeft-1); i < read.qualScores.size(); i++) { out << read.qualScores[i] << '\t'; } } }else{ - out << ">" << header.name << " length=" << read.qualScores.size() << endl; + out << ">" << header.name << " xy=" << header.xy << " length=" << read.qualScores.size() << endl; for (int i = 0; i < read.qualScores.size(); i++) { out << read.qualScores[i] << '\t'; } } @@ -653,7 +779,7 @@ int SffInfoCommand::printQualSeqData(ofstream& out, seqRead& read, Header& heade int SffInfoCommand::printFlowSeqData(ofstream& out, seqRead& read, Header& header) { try { - out << ">" << header.name << endl; + out << ">" << header.name << " xy=" << header.xy << endl; for (int i = 0; i < read.flowgram.size(); i++) { out << setprecision(2) << (read.flowgram[i]/(float)100) << '\t'; } out << endl;