Permalink
Browse files

Uses mothurOut readNames

  • Loading branch information...
1 parent 2cd73cb commit c2295deed329e46b8c77f785921923b3fad4964d @mothur-westcott mothur-westcott committed Sep 22, 2016
Showing with 8 additions and 34 deletions.
  1. +8 −31 source/commands/preclustercommand.cpp
  2. +0 −3 source/commands/preclustercommand.h
@@ -342,7 +342,6 @@ int PreClusterCommand::execute(){
}else {
if (processors != 1) { m->mothurOut("When using running without group information mothur can only use 1 processor, continuing."); m->mothurOutEndLine(); processors = 1; }
- if (namefile != "") { readNameFile(); }
//reads fasta file and return number of seqs
int numSeqs = readFASTA(); //fills alignSeqs and makes all seqs active
@@ -762,7 +761,10 @@ int PreClusterCommand::process(string newMapFile){
/**************************************************************************************************/
int PreClusterCommand::readFASTA(){
try {
- //ifstream inNames;
+ map<string, string> nameMap;
+ map<string, string>::iterator it;
+ if (namefile != "") { m->readNames(namefile, nameMap); }
+
ifstream inFasta;
m->openInputFile(fastafile, inFasta);
@@ -776,11 +778,12 @@ int PreClusterCommand::readFASTA(){
if (seq.getName() != "") { //can get "" if commented line is at end of fasta file
if (namefile != "") {
- itSize = sizes.find(seq.getName());
+ it = nameMap.find(seq.getName());
- if (itSize == sizes.end()) { m->mothurOut(seq.getName() + " is not in your names file, please correct."); m->mothurOutEndLine(); exit(1); }
+ if (it == nameMap.end()) { m->mothurOut(seq.getName() + " is not in your names file, please correct."); m->mothurOutEndLine(); exit(1); }
else{
- seqPNode tempNode(itSize->second, seq, names[seq.getName()]);
+ string second = it->second;
+ seqPNode tempNode(m->getNumNames(second), seq, second);
alignSeqs.push_back(tempNode);
lengths.insert(seq.getAligned().length());
}
@@ -1031,30 +1034,4 @@ void PreClusterCommand::printData(string newfasta, string newname, string group)
}
/**************************************************************************************************/
-void PreClusterCommand::readNameFile(){
- try {
- ifstream in;
- m->openInputFile(namefile, in);
- string firstCol, secondCol;
-
- while (!in.eof()) {
- in >> firstCol >> secondCol; m->gobble(in);
-
- m->checkName(firstCol);
- m->checkName(secondCol);
- int size = m->getNumNames(secondCol);
-
- names[firstCol] = secondCol;
- sizes[firstCol] = size;
- }
- in.close();
- }
- catch(exception& e) {
- m->errorOut(e, "PreClusterCommand", "readNameFile");
- exit(1);
- }
-}
-
-/**************************************************************************************************/
-
@@ -77,9 +77,6 @@ class PreClusterCommand : public Command {
bool abort, bygroup, topdown;
string fastafile, namefile, outputDir, groupfile, countfile, method, align;
vector<seqPNode> alignSeqs; //maps the number of identical seqs to a sequence
- map<string, string> names; //represents the names file first column maps to second column
- map<string, int> sizes; //this map a seq name to the number of identical seqs in the names file
- map<string, int>::iterator itSize;
vector<string> outputNames;
int readFASTA();

0 comments on commit c2295de

Please sign in to comment.