else {
//valid paramters for this command
- string Array[] = {"fasta","name", "group", "align", "accnos" };
+ string Array[] = {"fasta","name", "group", "alignreport", "accnos" };
vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
OptionParser parser(option);
if (groupfile == "not open") { abort = true; }
else if (groupfile == "not found") { groupfile = ""; }
- alignfile = validParameter.validFile(parameters, "align", true);
+ alignfile = validParameter.validFile(parameters, "alignreport", true);
if (alignfile == "not open") { abort = true; }
else if (alignfile == "not found") { alignfile = ""; }
- if ((fastafile == "") && (namefile == "") && (groupfile == "") && (alignfile == "")) { mothurOut("You must provide one of the following: fasta, name, group, align."); mothurOutEndLine(); abort = true; }
+ if ((fastafile == "") && (namefile == "") && (groupfile == "") && (alignfile == "")) { mothurOut("You must provide one of the following: fasta, name, group, alignreport."); mothurOutEndLine(); abort = true; }
- if (parameters.size() > 2) { mothurOut("You may only enter one of the following: fasta, name, group, align."); mothurOutEndLine(); abort = true; }
+ if (parameters.size() > 2) { mothurOut("You may only enter one of the following: fasta, name, group, alignreport."); mothurOutEndLine(); abort = true; }
}
}
try {
mothurOut("The get.seqs command reads an .accnos file and one of the following file types: fasta, name, group or alignreport file.\n");
mothurOut("It outputs a file containing only the sequences in the .accnos file.\n");
- mothurOut("The get.seqs command parameters are accnos, fasta, name, group and align. You must provide accnos and one of the other parameters.\n");
+ mothurOut("The get.seqs command parameters are accnos, fasta, name, group and alignreport. You must provide accnos and one of the other parameters.\n");
mothurOut("The get.seqs command should be in the following format: get.seqs(accnos=yourAccnos, fasta=yourFasta).\n");
mothurOut("Example get.seqs(accnos=amazon.accnos, fasta=amazon.fasta).\n");
mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n\n");
//**********************************************************************************************************************
void GetSeqsCommand::readFasta(){
try {
- string outputFileName = getRootName(fastafile) + "pick";
+ string outputFileName = getRootName(fastafile) + "pick" + getExtension(fastafile);
ofstream out;
openOutputFile(outputFileName, out);
openInputFile(fastafile, in);
string name;
+ bool wroteSomething = false;
+
while(!in.eof()){
Sequence currSeq(in);
name = currSeq.getName();
//if this name is in the accnos file
if (names.count(name) == 1) {
+ wroteSomething = true;
+
currSeq.printSequence(out);
+
+ names.erase(name);
}
gobble(in);
}
in.close();
- out.close();
+ out.close();
+
+ if (wroteSomething == false) {
+ mothurOut("Your file does not contain any sequence from the .accnos file."); mothurOutEndLine();
+ remove(outputFileName.c_str());
+ }
}
catch(exception& e) {
void GetSeqsCommand::readName(){
try {
- string outputFileName = getRootName(namefile) + "pick";
+ string outputFileName = getRootName(namefile) + "pick" + getExtension(namefile);
ofstream out;
openOutputFile(outputFileName, out);
openInputFile(namefile, in);
string name, firstCol, secondCol;
+ bool wroteSomething = false;
+
while(!in.eof()){
//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) == 1) {
+
+ wroteSomething = true;
+
out << firstCol << '\t';
//you know you have at least one valid second since first column is valid
for (int i = 0; i < validSecond.size()-1; i++) { out << validSecond[i] << ','; }
out << validSecond[validSecond.size()-1] << endl;
+
//make first name in set you come to first column and then add the remaining names to second column
}else {
//you want part of this row
if (validSecond.size() != 0) {
+
+ wroteSomething = true;
+
out << validSecond[0] << '\t';
//you know you have at least one valid second since first column is valid
in.close();
out.close();
+ if (wroteSomething == false) {
+ mothurOut("Your file does not contain any sequence from the .accnos file."); mothurOutEndLine();
+ remove(outputFileName.c_str());
+ }
+
}
catch(exception& e) {
errorOut(e, "GetSeqsCommand", "readName");
void GetSeqsCommand::readGroup(){
try {
- string outputFileName = getRootName(groupfile) + "pick";
+ string outputFileName = getRootName(groupfile) + "pick" + getExtension(groupfile);
ofstream out;
openOutputFile(outputFileName, out);
openInputFile(groupfile, in);
string name, group;
+ bool wroteSomething = false;
+
while(!in.eof()){
in >> name; //read from first column
//if this name is in the accnos file
if (names.count(name) == 1) {
+ wroteSomething = true;
+
out << name << '\t' << group << endl;
+
+ names.erase(name);
}
gobble(in);
}
in.close();
out.close();
+
+ if (wroteSomething == false) {
+ mothurOut("Your file does not contain any sequence from the .accnos file."); mothurOutEndLine();
+ remove(outputFileName.c_str());
+ }
}
catch(exception& e) {
//alignreport file has a column header line then all other lines contain 16 columns. we just want the first column since that contains the name
void GetSeqsCommand::readAlign(){
try {
- string outputFileName = getRootName(alignfile) + "pick";
+ string outputFileName = getRootName(getRootName(alignfile)) + "pick.align.report";
ofstream out;
openOutputFile(outputFileName, out);
openInputFile(alignfile, in);
string name, junk;
+ bool wroteSomething = false;
+
//read column headers
for (int i = 0; i < 16; i++) {
if (!in.eof()) { in >> junk; out << junk << '\t'; }
//if this name is in the accnos file
if (names.count(name) == 1) {
-
+ wroteSomething = true;
+
out << name << '\t';
//read rest
}
out << endl;
+ names.erase(name);
+
}else {//still read just don't do anything with it
//read rest
for (int i = 0; i < 15; i++) {
}
in.close();
out.close();
-
+
+ if (wroteSomething == false) {
+ mothurOut("Your file does not contain any sequence from the .accnos file."); mothurOutEndLine();
+ remove(outputFileName.c_str());
+ }
}
catch(exception& e) {
}
}
//**********************************************************************************************************************
+
void GetSeqsCommand::readAccnos(){
try {