X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=getseqscommand.cpp;h=ffe49b48810d7916e5324efd9480c87e8322ec92;hb=8742edef7a51b82834289e570d336f5a81ba1f2b;hp=a4697ca3fded8c34ec5320630a588e243601373d;hpb=f06fdb807822f8e06db003ed809c87250905cfc8;p=mothur.git diff --git a/getseqscommand.cpp b/getseqscommand.cpp index a4697ca..ffe49b4 100644 --- a/getseqscommand.cpp +++ b/getseqscommand.cpp @@ -201,21 +201,24 @@ GetSeqsCommand::GetSeqsCommand(string option) { m->mothurOut("You have no valid accnos file and accnos is required."); m->mothurOutEndLine(); abort = true; } - } + }else { m->setAccnosFile(accnosfile); } if (accnosfile2 == "not found") { accnosfile2 = ""; } fastafile = validParameter.validFile(parameters, "fasta", true); if (fastafile == "not open") { abort = true; } - else if (fastafile == "not found") { fastafile = ""; } + else if (fastafile == "not found") { fastafile = ""; } + else { m->setFastaFile(fastafile); } namefile = validParameter.validFile(parameters, "name", true); if (namefile == "not open") { abort = true; } else if (namefile == "not found") { namefile = ""; } + else { m->setNameFile(namefile); } groupfile = validParameter.validFile(parameters, "group", true); if (groupfile == "not open") { abort = true; } else if (groupfile == "not found") { groupfile = ""; } + else { m->setGroupFile(groupfile); } alignfile = validParameter.validFile(parameters, "alignreport", true); if (alignfile == "not open") { abort = true; } @@ -224,14 +227,17 @@ GetSeqsCommand::GetSeqsCommand(string option) { listfile = validParameter.validFile(parameters, "list", true); if (listfile == "not open") { abort = true; } else if (listfile == "not found") { listfile = ""; } + else { m->setListFile(listfile); } taxfile = validParameter.validFile(parameters, "taxonomy", true); if (taxfile == "not open") { abort = true; } else if (taxfile == "not found") { taxfile = ""; } + else { m->setTaxonomyFile(taxfile); } qualfile = validParameter.validFile(parameters, "qfile", true); if (qualfile == "not open") { abort = true; } else if (qualfile == "not found") { qualfile = ""; } + else { m->setQualFile(qualfile); } accnosfile2 = validParameter.validFile(parameters, "accnos2", true); if (accnosfile2 == "not open") { abort = true; } @@ -273,9 +279,8 @@ int GetSeqsCommand::execute(){ if (qualfile != "") { readQual(); } if (accnosfile2 != "") { compareAccnos(); } - if (m->control_pressed) { outputTypes.clear(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } + if (m->control_pressed) { outputTypes.clear(); for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; } - m->mothurOut("Selected " + toString(names.size()) + " sequences."); m->mothurOutEndLine(); if (outputNames.size() != 0) { m->mothurOutEndLine(); @@ -341,10 +346,11 @@ int GetSeqsCommand::readFasta(){ string name; bool wroteSomething = false; + int selectedCount = 0; while(!in.eof()){ - if (m->control_pressed) { in.close(); out.close(); remove(outputFileName.c_str()); return 0; } + if (m->control_pressed) { in.close(); out.close(); m->mothurRemove(outputFileName); return 0; } Sequence currSeq(in); name = currSeq.getName(); @@ -355,6 +361,7 @@ int GetSeqsCommand::readFasta(){ wroteSomething = true; currSeq.printSequence(out); + selectedCount++; } } m->gobble(in); @@ -366,6 +373,8 @@ int GetSeqsCommand::readFasta(){ if (wroteSomething == false) { m->mothurOut("Your file does not contain any sequence from the .accnos file."); m->mothurOutEndLine(); } outputNames.push_back(outputFileName); outputTypes["fasta"].push_back(outputFileName); + m->mothurOut("Selected " + toString(selectedCount) + " sequences from your fasta file."); m->mothurOutEndLine(); + return 0; } @@ -389,6 +398,7 @@ int GetSeqsCommand::readQual(){ string name; bool wroteSomething = false; + int selectedCount = 0; while(!in.eof()){ @@ -420,6 +430,7 @@ int GetSeqsCommand::readQual(){ wroteSomething = true; out << name << endl << scores; + selectedCount++; } m->gobble(in); @@ -431,6 +442,9 @@ int GetSeqsCommand::readQual(){ if (wroteSomething == false) { m->mothurOut("Your file does not contain any sequence from the .accnos file."); m->mothurOutEndLine(); } outputNames.push_back(outputFileName); outputTypes["qfile"].push_back(outputFileName); + m->mothurOut("Selected " + toString(selectedCount) + " sequences from your quality file."); m->mothurOutEndLine(); + + return 0; } @@ -452,10 +466,13 @@ int GetSeqsCommand::readList(){ m->openInputFile(listfile, in); bool wroteSomething = false; + int selectedCount = 0; while(!in.eof()){ - if (m->control_pressed) { in.close(); out.close(); remove(outputFileName.c_str()); return 0; } + selectedCount = 0; + + if (m->control_pressed) { in.close(); out.close(); m->mothurRemove(outputFileName); return 0; } //read in list vector ListVector list(in); @@ -476,11 +493,11 @@ int GetSeqsCommand::readList(){ binnames = binnames.substr(binnames.find_first_of(',')+1, binnames.length()); //if that name is in the .accnos file, add it - if (names.count(name) != 0) { newNames += name + ","; } + if (names.count(name) != 0) { newNames += name + ","; selectedCount++; } } //get last name - if (names.count(binnames) != 0) { newNames += binnames + ","; } + if (names.count(binnames) != 0) { newNames += binnames + ","; selectedCount++; } //if there are names in this bin add to new list if (newNames != "") { @@ -503,6 +520,8 @@ int GetSeqsCommand::readList(){ if (wroteSomething == false) { m->mothurOut("Your file does not contain any sequence from the .accnos file."); m->mothurOutEndLine(); } outputNames.push_back(outputFileName); outputTypes["list"].push_back(outputFileName); + m->mothurOut("Selected " + toString(selectedCount) + " sequences from your list file."); m->mothurOutEndLine(); + return 0; } @@ -526,11 +545,11 @@ int GetSeqsCommand::readName(){ string name, firstCol, secondCol; bool wroteSomething = false; - + int selectedCount = 0; while(!in.eof()){ - if (m->control_pressed) { in.close(); out.close(); remove(outputFileName.c_str()); return 0; } + if (m->control_pressed) { in.close(); out.close(); m->mothurRemove(outputFileName); return 0; } in >> firstCol; in >> secondCol; @@ -552,7 +571,10 @@ int GetSeqsCommand::readName(){ for (int i = 0; i < parsedNames.size(); i++) { names.insert(parsedNames[i]); } out << firstCol << '\t' << hold << endl; wroteSomething = true; + selectedCount += parsedNames.size(); }else { + selectedCount += validSecond.size(); + //if the name in the first column is in the set then print it and any other names in second column also in set if (names.count(firstCol) != 0) { @@ -588,6 +610,8 @@ int GetSeqsCommand::readName(){ if (wroteSomething == false) { m->mothurOut("Your file does not contain any sequence from the .accnos file."); m->mothurOutEndLine(); } outputNames.push_back(outputFileName); outputTypes["name"].push_back(outputFileName); + m->mothurOut("Selected " + toString(selectedCount) + " sequences from your name file."); m->mothurOutEndLine(); + return 0; } @@ -612,10 +636,11 @@ int GetSeqsCommand::readGroup(){ string name, group; bool wroteSomething = false; + int selectedCount = 0; while(!in.eof()){ - if (m->control_pressed) { in.close(); out.close(); remove(outputFileName.c_str()); return 0; } + if (m->control_pressed) { in.close(); out.close(); m->mothurRemove(outputFileName); return 0; } in >> name; //read from first column @@ -626,6 +651,7 @@ int GetSeqsCommand::readGroup(){ wroteSomething = true; out << name << '\t' << group << endl; + selectedCount++; } m->gobble(in); @@ -636,6 +662,9 @@ int GetSeqsCommand::readGroup(){ if (wroteSomething == false) { m->mothurOut("Your file does not contain any sequence from the .accnos file."); m->mothurOutEndLine(); } outputNames.push_back(outputFileName); outputTypes["group"].push_back(outputFileName); + m->mothurOut("Selected " + toString(selectedCount) + " sequences from your group file."); m->mothurOutEndLine(); + + return 0; } @@ -658,10 +687,11 @@ int GetSeqsCommand::readTax(){ string name, tax; bool wroteSomething = false; + int selectedCount = 0; while(!in.eof()){ - if (m->control_pressed) { in.close(); out.close(); remove(outputFileName.c_str()); return 0; } + if (m->control_pressed) { in.close(); out.close(); m->mothurRemove(outputFileName); return 0; } in >> name; //read from first column in >> tax; //read from second column @@ -671,6 +701,7 @@ int GetSeqsCommand::readTax(){ wroteSomething = true; out << name << '\t' << tax << endl; + selectedCount++; } m->gobble(in); @@ -680,6 +711,8 @@ int GetSeqsCommand::readTax(){ if (wroteSomething == false) { m->mothurOut("Your file does not contain any sequence from the .accnos file."); m->mothurOutEndLine(); } outputNames.push_back(outputFileName); outputTypes["taxonomy"].push_back(outputFileName); + + m->mothurOut("Selected " + toString(selectedCount) + " sequences from your taxonomy file."); m->mothurOutEndLine(); return 0; @@ -705,6 +738,7 @@ int GetSeqsCommand::readAlign(){ string name, junk; bool wroteSomething = false; + int selectedCount = 0; //read column headers for (int i = 0; i < 16; i++) { @@ -715,7 +749,7 @@ int GetSeqsCommand::readAlign(){ while(!in.eof()){ - if (m->control_pressed) { in.close(); out.close(); remove(outputFileName.c_str()); return 0; } + if (m->control_pressed) { in.close(); out.close(); m->mothurRemove(outputFileName); return 0; } in >> name; //read from first column @@ -723,6 +757,7 @@ int GetSeqsCommand::readAlign(){ //if this name is in the accnos file if (names.count(name) != 0) { wroteSomething = true; + selectedCount++; out << name << '\t'; @@ -749,6 +784,8 @@ int GetSeqsCommand::readAlign(){ if (wroteSomething == false) { m->mothurOut("Your file does not contain any sequence from the .accnos file."); m->mothurOutEndLine(); } outputNames.push_back(outputFileName); outputTypes["alignreport"].push_back(outputFileName); + m->mothurOut("Selected " + toString(selectedCount) + " sequences from your alignreport file."); m->mothurOutEndLine(); + return 0; }