X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=sequenceparser.cpp;h=e60f19b0df0034de0c1a693d7c5a55c59ef0ef82;hb=c47e480b743d1c242b8c527b6d12f992c68b8c2c;hp=44012d8ba8321fea520fbe613e0dac8f8911c760;hpb=ae57e166b2ed7b475ec3f466106bd76fabadd063;p=mothur.git diff --git a/sequenceparser.cpp b/sequenceparser.cpp index 44012d8..e60f19b 100644 --- a/sequenceparser.cpp +++ b/sequenceparser.cpp @@ -106,6 +106,8 @@ SequenceParser::SequenceParser(string groupFile, string fastaFile, string nameFi } } } + + allSeqsMap[names[i]] = names[0]; } @@ -247,6 +249,78 @@ vector SequenceParser::getSeqs(string g){ exit(1); } } +/************************************************************/ +int SequenceParser::getSeqs(string g, string filename, bool uchimeFormat=false){ + try { + map >::iterator it; + vector seqForThisGroup; + vector nameVector; + + it = seqs.find(g); + if(it == seqs.end()) { + m->mothurOut("[ERROR]: No sequences available for group " + g + ", please correct."); m->mothurOutEndLine(); + }else { + + ofstream out; + m->openOutputFile(filename, out); + + seqForThisGroup = it->second; + + if (uchimeFormat) { + // format should look like + //>seqName /ab=numRedundantSeqs/ + //sequence + + map nameMapForThisGroup = getNameMap(g); + map::iterator itNameMap; + int error = 0; + + for (int i = 0; i < seqForThisGroup.size(); i++) { + itNameMap = nameMapForThisGroup.find(seqForThisGroup[i].getName()); + + if (itNameMap == nameMapForThisGroup.end()){ + error = 1; + m->mothurOut("[ERROR]: " + seqForThisGroup[i].getName() + " is in your fastafile, but is not in your namesfile, please correct."); m->mothurOutEndLine(); + }else { + int num = m->getNumNames(itNameMap->second); + + seqPriorityNode temp(num, seqForThisGroup[i].getAligned(), seqForThisGroup[i].getName()); + nameVector.push_back(temp); + } + } + + if (error == 1) { out.close(); m->mothurRemove(filename); return 1; } + + //sort by num represented + sort(nameVector.begin(), nameVector.end(), compareSeqPriorityNodes); + + //print new file in order of + for (int i = 0; i < nameVector.size(); i++) { + + if(m->control_pressed) { out.close(); m->mothurRemove(filename); return 1; } + + out << ">" << nameVector[i].name << "/ab=" << nameVector[i].numIdentical << "/" << endl << nameVector[i].seq << endl; + } + + }else { + for (int i = 0; i < seqForThisGroup.size(); i++) { + + if(m->control_pressed) { out.close(); m->mothurRemove(filename); return 1; } + + seqForThisGroup[i].printSequence(out); + } + } + out.close(); + } + + return 0; + } + catch(exception& e) { + m->errorOut(e, "SequenceParser", "getSeqs"); + exit(1); + } +} + /************************************************************/ map SequenceParser::getNameMap(string g){ try { @@ -268,6 +342,38 @@ map SequenceParser::getNameMap(string g){ } } /************************************************************/ +int SequenceParser::getNameMap(string g, string filename){ + try { + map >::iterator it; + map nameMapForThisGroup; + + it = nameMapPerGroup.find(g); + if(it == nameMapPerGroup.end()) { + m->mothurOut("[ERROR]: No nameMap available for group " + g + ", please correct."); m->mothurOutEndLine(); + }else { + nameMapForThisGroup = it->second; + + ofstream out; + m->openOutputFile(filename, out); + + for (map::iterator itFile = nameMapForThisGroup.begin(); itFile != nameMapForThisGroup.end(); itFile++) { + + if(m->control_pressed) { out.close(); m->mothurRemove(filename); return 1; } + + out << itFile->first << '\t' << itFile->second << endl; + } + + out.close(); + } + + return 0; + } + catch(exception& e) { + m->errorOut(e, "SequenceParser", "getNameMap"); + exit(1); + } +} +/************************************************************/