X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=seqsummarycommand.h;h=a7ccb573490135c10c6fdb7258bb46228047d98b;hb=fc1ed1ae1b022719176910ab71993bd6535810ad;hp=c0d368770cfa8df11560d2b89fee200231cb0dc3;hpb=c651c46022761aef61644f78462365d8f767ff0b;p=mothur.git diff --git a/seqsummarycommand.h b/seqsummarycommand.h index c0d3687..a7ccb57 100644 --- a/seqsummarycommand.h +++ b/seqsummarycommand.h @@ -12,6 +12,9 @@ #include "mothur.h" #include "command.hpp" +#include "sequence.hpp" + +/**************************************************************************************************/ class SeqSummaryCommand : public Command { public: @@ -54,4 +57,118 @@ private: }; +/**************************************************************************************************/ +//custom data structure for threads to use. +// This is passed by void pointer so it can be any data type +// that can be passed using a single void pointer (LPVOID). +typedef struct seqSumData { + vector* startPosition; + vector* endPosition; + vector* seqLength; + vector* ambigBases; + vector* longHomoPolymer; + string filename; + string sumFile; + unsigned long int start; + unsigned long int end; + int count; + MothurOut* m; + string namefile; + map nameMap; + + + seqSumData(){} + seqSumData(vector* s, vector* e, vector* l, vector* a, vector* h, string f, string sf, MothurOut* mout, unsigned long int st, unsigned long int en, string na, map nam) { + startPosition = s; + endPosition = e; + seqLength = l; + ambigBases = a; + longHomoPolymer = h; + filename = f; + sumFile = sf; + m = mout; + start = st; + end = en; + namefile = na; + nameMap = nam; + count = 0; + } +}; + +/**************************************************************************************************/ +#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) +#else +static DWORD WINAPI MySeqSumThreadFunction(LPVOID lpParam){ + seqSumData* pDataArray; + pDataArray = (seqSumData*)lpParam; + + try { + ofstream outSummary; + pDataArray->m->openOutputFile(pDataArray->sumFile, outSummary); + + ifstream in; + pDataArray->m->openInputFile(pDataArray->filename, in); + + //print header if you are process 0 + if ((pDataArray->start == 0) || (pDataArray->start == 1)) { + outSummary << "seqname\tstart\tend\tnbases\tambigs\tpolymer\tnumSeqs" << endl; + in.seekg(0); + }else { //this accounts for the difference in line endings. + in.seekg(pDataArray->start-1); pDataArray->m->gobble(in); + } + + pDataArray->count = pDataArray->end; + for(int i = 0; i < pDataArray->end; i++){ //end is the number of sequences to process + + if (pDataArray->m->control_pressed) { in.close(); outSummary.close(); pDataArray->count = 1; return 1; } + + Sequence current(in); pDataArray->m->gobble(in); + + if (current.getName() != "") { + + int num = 1; + if (pDataArray->namefile != "") { + //make sure this sequence is in the namefile, else error + map::iterator it = pDataArray->nameMap.find(current.getName()); + + if (it == pDataArray->nameMap.end()) { pDataArray->m->mothurOut("[ERROR]: " + current.getName() + " is not in your namefile, please correct."); pDataArray->m->mothurOutEndLine(); pDataArray->m->control_pressed = true; } + else { num = it->second; } + } + + //for each sequence this sequence represents + for (int i = 0; i < num; i++) { + pDataArray->startPosition->push_back(current.getStartPos()); + pDataArray->endPosition->push_back(current.getEndPos()); + pDataArray->seqLength->push_back(current.getNumBases()); + pDataArray->ambigBases->push_back(current.getAmbigBases()); + pDataArray->longHomoPolymer->push_back(current.getLongHomoPolymer()); + } + + outSummary << current.getName() << '\t'; + outSummary << current.getStartPos() << '\t' << current.getEndPos() << '\t'; + outSummary << current.getNumBases() << '\t' << current.getAmbigBases() << '\t'; + outSummary << current.getLongHomoPolymer() << '\t' << num << endl; + } + } + + in.close(); + outSummary.close(); + + return 0; + + } + catch(exception& e) { + pDataArray->m->errorOut(e, "SeqSummaryCommand", "MySeqSumThreadFunction"); + exit(1); + } +} #endif + + + + +#endif + +/**************************************************************************************************/ + +