// Merge the indices for the two independent sets of reads in readsFile1 and readsFile2 void mergeIndependentIndices(const std::string& readsFile1, const std::string& readsFile2, const std::string& outPrefix, const std::string& bwt_extension, const std::string& sai_extension, bool doReverse, int numThreads, int storageLevel) { MergeItem item1; std::string prefix1 = stripFilename(readsFile1); item1.reads_filename = readsFile1; item1.bwt_filename = makeFilename(prefix1, bwt_extension); item1.sai_filename = makeFilename(prefix1, sai_extension); item1.start_index = 0; item1.end_index = -1; // this tells merge to read the entire file MergeItem item2; std::string prefix2 = stripFilename(readsFile2); item2.reads_filename = readsFile2; item2.bwt_filename = makeFilename(prefix2, bwt_extension); item2.sai_filename = makeFilename(prefix2, sai_extension); item2.start_index = 0; item2.end_index = -1; // Prepare the input filehandle SeqReader* pReader = new SeqReader(item1.reads_filename); // Build the outnames std::string bwt_merged_name = makeFilename(outPrefix, bwt_extension); std::string sai_merged_name = makeFilename(outPrefix, sai_extension); // Perform the actual merge merge(pReader, item1, item2, bwt_merged_name, sai_merged_name, doReverse, numThreads, storageLevel); delete pReader; }
// // Handle command line arguments // void parseRmdupOptions(int argc, char** argv) { // Set defaults bool die = false; for (char c; (c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1;) { std::istringstream arg(optarg != NULL ? optarg : ""); switch (c) { case 'p': arg >> opt::prefix; break; case 'o': arg >> opt::outFile; break; case 'e': arg >> opt::errorRate; break; case 'd': arg >> opt::sampleRate; break; case 't': arg >> opt::numThreads; break; case 'v': opt::verbose++; break; case OPT_HELP: std::cout << RMDUP_USAGE_MESSAGE; exit(EXIT_SUCCESS); case OPT_VERSION: std::cout << RMDUP_VERSION_MESSAGE; exit(EXIT_SUCCESS); } } if (argc - optind < 1) { std::cerr << SUBPROGRAM ": missing arguments\n"; die = true; } else if (argc - optind > 1) { std::cerr << SUBPROGRAM ": too many arguments\n"; die = true; } if (die) { std::cerr << "Try `" << SUBPROGRAM << " --help' for more information.\n"; exit(EXIT_FAILURE); } // Parse the input filenames opt::readsFile = argv[optind++]; if(opt::prefix.empty()) { opt::prefix = stripFilename(opt::readsFile); } if(opt::outFile.empty()) { opt::outFile = stripFilename(opt::readsFile) + ".rmdup.fa"; } }
int mergeMain(int argc, char** argv) { parseMergeOptions(argc, argv); StringVector inFiles; while(optind < argc) { inFiles.push_back(argv[optind++]); } assert(inFiles.size() == 2); if(inFiles[0] == inFiles[1]) return 0; // avoid self-merge std::string prefix1 = stripFilename(inFiles[0]); std::string prefix2 = stripFilename(inFiles[1]); if(opt::prefix.empty()) { opt::prefix = prefix1 + "." + prefix2; } // Merge the indices if(opt::bMergeForward) { mergeIndependentIndices(inFiles[0], inFiles[1], opt::prefix, BWT_EXT, SAI_EXT, false, opt::numThreads, opt::gapArrayStorage); } // Skip merging the reverse indices if the reverse bwt file does not exist. std::string rbwt_filename_1 = prefix1 + RBWT_EXT; std::string rbwt_filename_2 = prefix2 + RBWT_EXT; struct stat file_s_1; struct stat file_s_2; int ret1 = stat(rbwt_filename_1.c_str(), &file_s_1); int ret2 = stat(rbwt_filename_2.c_str(), &file_s_2); if((ret1 == 0 || ret2 == 0) && opt::bMergeReverse) { mergeIndependentIndices(inFiles[0], inFiles[1], opt::prefix, RBWT_EXT, RSAI_EXT, true, opt::numThreads, opt::gapArrayStorage); } // Merge the read files if(opt::bMergeSequence) { mergeReadFiles(inFiles[0], inFiles[1], opt::prefix); } if(opt::bRemove) { // Delete the original reads, bwt and sai files removeFiles(inFiles[0]); removeFiles(inFiles[1]); } return 0; }
// // Handle command line arguments // void parseClusterOptions(int argc, char** argv) { bool die = false; for (char c; (c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1;) { std::istringstream arg(optarg != NULL ? optarg : ""); switch (c) { case 'o': arg >> opt::outFile; break; case 'c': arg >> opt::minSize; break; case 'x': arg >> opt::maxSize; break; case 'e': arg >> opt::errorRate; break; case 'm': arg >> opt::minOverlap; break; case 't': arg >> opt::numThreads; break; case 'i': arg >> opt::maxIterations; break; case 'p': arg >> opt::prefix; break; case '?': die = true; break; case 'v': opt::verbose++; break; case OPT_EXTEND: arg >> opt::extendFile; break; case OPT_LIMIT: arg >> opt::limitFile; break; case OPT_HELP: std::cout << CLUSTER_USAGE_MESSAGE; exit(EXIT_SUCCESS); case OPT_VERSION: std::cout << CLUSTER_VERSION_MESSAGE; exit(EXIT_SUCCESS); } } if (argc - optind < 1) { std::cerr << SUBPROGRAM ": missing arguments\n"; die = true; } else if (argc - optind > 1) { std::cerr << SUBPROGRAM ": too many arguments\n"; die = true; } if (die) { std::cout << "\n" << CLUSTER_USAGE_MESSAGE; exit(EXIT_FAILURE); } // Parse the input filename opt::readsFile = argv[optind++]; opt::prefix = stripFilename(opt::readsFile); if(opt::outFile.empty()) opt::outFile = opt::prefix + ".clusters"; }
// // Handle command line arguments // void parseGenSSAOptions(int argc, char** argv) { bool die = false; for (char c; (c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1;) { std::istringstream arg(optarg != NULL ? optarg : ""); switch (c) { case '?': die = true; break; case 'c': opt::validate = true; break; case 't': arg >> opt::numThreads; break; case 'v': opt::verbose++; break; case OPT_HELP: std::cout << GENSSA_USAGE_MESSAGE; exit(EXIT_SUCCESS); case OPT_VERSION: std::cout << GENSSA_VERSION_MESSAGE; exit(EXIT_SUCCESS); } } if (argc - optind < 1) { std::cerr << SUBPROGRAM ": missing arguments\n"; die = true; } else if (argc - optind > 1) { std::cerr << SUBPROGRAM ": too many arguments\n"; die = true; } if(opt::numThreads <= 0) { std::cerr << SUBPROGRAM ": invalid number of threads: " << opt::numThreads << "\n"; die = true; } if (die) { std::cerr << "Try `" << SUBPROGRAM << " --help' for more information.\n"; exit(EXIT_FAILURE); } // Parse the input filenames opt::readsFile = argv[optind++]; if(opt::prefix.empty()) { opt::prefix = stripFilename(opt::readsFile); } }
void removeFiles(const std::string& inFile) { std::string prefix = stripFilename(inFile); std::string bwt_file = prefix + BWT_EXT; std::string rbwt_file = prefix + RBWT_EXT; std::string sai_file = prefix + SAI_EXT; std::string rsai_file = prefix + RSAI_EXT; unlink(bwt_file.c_str()); unlink(rbwt_file.c_str()); unlink(sai_file.c_str()); unlink(rsai_file.c_str()); unlink(inFile.c_str()); }
// // Handle command line arguments // void parseConvertBeetlOptions(int argc, char** argv) { bool die = false; for (char c; (c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1;) { std::istringstream arg(optarg != NULL ? optarg : ""); switch (c) { case 'p': arg >> opt::prefix; break; case '?': die = true; break; case 'v': opt::verbose++; break; case OPT_HELP: std::cout << CONVERT_BEETL_USAGE_MESSAGE; exit(EXIT_SUCCESS); case OPT_VERSION: std::cout << CONVERT_BEETL_VERSION_MESSAGE; exit(EXIT_SUCCESS); } } if (argc - optind < 2) { std::cerr << SUBPROGRAM ": missing arguments\n"; die = true; } else if (argc - optind > 2) { std::cerr << SUBPROGRAM ": too many arguments\n"; die = true; } if (die) { std::cout << "\n" << CONVERT_BEETL_USAGE_MESSAGE; exit(EXIT_FAILURE); } // Parse the input filenames opt::inBWTFile = argv[optind++]; opt::readsFile = argv[optind++]; if(opt::prefix.empty()) opt::prefix = stripFilename(opt::readsFile); }
// // Main // int filterMain(int argc, char** argv) { parseFilterOptions(argc, argv); Timer* pTimer = new Timer(PROGRAM_IDENT); BWT* pBWT = new BWT(opt::prefix + BWT_EXT, opt::sampleRate); BWT* pRBWT = new BWT(opt::prefix + RBWT_EXT, opt::sampleRate); //pBWT->printInfo(); std::ostream* pWriter = createWriter(opt::outFile); std::ostream* pDiscardWriter = createWriter(opt::discardFile); QCPostProcess* pPostProcessor = new QCPostProcess(pWriter, pDiscardWriter); // If performing duplicate check, create a bitvector to record // which reads are duplicates BitVector* pSharedBV = NULL; if(opt::dupCheck) pSharedBV = new BitVector(pBWT->getNumStrings()); // Set up QC parameters QCParameters params; params.pBWT = pBWT; params.pRevBWT = pRBWT; params.pSharedBV = pSharedBV; params.checkDuplicates = opt::dupCheck; params.substringOnly = opt::substringOnly; params.checkKmer = opt::kmerCheck; params.checkHPRuns = opt::hpCheck; params.checkDegenerate = opt::lowComplexityCheck; params.verbose = opt::verbose; params.kmerLength = opt::kmerLength; params.kmerThreshold = opt::kmerThreshold; params.hpKmerLength = 51; params.hpHardAcceptCount = 10; params.hpMinProportion = 0.1f; params.hpMinLength = 6; if(opt::numThreads <= 1) { // Serial mode QCProcess processor(params); PROCESS_FILTER_SERIAL(opt::readsFile, &processor, pPostProcessor); } else { // Parallel mode std::vector<QCProcess*> processorVector; for(int i = 0; i < opt::numThreads; ++i) { QCProcess* pProcessor = new QCProcess(params); processorVector.push_back(pProcessor); } PROCESS_FILTER_PARALLEL(opt::readsFile, processorVector, pPostProcessor); for(int i = 0; i < opt::numThreads; ++i) delete processorVector[i]; } delete pPostProcessor; delete pWriter; delete pDiscardWriter; delete pBWT; delete pRBWT; if(pSharedBV != NULL) delete pSharedBV; std::cout << "RE-building index for " << opt::outFile << " in memory using ropebwt2\n"; std::string prefix=stripFilename(opt::outFile); //BWT *pBWT, *pRBWT; #pragma omp parallel { #pragma omp single nowait { std::string bwt_filename = prefix + BWT_EXT; BWTCA::runRopebwt2(opt::outFile, bwt_filename, opt::numThreads, false); std::cout << "\t done bwt construction, generating .sai file\n"; pBWT = new BWT(bwt_filename); } #pragma omp single nowait { std::string rbwt_filename = prefix + RBWT_EXT; BWTCA::runRopebwt2(opt::outFile, rbwt_filename, opt::numThreads, true); std::cout << "\t done rbwt construction, generating .rsai file\n"; pRBWT = new BWT(rbwt_filename); } } std::string sai_filename = prefix + SAI_EXT; SampledSuffixArray ssa; ssa.buildLexicoIndex(pBWT, opt::numThreads); ssa.writeLexicoIndex(sai_filename); delete pBWT; std::string rsai_filename = prefix + RSAI_EXT; SampledSuffixArray rssa; rssa.buildLexicoIndex(pRBWT, opt::numThreads); rssa.writeLexicoIndex(rsai_filename); delete pRBWT; // Cleanup delete pTimer; return 0; }
int mainPDF2SWF(int argn, char *argv[], void *stream, void *pdfDoc, ExportSWFParams *exportParams) #endif { char buf[256]; int numfonts = 0; int t; char t1searchpath[1024]; int nup_pos = 0; int x,y; int one_file_per_page = 0; int ret = 0; initLog(0,-1,0,0,-1,loglevel); srand(time(0)); processargs(argn, argv); driver = gfxsource_pdf_create(); /* pass global parameters to PDF driver*/ parameter_t*p = device_config; while(p) { driver->setparameter(driver, p->name, p->value); p = p->next; } #ifndef _CONSOLE if(openStream) filename = "stream"; #endif if(!filename) { fprintf(stderr, "Please specify an input file\n"); RETERROR(1); } if (!info_only) { if(!outputname) { if(filename) { outputname = stripFilename(filename, ".swf"); msg("<notice> Output filename not given. Writing to %s", outputname); } } if(!outputname) { fprintf(stderr, "Please use -o to specify an output file\n"); RETERROR(2); } } // test if the page range is o.k. is_in_range(0x7fffffff, pagerange); if (!filename) { args_callback_usage(argv[0]); RETERROR(1,0); } char fullname[256]; if(password && *password) { sprintf(fullname, "%s|%s", filename, password); filename = fullname; } if(pagerange) driver->setparameter(driver, "pages", pagerange); /* add fonts */ for(t=0;t<fontpathpos;t++) { driver->setparameter(driver, "fontdir", fontpaths[t]); } #ifdef _CONSOLE if(info_only) { show_info(driver, filename); return 0; } #endif char*u = 0; if((u = strchr(outputname, '%'))) { if(strchr(u+1, '%') || strchr(outputname, '%')!=u) { msg("<error> only one %% allowed in filename\n"); RETERROR(3); } if(preloader || viewer) { msg("<error> -b/-l/-B/-L not supported together with %% in filename\n"); RETERROR(4); } //msg("<notice> outputting one file per page"); one_file_per_page = 1; char*pattern = (char*)malloc(strlen(outputname)+2); /* convert % to %d */ int l = u-outputname+1; memcpy(pattern, outputname, l); pattern[l]='d'; strcpy(pattern+l+1, outputname+l); outputname = pattern; } #ifdef _CONSOLE gfxdocument_t* pdf = driver->open(driver, filename); #else gfxdocument_t* pdf; if(openStream) pdf = driver->open_stream(driver, stream, pdfDoc); else pdf = driver->open(driver, filename); #endif if(!pdf) { msg("<error> Couldn't open %s", filename); RETERROR(5); } /* pass global parameters document */ p = device_config; while(p) { pdf->setparameter(pdf, p->name, p->value); p = p->next; } struct mypage_t { int x; int y; gfxpage_t*page; } pages[4]; int pagenum = 0; int frame = 1; int pagenr; for(pagenr = 1; pagenr <= pdf->num_pages; pagenr++) { if(is_in_range(pagenr, pagerange)) { char mapping[80]; sprintf(mapping, "%d:%d", pagenr, frame); pdf->setparameter(pdf, "pagemap", mapping); pagenum++; } if(pagenum == xnup*ynup || (pagenr == pdf->num_pages && pagenum>1)) { pagenum = 0; frame++; } } if(pagerange && !pagenum && frame==1) { fprintf(stderr, "No pages in range %s", pagerange); RETERROR(6); } pagenum = 0; gfxdevice_t*out = create_output_device();; pdf->prepare(pdf, out); for(pagenr = 1; pagenr <= pdf->num_pages; pagenr++) { DWORD waitRes = WaitForSingleObject(exportParams->hExportSwfCancel,0); if(waitRes == WAIT_OBJECT_0){ SetEvent(exportParams->hExportSwfCancelled); ret = 1; goto clean; }else{ if(exportParams->m_ExportSwfProgressHandle != 0){ if(!exportParams->m_ExportSwfProgressHandle(pdf->num_pages,pagenr) !=0){ SetEvent(exportParams->hExportSwfCancelled); ret = 4; goto clean; } } } if(is_in_range(pagenr, pagerange)) { gfxpage_t* page = pages[pagenum].page = pdf->getpage(pdf, pagenr); pages[pagenum].x = 0; pages[pagenum].y = 0; pages[pagenum].page = page; pagenum++; } if(pagenum == xnup*ynup || (pagenr == pdf->num_pages && pagenum>1)) { int t; int *xmax = new int[xnup]; //[xnup] int *ymax = new int[xnup]; //[xnup]; int x,y; int width=0, height=0; memset(xmax, 0, xnup*sizeof(int)); memset(ymax, 0, ynup*sizeof(int)); for(y=0;y<ynup;y++) for(x=0;x<xnup;x++) { int t = y*xnup + x; if(pages[t].page->width > xmax[x]) xmax[x] = (int)pages[t].page->width; if(pages[t].page->height > ymax[y]) ymax[y] = (int)pages[t].page->height; } for(x=0;x<xnup;x++) { width += xmax[x]; xmax[x] = width; } for(y=0;y<ynup;y++) { height += ymax[y]; ymax[y] = height; } if(custom_clip) { out->startpage(out,clip_x2 - clip_x1, clip_y2 - clip_y1); } else { out->startpage(out,width,height); } for(t=0;t<pagenum;t++) { int x = t%xnup; int y = t/xnup; int xpos = x>0?xmax[x-1]:0; int ypos = y>0?ymax[y-1]:0; msg("<verbose> Render (%d,%d) move:%d/%d\n", (int)(pages[t].page->width + xpos), (int)(pages[t].page->height + ypos), xpos, ypos); pages[t].page->rendersection(pages[t].page, out, custom_move? move_x : xpos, custom_move? move_y : ypos, custom_clip? clip_x1 : 0 + xpos, custom_clip? clip_y1 : 0 + ypos, custom_clip? clip_x2 : pages[t].page->width + xpos, custom_clip? clip_y2 : pages[t].page->height + ypos); } out->endpage(out); for(t=0;t<pagenum;t++) { pages[t].page->destroy(pages[t].page); } pagenum = 0; if(one_file_per_page) { gfxresult_t*result = out->finish(out);out=0; char buf[1024]; sprintf(buf, outputname, pagenr); if(result->save(result, buf) < 0) { return 1; } result->destroy(result);result=0; out = create_output_device();; msg("<notice> Writing SWF file %s", buf); } delete xmax; delete ymax; } } if(one_file_per_page) { // remove empty device gfxresult_t*result = out->finish(out);out=0; result->destroy(result);result=0; } else { gfxresult_t*result = out->finish(out); msg("<notice> Writing SWF file %s", outputname); if(result->save(result, outputname) < 0) ret = 7; int width = (int)(ptroff_t)result->get(result, "width"); int height = (int)(ptroff_t)result->get(result, "height"); result->destroy(result);result=0; if(preloader && viewer && ret == 0) { #ifdef HAVE_MKSTEMP char tmpname[] = "__swf__XXXXXX"; int fileTmp = mkstemp(tmpname); close(fileTmp); #else char*tmpname = "__tmp__.swf"; #endif char buf[1024]; char buf2[1024];char buf3[1024];char buf4[1024];char buf5[50]; char buf6[50]; char buf7[50]; sprintf(buf,"viewport=%s", outputname); sprintf(buf2, "-o%s", tmpname); char *argvCombine[4] = {"swfcombine", viewer, buf, buf2 }; mainCombine(4, argvCombine); sprintf(buf, "%s/PreLoaderTemplate.swf", SWFDIR); sprintf(buf2, "loader=%s", preloader); sprintf(buf3, "movie=%s", tmpname); sprintf(buf4, "-o%s", outputname); sprintf(buf5, "-X %d", width); sprintf(buf6, "-Y %d", height); sprintf(buf7, "-r %f", getRate(preloader)); if(zlib) { char *argvCombine2[9] = {"swfcombine","-z", buf5, buf6, buf7, buf, buf2, buf3, buf4 }; ret = mainCombine(9, argvCombine2); } else { char *argvCombine2[8] = {"swfcombine", buf5, buf6, buf7, buf, buf2, buf3, buf4 }; ret = mainCombine(8, argvCombine2); } remove(tmpname); } } clean: pdf->destroy(pdf); driver->destroy(driver); SetEvent(exportParams->hExportSwfFinished); if(exportParams->m_ExportSwfFinishHandle !=0) exportParams->m_ExportSwfFinishHandle(); /* free global parameters */ p = device_config; while(p) { parameter_t*next = p->next; if(p->name) free((void*)p->name);p->name = 0; if(p->value) free((void*)p->value);p->value =0; p->next = 0; free(p); p = next; } device_config=0; if(filters) { free(filters); } filters=0; return ret; }
// // Main // int graphDiffMain(int argc, char** argv) { parseGraphDiffOptions(argc, argv); // Create BWTS std::string basePrefix = stripFilename(opt::baseFile); BWT* pBaseBWT = new BWT(basePrefix + BWT_EXT, opt::sampleRate); BWT* pBaseRevBWT = new BWT(basePrefix + RBWT_EXT, opt::sampleRate); std::string variantPrefix = stripFilename(opt::variantFile); BWT* pVariantBWT = new BWT(variantPrefix + BWT_EXT, opt::sampleRate); BWT* pVariantRevBWT = new BWT(variantPrefix + RBWT_EXT, opt::sampleRate); // Create the shared bit vector and shared results aggregator BitVector* pSharedBitVector = new BitVector(pVariantBWT->getBWLen()); GraphCompareAggregateResults* pSharedResults = new GraphCompareAggregateResults(opt::outFile); // Create interval caches to speed up k-mer lookups BWTIntervalCache varBWTCache(opt::cacheLength, pVariantBWT); BWTIntervalCache varRBWTCache(opt::cacheLength, pVariantRevBWT); BWTIntervalCache baseBWTCache(opt::cacheLength, pBaseBWT); BWTIntervalCache baseRBWTCache(opt::cacheLength, pBaseRevBWT); // Set the parameters shared between all threads GraphCompareParameters sharedParameters; sharedParameters.pVariantBWT = pVariantBWT; sharedParameters.pVariantRevBWT = pVariantRevBWT; sharedParameters.pBaseBWT = pBaseBWT; sharedParameters.pBaseRevBWT = pBaseRevBWT; sharedParameters.kmer = opt::kmer; sharedParameters.pBitVector = pSharedBitVector; sharedParameters.kmerThreshold = 3; sharedParameters.maxBranches = opt::maxBranches; sharedParameters.pVarBWTCache = &varBWTCache; sharedParameters.pVarRevBWTCache = &varRBWTCache; sharedParameters.pBaseBWTCache = &baseBWTCache; sharedParameters.pBaseRevBWTCache = &baseRBWTCache; if(opt::numThreads <= 1) { printf("[%s] starting serial-mode graph diff\n", PROGRAM_IDENT); GraphCompare graphCompare(sharedParameters); PROCESS_GDIFF_SERIAL(opt::variantFile, &graphCompare, pSharedResults); graphCompare.updateSharedStats(pSharedResults); } else { printf("[%s] starting parallel-mode graph diff with %d threads\n", PROGRAM_IDENT, opt::numThreads); std::vector<GraphCompare*> processorVector; for(int i = 0; i < opt::numThreads; ++i) { GraphCompare* pProcessor = new GraphCompare(sharedParameters); processorVector.push_back(pProcessor); } PROCESS_GDIFF_PARALLEL(opt::variantFile, processorVector, pSharedResults); for(size_t i = 0; i < processorVector.size(); ++i) { // Update the shared stats processorVector[i]->updateSharedStats(pSharedResults); delete processorVector[i]; processorVector[i] = NULL; } } pSharedResults->printStats(); // Cleanup delete pBaseBWT; delete pBaseRevBWT; delete pVariantBWT; delete pVariantRevBWT; delete pSharedBitVector; delete pSharedResults; if(opt::numThreads > 1) pthread_exit(NULL); return 0; }
// // Handle command line arguments // void parseFMWalkOptions(int argc, char** argv) { optind=1; //reset getopt std::string algo_str; bool die = false; for (char c; (c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1;) { std::istringstream arg(optarg != NULL ? optarg : ""); switch (c) { case 'p': arg >> opt::prefix; break; case 'o': arg >> opt::outFile; break; case 't': arg >> opt::numThreads; break; case 'a': arg >> algo_str; break; case 'k': arg >> opt::kmerLength; break; case 'x': arg >> opt::kmerThreshold; break; case '?': die = true; break; case 'v': opt::verbose++; break; case 'L': arg >> opt::maxLeaves; break; case 'I': arg >> opt::maxInsertSize; break; case 'm': arg >> opt::minOverlap; break; case 'M': arg >> opt::maxOverlap; break; case OPT_LEARN: opt::bLearnKmerParams = true; break; case OPT_HELP: std::cout << CORRECT_USAGE_MESSAGE; exit(EXIT_SUCCESS); case OPT_VERSION: std::cout << CORRECT_VERSION_MESSAGE; exit(EXIT_SUCCESS); } } if (argc - optind < 1) { std::cerr << SUBPROGRAM ": missing arguments\n"; die = true; } else if (argc - optind > 1) { std::cerr << SUBPROGRAM ": too many arguments\n"; die = true; } if(opt::numThreads <= 0) { std::cerr << SUBPROGRAM ": invalid number of threads: " << opt::numThreads << "\n"; die = true; } if(opt::kmerLength <= 0) { std::cerr << SUBPROGRAM ": invalid kmer length: " << opt::kmerLength << ", must be greater than zero\n"; die = true; } if(opt::kmerThreshold <= 0) { std::cerr << SUBPROGRAM ": invalid kmer threshold: " << opt::kmerThreshold << ", must be greater than zero\n"; die = true; } // Determine the correction algorithm to use if(!algo_str.empty()) { if(algo_str == "merge") opt::algorithm = FMW_MERGE; else if(algo_str == "hybrid") opt::algorithm = FMW_HYBRID; else { std::cerr << SUBPROGRAM << ": unrecognized -a,--algorithm parameter: " << algo_str << "\n"; die = true; } } if (die) { std::cout << "\n" << CORRECT_USAGE_MESSAGE; exit(EXIT_FAILURE); } // Parse the input filenames opt::readsFile = argv[optind++]; if(opt::prefix.empty()) { opt::prefix = stripFilename(opt::readsFile); } // Set the correction threshold if(opt::kmerThreshold <= 0) { std::cerr << "Invalid kmer support threshold: " << opt::kmerThreshold << "\n"; exit(EXIT_FAILURE); } CorrectionThresholds::Instance().setBaseMinSupport(opt::kmerThreshold); std::string out_prefix = stripFilename(opt::readsFile); if(opt::outFile.empty()) { if (opt::algorithm == FMW_HYBRID || opt::algorithm == FMW_MERGE ) opt::outFile = out_prefix + ".merge.fa"; else opt::outFile = out_prefix + ".origin.fa"; } if (opt::algorithm == FMW_KMERIZE || opt::algorithm == FMW_HYBRID) { opt::discardFile.clear(); opt::discardFile = out_prefix + ".kmerized.fa"; } }
// // Handle command line arguments // void parseIndexOptions(int argc, char** argv) { bool die = false; for (char c; (c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1;) { std::istringstream arg(optarg != NULL ? optarg : ""); switch (c) { case 'p': arg >> opt::prefix; break; case '?': die = true; break; case 'c': opt::validate = true; break; case 'd': opt::bDiskAlgo = true; arg >> opt::numReadsPerBatch; break; case 't': arg >> opt::numThreads; break; case 'g': arg >> opt::gapArrayStorage; break; case 'a': arg >> opt::algorithm; break; case 'v': opt::verbose++; break; case OPT_NO_REVERSE: opt::bBuildReverse = false; break; case OPT_NO_FWD: opt::bBuildForward = false; break; case OPT_NO_SAI: opt::bBuildSAI = false; break; case OPT_HELP: std::cout << INDEX_USAGE_MESSAGE; exit(EXIT_SUCCESS); case OPT_VERSION: std::cout << INDEX_VERSION_MESSAGE; exit(EXIT_SUCCESS); } } // Transform algorithm parameter to lower case std::transform(opt::algorithm.begin(), opt::algorithm.end(), opt::algorithm.begin(), ::tolower); if (argc - optind < 1) { std::cerr << SUBPROGRAM ": missing arguments\n"; die = true; } else if (argc - optind > 1) { std::cerr << SUBPROGRAM ": too many arguments\n"; die = true; } if(opt::gapArrayStorage != 4 && opt::gapArrayStorage != 8 && opt::gapArrayStorage != 16 && opt::gapArrayStorage != 32) { std::cerr << SUBPROGRAM ": invalid argument, --gap-array,-g must be one of 4,8,16,32 (found: " << opt::gapArrayStorage << ")\n"; die = true; } if(opt::numThreads <= 0) { std::cerr << SUBPROGRAM ": invalid number of threads: " << opt::numThreads << "\n"; die = true; } if(opt::algorithm != "sais" && opt::algorithm != "bcr" && opt::algorithm != "ropebwt") { std::cerr << SUBPROGRAM ": unrecognized algorithm string " << opt::algorithm << ". --algorithm must be sais, bcr or ropebwt\n"; die = true; } if(opt::algorithm == "ropebwt" && opt::bDiskAlgo) { std::cerr << SUBPROGRAM ": the options -a ropebwt and -d are not compatible, please only use one.\n"; die = true; } if (die) { std::cout << "\n" << INDEX_USAGE_MESSAGE; exit(EXIT_FAILURE); } // Parse the input filenames opt::readsFile = argv[optind++]; if(opt::prefix.empty()) opt::prefix = stripFilename(opt::readsFile); // Check if input file is empty size_t filesize = getFilesize(opt::readsFile); if(filesize == 0) { std::cerr << SUBPROGRAM ": input file is empty\n"; exit(EXIT_FAILURE); } }
// // Handle command line arguments // void parseStatsOptions(int argc, char** argv) { std::string algo_str; bool die = false; for (char c; (c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1;) { std::istringstream arg(optarg != NULL ? optarg : ""); switch (c) { case 'p': arg >> opt::prefix; break; case 't': arg >> opt::numThreads; break; case 'd': arg >> opt::sampleRate; break; case 'k': arg >> opt::kmerLength; break; case 'n': arg >> opt::numReads; break; case 'b': arg >> opt::branchCutoff; break; case '?': die = true; break; case 'v': opt::verbose++; break; case OPT_KMERDIST: opt::bPrintKmerDist = true; break; case OPT_RUNLENGTHS: opt::bPrintRunLengths = true; break; case OPT_NOOVERLAP: opt::bNoOverlap = true; break; case OPT_HELP: std::cout << STATS_USAGE_MESSAGE; exit(EXIT_SUCCESS); case OPT_VERSION: std::cout << STATS_VERSION_MESSAGE; exit(EXIT_SUCCESS); } } if (argc - optind < 1) { std::cerr << SUBPROGRAM ": missing arguments\n"; die = true; } else if (argc - optind > 1) { std::cerr << SUBPROGRAM ": too many arguments\n"; die = true; } if(opt::numThreads <= 0) { std::cerr << SUBPROGRAM ": invalid number of threads: " << opt::numThreads << "\n"; die = true; } if(opt::kmerLength <= 0) { std::cerr << SUBPROGRAM ": invalid kmer length: " << opt::kmerLength << ", must be greater than zero\n"; die = true; } if (die) { std::cout << "\n" << STATS_USAGE_MESSAGE; exit(EXIT_FAILURE); } // Parse the input filenames opt::readsFile = argv[optind++]; if(opt::prefix.empty()) { opt::prefix = stripFilename(opt::readsFile); } }
// // Handle command line arguments // void parseOverlapLongOptions(int argc, char** argv) { bool die = false; for (char c; (c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1;) { std::istringstream arg(optarg != NULL ? optarg : ""); switch (c) { case 'm': arg >> opt::minOverlap; break; case 'o': arg >> opt::outFile; break; case 'e': arg >> opt::errorRate; break; case 't': arg >> opt::numThreads; break; case 'l': arg >> opt::seedLength; break; case 's': arg >> opt::seedStride; break; case 'd': arg >> opt::sampleRate; break; case 'f': arg >> opt::targetFile; break; case OPT_EXACT: opt::bExactIrreducible = true; break; case 'x': opt::bIrreducibleOnly = false; break; case '?': die = true; break; case 'v': opt::verbose++; break; case OPT_HELP: std::cout << OVERLAP_LONG_USAGE_MESSAGE; exit(EXIT_SUCCESS); case OPT_VERSION: std::cout << OVERLAP_LONG_VERSION_MESSAGE; exit(EXIT_SUCCESS); } } if (argc - optind < 1) { std::cerr << SUBPROGRAM ": missing arguments\n"; die = true; } else if (argc - optind > 1) { std::cerr << SUBPROGRAM ": too many arguments\n"; die = true; } if(opt::numThreads <= 0) { std::cerr << SUBPROGRAM ": invalid number of threads: " << opt::numThreads << "\n"; die = true; } if(!IS_POWER_OF_2(opt::sampleRate)) { std::cerr << SUBPROGRAM ": invalid parameter to -d/--sample-rate, must be power of 2. got: " << opt::sampleRate << "\n"; die = true; } if (die) { std::cout << "\n" << OVERLAP_LONG_USAGE_MESSAGE; exit(EXIT_FAILURE); } // Validate parameters if(opt::errorRate <= 0) opt::errorRate = 0.0f; if(opt::seedLength < 0) opt::seedLength = 0; if(opt::seedLength > 0 && opt::seedStride <= 0) opt::seedStride = opt::seedLength; // Parse the input filenames opt::readsFile = argv[optind++]; if(opt::outFile.empty()) { std::string prefix = stripFilename(opt::readsFile); if(!opt::targetFile.empty()) { prefix.append(1,'.'); prefix.append(stripFilename(opt::targetFile)); } opt::outFile = prefix + ASQG_EXT + GZIP_EXT; } }
// // Main // int overlapLongMain(int argc, char** argv) { parseOverlapLongOptions(argc, argv); // Open output file std::ostream* pASQGWriter = createWriter(opt::outFile); // Build and write the ASQG header ASQG::HeaderRecord headerRecord; headerRecord.setOverlapTag(opt::minOverlap); headerRecord.setErrorRateTag(opt::errorRate); headerRecord.setInputFileTag(opt::readsFile); headerRecord.setTransitiveTag(true); headerRecord.write(*pASQGWriter); // Determine which index files to use. If a target file was provided, // use the index of the target reads std::string indexPrefix; if(!opt::targetFile.empty()) indexPrefix = stripFilename(opt::targetFile); else indexPrefix = stripFilename(opt::readsFile); BWT* pBWT = new BWT(indexPrefix + BWT_EXT, opt::sampleRate); SampledSuffixArray* pSSA = new SampledSuffixArray(indexPrefix + SAI_EXT, SSA_FT_SAI); Timer* pTimer = new Timer(PROGRAM_IDENT); pBWT->printInfo(); // Read the sequence file and write vertex records for each // Also store the read names in a vector of strings ReadTable reads; SeqReader* pReader = new SeqReader(opt::readsFile, SRF_NO_VALIDATION); SeqRecord record; while(pReader->get(record)) { reads.addRead(record.toSeqItem()); ASQG::VertexRecord vr(record.id, record.seq.toString()); vr.write(*pASQGWriter); if(reads.getCount() % 100000 == 0) printf("Read %zu sequences\n", reads.getCount()); } delete pReader; pReader = NULL; BWTIndexSet index; index.pBWT = pBWT; index.pSSA = pSSA; index.pReadTable = &reads; // Make a prefix for the temporary hits files size_t n_reads = reads.getCount(); omp_set_num_threads(opt::numThreads); #pragma omp parallel for for(size_t read_idx = 0; read_idx < n_reads; ++read_idx) { const SeqItem& curr_read = reads.getRead(read_idx); printf("read %s %zubp\n", curr_read.id.c_str(), curr_read.seq.length()); SequenceOverlapPairVector sopv = KmerOverlaps::retrieveMatches(curr_read.seq.toString(), opt::seedLength, opt::minOverlap, 1 - opt::errorRate, 100, index); printf("Found %zu matches\n", sopv.size()); for(size_t i = 0; i < sopv.size(); ++i) { std::string match_id = reads.getRead(sopv[i].match_idx).id; // We only want to output each edge once so skip this overlap // if the matched read has a lexicographically lower ID if(curr_read.id > match_id) continue; std::string ao = ascii_overlap(sopv[i].sequence[0], sopv[i].sequence[1], sopv[i].overlap, 50); printf("\t%s\t[%d %d] ID=%s OL=%d PI:%.2lf C=%s\n", ao.c_str(), sopv[i].overlap.match[0].start, sopv[i].overlap.match[0].end, match_id.c_str(), sopv[i].overlap.getOverlapLength(), sopv[i].overlap.getPercentIdentity(), sopv[i].overlap.cigar.c_str()); // Convert to ASQG SeqCoord sc1(sopv[i].overlap.match[0].start, sopv[i].overlap.match[0].end, sopv[i].overlap.length[0]); SeqCoord sc2(sopv[i].overlap.match[1].start, sopv[i].overlap.match[1].end, sopv[i].overlap.length[1]); // KmerOverlaps returns the coordinates of the overlap after flipping the reads // to ensure the strand matches. The ASQG file wants the coordinate of the original // sequencing strand. Flip here if necessary if(sopv[i].is_reversed) sc2.flip(); // Convert the SequenceOverlap the ASQG's overlap format Overlap ovr(curr_read.id, sc1, match_id, sc2, sopv[i].is_reversed, -1); ASQG::EdgeRecord er(ovr); er.setCigarTag(sopv[i].overlap.cigar); er.setPercentIdentityTag(sopv[i].overlap.getPercentIdentity()); #pragma omp critical { er.write(*pASQGWriter); } } } // Cleanup delete pReader; delete pBWT; delete pSSA; delete pASQGWriter; delete pTimer; if(opt::numThreads > 1) pthread_exit(NULL); return 0; }
// // Main // int filterMain(int argc, char** argv) { parseFilterOptions(argc, argv); Timer* pTimer = new Timer(PROGRAM_IDENT); BWT* pBWT = new BWT(opt::prefix + BWT_EXT, opt::sampleRate); BWT* pRBWT = new BWT(opt::prefix + RBWT_EXT, opt::sampleRate); pBWT->printInfo(); std::ostream* pWriter = createWriter(opt::outFile); std::ostream* pDiscardWriter = createWriter(opt::discardFile); QCPostProcess* pPostProcessor = new QCPostProcess(pWriter, pDiscardWriter); // If performing duplicate check, create a bitvector to record // which reads are duplicates BitVector* pSharedBV = NULL; if(opt::dupCheck) pSharedBV = new BitVector(pBWT->getNumStrings()); // Set up QC parameters QCParameters params; params.pBWT = pBWT; params.pRevBWT = pRBWT; params.pSharedBV = pSharedBV; params.checkDuplicates = opt::dupCheck; params.substringOnly = opt::substringOnly; params.checkKmer = opt::kmerCheck; params.kmerBothStrand = opt::kmerBothStrand; params.checkHPRuns = opt::hpCheck; params.checkDegenerate = opt::lowComplexityCheck; params.verbose = opt::verbose; params.kmerLength = opt::kmerLength; params.kmerThreshold = opt::kmerThreshold; params.hpKmerLength = 51; params.hpHardAcceptCount = 10; params.hpMinProportion = 0.1f; params.hpMinLength = 6; if(opt::numThreads <= 1) { // Serial mode QCProcess processor(params); PROCESS_FILTER_SERIAL(opt::readsFile, &processor, pPostProcessor); } else { // Parallel mode std::vector<QCProcess*> processorVector; for(int i = 0; i < opt::numThreads; ++i) { QCProcess* pProcessor = new QCProcess(params); processorVector.push_back(pProcessor); } PROCESS_FILTER_PARALLEL(opt::readsFile, processorVector, pPostProcessor); for(int i = 0; i < opt::numThreads; ++i) delete processorVector[i]; } delete pPostProcessor; delete pWriter; delete pDiscardWriter; delete pBWT; delete pRBWT; if(pSharedBV != NULL) delete pSharedBV; // Rebuild the FM-index without the discarded reads std::string out_prefix = stripFilename(opt::outFile); removeReadsFromIndices(opt::prefix, opt::discardFile, out_prefix, BWT_EXT, SAI_EXT, false, opt::numThreads); removeReadsFromIndices(opt::prefix, opt::discardFile, out_prefix, RBWT_EXT, RSAI_EXT, true, opt::numThreads); // Cleanup delete pTimer; if(opt::numThreads > 1) pthread_exit(NULL); return 0; }
int main(int argn, char *argv[]) { processargs(argn, argv); initLog(0,-1,0,0,-1,loglevel); if(!filename) { fprintf(stderr, "Please specify an input file\n"); exit(1); } if(!outputname) { if(filename) { outputname = stripFilename(filename, ".out"); msg("<notice> Output filename not given. Writing to %s", outputname); } } if(!outputname) { fprintf(stderr, "Please use -o to specify an output file\n"); exit(1); } is_in_range(0x7fffffff, pagerange); if(pagerange) driver->setparameter(driver, "pages", pagerange); if(!filename) { args_callback_usage(argv[0]); exit(0); } gfxdocument_t* doc = driver->open(driver, filename); if(!doc) { msg("<error> Couldn't open %s", filename); exit(1); } if(!format) { char*x = strrchr(outputname, '.'); if(x) format = x+1; } gfxresult_t*result = 0; #ifdef HAVE_LRF if(!strcasecmp(format, "lrf")) { gfxdevice_t lrf; gfxdevice_lrf_init(&lrf); gfxdevice_t rescale; gfxdevice_rescale_init(&rescale, &lrf, 592, 732, 0); gfxdevice_t*out = &rescale; out->setparameter(out, "keepratio", "1"); out->setparameter(out, "pagepattern", outputname); gfxdevice_t bbox2,*bbox=&bbox2; gfxdevice_bbox_init(bbox); bbox->setparameter(bbox, "graphics", "0"); int pagenr; for(pagenr = 1; pagenr <= doc->num_pages; pagenr++) { if(is_in_range(pagenr, pagerange)) { gfxpage_t* page = doc->getpage(doc, pagenr); bbox->startpage(bbox,-1,-1); page->render(page, bbox); gfxbbox_t b = gfxdevice_bbox_getbbox(bbox); out->startpage(out, b.xmax-b.xmin, b.ymax-b.ymin); page->rendersection(page, out, -b.xmin, -b.ymin, 0,0,b.xmax-b.xmin,b.ymax-b.ymin); out->endpage(out); page->destroy(page); } } result = out->finish(out); } else #endif { gfxdevice_t _out,*out=&_out; if(!strcasecmp(format, "ocr")) { gfxdevice_ocr_init(out); } else if(!strcasecmp(format, "swf")) { gfxdevice_swf_init(out); } else if(!strcasecmp(format, "img") || !strcasecmp(format, "png")) { gfxdevice_render_init(out); out->setparameter(out, "antialize", "4"); } else if(!strcasecmp(format, "txt")) { gfxdevice_text_init(out); } else if(!strcasecmp(format, "log")) { gfxdevice_file_init(out, "/tmp/device.log"); } else if(!strcasecmp(format, "pdf")) { gfxdevice_pdf_init(out); } else { msg("<error> Invalid output format: %s", format); exit(1); } int pagenr; for(pagenr = 1; pagenr <= doc->num_pages; pagenr++) { if(is_in_range(pagenr, pagerange)) { gfxpage_t* page = doc->getpage(doc, pagenr); out->startpage(out, page->width, page->height); page->render(page, out); out->endpage(out); page->destroy(page); } } result = out->finish(out); } if(result) { if(result->save(result, outputname) < 0) { exit(1); } result->destroy(result); } doc->destroy(doc); driver->destroy(driver); return 0; }
// // Main // int overlapMain(int argc, char** argv) { parseOverlapOptions(argc, argv); // Prepare the output ASQG file assert(opt::outputType == OT_ASQG); // Open output file std::ostream* pASQGWriter = createWriter(opt::outFile); // Build and write the ASQG header ASQG::HeaderRecord headerRecord; headerRecord.setOverlapTag(opt::minOverlap); headerRecord.setErrorRateTag(opt::errorRate); headerRecord.setInputFileTag(opt::readsFile); headerRecord.setContainmentTag(true); // containments are always present headerRecord.setTransitiveTag(!opt::bIrreducibleOnly); headerRecord.write(*pASQGWriter); // Compute the overlap hits StringVector hitsFilenames; // Determine which index files to use. If a target file was provided, // use the index of the target reads std::string indexPrefix; if(!opt::prefix.empty()) indexPrefix = opt::prefix; else { if(!opt::targetFile.empty()) indexPrefix = stripFilename(opt::targetFile); else indexPrefix = stripFilename(opt::readsFile); } BWT* pBWT = new BWT(indexPrefix + BWT_EXT, opt::sampleRate); BWT* pRBWT = new BWT(indexPrefix + RBWT_EXT, opt::sampleRate); OverlapAlgorithm* pOverlapper = new OverlapAlgorithm(pBWT, pRBWT, opt::errorRate, opt::seedLength, opt::seedStride, opt::bIrreducibleOnly); pOverlapper->setExactModeOverlap(opt::errorRate <= 0.0001); pOverlapper->setExactModeIrreducible(opt::errorRate <= 0.0001); Timer* pTimer = new Timer(PROGRAM_IDENT); pBWT->printInfo(); // Make a prefix for the temporary hits files std::string outPrefix; outPrefix = stripFilename(opt::readsFile); if(!opt::targetFile.empty()) { outPrefix.append(1, '.'); outPrefix.append(stripFilename(opt::targetFile)); } if(opt::numThreads <= 1) { printf("[%s] starting serial-mode overlap computation\n", PROGRAM_IDENT); computeHitsSerial(outPrefix, opt::readsFile, pOverlapper, opt::minOverlap, hitsFilenames, pASQGWriter); } else { printf("[%s] starting parallel-mode overlap computation with %d threads\n", PROGRAM_IDENT, opt::numThreads); computeHitsParallel(opt::numThreads, outPrefix, opt::readsFile, pOverlapper, opt::minOverlap, hitsFilenames, pASQGWriter); } // Get the number of strings in the BWT, this is used to pre-allocated the read table delete pOverlapper; delete pBWT; delete pRBWT; // Parse the hits files and write the overlaps to the ASQG file convertHitsToASQG(indexPrefix, hitsFilenames, pASQGWriter); // Cleanup delete pASQGWriter; delete pTimer; if(opt::numThreads > 1) pthread_exit(NULL); return 0; }
// // Handle command line arguments // void parsePacBioCorrectionOptions(int argc, char** argv) { optind=1; //reset getopt std::string algo_str; bool die = false; for (char c; (c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1;) { std::istringstream arg(optarg != NULL ? optarg : ""); switch (c) { case 'p': arg >> opt::prefix; break; case 'o': arg >> opt::outFile; break; case 't': arg >> opt::numThreads; break; case 'a': arg >> algo_str; break; case 'k': arg >> opt::kmerLength; break; case 'x': arg >> opt::kmerThreshold; break; case '?': die = true; break; case 'v': opt::verbose++; break; case 'L': arg >> opt::maxLeaves; break; case 'm': arg >> opt::minOverlap; break; case 'M': arg >> opt::maxOverlap; break; case 's': arg >> opt::minKmerLength; break; case 'y': arg >> opt::seedKmerThreshold; break; case 'd': arg >> opt::numOfNextTarget; break; case 'c': arg >> opt::collect; break; case OPT_SPLIT: opt::split = true; break; case OPT_FIRST: opt::isFirst = true; break; case OPT_HELP: std::cout << CORRECT_USAGE_MESSAGE; exit(EXIT_SUCCESS); case OPT_VERSION: std::cout << CORRECT_VERSION_MESSAGE; exit(EXIT_SUCCESS); } } if (argc - optind < 1) { std::cerr << SUBPROGRAM ": missing arguments\n"; die = true; } else if (argc - optind > 1) { std::cerr << SUBPROGRAM ": too many arguments\n"; die = true; } if(opt::numThreads <= 0) { std::cerr << SUBPROGRAM ": invalid number of threads: " << opt::numThreads << "\n"; die = true; } if(opt::kmerLength <= 0) { std::cerr << SUBPROGRAM ": invalid kmer length: " << opt::kmerLength << ", must be greater than zero\n"; die = true; } if(opt::kmerThreshold <= 0) { std::cerr << SUBPROGRAM ": invalid kmer threshold: " << opt::kmerThreshold << ", must be greater than zero\n"; die = true; } // Determine the correction algorithm to use if(!algo_str.empty()) { if(algo_str == "pacbioS") opt::algorithm = PBC_SELF; else if(algo_str == "pacbioH") opt::algorithm = PBC_HYBRID; else { std::cerr << SUBPROGRAM << ": unrecognized -a,--algorithm parameter: " << algo_str << "\n"; die = true; } } if (die) { std::cout << "\n" << CORRECT_USAGE_MESSAGE; exit(EXIT_FAILURE); } // Parse the input filenames opt::readsFile = argv[optind++]; if(opt::prefix.empty()) { opt::prefix = stripFilename(opt::readsFile); } // Set the correction threshold if(opt::kmerThreshold <= 0) { std::cerr << "Invalid kmer support threshold: " << opt::kmerThreshold << "\n"; exit(EXIT_FAILURE); } CorrectionThresholds::Instance().setBaseMinSupport(opt::kmerThreshold); std::string out_prefix = stripFilename(opt::readsFile); if(opt::outFile.empty()) { if (opt::algorithm == PBC_SELF) opt::outFile = out_prefix + ".PBSelfCor.fa"; else if (opt::algorithm == PBC_HYBRID) opt::outFile = out_prefix + ".PBHybridCor.fa"; else assert(false); } opt::discardFile = out_prefix + ".discard.fa"; }
// // Handle command line arguments // void parseFilterOptions(int argc, char** argv) { optind=1; std::string algo_str; bool die = false; for (char c; (c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1;) { std::istringstream arg(optarg != NULL ? optarg : ""); switch (c) { case 'p': arg >> opt::prefix; break; case 'o': arg >> opt::outFile; break; case 't': arg >> opt::numThreads; break; case 'd': arg >> opt::sampleRate; break; case 'k': arg >> opt::kmerLength; break; case 'x': arg >> opt::kmerThreshold; break; case OPT_NO_RMDUP: opt::dupCheck = false; break; case OPT_NO_KMER: opt::kmerCheck = false; break; case OPT_CHECK_HPRUNS: opt::hpCheck = true; break; case OPT_CHECK_COMPLEXITY: opt::lowComplexityCheck = true; break; case OPT_SUBSTRING_ONLY: opt::substringOnly = true; break; case '?': die = true; break; case 'v': opt::verbose++; break; case OPT_HELP: std::cout << FILTER_USAGE_MESSAGE; exit(EXIT_SUCCESS); case OPT_VERSION: std::cout << FILTER_VERSION_MESSAGE; exit(EXIT_SUCCESS); } } if (argc - optind < 1) { std::cerr << SUBPROGRAM ": missing arguments\n"; die = true; } else if (argc - optind > 1) { std::cerr << SUBPROGRAM ": too many arguments\n"; die = true; } if(opt::numThreads <= 0) { std::cerr << SUBPROGRAM ": invalid number of threads: " << opt::numThreads << "\n"; die = true; } if(opt::kmerLength <= 0) { std::cerr << SUBPROGRAM ": invalid kmer length: " << opt::kmerLength << ", must be greater than zero\n"; die = true; } if(opt::kmerThreshold <= 0) { std::cerr << SUBPROGRAM ": invalid kmer threshold: " << opt::kmerThreshold << ", must be greater than zero\n"; die = true; } if (die) { std::cout << "\n" << FILTER_USAGE_MESSAGE; exit(EXIT_FAILURE); } // Parse the input filenames opt::readsFile = argv[optind++]; if(opt::prefix.empty()) { opt::prefix = stripFilename(opt::readsFile); } if(opt::outFile.empty()) { opt::outFile = opt::prefix + ".filter.pass.fa"; opt::discardFile = opt::prefix + ".discard.fa"; } else { opt::discardFile = stripFilename(opt::outFile) + ".discard.fa"; } }
int main(int argn, char *argv[]) { int ret; char buf[256]; int numfonts = 0; int t; char t1searchpath[1024]; int nup_pos = 0; int x,y; int one_file_per_page = 0; initLog(0,-1,0,0,-1,loglevel); /* not needed anymore since fonts are embedded if(installPath) { fontpaths[fontpathpos++] = concatPaths(installPath, "fonts"); }*/ #ifdef HAVE_SRAND48 srand48(time(0)*getpid()); #else #ifdef HAVE_SRAND srand(time(0)*getpid()); #endif #endif processargs(argn, argv); driver = gfxsource_pdf_create(); /* pass global parameters to PDF driver*/ parameter_t*p = device_config; while(p) { driver->setparameter(driver, p->name, p->value); p = p->next; } if(!filename) { fprintf(stderr, "Please specify an input file\n"); exit(1); } if (!info_only) { if(!outputname) { if(filename) { outputname = stripFilename(filename, ".swf"); msg("<notice> Output filename not given. Writing to %s", outputname); } } if(!outputname) { fprintf(stderr, "Please use -o to specify an output file\n"); exit(1); } } // test if the page range is o.k. is_in_range(0x7fffffff, pagerange); if (!filename) { args_callback_usage(argv[0]); exit(0); } char fullname[256]; if(password && *password) { sprintf(fullname, "%s|%s", filename, password); filename = fullname; } if(pagerange) driver->setparameter(driver, "pages", pagerange); /* add fonts */ for(t=0;t<fontpathpos;t++) { driver->setparameter(driver, "fontdir", fontpaths[t]); } if(info_only) { show_info(driver, filename); return 0; } char*u = 0; if((u = strchr(outputname, '%'))) { if(strchr(u+1, '%') || strchr(outputname, '%')!=u) { msg("<error> only one %% allowed in filename\n"); return 1; } if(preloader || viewer) { msg("<error> -b/-l/-B/-L not supported together with %% in filename\n"); return 1; } msg("<notice> outputting one file per page"); one_file_per_page = 1; char*pattern = (char*)malloc(strlen(outputname)+2); /* convert % to %d */ int l = u-outputname+1; memcpy(pattern, outputname, l); pattern[l]='d'; strcpy(pattern+l+1, outputname+l); outputname = pattern; } gfxdocument_t* pdf = driver->open(driver, filename); if(!pdf) { msg("<error> Couldn't open %s", filename); exit(1); } /* pass global parameters document */ p = device_config; while(p) { pdf->setparameter(pdf, p->name, p->value); p = p->next; } struct mypage_t { int x; int y; gfxpage_t*page; } pages[4]; int pagenum = 0; int frame = 1; int pagenr; for(pagenr = 1; pagenr <= pdf->num_pages; pagenr++) { if(is_in_range(pagenr, pagerange)) { char mapping[80]; sprintf(mapping, "%d:%d", pagenr, frame); pdf->setparameter(pdf, "pagemap", mapping); pagenum++; } if(pagenum == xnup*ynup || (pagenr == pdf->num_pages && pagenum>1)) { pagenum = 0; frame++; } } if(pagerange && !pagenum && frame==1) { fprintf(stderr, "No pages in range %s", pagerange); exit(1); } pagenum = 0; gfxdevice_t*out = create_output_device();; pdf->prepare(pdf, out); for(pagenr = 1; pagenr <= pdf->num_pages; pagenr++) { if(is_in_range(pagenr, pagerange)) { gfxpage_t* page = pages[pagenum].page = pdf->getpage(pdf, pagenr); pages[pagenum].x = 0; pages[pagenum].y = 0; pages[pagenum].page = page; pagenum++; } if(pagenum == xnup*ynup || (pagenr == pdf->num_pages && pagenum>1)) { int t; int xmax[xnup], ymax[xnup]; int x,y; int width=0, height=0; memset(xmax, 0, xnup*sizeof(int)); memset(ymax, 0, ynup*sizeof(int)); for(y=0;y<ynup;y++) for(x=0;x<xnup;x++) { int t = y*xnup + x; if(pages[t].page->width > xmax[x]) xmax[x] = (int)pages[t].page->width; if(pages[t].page->height > ymax[y]) ymax[y] = (int)pages[t].page->height; } for(x=0;x<xnup;x++) { width += xmax[x]; xmax[x] = width; } for(y=0;y<ynup;y++) { height += ymax[y]; ymax[y] = height; } if(custom_clip) { out->startpage(out,clip_x2 - clip_x1, clip_y2 - clip_y1); } else { out->startpage(out,width,height); } for(t=0;t<pagenum;t++) { int x = t%xnup; int y = t/xnup; int xpos = x>0?xmax[x-1]:0; int ypos = y>0?ymax[y-1]:0; msg("<verbose> Render (%d,%d) move:%d/%d\n", (int)(pages[t].page->width + xpos), (int)(pages[t].page->height + ypos), xpos, ypos); pages[t].page->rendersection(pages[t].page, out, custom_move? move_x : xpos, custom_move? move_y : ypos, custom_clip? clip_x1 : 0 + xpos, custom_clip? clip_y1 : 0 + ypos, custom_clip? clip_x2 : pages[t].page->width + xpos, custom_clip? clip_y2 : pages[t].page->height + ypos); } out->endpage(out); for(t=0;t<pagenum;t++) { pages[t].page->destroy(pages[t].page); } pagenum = 0; if(one_file_per_page) { gfxresult_t*result = out->finish(out);out=0; char buf[1024]; sprintf(buf, outputname, pagenr); if(result->save(result, buf) < 0) { return 1; } result->destroy(result);result=0; out = create_output_device();; pdf->prepare(pdf, out); msg("<notice> Writing SWF file %s", buf); } } } if(one_file_per_page) { // remove empty device gfxresult_t*result = out->finish(out);out=0; result->destroy(result);result=0; } else { gfxresult_t*result = out->finish(out); msg("<notice> Writing SWF file %s", outputname); if(result->save(result, outputname) < 0) { exit(1); } int width = (int)(ptroff_t)result->get(result, "width"); int height = (int)(ptroff_t)result->get(result, "height"); result->destroy(result);result=0; if(preloader || viewer) { const char*zip = ""; if(zlib) { zip = "-z"; } if(!preloader && viewer) { systemf("swfcombine %s -X %d -Y %d \"%s\" viewport=\"%s\" -o \"%s\"",zip,width,height, viewer, outputname, outputname); if(!system_quiet) printf("\n"); } if(preloader && !viewer) { msg("<warning> --preloader option without --viewer option doesn't make very much sense."); ret = systemf("swfcombine %s -Y %d -X %d %s/PreLoaderTemplate.swf loader=\"%s\" movie=\"%s\" -o \"%s\"",zip,width,height, SWFDIR, preloader, outputname, outputname); if(!system_quiet) printf("\n"); } if(preloader && viewer) { #ifdef HAVE_MKSTEMP char tmpname[] = "__swf__XXXXXX"; mkstemp(tmpname); #else char*tmpname = "__tmp__.swf"; #endif systemf("swfcombine \"%s\" viewport=%s -o %s", viewer, outputname, tmpname); systemf("swfcombine %s -X %d -Y %d -r %f %s/PreLoaderTemplate.swf loader=%s movie=%s -o \"%s\"",zip,width,height, getRate(preloader), SWFDIR, preloader, tmpname, outputname); systemf("rm %s", tmpname); } } } pdf->destroy(pdf); driver->destroy(driver); /* free global parameters */ p = device_config; while(p) { parameter_t*next = p->next; if(p->name) free((void*)p->name);p->name = 0; if(p->value) free((void*)p->value);p->value =0; p->next = 0;free(p); p = next; } if(filters) { free(filters); } return 0; }
int main (int argc,char ** argv) { char buf[512]; char*currentdir = getcwd(buf, 512); if(!currentdir) { as3_warning("Could not determine the current directory"); } else { as3_add_include_dir(currentdir); } int t; processargs(argc, argv); as3_setverbosity(verbose); if(!filename) { args_callback_usage(argv[0]); exit(1); } if(!outputname) { outputname = stripFilename(filename, ".swf"); //as3_warning("output name not given, writing to %s", outputname); } if(!strcmp(filename, ".")) { as3_parse_directory("."); } else { as3_parse_file(filename); } void*code = as3_getcode(); SWF swf; memset(&swf, 0, sizeof(swf)); swf.fileVersion = flashversion; swf.frameRate = framerate*0x100; swf.movieSize.xmin = 0; swf.movieSize.ymin = 0; swf.movieSize.xmax = width*20; swf.movieSize.ymax = height*20; TAG*tag = swf.firstTag = swf_InsertTag(0, ST_DOABC); swf_WriteABC(tag, code); if(!mainclass) mainclass = as3_getglobalclass(); if(mainclass) { tag = swf_InsertTag(tag, ST_SYMBOLCLASS); swf_SetU16(tag, 1); swf_SetU16(tag, 0); swf_SetString(tag, mainclass); } else { as3_warning("no global public MovieClip subclass"); } as3_destroy(); tag = swf_InsertTag(tag, ST_SHOWFRAME); tag = swf_InsertTag(tag, ST_END); swf_FreeABC(code); if(local_with_filesystem) swf.fileAttributes &= ~FILEATTRIBUTE_USENETWORK; if(local_with_networking) swf.fileAttributes |= FILEATTRIBUTE_USENETWORK; writeSWF(&swf); swf_FreeTags(&swf); return 0; }
// // Handle command line arguments // void parseIndexOptions(int argc, char** argv) { bool die = false; for (char c; (c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1;) { std::istringstream arg(optarg != NULL ? optarg : ""); switch (c) { case 'p': arg >> opt::prefix; break; case '?': die = true; break; case 'c': opt::validate = true; break; case 'd': opt::bDiskAlgo = true; arg >> opt::numReadsPerBatch; break; case 't': arg >> opt::numThreads; break; case 'g': arg >> opt::gapArrayStorage; break; case 'v': opt::verbose++; break; case OPT_NO_REVERSE: opt::bBuildReverse = false; break; case OPT_HELP: std::cout << INDEX_USAGE_MESSAGE; exit(EXIT_SUCCESS); case OPT_VERSION: std::cout << INDEX_VERSION_MESSAGE; exit(EXIT_SUCCESS); } } if (argc - optind < 1) { std::cerr << SUBPROGRAM ": missing arguments\n"; die = true; } else if (argc - optind > 1) { std::cerr << SUBPROGRAM ": too many arguments\n"; die = true; } if(opt::gapArrayStorage != 4 && opt::gapArrayStorage != 8 && opt::gapArrayStorage != 16 && opt::gapArrayStorage != 32) { std::cerr << SUBPROGRAM ": invalid argument, --gap-array,-g must be one of 4,8,16,32 (found: " << opt::gapArrayStorage << ")\n"; die = true; } if(opt::numThreads <= 0) { std::cerr << SUBPROGRAM ": invalid number of threads: " << opt::numThreads << "\n"; die = true; } if (die) { std::cerr << "Try `" << SUBPROGRAM << " --help' for more information.\n"; exit(EXIT_FAILURE); } // Parse the input filenames opt::readsFile = argv[optind++]; if(opt::prefix.empty()) { opt::prefix = stripFilename(opt::readsFile); } }
// // Handle command line arguments // void parseCorrectOptions(int argc, char** argv) { std::string algo_str; bool bDiscardReads = false; bool die = false; for (char c; (c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1;) { std::istringstream arg(optarg != NULL ? optarg : ""); switch (c) { case 'm': arg >> opt::minOverlap; break; case 'p': arg >> opt::prefix; break; case 'o': arg >> opt::outFile; break; case 'e': arg >> opt::errorRate; break; case 't': arg >> opt::numThreads; break; case 'l': arg >> opt::seedLength; break; case 's': arg >> opt::seedStride; break; case 'r': arg >> opt::numOverlapRounds; break; case 'a': arg >> algo_str; break; case 'd': arg >> opt::sampleRate; break; case 'c': arg >> opt::conflictCutoff; break; case 'k': arg >> opt::kmerLength; break; case 'x': arg >> opt::kmerThreshold; break; case '?': die = true; break; case 'v': opt::verbose++; break; case 'b': arg >> opt::branchCutoff; break; case 'i': arg >> opt::numKmerRounds; break; case OPT_LEARN: opt::bLearnKmerParams = true; break; case OPT_DISCARD: bDiscardReads = true; break; case OPT_METRICS: arg >> opt::metricsFile; break; case OPT_HELP: std::cout << CORRECT_USAGE_MESSAGE; exit(EXIT_SUCCESS); case OPT_VERSION: std::cout << CORRECT_VERSION_MESSAGE; exit(EXIT_SUCCESS); } } if (argc - optind < 1) { std::cerr << SUBPROGRAM ": missing arguments\n"; die = true; } else if (argc - optind > 1) { std::cerr << SUBPROGRAM ": too many arguments\n"; die = true; } if(opt::numThreads <= 0) { std::cerr << SUBPROGRAM ": invalid number of threads: " << opt::numThreads << "\n"; die = true; } if(opt::numOverlapRounds <= 0) { std::cerr << SUBPROGRAM ": invalid number of overlap rounds: " << opt::numOverlapRounds << ", must be at least 1\n"; die = true; } if(opt::numKmerRounds <= 0) { std::cerr << SUBPROGRAM ": invalid number of kmer rounds: " << opt::numKmerRounds << ", must be at least 1\n"; die = true; } if(opt::kmerLength <= 0) { std::cerr << SUBPROGRAM ": invalid kmer length: " << opt::kmerLength << ", must be greater than zero\n"; die = true; } if(opt::kmerThreshold <= 0) { std::cerr << SUBPROGRAM ": invalid kmer threshold: " << opt::kmerThreshold << ", must be greater than zero\n"; die = true; } // Determine the correction algorithm to use if(!algo_str.empty()) { if(algo_str == "hybrid") opt::algorithm = ECA_HYBRID; else if(algo_str == "kmer") opt::algorithm = ECA_KMER; else if(algo_str == "overlap") opt::algorithm = ECA_OVERLAP; else { std::cerr << SUBPROGRAM << ": unrecognized -a,--algorithm parameter: " << algo_str << "\n"; die = true; } } if (die) { std::cout << "\n" << CORRECT_USAGE_MESSAGE; exit(EXIT_FAILURE); } // Validate parameters if(opt::errorRate <= 0) opt::errorRate = 0.0f; if(opt::errorRate > 1.0f) { std::cerr << "Invalid error-rate parameter: " << opt::errorRate << "\n"; exit(EXIT_FAILURE); } if(opt::seedLength < 0) opt::seedLength = 0; if(opt::seedLength > 0 && opt::seedStride <= 0) opt::seedStride = opt::seedLength; // Parse the input filenames opt::readsFile = argv[optind++]; if(opt::prefix.empty()) { opt::prefix = stripFilename(opt::readsFile); } // Set the correction threshold if(opt::kmerThreshold <= 0) { std::cerr << "Invalid kmer support threshold: " << opt::kmerThreshold << "\n"; exit(EXIT_FAILURE); } CorrectionThresholds::Instance().setBaseMinSupport(opt::kmerThreshold); std::string out_prefix = stripFilename(opt::readsFile); if(opt::outFile.empty()) { opt::outFile = out_prefix + ".ec.fa"; } if(bDiscardReads) { opt::discardFile = out_prefix + ".discard.fa"; } else { opt::discardFile.clear(); } }