]> git.donarmstrong.com Git - mothur.git/blobdiff - sffinfocommand.cpp
fixed problem with sffinfo that caused a file mismatch when the trimming trimmed...
[mothur.git] / sffinfocommand.cpp
index 4a9271ce94df57f99e9734ba2b4d9d30d20872e9..f9f6db6cead382e12e85068ac66d56b4b7c7d148 100644 (file)
@@ -30,7 +30,7 @@ SffInfoCommand::SffInfoCommand(){
                outputTypes["fasta"] = tempOutNames;
                outputTypes["flow"] = tempOutNames;
                outputTypes["sfftxt"] = tempOutNames;
-               outputTypes["qual"] = tempOutNames;
+               outputTypes["qfile"] = tempOutNames;
        }
        catch(exception& e) {
                m->errorOut(e, "SffInfoCommand", "SffInfoCommand");
@@ -89,7 +89,7 @@ SffInfoCommand::SffInfoCommand(string option)  {
                        outputTypes["fasta"] = tempOutNames;
                        outputTypes["flow"] = tempOutNames;
                        outputTypes["sfftxt"] = tempOutNames;
-                       outputTypes["qual"] = tempOutNames;
+                       outputTypes["qfile"] = 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 = "";         }
@@ -300,6 +300,18 @@ int SffInfoCommand::execute(){
                
                if (m->control_pressed) {  for (int i = 0; i < outputNames.size(); i++) {       remove(outputNames[i].c_str());         } return 0; }
                
+               //set fasta file as new current fastafile
+               string current = "";
+               itTypes = outputTypes.find("fasta");
+               if (itTypes != outputTypes.end()) {
+                       if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setFastaFile(current); }
+               }
+               
+               itTypes = outputTypes.find("qfile");
+               if (itTypes != outputTypes.end()) {
+                       if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setQualFile(current); }
+               }       
+               
                //report output filenames
                m->mothurOutEndLine();
                m->mothurOut("Output File Names: "); m->mothurOutEndLine();
@@ -336,7 +348,7 @@ int SffInfoCommand::extractSffInfo(string input, string accnos){
                
                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 (qual)       { m->openOutputFile(outQualFileName, outQual);          outputNames.push_back(outQualFileName); outputTypes["qfile"].push_back(outQualFileName);  }
                if (flow)       { m->openOutputFile(outFlowFileName, outFlow);          outputNames.push_back(outFlowFileName);  outFlow.setf(ios::fixed, ios::floatfield); outFlow.setf(ios::showpoint); outputTypes["flow"].push_back(outFlowFileName);  }
                
                ifstream in;
@@ -344,8 +356,9 @@ int SffInfoCommand::extractSffInfo(string input, string accnos){
                
                CommonHeader header; 
                readCommonHeader(in, header);
-               
+       
                int count = 0;
+               mycount = 0;
                
                //check magic number and version
                if (header.magicNumber != 779314790) { m->mothurOut("Magic Number is not correct, not a valid .sff file"); m->mothurOutEndLine(); return count; }
@@ -380,6 +393,7 @@ int SffInfoCommand::extractSffInfo(string input, string accnos){
                        }
                        
                        count++;
+                       mycount++;
                
                        //report progress
                        if((count+1) % 10000 == 0){     m->mothurOut(toString(count+1)); m->mothurOutEndLine();         }
@@ -613,32 +627,36 @@ 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);
+               if (name.length() >= 6) {
+                       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);
+               }
+               
+               if (name.length() >= 9) {
+                       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) {
@@ -772,6 +790,7 @@ int SffInfoCommand::printQualSeqData(ofstream& out, seqRead& read, Header& heade
                
                if (trim) {
                        if(header.clipQualRight < header.clipQualLeft){
+                               out << ">" << header.name << " xy=" << header.xy << endl;
                                out << "0\t0\t0\t0";
                        }
                        else if((header.clipQualRight != 0) && ((header.clipQualRight-header.clipQualLeft) >= 0)){