+/**************************************************************************************************/
+#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
+#else
+static DWORD WINAPI MyTrimFlowThreadFunction(LPVOID lpParam){
+ trimFlowData* pDataArray;
+ pDataArray = (trimFlowData*)lpParam;
+
+ try {
+ ofstream trimFlowFile;
+ pDataArray->m->openOutputFile(pDataArray->trimFlowFileName, trimFlowFile);
+ trimFlowFile.setf(ios::fixed, ios::floatfield); trimFlowFile.setf(ios::showpoint);
+
+ ofstream scrapFlowFile;
+ pDataArray->m->openOutputFile(pDataArray->scrapFlowFileName, scrapFlowFile);
+ scrapFlowFile.setf(ios::fixed, ios::floatfield); scrapFlowFile.setf(ios::showpoint);
+
+ ofstream fastaFile;
+ if(pDataArray->fasta){ pDataArray->m->openOutputFile(pDataArray->fastaFileName, fastaFile); }
+
+ ifstream flowFile;
+ pDataArray->m->openInputFile(pDataArray->flowFileName, flowFile);
+
+ flowFile.seekg(pDataArray->start);
+
+ if(pDataArray->start == 0){
+ flowFile >> pDataArray->numFlows; pDataArray->m->gobble(flowFile);
+ scrapFlowFile << pDataArray->maxFlows << endl;
+ trimFlowFile << pDataArray->maxFlows << endl;
+ if(pDataArray->allFiles){
+ for(int i=0;i<pDataArray->barcodePrimerComboFileNames.size();i++){
+ for(int j=0;j<pDataArray->barcodePrimerComboFileNames[0].size();j++){
+ ofstream temp;
+ pDataArray->m->openOutputFile(pDataArray->barcodePrimerComboFileNames[i][j], temp);
+ temp << pDataArray->maxFlows << endl;
+ temp.close();
+ }
+ }
+ }
+ }
+
+ FlowData flowData(pDataArray->numFlows, pDataArray->signal, pDataArray->noise, pDataArray->maxHomoP, pDataArray->flowOrder);
+ cout << " thread flowdata address " << &flowData << '\t' << &flowFile << endl;
+ TrimOligos trimOligos(pDataArray->pdiffs, pDataArray->bdiffs, pDataArray->primers, pDataArray->barcodes, pDataArray->revPrimer);
+
+ pDataArray->count = pDataArray->end;
+ cout << pDataArray->threadID << '\t' << pDataArray->count << endl;
+ int count = 0;
+ for(int i = 0; i < pDataArray->end; i++){ //end is the number of sequences to process
+
+ if (pDataArray->m->control_pressed) { break; }
+ cout << pDataArray->threadID << '\t' << count << endl;
+ int success = 1;
+ int currentSeqDiffs = 0;
+ string trashCode = "";
+
+ flowData.getNext(flowFile);
+ cout << "thread good bit " << flowFile.good() << endl;
+ flowData.capFlows(pDataArray->maxFlows);
+
+ Sequence currSeq = flowData.getSequence();
+ if(!flowData.hasMinFlows(pDataArray->minFlows)){ //screen to see if sequence is of a minimum number of flows
+ success = 0;
+ trashCode += 'l';
+ }
+
+ int primerIndex = 0;
+ int barcodeIndex = 0;
+
+ if(pDataArray->barcodes.size() != 0){
+ success = trimOligos.stripBarcode(currSeq, barcodeIndex);
+ if(success > pDataArray->bdiffs) { trashCode += 'b'; }
+ else{ currentSeqDiffs += success; }
+ }
+
+ if(pDataArray->primers.size() != 0){
+ success = trimOligos.stripForward(currSeq, primerIndex);
+ if(success > pDataArray->pdiffs) { trashCode += 'f'; }
+ else{ currentSeqDiffs += success; }
+ }
+
+ if (currentSeqDiffs > pDataArray->tdiffs) { trashCode += 't'; }
+
+ if(pDataArray->revPrimer.size() != 0){
+ success = trimOligos.stripReverse(currSeq);
+ if(!success) { trashCode += 'r'; }
+ }
+
+ if(trashCode.length() == 0){
+
+ flowData.printFlows(trimFlowFile);
+
+ if(pDataArray->fasta) { currSeq.setAligned(currSeq.getUnaligned()); currSeq.printSequence(fastaFile); }
+
+ if(pDataArray->allFiles){
+ ofstream output;
+ pDataArray->m->openOutputFileAppend(pDataArray->barcodePrimerComboFileNames[barcodeIndex][primerIndex], output);
+ output.setf(ios::fixed, ios::floatfield); trimFlowFile.setf(ios::showpoint);
+
+ flowData.printFlows(output);
+ output.close();
+ }
+ }
+ else{
+ flowData.printFlows(scrapFlowFile, trashCode);
+ }
+
+ count++;
+ cout << pDataArray->threadID << '\t' << currSeq.getName() << endl;
+ //report progress
+ if((count) % 10000 == 0){ pDataArray->m->mothurOut(toString(count)); pDataArray->m->mothurOutEndLine(); }
+
+ }
+ //report progress
+ if((count) % 10000 != 0){ pDataArray->m->mothurOut(toString(count)); pDataArray->m->mothurOutEndLine(); }
+
+ trimFlowFile.close();
+ scrapFlowFile.close();
+ flowFile.close();
+ if(pDataArray->fasta){ fastaFile.close(); }
+
+ }
+ catch(exception& e) {
+ pDataArray->m->errorOut(e, "TrimFlowsCommand", "MyTrimFlowsThreadFunction");
+ exit(1);
+ }
+}
+#endif
+