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 getHelpString();
30 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"; }
31 string getDescription() { return "detect chimeric sequences"; }
34 void help() { m->mothurOut(getHelpString()); }
40 linePair(int i, int j) : start(i), end(j) {}
43 vector<int> processIDS; //processid
44 int driver(string, string, string, string, int&);
45 int createProcesses(string, string, string, string, int&);
47 bool abort, useAbskew, chimealns, useMinH, useMindiv, useXn, useDn, useXa, useChunks, useMinchunk, useIdsmoothwindow, useMinsmoothid, useMaxp, skipgaps, skipgaps2, useMinlen, useMaxlen, ucl, useQueryfract;
48 string fastafile, groupfile, templatefile, outputDir, namefile, abskew, minh, mindiv, xn, dn, xa, chunks, minchunk, idsmoothwindow, minsmoothid, maxp, minlen, maxlen, queryfract, uchimeLocation;
52 vector<string> outputNames;
53 vector<string> fastaFileNames;
54 vector<string> nameFileNames;
55 vector<string> groupFileNames;
57 string getNamesFile(string&);
58 int readFasta(string, map<string, string>&);
59 int printFile(vector<seqPriorityNode>&, string);
60 int deconvoluteResults(SequenceParser&, string, string, string);
61 int driverGroups(SequenceParser&, string, string, string, string, int, int, vector<string>);
62 int createProcessesGroups(SequenceParser&, string, string, string, string, vector<string>, string, string, string);
67 /***********************************************************/
68 /**************************************************************************************************/
69 //custom data structure for threads to use.
70 // This is passed by void pointer so it can be any data type
71 // that can be passed using a single void pointer (LPVOID).
77 string accnos, alns, filename, templatefile, uchimeLocation;
81 int threadID, count, numChimeras;
82 vector<string> groups;
83 bool useAbskew, chimealns, useMinH, useMindiv, useXn, useDn, useXa, useChunks, useMinchunk, useIdsmoothwindow, useMinsmoothid, useMaxp, skipgaps, skipgaps2, useMinlen, useMaxlen, ucl, useQueryfract;
84 string abskew, minh, mindiv, xn, dn, xa, chunks, minchunk, idsmoothwindow, minsmoothid, maxp, minlen, maxlen, queryfract;
87 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) {
103 uchimeLocation = uloc;
105 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) {
114 useMinchunk = Minchunk;
115 useIdsmoothwindow = Idsmoothwindow;
116 useMinsmoothid = Minsmoothid;
119 skipgaps2 = skipgap2;
123 useQueryfract = Queryfract;
126 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) {
135 idsmoothwindow = idsmoothwindo;
136 minsmoothid = minsmoothi;
140 queryfract = queryfrac;
144 /**************************************************************************************************/
145 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
147 static DWORD WINAPI MyUchimeThreadFunction(LPVOID lpParam){
148 uchimeData* pDataArray;
149 pDataArray = (uchimeData*)lpParam;
153 pDataArray->outputFName = pDataArray->m->getFullPathName(pDataArray->outputFName);
154 pDataArray->filename = pDataArray->m->getFullPathName(pDataArray->filename);
155 pDataArray->alns = pDataArray->m->getFullPathName(pDataArray->alns);
158 ofstream out, out1, out2;
159 pDataArray->m->openOutputFile(pDataArray->outputFName, out); out.close();
160 pDataArray->m->openOutputFile(pDataArray->accnos, out1); out1.close();
161 if (pDataArray->chimealns) { pDataArray->m->openOutputFile(pDataArray->alns, out2); out2.close(); }
163 //parse fasta and name file by group
164 SequenceParser* parser;
165 if (pDataArray->namefile != "") { parser = new SequenceParser(pDataArray->groupfile, pDataArray->fastafile, pDataArray->namefile); }
166 else { parser = new SequenceParser(pDataArray->groupfile, pDataArray->fastafile); }
171 for (int i = pDataArray->start; i < pDataArray->end; i++) {
172 int start = time(NULL); if (pDataArray->m->control_pressed) { delete parser; return 0; }
174 int error = parser->getSeqs(pDataArray->groups[i], pDataArray->filename, true); if ((error == 1) || pDataArray->m->control_pressed) { delete parser; return 0; }
176 //int numSeqs = driver((outputFName + groups[i]), filename, (accnos+ groups[i]), (alns+ groups[i]), numChimeras);
177 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
179 //to allow for spaces in the path
180 string outputFName = "\"" + pDataArray->outputFName+pDataArray->groups[i] + "\"";
181 string filename = "\"" + pDataArray->filename + "\"";
182 string alns = "\"" + pDataArray->alns+pDataArray->groups[i] + "\"";
183 string accnos = pDataArray->accnos+pDataArray->groups[i];
187 string uchimeCommand = pDataArray->uchimeLocation;
188 uchimeCommand = "\"" + uchimeCommand + "\"";
191 tempUchime= new char[uchimeCommand.length()+1];
193 strncat(tempUchime, uchimeCommand.c_str(), uchimeCommand.length());
194 cPara.push_back(tempUchime);
196 char* tempIn = new char[8];
197 *tempIn = '\0'; strncat(tempIn, "--input", 7);
198 //strcpy(tempIn, "--input");
199 cPara.push_back(tempIn);
200 char* temp = new char[filename.length()+1];
201 *temp = '\0'; strncat(temp, filename.c_str(), filename.length());
202 //strcpy(temp, filename.c_str());
203 cPara.push_back(temp);
205 char* tempO = new char[12];
206 *tempO = '\0'; strncat(tempO, "--uchimeout", 11);
207 //strcpy(tempO, "--uchimeout");
208 cPara.push_back(tempO);
209 char* tempout = new char[outputFName.length()+1];
210 //strcpy(tempout, outputFName.c_str());
211 *tempout = '\0'; strncat(tempout, outputFName.c_str(), outputFName.length());
212 cPara.push_back(tempout);
214 if (pDataArray->chimealns) {
215 char* tempA = new char[13];
216 *tempA = '\0'; strncat(tempA, "--uchimealns", 12);
217 //strcpy(tempA, "--uchimealns");
218 cPara.push_back(tempA);
219 char* tempa = new char[alns.length()+1];
220 //strcpy(tempa, alns.c_str());
221 *tempa = '\0'; strncat(tempa, alns.c_str(), alns.length());
222 cPara.push_back(tempa);
225 if (pDataArray->useAbskew) {
226 char* tempskew = new char[9];
227 *tempskew = '\0'; strncat(tempskew, "--abskew", 8);
228 //strcpy(tempskew, "--abskew");
229 cPara.push_back(tempskew);
230 char* tempSkew = new char[pDataArray->abskew.length()+1];
231 //strcpy(tempSkew, abskew.c_str());
232 *tempSkew = '\0'; strncat(tempSkew, pDataArray->abskew.c_str(), pDataArray->abskew.length());
233 cPara.push_back(tempSkew);
236 if (pDataArray->useMinH) {
237 char* tempminh = new char[7];
238 *tempminh = '\0'; strncat(tempminh, "--minh", 6);
239 //strcpy(tempminh, "--minh");
240 cPara.push_back(tempminh);
241 char* tempMinH = new char[pDataArray->minh.length()+1];
242 *tempMinH = '\0'; strncat(tempMinH, pDataArray->minh.c_str(), pDataArray->minh.length());
243 //strcpy(tempMinH, minh.c_str());
244 cPara.push_back(tempMinH);
247 if (pDataArray->useMindiv) {
248 char* tempmindiv = new char[9];
249 *tempmindiv = '\0'; strncat(tempmindiv, "--mindiv", 8);
250 //strcpy(tempmindiv, "--mindiv");
251 cPara.push_back(tempmindiv);
252 char* tempMindiv = new char[pDataArray->mindiv.length()+1];
253 *tempMindiv = '\0'; strncat(tempMindiv, pDataArray->mindiv.c_str(), pDataArray->mindiv.length());
254 //strcpy(tempMindiv, mindiv.c_str());
255 cPara.push_back(tempMindiv);
258 if (pDataArray->useXn) {
259 char* tempxn = new char[5];
260 //strcpy(tempxn, "--xn");
261 *tempxn = '\0'; strncat(tempxn, "--xn", 4);
262 cPara.push_back(tempxn);
263 char* tempXn = new char[pDataArray->xn.length()+1];
264 //strcpy(tempXn, xn.c_str());
265 *tempXn = '\0'; strncat(tempXn, pDataArray->xn.c_str(), pDataArray->xn.length());
266 cPara.push_back(tempXn);
269 if (pDataArray->useDn) {
270 char* tempdn = new char[5];
271 //strcpy(tempdn, "--dn");
272 *tempdn = '\0'; strncat(tempdn, "--dn", 4);
273 cPara.push_back(tempdn);
274 char* tempDn = new char[pDataArray->dn.length()+1];
275 *tempDn = '\0'; strncat(tempDn, pDataArray->dn.c_str(), pDataArray->dn.length());
276 //strcpy(tempDn, dn.c_str());
277 cPara.push_back(tempDn);
280 if (pDataArray->useXa) {
281 char* tempxa = new char[5];
282 //strcpy(tempxa, "--xa");
283 *tempxa = '\0'; strncat(tempxa, "--xa", 4);
284 cPara.push_back(tempxa);
285 char* tempXa = new char[pDataArray->xa.length()+1];
286 *tempXa = '\0'; strncat(tempXa, pDataArray->xa.c_str(), pDataArray->xa.length());
287 //strcpy(tempXa, xa.c_str());
288 cPara.push_back(tempXa);
291 if (pDataArray->useChunks) {
292 char* tempchunks = new char[9];
293 //strcpy(tempchunks, "--chunks");
294 *tempchunks = '\0'; strncat(tempchunks, "--chunks", 8);
295 cPara.push_back(tempchunks);
296 char* tempChunks = new char[pDataArray->chunks.length()+1];
297 *tempChunks = '\0'; strncat(tempChunks, pDataArray->chunks.c_str(), pDataArray->chunks.length());
298 //strcpy(tempChunks, chunks.c_str());
299 cPara.push_back(tempChunks);
302 if (pDataArray->useMinchunk) {
303 char* tempminchunk = new char[11];
304 //strcpy(tempminchunk, "--minchunk");
305 *tempminchunk = '\0'; strncat(tempminchunk, "--minchunk", 10);
306 cPara.push_back(tempminchunk);
307 char* tempMinchunk = new char[pDataArray->minchunk.length()+1];
308 *tempMinchunk = '\0'; strncat(tempMinchunk, pDataArray->minchunk.c_str(), pDataArray->minchunk.length());
309 //strcpy(tempMinchunk, minchunk.c_str());
310 cPara.push_back(tempMinchunk);
313 if (pDataArray->useIdsmoothwindow) {
314 char* tempidsmoothwindow = new char[17];
315 *tempidsmoothwindow = '\0'; strncat(tempidsmoothwindow, "--idsmoothwindow", 16);
316 //strcpy(tempidsmoothwindow, "--idsmoothwindow");
317 cPara.push_back(tempidsmoothwindow);
318 char* tempIdsmoothwindow = new char[pDataArray->idsmoothwindow.length()+1];
319 *tempIdsmoothwindow = '\0'; strncat(tempIdsmoothwindow, pDataArray->idsmoothwindow.c_str(), pDataArray->idsmoothwindow.length());
320 //strcpy(tempIdsmoothwindow, idsmoothwindow.c_str());
321 cPara.push_back(tempIdsmoothwindow);
324 if (pDataArray->useMaxp) {
325 char* tempmaxp = new char[7];
326 //strcpy(tempmaxp, "--maxp");
327 *tempmaxp = '\0'; strncat(tempmaxp, "--maxp", 6);
328 cPara.push_back(tempmaxp);
329 char* tempMaxp = new char[pDataArray->maxp.length()+1];
330 *tempMaxp = '\0'; strncat(tempMaxp, pDataArray->maxp.c_str(), pDataArray->maxp.length());
331 //strcpy(tempMaxp, maxp.c_str());
332 cPara.push_back(tempMaxp);
335 if (!pDataArray->skipgaps) {
336 char* tempskipgaps = new char[13];
337 //strcpy(tempskipgaps, "--[no]skipgaps");
338 *tempskipgaps = '\0'; strncat(tempskipgaps, "--noskipgaps", 12);
339 cPara.push_back(tempskipgaps);
342 if (!pDataArray->skipgaps2) {
343 char* tempskipgaps2 = new char[14];
344 //strcpy(tempskipgaps2, "--[no]skipgaps2");
345 *tempskipgaps2 = '\0'; strncat(tempskipgaps2, "--noskipgaps2", 13);
346 cPara.push_back(tempskipgaps2);
349 if (pDataArray->useMinlen) {
350 char* tempminlen = new char[9];
351 *tempminlen = '\0'; strncat(tempminlen, "--minlen", 8);
352 //strcpy(tempminlen, "--minlen");
353 cPara.push_back(tempminlen);
354 char* tempMinlen = new char[pDataArray->minlen.length()+1];
355 //strcpy(tempMinlen, minlen.c_str());
356 *tempMinlen = '\0'; strncat(tempMinlen, pDataArray->minlen.c_str(), pDataArray->minlen.length());
357 cPara.push_back(tempMinlen);
360 if (pDataArray->useMaxlen) {
361 char* tempmaxlen = new char[9];
362 //strcpy(tempmaxlen, "--maxlen");
363 *tempmaxlen = '\0'; strncat(tempmaxlen, "--maxlen", 8);
364 cPara.push_back(tempmaxlen);
365 char* tempMaxlen = new char[pDataArray->maxlen.length()+1];
366 *tempMaxlen = '\0'; strncat(tempMaxlen, pDataArray->maxlen.c_str(), pDataArray->maxlen.length());
367 //strcpy(tempMaxlen, maxlen.c_str());
368 cPara.push_back(tempMaxlen);
371 if (pDataArray->ucl) {
372 char* tempucl = new char[5];
373 strcpy(tempucl, "--ucl");
374 cPara.push_back(tempucl);
377 if (pDataArray->useQueryfract) {
378 char* tempqueryfract = new char[13];
379 *tempqueryfract = '\0'; strncat(tempqueryfract, "--queryfract", 12);
380 //strcpy(tempqueryfract, "--queryfract");
381 cPara.push_back(tempqueryfract);
382 char* tempQueryfract = new char[pDataArray->queryfract.length()+1];
383 *tempQueryfract = '\0'; strncat(tempQueryfract, pDataArray->queryfract.c_str(), pDataArray->queryfract.length());
384 //strcpy(tempQueryfract, queryfract.c_str());
385 cPara.push_back(tempQueryfract);
389 char** uchimeParameters;
390 uchimeParameters = new char*[cPara.size()];
391 string commandString = "";
392 for (int j = 0; j < cPara.size(); j++) { uchimeParameters[j] = cPara[j]; commandString += toString(cPara[j]) + " "; }
393 //int numArgs = cPara.size();
395 //uchime_main(numArgs, uchimeParameters);
396 //cout << "commandString = " << commandString << endl;
397 commandString = "\"" + commandString + "\"";
399 if (pDataArray->m->debug) { pDataArray->m->mothurOut("[DEBUG]: uchime command = " + commandString + ".\n"); }
401 system(commandString.c_str());
404 for(int j = 0; j < cPara.size(); j++) { delete cPara[j]; }
405 delete[] uchimeParameters;
407 //remove "" from filenames
408 outputFName = outputFName.substr(1, outputFName.length()-2);
409 filename = filename.substr(1, filename.length()-2);
410 alns = alns.substr(1, alns.length()-2);
412 if (pDataArray->m->control_pressed) { delete parser; return 0; }
414 //create accnos file from uchime results
416 pDataArray->m->openInputFile(outputFName, in);
419 pDataArray->m->openOutputFile(accnos, out);
425 if (pDataArray->m->control_pressed) { break; }
428 string chimeraFlag = "";
429 in >> chimeraFlag >> name;
432 name = name.substr(0, name.length()-1); //rip off last /
433 name = name.substr(0, name.find_last_of('/'));
435 for (int j = 0; j < 15; j++) { in >> chimeraFlag; }
436 pDataArray->m->gobble(in);
438 if (chimeraFlag == "Y") { out << name << endl; numChimeras++; }
445 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
447 pDataArray->numChimeras += numChimeras;
449 if (pDataArray->m->control_pressed) { delete parser; return 0; }
451 //remove file made for uchime
452 pDataArray->m->mothurRemove(filename);
455 pDataArray->m->appendFiles(outputFName, pDataArray->outputFName); pDataArray->m->mothurRemove(outputFName);
456 pDataArray->m->appendFiles(accnos, pDataArray->accnos); pDataArray->m->mothurRemove(accnos);
457 if (pDataArray->chimealns) { pDataArray->m->appendFiles(alns, pDataArray->alns); pDataArray->m->mothurRemove(alns); }
459 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();
463 pDataArray->count = totalSeqs;
468 catch(exception& e) {
469 pDataArray->m->errorOut(e, "ChimeraUchimeCommand", "MyUchimeThreadFunction");
473 /**************************************************************************************************/
475 static DWORD WINAPI MyUchimeSeqsThreadFunction(LPVOID lpParam){
476 uchimeData* pDataArray;
477 pDataArray = (uchimeData*)lpParam;
481 pDataArray->outputFName = pDataArray->m->getFullPathName(pDataArray->outputFName);
482 pDataArray->filename = pDataArray->m->getFullPathName(pDataArray->filename);
483 pDataArray->alns = pDataArray->m->getFullPathName(pDataArray->alns);
488 int start = time(NULL); if (pDataArray->m->control_pressed) { return 0; }
490 //to allow for spaces in the path
491 string outputFName = "\"" + pDataArray->outputFName + "\"";
492 string filename = "\"" + pDataArray->filename + "\"";
493 string alns = "\"" + pDataArray->alns+ "\"";
494 string templatefile = "\"" + pDataArray->templatefile + "\"";
495 string accnos = pDataArray->accnos;
499 string uchimeCommand = pDataArray->uchimeLocation;
500 uchimeCommand = "\"" + uchimeCommand + "\"";
503 tempUchime= new char[uchimeCommand.length()+1];
505 strncat(tempUchime, uchimeCommand.c_str(), uchimeCommand.length());
506 cPara.push_back(tempUchime);
508 char* tempIn = new char[8];
509 *tempIn = '\0'; strncat(tempIn, "--input", 7);
510 //strcpy(tempIn, "--input");
511 cPara.push_back(tempIn);
512 char* temp = new char[filename.length()+1];
513 *temp = '\0'; strncat(temp, filename.c_str(), filename.length());
514 //strcpy(temp, filename.c_str());
515 cPara.push_back(temp);
518 char* tempRef = new char[5];
519 //strcpy(tempRef, "--db");
520 *tempRef = '\0'; strncat(tempRef, "--db", 4);
521 cPara.push_back(tempRef);
522 char* tempR = new char[templatefile.length()+1];
523 //strcpy(tempR, templatefile.c_str());
524 *tempR = '\0'; strncat(tempR, templatefile.c_str(), templatefile.length());
525 cPara.push_back(tempR);
527 char* tempO = new char[12];
528 *tempO = '\0'; strncat(tempO, "--uchimeout", 11);
529 //strcpy(tempO, "--uchimeout");
530 cPara.push_back(tempO);
531 char* tempout = new char[outputFName.length()+1];
532 //strcpy(tempout, outputFName.c_str());
533 *tempout = '\0'; strncat(tempout, outputFName.c_str(), outputFName.length());
534 cPara.push_back(tempout);
536 if (pDataArray->chimealns) {
537 char* tempA = new char[13];
538 *tempA = '\0'; strncat(tempA, "--uchimealns", 12);
539 //strcpy(tempA, "--uchimealns");
540 cPara.push_back(tempA);
541 char* tempa = new char[alns.length()+1];
542 //strcpy(tempa, alns.c_str());
543 *tempa = '\0'; strncat(tempa, alns.c_str(), alns.length());
544 cPara.push_back(tempa);
547 if (pDataArray->useAbskew) {
548 char* tempskew = new char[9];
549 *tempskew = '\0'; strncat(tempskew, "--abskew", 8);
550 //strcpy(tempskew, "--abskew");
551 cPara.push_back(tempskew);
552 char* tempSkew = new char[pDataArray->abskew.length()+1];
553 //strcpy(tempSkew, abskew.c_str());
554 *tempSkew = '\0'; strncat(tempSkew, pDataArray->abskew.c_str(), pDataArray->abskew.length());
555 cPara.push_back(tempSkew);
558 if (pDataArray->useMinH) {
559 char* tempminh = new char[7];
560 *tempminh = '\0'; strncat(tempminh, "--minh", 6);
561 //strcpy(tempminh, "--minh");
562 cPara.push_back(tempminh);
563 char* tempMinH = new char[pDataArray->minh.length()+1];
564 *tempMinH = '\0'; strncat(tempMinH, pDataArray->minh.c_str(), pDataArray->minh.length());
565 //strcpy(tempMinH, minh.c_str());
566 cPara.push_back(tempMinH);
569 if (pDataArray->useMindiv) {
570 char* tempmindiv = new char[9];
571 *tempmindiv = '\0'; strncat(tempmindiv, "--mindiv", 8);
572 //strcpy(tempmindiv, "--mindiv");
573 cPara.push_back(tempmindiv);
574 char* tempMindiv = new char[pDataArray->mindiv.length()+1];
575 *tempMindiv = '\0'; strncat(tempMindiv, pDataArray->mindiv.c_str(), pDataArray->mindiv.length());
576 //strcpy(tempMindiv, mindiv.c_str());
577 cPara.push_back(tempMindiv);
580 if (pDataArray->useXn) {
581 char* tempxn = new char[5];
582 //strcpy(tempxn, "--xn");
583 *tempxn = '\0'; strncat(tempxn, "--xn", 4);
584 cPara.push_back(tempxn);
585 char* tempXn = new char[pDataArray->xn.length()+1];
586 //strcpy(tempXn, xn.c_str());
587 *tempXn = '\0'; strncat(tempXn, pDataArray->xn.c_str(), pDataArray->xn.length());
588 cPara.push_back(tempXn);
591 if (pDataArray->useDn) {
592 char* tempdn = new char[5];
593 //strcpy(tempdn, "--dn");
594 *tempdn = '\0'; strncat(tempdn, "--dn", 4);
595 cPara.push_back(tempdn);
596 char* tempDn = new char[pDataArray->dn.length()+1];
597 *tempDn = '\0'; strncat(tempDn, pDataArray->dn.c_str(), pDataArray->dn.length());
598 //strcpy(tempDn, dn.c_str());
599 cPara.push_back(tempDn);
602 if (pDataArray->useXa) {
603 char* tempxa = new char[5];
604 //strcpy(tempxa, "--xa");
605 *tempxa = '\0'; strncat(tempxa, "--xa", 4);
606 cPara.push_back(tempxa);
607 char* tempXa = new char[pDataArray->xa.length()+1];
608 *tempXa = '\0'; strncat(tempXa, pDataArray->xa.c_str(), pDataArray->xa.length());
609 //strcpy(tempXa, xa.c_str());
610 cPara.push_back(tempXa);
613 if (pDataArray->useChunks) {
614 char* tempchunks = new char[9];
615 //strcpy(tempchunks, "--chunks");
616 *tempchunks = '\0'; strncat(tempchunks, "--chunks", 8);
617 cPara.push_back(tempchunks);
618 char* tempChunks = new char[pDataArray->chunks.length()+1];
619 *tempChunks = '\0'; strncat(tempChunks, pDataArray->chunks.c_str(), pDataArray->chunks.length());
620 //strcpy(tempChunks, chunks.c_str());
621 cPara.push_back(tempChunks);
624 if (pDataArray->useMinchunk) {
625 char* tempminchunk = new char[11];
626 //strcpy(tempminchunk, "--minchunk");
627 *tempminchunk = '\0'; strncat(tempminchunk, "--minchunk", 10);
628 cPara.push_back(tempminchunk);
629 char* tempMinchunk = new char[pDataArray->minchunk.length()+1];
630 *tempMinchunk = '\0'; strncat(tempMinchunk, pDataArray->minchunk.c_str(), pDataArray->minchunk.length());
631 //strcpy(tempMinchunk, minchunk.c_str());
632 cPara.push_back(tempMinchunk);
635 if (pDataArray->useIdsmoothwindow) {
636 char* tempidsmoothwindow = new char[17];
637 *tempidsmoothwindow = '\0'; strncat(tempidsmoothwindow, "--idsmoothwindow", 16);
638 //strcpy(tempidsmoothwindow, "--idsmoothwindow");
639 cPara.push_back(tempidsmoothwindow);
640 char* tempIdsmoothwindow = new char[pDataArray->idsmoothwindow.length()+1];
641 *tempIdsmoothwindow = '\0'; strncat(tempIdsmoothwindow, pDataArray->idsmoothwindow.c_str(), pDataArray->idsmoothwindow.length());
642 //strcpy(tempIdsmoothwindow, idsmoothwindow.c_str());
643 cPara.push_back(tempIdsmoothwindow);
646 if (pDataArray->useMaxp) {
647 char* tempmaxp = new char[7];
648 //strcpy(tempmaxp, "--maxp");
649 *tempmaxp = '\0'; strncat(tempmaxp, "--maxp", 6);
650 cPara.push_back(tempmaxp);
651 char* tempMaxp = new char[pDataArray->maxp.length()+1];
652 *tempMaxp = '\0'; strncat(tempMaxp, pDataArray->maxp.c_str(), pDataArray->maxp.length());
653 //strcpy(tempMaxp, maxp.c_str());
654 cPara.push_back(tempMaxp);
657 if (!pDataArray->skipgaps) {
658 char* tempskipgaps = new char[13];
659 //strcpy(tempskipgaps, "--[no]skipgaps");
660 *tempskipgaps = '\0'; strncat(tempskipgaps, "--noskipgaps", 12);
661 cPara.push_back(tempskipgaps);
664 if (!pDataArray->skipgaps2) {
665 char* tempskipgaps2 = new char[14];
666 //strcpy(tempskipgaps2, "--[no]skipgaps2");
667 *tempskipgaps2 = '\0'; strncat(tempskipgaps2, "--noskipgaps2", 13);
668 cPara.push_back(tempskipgaps2);
671 if (pDataArray->useMinlen) {
672 char* tempminlen = new char[9];
673 *tempminlen = '\0'; strncat(tempminlen, "--minlen", 8);
674 //strcpy(tempminlen, "--minlen");
675 cPara.push_back(tempminlen);
676 char* tempMinlen = new char[pDataArray->minlen.length()+1];
677 //strcpy(tempMinlen, minlen.c_str());
678 *tempMinlen = '\0'; strncat(tempMinlen, pDataArray->minlen.c_str(), pDataArray->minlen.length());
679 cPara.push_back(tempMinlen);
682 if (pDataArray->useMaxlen) {
683 char* tempmaxlen = new char[9];
684 //strcpy(tempmaxlen, "--maxlen");
685 *tempmaxlen = '\0'; strncat(tempmaxlen, "--maxlen", 8);
686 cPara.push_back(tempmaxlen);
687 char* tempMaxlen = new char[pDataArray->maxlen.length()+1];
688 *tempMaxlen = '\0'; strncat(tempMaxlen, pDataArray->maxlen.c_str(), pDataArray->maxlen.length());
689 //strcpy(tempMaxlen, maxlen.c_str());
690 cPara.push_back(tempMaxlen);
693 if (pDataArray->ucl) {
694 char* tempucl = new char[5];
695 strcpy(tempucl, "--ucl");
696 cPara.push_back(tempucl);
699 if (pDataArray->useQueryfract) {
700 char* tempqueryfract = new char[13];
701 *tempqueryfract = '\0'; strncat(tempqueryfract, "--queryfract", 12);
702 //strcpy(tempqueryfract, "--queryfract");
703 cPara.push_back(tempqueryfract);
704 char* tempQueryfract = new char[pDataArray->queryfract.length()+1];
705 *tempQueryfract = '\0'; strncat(tempQueryfract, pDataArray->queryfract.c_str(), pDataArray->queryfract.length());
706 //strcpy(tempQueryfract, queryfract.c_str());
707 cPara.push_back(tempQueryfract);
711 char** uchimeParameters;
712 uchimeParameters = new char*[cPara.size()];
713 string commandString = "";
714 for (int j = 0; j < cPara.size(); j++) { uchimeParameters[j] = cPara[j]; commandString += toString(cPara[j]) + " "; }
715 //int numArgs = cPara.size();
717 //uchime_main(numArgs, uchimeParameters);
718 //cout << "commandString = " << commandString << endl;
719 if (pDataArray->m->debug) { pDataArray->m->mothurOut("[DEBUG]: uchime command = " + commandString + ".\n"); }
720 system(commandString.c_str());
723 for(int j = 0; j < cPara.size(); j++) { delete cPara[j]; }
724 delete[] uchimeParameters;
726 //remove "" from filenames
727 outputFName = outputFName.substr(1, outputFName.length()-2);
728 filename = filename.substr(1, filename.length()-2);
729 alns = alns.substr(1, alns.length()-2);
731 if (pDataArray->m->control_pressed) { return 0; }
733 //create accnos file from uchime results
735 pDataArray->m->openInputFile(outputFName, in);
738 pDataArray->m->openOutputFile(accnos, out);
743 if (pDataArray->m->control_pressed) { break; }
746 string chimeraFlag = "";
747 in >> chimeraFlag >> name;
749 for (int j = 0; j < 15; j++) { in >> chimeraFlag; }
750 pDataArray->m->gobble(in);
752 if (chimeraFlag == "Y") { out << name << endl; numChimeras++; }
758 if (pDataArray->m->control_pressed) { return 0; }
760 pDataArray->m->mothurOutEndLine(); pDataArray->m->mothurOut("It took " + toString(time(NULL) - start) + " secs to check " + toString(totalSeqs) + " sequences."); pDataArray->m->mothurOutEndLine();
762 pDataArray->count = totalSeqs;
763 pDataArray->numChimeras = numChimeras;
767 catch(exception& e) {
768 pDataArray->m->errorOut(e, "ChimeraUchimeCommand", "MyUchimeSeqsThreadFunction");
775 /**************************************************************************************************/