1 #ifndef CHIMERAUCHIMECOMMAND_H
2 #define CHIMERAUCHIMECOMMAND_H
6 * chimerauchimecommand.h
9 * Created by westcott on 5/13/11.
10 * Copyright 2011 Schloss Lab. All rights reserved.
15 #include "command.hpp"
16 #include "sequenceparser.h"
18 /***********************************************************/
20 class ChimeraUchimeCommand : public Command {
22 ChimeraUchimeCommand(string);
23 ChimeraUchimeCommand();
24 ~ChimeraUchimeCommand() {}
26 vector<string> setParameters();
27 string getCommandName() { return "chimera.uchime"; }
28 string getCommandCategory() { return "Sequence Processing"; }
29 string getOutputFileNameTag(string, string);
30 string getHelpString();
31 string getCitation() { return "uchime by Robert C. Edgar\nhttp://drive5.com/uchime\nThis code is donated to the public domain.\nhttp://www.mothur.org/wiki/Chimera.uchime\nEdgar,R.C., Haas,B.J., Clemente,J.C., Quince,C. and Knight,R. (2011), UCHIME improves sensitivity and speed of chimera detection, Bioinformatics, in press.\n"; }
32 string getDescription() { return "detect chimeric sequences"; }
35 void help() { m->mothurOut(getHelpString()); }
41 linePair(int i, int j) : start(i), end(j) {}
44 vector<int> processIDS; //processid
45 int driver(string, string, string, string, int&);
46 int createProcesses(string, string, string, string, int&);
48 bool abort, useAbskew, chimealns, useMinH, useMindiv, useXn, useDn, useXa, useChunks, useMinchunk, useIdsmoothwindow, useMinsmoothid, useMaxp, skipgaps, skipgaps2, useMinlen, useMaxlen, ucl, useQueryfract;
49 string fastafile, groupfile, templatefile, outputDir, namefile, abskew, minh, mindiv, xn, dn, xa, chunks, minchunk, idsmoothwindow, minsmoothid, maxp, minlen, maxlen, queryfract, uchimeLocation;
53 vector<string> outputNames;
54 vector<string> fastaFileNames;
55 vector<string> nameFileNames;
56 vector<string> groupFileNames;
58 string getNamesFile(string&);
59 int readFasta(string, map<string, string>&);
60 int printFile(vector<seqPriorityNode>&, string);
61 int deconvoluteResults(SequenceParser&, string, string, string);
62 int driverGroups(SequenceParser&, string, string, string, string, int, int, vector<string>);
63 int createProcessesGroups(SequenceParser&, string, string, string, string, vector<string>, string, string, string);
68 /***********************************************************/
69 /**************************************************************************************************/
70 //custom data structure for threads to use.
71 // This is passed by void pointer so it can be any data type
72 // that can be passed using a single void pointer (LPVOID).
78 string accnos, alns, filename, templatefile, uchimeLocation;
82 int threadID, count, numChimeras;
83 vector<string> groups;
84 bool useAbskew, chimealns, useMinH, useMindiv, useXn, useDn, useXa, useChunks, useMinchunk, useIdsmoothwindow, useMinsmoothid, useMaxp, skipgaps, skipgaps2, useMinlen, useMaxlen, ucl, useQueryfract;
85 string abskew, minh, mindiv, xn, dn, xa, chunks, minchunk, idsmoothwindow, minsmoothid, maxp, minlen, maxlen, queryfract;
88 uchimeData(string o, string uloc, string t, string file, string f, string n, string g, string ac, string al, vector<string> gr, MothurOut* mout, int st, int en, int tid) {
104 uchimeLocation = uloc;
106 void setBooleans(bool Abskew, bool calns, bool MinH, bool Mindiv, bool Xn, bool Dn, bool Xa, bool Chunks, bool Minchunk, bool Idsmoothwindow, bool Minsmoothid, bool Maxp, bool skipgap, bool skipgap2, bool Minlen, bool Maxlen, bool uc, bool Queryfract) {
115 useMinchunk = Minchunk;
116 useIdsmoothwindow = Idsmoothwindow;
117 useMinsmoothid = Minsmoothid;
120 skipgaps2 = skipgap2;
124 useQueryfract = Queryfract;
127 void setVariables(string abske, string min, string mindi, string x, string d, string xa2, string chunk, string minchun, string idsmoothwindo, string minsmoothi, string max, string minle, string maxle, string queryfrac) {
136 idsmoothwindow = idsmoothwindo;
137 minsmoothid = minsmoothi;
141 queryfract = queryfrac;
145 /**************************************************************************************************/
146 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
148 static DWORD WINAPI MyUchimeThreadFunction(LPVOID lpParam){
149 uchimeData* pDataArray;
150 pDataArray = (uchimeData*)lpParam;
154 pDataArray->outputFName = pDataArray->m->getFullPathName(pDataArray->outputFName);
155 pDataArray->filename = pDataArray->m->getFullPathName(pDataArray->filename);
156 pDataArray->alns = pDataArray->m->getFullPathName(pDataArray->alns);
159 ofstream out, out1, out2;
160 pDataArray->m->openOutputFile(pDataArray->outputFName, out); out.close();
161 pDataArray->m->openOutputFile(pDataArray->accnos, out1); out1.close();
162 if (pDataArray->chimealns) { pDataArray->m->openOutputFile(pDataArray->alns, out2); out2.close(); }
164 //parse fasta and name file by group
165 SequenceParser* parser;
166 if (pDataArray->namefile != "") { parser = new SequenceParser(pDataArray->groupfile, pDataArray->fastafile, pDataArray->namefile); }
167 else { parser = new SequenceParser(pDataArray->groupfile, pDataArray->fastafile); }
172 for (int i = pDataArray->start; i < pDataArray->end; i++) {
173 int start = time(NULL); if (pDataArray->m->control_pressed) { delete parser; return 0; }
175 int error = parser->getSeqs(pDataArray->groups[i], pDataArray->filename, true); if ((error == 1) || pDataArray->m->control_pressed) { delete parser; return 0; }
177 //int numSeqs = driver((outputFName + groups[i]), filename, (accnos+ groups[i]), (alns+ groups[i]), numChimeras);
178 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
180 //to allow for spaces in the path
181 string outputFName = "\"" + pDataArray->outputFName+pDataArray->groups[i] + "\"";
182 string filename = "\"" + pDataArray->filename + "\"";
183 string alns = "\"" + pDataArray->alns+pDataArray->groups[i] + "\"";
184 string accnos = pDataArray->accnos+pDataArray->groups[i];
188 string uchimeCommand = pDataArray->uchimeLocation;
189 uchimeCommand = "\"" + uchimeCommand + "\"";
192 tempUchime= new char[uchimeCommand.length()+1];
194 strncat(tempUchime, uchimeCommand.c_str(), uchimeCommand.length());
195 cPara.push_back(tempUchime);
197 char* tempIn = new char[8];
198 *tempIn = '\0'; strncat(tempIn, "--input", 7);
199 //strcpy(tempIn, "--input");
200 cPara.push_back(tempIn);
201 char* temp = new char[filename.length()+1];
202 *temp = '\0'; strncat(temp, filename.c_str(), filename.length());
203 //strcpy(temp, filename.c_str());
204 cPara.push_back(temp);
206 char* tempO = new char[12];
207 *tempO = '\0'; strncat(tempO, "--uchimeout", 11);
208 //strcpy(tempO, "--uchimeout");
209 cPara.push_back(tempO);
210 char* tempout = new char[outputFName.length()+1];
211 //strcpy(tempout, outputFName.c_str());
212 *tempout = '\0'; strncat(tempout, outputFName.c_str(), outputFName.length());
213 cPara.push_back(tempout);
215 if (pDataArray->chimealns) {
216 char* tempA = new char[13];
217 *tempA = '\0'; strncat(tempA, "--uchimealns", 12);
218 //strcpy(tempA, "--uchimealns");
219 cPara.push_back(tempA);
220 char* tempa = new char[alns.length()+1];
221 //strcpy(tempa, alns.c_str());
222 *tempa = '\0'; strncat(tempa, alns.c_str(), alns.length());
223 cPara.push_back(tempa);
226 if (pDataArray->useAbskew) {
227 char* tempskew = new char[9];
228 *tempskew = '\0'; strncat(tempskew, "--abskew", 8);
229 //strcpy(tempskew, "--abskew");
230 cPara.push_back(tempskew);
231 char* tempSkew = new char[pDataArray->abskew.length()+1];
232 //strcpy(tempSkew, abskew.c_str());
233 *tempSkew = '\0'; strncat(tempSkew, pDataArray->abskew.c_str(), pDataArray->abskew.length());
234 cPara.push_back(tempSkew);
237 if (pDataArray->useMinH) {
238 char* tempminh = new char[7];
239 *tempminh = '\0'; strncat(tempminh, "--minh", 6);
240 //strcpy(tempminh, "--minh");
241 cPara.push_back(tempminh);
242 char* tempMinH = new char[pDataArray->minh.length()+1];
243 *tempMinH = '\0'; strncat(tempMinH, pDataArray->minh.c_str(), pDataArray->minh.length());
244 //strcpy(tempMinH, minh.c_str());
245 cPara.push_back(tempMinH);
248 if (pDataArray->useMindiv) {
249 char* tempmindiv = new char[9];
250 *tempmindiv = '\0'; strncat(tempmindiv, "--mindiv", 8);
251 //strcpy(tempmindiv, "--mindiv");
252 cPara.push_back(tempmindiv);
253 char* tempMindiv = new char[pDataArray->mindiv.length()+1];
254 *tempMindiv = '\0'; strncat(tempMindiv, pDataArray->mindiv.c_str(), pDataArray->mindiv.length());
255 //strcpy(tempMindiv, mindiv.c_str());
256 cPara.push_back(tempMindiv);
259 if (pDataArray->useXn) {
260 char* tempxn = new char[5];
261 //strcpy(tempxn, "--xn");
262 *tempxn = '\0'; strncat(tempxn, "--xn", 4);
263 cPara.push_back(tempxn);
264 char* tempXn = new char[pDataArray->xn.length()+1];
265 //strcpy(tempXn, xn.c_str());
266 *tempXn = '\0'; strncat(tempXn, pDataArray->xn.c_str(), pDataArray->xn.length());
267 cPara.push_back(tempXn);
270 if (pDataArray->useDn) {
271 char* tempdn = new char[5];
272 //strcpy(tempdn, "--dn");
273 *tempdn = '\0'; strncat(tempdn, "--dn", 4);
274 cPara.push_back(tempdn);
275 char* tempDn = new char[pDataArray->dn.length()+1];
276 *tempDn = '\0'; strncat(tempDn, pDataArray->dn.c_str(), pDataArray->dn.length());
277 //strcpy(tempDn, dn.c_str());
278 cPara.push_back(tempDn);
281 if (pDataArray->useXa) {
282 char* tempxa = new char[5];
283 //strcpy(tempxa, "--xa");
284 *tempxa = '\0'; strncat(tempxa, "--xa", 4);
285 cPara.push_back(tempxa);
286 char* tempXa = new char[pDataArray->xa.length()+1];
287 *tempXa = '\0'; strncat(tempXa, pDataArray->xa.c_str(), pDataArray->xa.length());
288 //strcpy(tempXa, xa.c_str());
289 cPara.push_back(tempXa);
292 if (pDataArray->useChunks) {
293 char* tempchunks = new char[9];
294 //strcpy(tempchunks, "--chunks");
295 *tempchunks = '\0'; strncat(tempchunks, "--chunks", 8);
296 cPara.push_back(tempchunks);
297 char* tempChunks = new char[pDataArray->chunks.length()+1];
298 *tempChunks = '\0'; strncat(tempChunks, pDataArray->chunks.c_str(), pDataArray->chunks.length());
299 //strcpy(tempChunks, chunks.c_str());
300 cPara.push_back(tempChunks);
303 if (pDataArray->useMinchunk) {
304 char* tempminchunk = new char[11];
305 //strcpy(tempminchunk, "--minchunk");
306 *tempminchunk = '\0'; strncat(tempminchunk, "--minchunk", 10);
307 cPara.push_back(tempminchunk);
308 char* tempMinchunk = new char[pDataArray->minchunk.length()+1];
309 *tempMinchunk = '\0'; strncat(tempMinchunk, pDataArray->minchunk.c_str(), pDataArray->minchunk.length());
310 //strcpy(tempMinchunk, minchunk.c_str());
311 cPara.push_back(tempMinchunk);
314 if (pDataArray->useIdsmoothwindow) {
315 char* tempidsmoothwindow = new char[17];
316 *tempidsmoothwindow = '\0'; strncat(tempidsmoothwindow, "--idsmoothwindow", 16);
317 //strcpy(tempidsmoothwindow, "--idsmoothwindow");
318 cPara.push_back(tempidsmoothwindow);
319 char* tempIdsmoothwindow = new char[pDataArray->idsmoothwindow.length()+1];
320 *tempIdsmoothwindow = '\0'; strncat(tempIdsmoothwindow, pDataArray->idsmoothwindow.c_str(), pDataArray->idsmoothwindow.length());
321 //strcpy(tempIdsmoothwindow, idsmoothwindow.c_str());
322 cPara.push_back(tempIdsmoothwindow);
325 if (pDataArray->useMaxp) {
326 char* tempmaxp = new char[7];
327 //strcpy(tempmaxp, "--maxp");
328 *tempmaxp = '\0'; strncat(tempmaxp, "--maxp", 6);
329 cPara.push_back(tempmaxp);
330 char* tempMaxp = new char[pDataArray->maxp.length()+1];
331 *tempMaxp = '\0'; strncat(tempMaxp, pDataArray->maxp.c_str(), pDataArray->maxp.length());
332 //strcpy(tempMaxp, maxp.c_str());
333 cPara.push_back(tempMaxp);
336 if (!pDataArray->skipgaps) {
337 char* tempskipgaps = new char[13];
338 //strcpy(tempskipgaps, "--[no]skipgaps");
339 *tempskipgaps = '\0'; strncat(tempskipgaps, "--noskipgaps", 12);
340 cPara.push_back(tempskipgaps);
343 if (!pDataArray->skipgaps2) {
344 char* tempskipgaps2 = new char[14];
345 //strcpy(tempskipgaps2, "--[no]skipgaps2");
346 *tempskipgaps2 = '\0'; strncat(tempskipgaps2, "--noskipgaps2", 13);
347 cPara.push_back(tempskipgaps2);
350 if (pDataArray->useMinlen) {
351 char* tempminlen = new char[9];
352 *tempminlen = '\0'; strncat(tempminlen, "--minlen", 8);
353 //strcpy(tempminlen, "--minlen");
354 cPara.push_back(tempminlen);
355 char* tempMinlen = new char[pDataArray->minlen.length()+1];
356 //strcpy(tempMinlen, minlen.c_str());
357 *tempMinlen = '\0'; strncat(tempMinlen, pDataArray->minlen.c_str(), pDataArray->minlen.length());
358 cPara.push_back(tempMinlen);
361 if (pDataArray->useMaxlen) {
362 char* tempmaxlen = new char[9];
363 //strcpy(tempmaxlen, "--maxlen");
364 *tempmaxlen = '\0'; strncat(tempmaxlen, "--maxlen", 8);
365 cPara.push_back(tempmaxlen);
366 char* tempMaxlen = new char[pDataArray->maxlen.length()+1];
367 *tempMaxlen = '\0'; strncat(tempMaxlen, pDataArray->maxlen.c_str(), pDataArray->maxlen.length());
368 //strcpy(tempMaxlen, maxlen.c_str());
369 cPara.push_back(tempMaxlen);
372 if (pDataArray->ucl) {
373 char* tempucl = new char[5];
374 strcpy(tempucl, "--ucl");
375 cPara.push_back(tempucl);
378 if (pDataArray->useQueryfract) {
379 char* tempqueryfract = new char[13];
380 *tempqueryfract = '\0'; strncat(tempqueryfract, "--queryfract", 12);
381 //strcpy(tempqueryfract, "--queryfract");
382 cPara.push_back(tempqueryfract);
383 char* tempQueryfract = new char[pDataArray->queryfract.length()+1];
384 *tempQueryfract = '\0'; strncat(tempQueryfract, pDataArray->queryfract.c_str(), pDataArray->queryfract.length());
385 //strcpy(tempQueryfract, queryfract.c_str());
386 cPara.push_back(tempQueryfract);
390 char** uchimeParameters;
391 uchimeParameters = new char*[cPara.size()];
392 string commandString = "";
393 for (int j = 0; j < cPara.size(); j++) { uchimeParameters[j] = cPara[j]; commandString += toString(cPara[j]) + " "; }
394 //int numArgs = cPara.size();
396 //uchime_main(numArgs, uchimeParameters);
397 //cout << "commandString = " << commandString << endl;
398 commandString = "\"" + commandString + "\"";
400 if (pDataArray->m->debug) { pDataArray->m->mothurOut("[DEBUG]: uchime command = " + commandString + ".\n"); }
402 system(commandString.c_str());
405 for(int j = 0; j < cPara.size(); j++) { delete cPara[j]; }
406 delete[] uchimeParameters;
408 //remove "" from filenames
409 outputFName = outputFName.substr(1, outputFName.length()-2);
410 filename = filename.substr(1, filename.length()-2);
411 alns = alns.substr(1, alns.length()-2);
413 if (pDataArray->m->control_pressed) { delete parser; return 0; }
415 //create accnos file from uchime results
417 pDataArray->m->openInputFile(outputFName, in);
420 pDataArray->m->openOutputFile(accnos, out);
426 if (pDataArray->m->control_pressed) { break; }
429 string chimeraFlag = "";
430 in >> chimeraFlag >> name;
433 name = name.substr(0, name.length()-1); //rip off last /
434 name = name.substr(0, name.find_last_of('/'));
436 for (int j = 0; j < 15; j++) { in >> chimeraFlag; }
437 pDataArray->m->gobble(in);
439 if (chimeraFlag == "Y") { out << name << endl; numChimeras++; }
446 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
448 pDataArray->numChimeras += numChimeras;
450 if (pDataArray->m->control_pressed) { delete parser; return 0; }
452 //remove file made for uchime
453 pDataArray->m->mothurRemove(filename);
456 pDataArray->m->appendFiles(outputFName, pDataArray->outputFName); pDataArray->m->mothurRemove(outputFName);
457 pDataArray->m->appendFiles(accnos, pDataArray->accnos); pDataArray->m->mothurRemove(accnos);
458 if (pDataArray->chimealns) { pDataArray->m->appendFiles(alns, pDataArray->alns); pDataArray->m->mothurRemove(alns); }
460 pDataArray->m->mothurOutEndLine(); pDataArray->m->mothurOut("It took " + toString(time(NULL) - start) + " secs to check " + toString(num) + " sequences from group " + pDataArray->groups[i] + "."); pDataArray->m->mothurOutEndLine();
464 pDataArray->count = totalSeqs;
469 catch(exception& e) {
470 pDataArray->m->errorOut(e, "ChimeraUchimeCommand", "MyUchimeThreadFunction");
474 /**************************************************************************************************/
476 static DWORD WINAPI MyUchimeSeqsThreadFunction(LPVOID lpParam){
477 uchimeData* pDataArray;
478 pDataArray = (uchimeData*)lpParam;
482 pDataArray->outputFName = pDataArray->m->getFullPathName(pDataArray->outputFName);
483 pDataArray->filename = pDataArray->m->getFullPathName(pDataArray->filename);
484 pDataArray->alns = pDataArray->m->getFullPathName(pDataArray->alns);
489 int start = time(NULL); if (pDataArray->m->control_pressed) { return 0; }
491 //to allow for spaces in the path
492 string outputFName = "\"" + pDataArray->outputFName + "\"";
493 string filename = "\"" + pDataArray->filename + "\"";
494 string alns = "\"" + pDataArray->alns+ "\"";
495 string templatefile = "\"" + pDataArray->templatefile + "\"";
496 string accnos = pDataArray->accnos;
500 string uchimeCommand = pDataArray->uchimeLocation;
501 uchimeCommand = "\"" + uchimeCommand + "\"";
504 tempUchime= new char[uchimeCommand.length()+1];
506 strncat(tempUchime, uchimeCommand.c_str(), uchimeCommand.length());
507 cPara.push_back(tempUchime);
509 char* tempIn = new char[8];
510 *tempIn = '\0'; strncat(tempIn, "--input", 7);
511 //strcpy(tempIn, "--input");
512 cPara.push_back(tempIn);
513 char* temp = new char[filename.length()+1];
514 *temp = '\0'; strncat(temp, filename.c_str(), filename.length());
515 //strcpy(temp, filename.c_str());
516 cPara.push_back(temp);
519 char* tempRef = new char[5];
520 //strcpy(tempRef, "--db");
521 *tempRef = '\0'; strncat(tempRef, "--db", 4);
522 cPara.push_back(tempRef);
523 char* tempR = new char[templatefile.length()+1];
524 //strcpy(tempR, templatefile.c_str());
525 *tempR = '\0'; strncat(tempR, templatefile.c_str(), templatefile.length());
526 cPara.push_back(tempR);
528 char* tempO = new char[12];
529 *tempO = '\0'; strncat(tempO, "--uchimeout", 11);
530 //strcpy(tempO, "--uchimeout");
531 cPara.push_back(tempO);
532 char* tempout = new char[outputFName.length()+1];
533 //strcpy(tempout, outputFName.c_str());
534 *tempout = '\0'; strncat(tempout, outputFName.c_str(), outputFName.length());
535 cPara.push_back(tempout);
537 if (pDataArray->chimealns) {
538 char* tempA = new char[13];
539 *tempA = '\0'; strncat(tempA, "--uchimealns", 12);
540 //strcpy(tempA, "--uchimealns");
541 cPara.push_back(tempA);
542 char* tempa = new char[alns.length()+1];
543 //strcpy(tempa, alns.c_str());
544 *tempa = '\0'; strncat(tempa, alns.c_str(), alns.length());
545 cPara.push_back(tempa);
548 if (pDataArray->useAbskew) {
549 char* tempskew = new char[9];
550 *tempskew = '\0'; strncat(tempskew, "--abskew", 8);
551 //strcpy(tempskew, "--abskew");
552 cPara.push_back(tempskew);
553 char* tempSkew = new char[pDataArray->abskew.length()+1];
554 //strcpy(tempSkew, abskew.c_str());
555 *tempSkew = '\0'; strncat(tempSkew, pDataArray->abskew.c_str(), pDataArray->abskew.length());
556 cPara.push_back(tempSkew);
559 if (pDataArray->useMinH) {
560 char* tempminh = new char[7];
561 *tempminh = '\0'; strncat(tempminh, "--minh", 6);
562 //strcpy(tempminh, "--minh");
563 cPara.push_back(tempminh);
564 char* tempMinH = new char[pDataArray->minh.length()+1];
565 *tempMinH = '\0'; strncat(tempMinH, pDataArray->minh.c_str(), pDataArray->minh.length());
566 //strcpy(tempMinH, minh.c_str());
567 cPara.push_back(tempMinH);
570 if (pDataArray->useMindiv) {
571 char* tempmindiv = new char[9];
572 *tempmindiv = '\0'; strncat(tempmindiv, "--mindiv", 8);
573 //strcpy(tempmindiv, "--mindiv");
574 cPara.push_back(tempmindiv);
575 char* tempMindiv = new char[pDataArray->mindiv.length()+1];
576 *tempMindiv = '\0'; strncat(tempMindiv, pDataArray->mindiv.c_str(), pDataArray->mindiv.length());
577 //strcpy(tempMindiv, mindiv.c_str());
578 cPara.push_back(tempMindiv);
581 if (pDataArray->useXn) {
582 char* tempxn = new char[5];
583 //strcpy(tempxn, "--xn");
584 *tempxn = '\0'; strncat(tempxn, "--xn", 4);
585 cPara.push_back(tempxn);
586 char* tempXn = new char[pDataArray->xn.length()+1];
587 //strcpy(tempXn, xn.c_str());
588 *tempXn = '\0'; strncat(tempXn, pDataArray->xn.c_str(), pDataArray->xn.length());
589 cPara.push_back(tempXn);
592 if (pDataArray->useDn) {
593 char* tempdn = new char[5];
594 //strcpy(tempdn, "--dn");
595 *tempdn = '\0'; strncat(tempdn, "--dn", 4);
596 cPara.push_back(tempdn);
597 char* tempDn = new char[pDataArray->dn.length()+1];
598 *tempDn = '\0'; strncat(tempDn, pDataArray->dn.c_str(), pDataArray->dn.length());
599 //strcpy(tempDn, dn.c_str());
600 cPara.push_back(tempDn);
603 if (pDataArray->useXa) {
604 char* tempxa = new char[5];
605 //strcpy(tempxa, "--xa");
606 *tempxa = '\0'; strncat(tempxa, "--xa", 4);
607 cPara.push_back(tempxa);
608 char* tempXa = new char[pDataArray->xa.length()+1];
609 *tempXa = '\0'; strncat(tempXa, pDataArray->xa.c_str(), pDataArray->xa.length());
610 //strcpy(tempXa, xa.c_str());
611 cPara.push_back(tempXa);
614 if (pDataArray->useChunks) {
615 char* tempchunks = new char[9];
616 //strcpy(tempchunks, "--chunks");
617 *tempchunks = '\0'; strncat(tempchunks, "--chunks", 8);
618 cPara.push_back(tempchunks);
619 char* tempChunks = new char[pDataArray->chunks.length()+1];
620 *tempChunks = '\0'; strncat(tempChunks, pDataArray->chunks.c_str(), pDataArray->chunks.length());
621 //strcpy(tempChunks, chunks.c_str());
622 cPara.push_back(tempChunks);
625 if (pDataArray->useMinchunk) {
626 char* tempminchunk = new char[11];
627 //strcpy(tempminchunk, "--minchunk");
628 *tempminchunk = '\0'; strncat(tempminchunk, "--minchunk", 10);
629 cPara.push_back(tempminchunk);
630 char* tempMinchunk = new char[pDataArray->minchunk.length()+1];
631 *tempMinchunk = '\0'; strncat(tempMinchunk, pDataArray->minchunk.c_str(), pDataArray->minchunk.length());
632 //strcpy(tempMinchunk, minchunk.c_str());
633 cPara.push_back(tempMinchunk);
636 if (pDataArray->useIdsmoothwindow) {
637 char* tempidsmoothwindow = new char[17];
638 *tempidsmoothwindow = '\0'; strncat(tempidsmoothwindow, "--idsmoothwindow", 16);
639 //strcpy(tempidsmoothwindow, "--idsmoothwindow");
640 cPara.push_back(tempidsmoothwindow);
641 char* tempIdsmoothwindow = new char[pDataArray->idsmoothwindow.length()+1];
642 *tempIdsmoothwindow = '\0'; strncat(tempIdsmoothwindow, pDataArray->idsmoothwindow.c_str(), pDataArray->idsmoothwindow.length());
643 //strcpy(tempIdsmoothwindow, idsmoothwindow.c_str());
644 cPara.push_back(tempIdsmoothwindow);
647 if (pDataArray->useMaxp) {
648 char* tempmaxp = new char[7];
649 //strcpy(tempmaxp, "--maxp");
650 *tempmaxp = '\0'; strncat(tempmaxp, "--maxp", 6);
651 cPara.push_back(tempmaxp);
652 char* tempMaxp = new char[pDataArray->maxp.length()+1];
653 *tempMaxp = '\0'; strncat(tempMaxp, pDataArray->maxp.c_str(), pDataArray->maxp.length());
654 //strcpy(tempMaxp, maxp.c_str());
655 cPara.push_back(tempMaxp);
658 if (!pDataArray->skipgaps) {
659 char* tempskipgaps = new char[13];
660 //strcpy(tempskipgaps, "--[no]skipgaps");
661 *tempskipgaps = '\0'; strncat(tempskipgaps, "--noskipgaps", 12);
662 cPara.push_back(tempskipgaps);
665 if (!pDataArray->skipgaps2) {
666 char* tempskipgaps2 = new char[14];
667 //strcpy(tempskipgaps2, "--[no]skipgaps2");
668 *tempskipgaps2 = '\0'; strncat(tempskipgaps2, "--noskipgaps2", 13);
669 cPara.push_back(tempskipgaps2);
672 if (pDataArray->useMinlen) {
673 char* tempminlen = new char[9];
674 *tempminlen = '\0'; strncat(tempminlen, "--minlen", 8);
675 //strcpy(tempminlen, "--minlen");
676 cPara.push_back(tempminlen);
677 char* tempMinlen = new char[pDataArray->minlen.length()+1];
678 //strcpy(tempMinlen, minlen.c_str());
679 *tempMinlen = '\0'; strncat(tempMinlen, pDataArray->minlen.c_str(), pDataArray->minlen.length());
680 cPara.push_back(tempMinlen);
683 if (pDataArray->useMaxlen) {
684 char* tempmaxlen = new char[9];
685 //strcpy(tempmaxlen, "--maxlen");
686 *tempmaxlen = '\0'; strncat(tempmaxlen, "--maxlen", 8);
687 cPara.push_back(tempmaxlen);
688 char* tempMaxlen = new char[pDataArray->maxlen.length()+1];
689 *tempMaxlen = '\0'; strncat(tempMaxlen, pDataArray->maxlen.c_str(), pDataArray->maxlen.length());
690 //strcpy(tempMaxlen, maxlen.c_str());
691 cPara.push_back(tempMaxlen);
694 if (pDataArray->ucl) {
695 char* tempucl = new char[5];
696 strcpy(tempucl, "--ucl");
697 cPara.push_back(tempucl);
700 if (pDataArray->useQueryfract) {
701 char* tempqueryfract = new char[13];
702 *tempqueryfract = '\0'; strncat(tempqueryfract, "--queryfract", 12);
703 //strcpy(tempqueryfract, "--queryfract");
704 cPara.push_back(tempqueryfract);
705 char* tempQueryfract = new char[pDataArray->queryfract.length()+1];
706 *tempQueryfract = '\0'; strncat(tempQueryfract, pDataArray->queryfract.c_str(), pDataArray->queryfract.length());
707 //strcpy(tempQueryfract, queryfract.c_str());
708 cPara.push_back(tempQueryfract);
712 char** uchimeParameters;
713 uchimeParameters = new char*[cPara.size()];
714 string commandString = "";
715 for (int j = 0; j < cPara.size(); j++) { uchimeParameters[j] = cPara[j]; commandString += toString(cPara[j]) + " "; }
716 //int numArgs = cPara.size();
718 //uchime_main(numArgs, uchimeParameters);
719 //cout << "commandString = " << commandString << endl;
720 if (pDataArray->m->debug) { pDataArray->m->mothurOut("[DEBUG]: uchime command = " + commandString + ".\n"); }
721 system(commandString.c_str());
724 for(int j = 0; j < cPara.size(); j++) { delete cPara[j]; }
725 delete[] uchimeParameters;
727 //remove "" from filenames
728 outputFName = outputFName.substr(1, outputFName.length()-2);
729 filename = filename.substr(1, filename.length()-2);
730 alns = alns.substr(1, alns.length()-2);
732 if (pDataArray->m->control_pressed) { return 0; }
734 //create accnos file from uchime results
736 pDataArray->m->openInputFile(outputFName, in);
739 pDataArray->m->openOutputFile(accnos, out);
744 if (pDataArray->m->control_pressed) { break; }
747 string chimeraFlag = "";
748 in >> chimeraFlag >> name;
750 for (int j = 0; j < 15; j++) { in >> chimeraFlag; }
751 pDataArray->m->gobble(in);
753 if (chimeraFlag == "Y") { out << name << endl; numChimeras++; }
759 if (pDataArray->m->control_pressed) { return 0; }
761 pDataArray->m->mothurOutEndLine(); pDataArray->m->mothurOut("It took " + toString(time(NULL) - start) + " secs to check " + toString(totalSeqs) + " sequences."); pDataArray->m->mothurOutEndLine();
763 pDataArray->count = totalSeqs;
764 pDataArray->numChimeras = numChimeras;
768 catch(exception& e) {
769 pDataArray->m->errorOut(e, "ChimeraUchimeCommand", "MyUchimeSeqsThreadFunction");
776 /**************************************************************************************************/