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;
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>);
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;
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 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 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) {
113 useMinchunk = Minchunk;
114 useIdsmoothwindow = Idsmoothwindow;
115 useMinsmoothid = Minsmoothid;
118 skipgaps2 = skipgap2;
122 useQueryfract = Queryfract;
125 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) {
134 idsmoothwindow = idsmoothwindo;
135 minsmoothid = minsmoothi;
139 queryfract = queryfrac;
143 /**************************************************************************************************/
144 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
146 static DWORD WINAPI MyUchimeThreadFunction(LPVOID lpParam){
147 uchimeData* pDataArray;
148 pDataArray = (uchimeData*)lpParam;
152 pDataArray->outputFName = pDataArray->m->getFullPathName(outputFName);
153 pDataArray->filename = pDataArray->m->getFullPathName(filename);
154 pDataArray->alns = pDataArray->m->getFullPathName(alns);
157 ofstream out, out1, out2;
158 pDataArray->m->openOutputFile(pDataArray->outputFName, out); out.close();
159 pDataArray->m->openOutputFile(pDataArray->accnos, out1); out1.close();
160 if (pDataArray->chimealns) { pDataArray->m->openOutputFile(pDataArray->alns, out2); out2.close(); }
162 //parse fasta and name file by group
163 SequenceParser* parser;
164 if (pDataArray->namefile != "") { parser = new SequenceParser(pDataArray->groupfile, pDataArray->fastafile, pDataArray->namefile); }
165 else { parser = new SequenceParser(pDataArray->groupfile, pDataArray->fastafile); }
170 for (int i = pDataArray->start; i < pDataArray->end; i++) {
171 int start = time(NULL); if (pDataArray->m->control_pressed) { delete parser; return 0; }
173 int error = parser->getSeqs(pDataArray->groups[i], pDataArray->filename, true); if ((error == 1) || pDataArray->m->control_pressed) { delete parser; return 0; }
175 //int numSeqs = driver((outputFName + groups[i]), filename, (accnos+ groups[i]), (alns+ groups[i]), numChimeras);
176 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
178 //to allow for spaces in the path
179 string outputFName = "\"" + pDataArray->outputFName+pDataArray->groups[i] + "\"";
180 string filename = "\"" + pDataArray->filename + "\"";
181 string alns = "\"" + pDataArray->alns+pDataArray->groups[i] + "\"";
182 string accnos = pDataArray->accnos+pDataArray->groups[i];
186 string path = pDataArray->m->argv;
187 string tempPath = path;
188 for (int j = 0; j < path.length(); j++) { tempPath[j] = tolower(path[j]); }
189 path = path.substr(0, (tempPath.find_last_of('m')));
191 string uchimeCommand = path;
192 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
193 uchimeCommand += "uchime ";
195 uchimeCommand += "uchime";
196 uchimeCommand = "\"" + uchimeCommand + "\"";
200 tempUchime= new char[uchimeCommand.length()+1];
202 strncat(tempUchime, uchimeCommand.c_str(), uchimeCommand.length());
203 cPara.push_back(tempUchime);
205 char* tempIn = new char[8];
206 *tempIn = '\0'; strncat(tempIn, "--input", 7);
207 //strcpy(tempIn, "--input");
208 cPara.push_back(tempIn);
209 char* temp = new char[filename.length()+1];
210 *temp = '\0'; strncat(temp, filename.c_str(), filename.length());
211 //strcpy(temp, filename.c_str());
212 cPara.push_back(temp);
214 char* tempO = new char[12];
215 *tempO = '\0'; strncat(tempO, "--uchimeout", 11);
216 //strcpy(tempO, "--uchimeout");
217 cPara.push_back(tempO);
218 char* tempout = new char[outputFName.length()+1];
219 //strcpy(tempout, outputFName.c_str());
220 *tempout = '\0'; strncat(tempout, outputFName.c_str(), outputFName.length());
221 cPara.push_back(tempout);
223 if (pDataArray->chimealns) {
224 char* tempA = new char[13];
225 *tempA = '\0'; strncat(tempA, "--uchimealns", 12);
226 //strcpy(tempA, "--uchimealns");
227 cPara.push_back(tempA);
228 char* tempa = new char[alns.length()+1];
229 //strcpy(tempa, alns.c_str());
230 *tempa = '\0'; strncat(tempa, alns.c_str(), alns.length());
231 cPara.push_back(tempa);
234 if (pDataArray->useAbskew) {
235 char* tempskew = new char[9];
236 *tempskew = '\0'; strncat(tempskew, "--abskew", 8);
237 //strcpy(tempskew, "--abskew");
238 cPara.push_back(tempskew);
239 char* tempSkew = new char[pDataArray->abskew.length()+1];
240 //strcpy(tempSkew, abskew.c_str());
241 *tempSkew = '\0'; strncat(tempSkew, pDataArray->abskew.c_str(), pDataArray->abskew.length());
242 cPara.push_back(tempSkew);
245 if (pDataArray->useMinH) {
246 char* tempminh = new char[7];
247 *tempminh = '\0'; strncat(tempminh, "--minh", 6);
248 //strcpy(tempminh, "--minh");
249 cPara.push_back(tempminh);
250 char* tempMinH = new char[pDataArray->minh.length()+1];
251 *tempMinH = '\0'; strncat(tempMinH, pDataArray->minh.c_str(), pDataArray->minh.length());
252 //strcpy(tempMinH, minh.c_str());
253 cPara.push_back(tempMinH);
256 if (pDataArray->useMindiv) {
257 char* tempmindiv = new char[9];
258 *tempmindiv = '\0'; strncat(tempmindiv, "--mindiv", 8);
259 //strcpy(tempmindiv, "--mindiv");
260 cPara.push_back(tempmindiv);
261 char* tempMindiv = new char[pDataArray->mindiv.length()+1];
262 *tempMindiv = '\0'; strncat(tempMindiv, pDataArray->mindiv.c_str(), pDataArray->mindiv.length());
263 //strcpy(tempMindiv, mindiv.c_str());
264 cPara.push_back(tempMindiv);
267 if (pDataArray->useXn) {
268 char* tempxn = new char[5];
269 //strcpy(tempxn, "--xn");
270 *tempxn = '\0'; strncat(tempxn, "--xn", 4);
271 cPara.push_back(tempxn);
272 char* tempXn = new char[pDataArray->xn.length()+1];
273 //strcpy(tempXn, xn.c_str());
274 *tempXn = '\0'; strncat(tempXn, pDataArray->xn.c_str(), pDataArray->xn.length());
275 cPara.push_back(tempXn);
278 if (pDataArray->useDn) {
279 char* tempdn = new char[5];
280 //strcpy(tempdn, "--dn");
281 *tempdn = '\0'; strncat(tempdn, "--dn", 4);
282 cPara.push_back(tempdn);
283 char* tempDn = new char[pDataArray->dn.length()+1];
284 *tempDn = '\0'; strncat(tempDn, pDataArray->dn.c_str(), pDataArray->dn.length());
285 //strcpy(tempDn, dn.c_str());
286 cPara.push_back(tempDn);
289 if (pDataArray->useXa) {
290 char* tempxa = new char[5];
291 //strcpy(tempxa, "--xa");
292 *tempxa = '\0'; strncat(tempxa, "--xa", 4);
293 cPara.push_back(tempxa);
294 char* tempXa = new char[pDataArray->xa.length()+1];
295 *tempXa = '\0'; strncat(tempXa, pDataArray->xa.c_str(), pDataArray->xa.length());
296 //strcpy(tempXa, xa.c_str());
297 cPara.push_back(tempXa);
300 if (pDataArray->useChunks) {
301 char* tempchunks = new char[9];
302 //strcpy(tempchunks, "--chunks");
303 *tempchunks = '\0'; strncat(tempchunks, "--chunks", 8);
304 cPara.push_back(tempchunks);
305 char* tempChunks = new char[pDataArray->chunks.length()+1];
306 *tempChunks = '\0'; strncat(tempChunks, pDataArray->chunks.c_str(), pDataArray->chunks.length());
307 //strcpy(tempChunks, chunks.c_str());
308 cPara.push_back(tempChunks);
311 if (pDataArray->useMinchunk) {
312 char* tempminchunk = new char[11];
313 //strcpy(tempminchunk, "--minchunk");
314 *tempminchunk = '\0'; strncat(tempminchunk, "--minchunk", 10);
315 cPara.push_back(tempminchunk);
316 char* tempMinchunk = new char[pDataArray->minchunk.length()+1];
317 *tempMinchunk = '\0'; strncat(tempMinchunk, pDataArray->minchunk.c_str(), pDataArray->minchunk.length());
318 //strcpy(tempMinchunk, minchunk.c_str());
319 cPara.push_back(tempMinchunk);
322 if (pDataArray->useIdsmoothwindow) {
323 char* tempidsmoothwindow = new char[17];
324 *tempidsmoothwindow = '\0'; strncat(tempidsmoothwindow, "--idsmoothwindow", 16);
325 //strcpy(tempidsmoothwindow, "--idsmoothwindow");
326 cPara.push_back(tempidsmoothwindow);
327 char* tempIdsmoothwindow = new char[pDataArray->idsmoothwindow.length()+1];
328 *tempIdsmoothwindow = '\0'; strncat(tempIdsmoothwindow, pDataArray->idsmoothwindow.c_str(), pDataArray->idsmoothwindow.length());
329 //strcpy(tempIdsmoothwindow, idsmoothwindow.c_str());
330 cPara.push_back(tempIdsmoothwindow);
333 /*if (useMinsmoothid) {
334 char* tempminsmoothid = new char[14];
335 //strcpy(tempminsmoothid, "--minsmoothid");
336 *tempminsmoothid = '\0'; strncat(tempminsmoothid, "--minsmoothid", 13);
337 cPara.push_back(tempminsmoothid);
338 char* tempMinsmoothid = new char[minsmoothid.length()+1];
339 *tempMinsmoothid = '\0'; strncat(tempMinsmoothid, minsmoothid.c_str(), minsmoothid.length());
340 //strcpy(tempMinsmoothid, minsmoothid.c_str());
341 cPara.push_back(tempMinsmoothid);
344 if (pDataArray->useMaxp) {
345 char* tempmaxp = new char[7];
346 //strcpy(tempmaxp, "--maxp");
347 *tempmaxp = '\0'; strncat(tempmaxp, "--maxp", 6);
348 cPara.push_back(tempmaxp);
349 char* tempMaxp = new char[pDataArray->maxp.length()+1];
350 *tempMaxp = '\0'; strncat(tempMaxp, pDataArray->maxp.c_str(), pDataArray->maxp.length());
351 //strcpy(tempMaxp, maxp.c_str());
352 cPara.push_back(tempMaxp);
355 if (!pDataArray->skipgaps) {
356 char* tempskipgaps = new char[13];
357 //strcpy(tempskipgaps, "--[no]skipgaps");
358 *tempskipgaps = '\0'; strncat(tempskipgaps, "--noskipgaps", 12);
359 cPara.push_back(tempskipgaps);
362 if (!pDataArray->skipgaps2) {
363 char* tempskipgaps2 = new char[14];
364 //strcpy(tempskipgaps2, "--[no]skipgaps2");
365 *tempskipgaps2 = '\0'; strncat(tempskipgaps2, "--noskipgaps2", 13);
366 cPara.push_back(tempskipgaps2);
369 if (pDataArray->useMinlen) {
370 char* tempminlen = new char[9];
371 *tempminlen = '\0'; strncat(tempminlen, "--minlen", 8);
372 //strcpy(tempminlen, "--minlen");
373 cPara.push_back(tempminlen);
374 char* tempMinlen = new char[pDataArray->minlen.length()+1];
375 //strcpy(tempMinlen, minlen.c_str());
376 *tempMinlen = '\0'; strncat(tempMinlen, pDataArray->minlen.c_str(), pDataArray->minlen.length());
377 cPara.push_back(tempMinlen);
380 if (pDataArray->useMaxlen) {
381 char* tempmaxlen = new char[9];
382 //strcpy(tempmaxlen, "--maxlen");
383 *tempmaxlen = '\0'; strncat(tempmaxlen, "--maxlen", 8);
384 cPara.push_back(tempmaxlen);
385 char* tempMaxlen = new char[pDataArray->maxlen.length()+1];
386 *tempMaxlen = '\0'; strncat(tempMaxlen, pDataArray->maxlen.c_str(), pDataArray->maxlen.length());
387 //strcpy(tempMaxlen, maxlen.c_str());
388 cPara.push_back(tempMaxlen);
391 if (pDataArray->ucl) {
392 char* tempucl = new char[5];
393 strcpy(tempucl, "--ucl");
394 cPara.push_back(tempucl);
397 if (pDataArray->useQueryfract) {
398 char* tempqueryfract = new char[13];
399 *tempqueryfract = '\0'; strncat(tempqueryfract, "--queryfract", 12);
400 //strcpy(tempqueryfract, "--queryfract");
401 cPara.push_back(tempqueryfract);
402 char* tempQueryfract = new char[pDataArray->queryfract.length()+1];
403 *tempQueryfract = '\0'; strncat(tempQueryfract, pDataArray->queryfract.c_str(), pDataArray->queryfract.length());
404 //strcpy(tempQueryfract, queryfract.c_str());
405 cPara.push_back(tempQueryfract);
409 char** uchimeParameters;
410 uchimeParameters = new char*[cPara.size()];
411 string commandString = "";
412 for (int j = 0; j < cPara.size(); j++) { uchimeParameters[j] = cPara[j]; commandString += toString(cPara[j]) + " "; }
413 //int numArgs = cPara.size();
415 //uchime_main(numArgs, uchimeParameters);
416 //cout << "commandString = " << commandString << endl;
417 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
419 commandString = "\"" + commandString + "\"";
421 system(commandString.c_str());
424 for(int j = 0; j < cPara.size(); j++) { delete cPara[j]; }
425 delete[] uchimeParameters;
427 //remove "" from filenames
428 outputFName = outputFName.substr(1, outputFName.length()-2);
429 filename = filename.substr(1, filename.length()-2);
430 alns = alns.substr(1, alns.length()-2);
432 if (pDataArray->m->control_pressed) { delete parser; return 0; }
434 //create accnos file from uchime results
436 pDataArray->m->openInputFile(outputFName, in);
439 pDataArray->m->openOutputFile(accnos, out);
445 if (pDataArray->m->control_pressed) { break; }
448 string chimeraFlag = "";
449 in >> chimeraFlag >> name;
452 name = name.substr(0, name.length()-1); //rip off last /
453 name = name.substr(0, name.find_last_of('/'));
455 for (int j = 0; j < 15; j++) { in >> chimeraFlag; }
456 pDataArray->m->gobble(in);
458 if (chimeraFlag == "Y") { out << name << endl; numChimeras++; }
465 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
467 pDataArray->numChimeras += numChimeras;
469 if (pDataArray->m->control_pressed) { delete parser; return 0; }
471 //remove file made for uchime
472 pDataArray->m->mothurRemove(filename);
475 pDataArray->m->appendFiles(outputFName, pDataArray->outputFName); pDataArray->m->mothurRemove(outputFName);
476 pDataArray->m->appendFiles(accnos, pDataArray->accnos); pDataArray->m->mothurRemove(accnos);
477 if (pDataArray->chimealns) { pDataArray->m->appendFiles(alns, pDataArray->alns); pDataArray->m->mothurRemove(alns); }
479 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();
483 pDataArray->count = totalSeqs;
488 catch(exception& e) {
489 pDataArray->m->errorOut(e, "ChimeraUchimeCommand", "MyUchimeThreadFunction");
493 /**************************************************************************************************/
495 static DWORD WINAPI MyUchimeSeqsThreadFunction(LPVOID lpParam){
496 uchimeData* pDataArray;
497 pDataArray = (uchimeData*)lpParam;
501 pDataArray->outputFName = pDataArray->m->getFullPathName(outputFName);
502 pDataArray->filename = pDataArray->m->getFullPathName(filename);
503 pDataArray->alns = pDataArray->m->getFullPathName(alns);
508 int start = time(NULL); if (pDataArray->m->control_pressed) { return 0; }
510 //to allow for spaces in the path
511 string outputFName = "\"" + pDataArray->outputFName + "\"";
512 string filename = "\"" + pDataArray->filename + "\"";
513 string alns = "\"" + pDataArray->alns+ "\"";
514 string templatefile = "\"" + pDataArray->templatefile + "\"";
515 string accnos = pDataArray->accnos;
520 tempUchime= new char[8];
522 strncat(tempUchime, "uchime ", 7);
523 cPara.push_back(tempUchime);
525 char* tempIn = new char[8];
526 *tempIn = '\0'; strncat(tempIn, "--input", 7);
527 //strcpy(tempIn, "--input");
528 cPara.push_back(tempIn);
529 char* temp = new char[filename.length()+1];
530 *temp = '\0'; strncat(temp, filename.c_str(), filename.length());
531 //strcpy(temp, filename.c_str());
532 cPara.push_back(temp);
535 char* tempRef = new char[5];
536 //strcpy(tempRef, "--db");
537 *tempRef = '\0'; strncat(tempRef, "--db", 4);
538 cPara.push_back(tempRef);
539 char* tempR = new char[templatefile.length()+1];
540 //strcpy(tempR, templatefile.c_str());
541 *tempR = '\0'; strncat(tempR, templatefile.c_str(), templatefile.length());
542 cPara.push_back(tempR);
544 char* tempO = new char[12];
545 *tempO = '\0'; strncat(tempO, "--uchimeout", 11);
546 //strcpy(tempO, "--uchimeout");
547 cPara.push_back(tempO);
548 char* tempout = new char[outputFName.length()+1];
549 //strcpy(tempout, outputFName.c_str());
550 *tempout = '\0'; strncat(tempout, outputFName.c_str(), outputFName.length());
551 cPara.push_back(tempout);
553 if (pDataArray->chimealns) {
554 char* tempA = new char[13];
555 *tempA = '\0'; strncat(tempA, "--uchimealns", 12);
556 //strcpy(tempA, "--uchimealns");
557 cPara.push_back(tempA);
558 char* tempa = new char[alns.length()+1];
559 //strcpy(tempa, alns.c_str());
560 *tempa = '\0'; strncat(tempa, alns.c_str(), alns.length());
561 cPara.push_back(tempa);
564 if (pDataArray->useAbskew) {
565 char* tempskew = new char[9];
566 *tempskew = '\0'; strncat(tempskew, "--abskew", 8);
567 //strcpy(tempskew, "--abskew");
568 cPara.push_back(tempskew);
569 char* tempSkew = new char[pDataArray->abskew.length()+1];
570 //strcpy(tempSkew, abskew.c_str());
571 *tempSkew = '\0'; strncat(tempSkew, pDataArray->abskew.c_str(), pDataArray->abskew.length());
572 cPara.push_back(tempSkew);
575 if (pDataArray->useMinH) {
576 char* tempminh = new char[7];
577 *tempminh = '\0'; strncat(tempminh, "--minh", 6);
578 //strcpy(tempminh, "--minh");
579 cPara.push_back(tempminh);
580 char* tempMinH = new char[pDataArray->minh.length()+1];
581 *tempMinH = '\0'; strncat(tempMinH, pDataArray->minh.c_str(), pDataArray->minh.length());
582 //strcpy(tempMinH, minh.c_str());
583 cPara.push_back(tempMinH);
586 if (pDataArray->useMindiv) {
587 char* tempmindiv = new char[9];
588 *tempmindiv = '\0'; strncat(tempmindiv, "--mindiv", 8);
589 //strcpy(tempmindiv, "--mindiv");
590 cPara.push_back(tempmindiv);
591 char* tempMindiv = new char[pDataArray->mindiv.length()+1];
592 *tempMindiv = '\0'; strncat(tempMindiv, pDataArray->mindiv.c_str(), pDataArray->mindiv.length());
593 //strcpy(tempMindiv, mindiv.c_str());
594 cPara.push_back(tempMindiv);
597 if (pDataArray->useXn) {
598 char* tempxn = new char[5];
599 //strcpy(tempxn, "--xn");
600 *tempxn = '\0'; strncat(tempxn, "--xn", 4);
601 cPara.push_back(tempxn);
602 char* tempXn = new char[pDataArray->xn.length()+1];
603 //strcpy(tempXn, xn.c_str());
604 *tempXn = '\0'; strncat(tempXn, pDataArray->xn.c_str(), pDataArray->xn.length());
605 cPara.push_back(tempXn);
608 if (pDataArray->useDn) {
609 char* tempdn = new char[5];
610 //strcpy(tempdn, "--dn");
611 *tempdn = '\0'; strncat(tempdn, "--dn", 4);
612 cPara.push_back(tempdn);
613 char* tempDn = new char[pDataArray->dn.length()+1];
614 *tempDn = '\0'; strncat(tempDn, pDataArray->dn.c_str(), pDataArray->dn.length());
615 //strcpy(tempDn, dn.c_str());
616 cPara.push_back(tempDn);
619 if (pDataArray->useXa) {
620 char* tempxa = new char[5];
621 //strcpy(tempxa, "--xa");
622 *tempxa = '\0'; strncat(tempxa, "--xa", 4);
623 cPara.push_back(tempxa);
624 char* tempXa = new char[pDataArray->xa.length()+1];
625 *tempXa = '\0'; strncat(tempXa, pDataArray->xa.c_str(), pDataArray->xa.length());
626 //strcpy(tempXa, xa.c_str());
627 cPara.push_back(tempXa);
630 if (pDataArray->useChunks) {
631 char* tempchunks = new char[9];
632 //strcpy(tempchunks, "--chunks");
633 *tempchunks = '\0'; strncat(tempchunks, "--chunks", 8);
634 cPara.push_back(tempchunks);
635 char* tempChunks = new char[pDataArray->chunks.length()+1];
636 *tempChunks = '\0'; strncat(tempChunks, pDataArray->chunks.c_str(), pDataArray->chunks.length());
637 //strcpy(tempChunks, chunks.c_str());
638 cPara.push_back(tempChunks);
641 if (pDataArray->useMinchunk) {
642 char* tempminchunk = new char[11];
643 //strcpy(tempminchunk, "--minchunk");
644 *tempminchunk = '\0'; strncat(tempminchunk, "--minchunk", 10);
645 cPara.push_back(tempminchunk);
646 char* tempMinchunk = new char[pDataArray->minchunk.length()+1];
647 *tempMinchunk = '\0'; strncat(tempMinchunk, pDataArray->minchunk.c_str(), pDataArray->minchunk.length());
648 //strcpy(tempMinchunk, minchunk.c_str());
649 cPara.push_back(tempMinchunk);
652 if (pDataArray->useIdsmoothwindow) {
653 char* tempidsmoothwindow = new char[17];
654 *tempidsmoothwindow = '\0'; strncat(tempidsmoothwindow, "--idsmoothwindow", 16);
655 //strcpy(tempidsmoothwindow, "--idsmoothwindow");
656 cPara.push_back(tempidsmoothwindow);
657 char* tempIdsmoothwindow = new char[pDataArray->idsmoothwindow.length()+1];
658 *tempIdsmoothwindow = '\0'; strncat(tempIdsmoothwindow, pDataArray->idsmoothwindow.c_str(), pDataArray->idsmoothwindow.length());
659 //strcpy(tempIdsmoothwindow, idsmoothwindow.c_str());
660 cPara.push_back(tempIdsmoothwindow);
663 if (pDataArray->useMaxp) {
664 char* tempmaxp = new char[7];
665 //strcpy(tempmaxp, "--maxp");
666 *tempmaxp = '\0'; strncat(tempmaxp, "--maxp", 6);
667 cPara.push_back(tempmaxp);
668 char* tempMaxp = new char[pDataArray->maxp.length()+1];
669 *tempMaxp = '\0'; strncat(tempMaxp, pDataArray->maxp.c_str(), pDataArray->maxp.length());
670 //strcpy(tempMaxp, maxp.c_str());
671 cPara.push_back(tempMaxp);
674 if (!pDataArray->skipgaps) {
675 char* tempskipgaps = new char[13];
676 //strcpy(tempskipgaps, "--[no]skipgaps");
677 *tempskipgaps = '\0'; strncat(tempskipgaps, "--noskipgaps", 12);
678 cPara.push_back(tempskipgaps);
681 if (!pDataArray->skipgaps2) {
682 char* tempskipgaps2 = new char[14];
683 //strcpy(tempskipgaps2, "--[no]skipgaps2");
684 *tempskipgaps2 = '\0'; strncat(tempskipgaps2, "--noskipgaps2", 13);
685 cPara.push_back(tempskipgaps2);
688 if (pDataArray->useMinlen) {
689 char* tempminlen = new char[9];
690 *tempminlen = '\0'; strncat(tempminlen, "--minlen", 8);
691 //strcpy(tempminlen, "--minlen");
692 cPara.push_back(tempminlen);
693 char* tempMinlen = new char[pDataArray->minlen.length()+1];
694 //strcpy(tempMinlen, minlen.c_str());
695 *tempMinlen = '\0'; strncat(tempMinlen, pDataArray->minlen.c_str(), pDataArray->minlen.length());
696 cPara.push_back(tempMinlen);
699 if (pDataArray->useMaxlen) {
700 char* tempmaxlen = new char[9];
701 //strcpy(tempmaxlen, "--maxlen");
702 *tempmaxlen = '\0'; strncat(tempmaxlen, "--maxlen", 8);
703 cPara.push_back(tempmaxlen);
704 char* tempMaxlen = new char[pDataArray->maxlen.length()+1];
705 *tempMaxlen = '\0'; strncat(tempMaxlen, pDataArray->maxlen.c_str(), pDataArray->maxlen.length());
706 //strcpy(tempMaxlen, maxlen.c_str());
707 cPara.push_back(tempMaxlen);
710 if (pDataArray->ucl) {
711 char* tempucl = new char[5];
712 strcpy(tempucl, "--ucl");
713 cPara.push_back(tempucl);
716 if (pDataArray->useQueryfract) {
717 char* tempqueryfract = new char[13];
718 *tempqueryfract = '\0'; strncat(tempqueryfract, "--queryfract", 12);
719 //strcpy(tempqueryfract, "--queryfract");
720 cPara.push_back(tempqueryfract);
721 char* tempQueryfract = new char[pDataArray->queryfract.length()+1];
722 *tempQueryfract = '\0'; strncat(tempQueryfract, pDataArray->queryfract.c_str(), pDataArray->queryfract.length());
723 //strcpy(tempQueryfract, queryfract.c_str());
724 cPara.push_back(tempQueryfract);
728 char** uchimeParameters;
729 uchimeParameters = new char*[cPara.size()];
730 string commandString = "";
731 for (int j = 0; j < cPara.size(); j++) { uchimeParameters[j] = cPara[j]; commandString += toString(cPara[j]) + " "; }
732 //int numArgs = cPara.size();
734 //uchime_main(numArgs, uchimeParameters);
735 //cout << "commandString = " << commandString << endl;
736 system(commandString.c_str());
739 for(int j = 0; j < cPara.size(); j++) { delete cPara[j]; }
740 delete[] uchimeParameters;
742 //remove "" from filenames
743 outputFName = outputFName.substr(1, outputFName.length()-2);
744 filename = filename.substr(1, filename.length()-2);
745 alns = alns.substr(1, alns.length()-2);
747 if (pDataArray->m->control_pressed) { return 0; }
749 //create accnos file from uchime results
751 pDataArray->m->openInputFile(outputFName, in);
754 pDataArray->m->openOutputFile(accnos, out);
759 if (pDataArray->m->control_pressed) { break; }
762 string chimeraFlag = "";
763 in >> chimeraFlag >> name;
765 for (int j = 0; j < 15; j++) { in >> chimeraFlag; }
766 pDataArray->m->gobble(in);
768 if (chimeraFlag == "Y") { out << name << endl; numChimeras++; }
774 if (pDataArray->m->control_pressed) { return 0; }
776 pDataArray->m->mothurOutEndLine(); pDataArray->m->mothurOut("It took " + toString(time(NULL) - start) + " secs to check " + toString(totalSeqs) + " sequences."); pDataArray->m->mothurOutEndLine();
778 pDataArray->count = totalSeqs;
779 pDataArray->numChimeras = numChimeras;
783 catch(exception& e) {
784 pDataArray->m->errorOut(e, "ChimeraUchimeCommand", "MyUchimeSeqsThreadFunction");
791 /**************************************************************************************************/