void parseArgs(int argc, char **argv) { try { TCLAP::CmdLine cmd("PBI consensus module", ' ', "0.3"); TCLAP::ValueArg<int> threadArg( "j","threads", // short, long name "Number of consensus threads", // description false, 4, // required, default "int", cmd); TCLAP::ValueArg<unsigned int> minCovArg( "c","min-coverage", "Minimum coverage for correction", false, 6, "uint", cmd); TCLAP::ValueArg<unsigned int> minLenArg( "l","min-len", "Minimum length for correction", false, 500, "uint", cmd); TCLAP::ValueArg<unsigned int> trimArg( "t","trim", "Trim alignments on either size", false, 10, "uint", cmd); TCLAP::ValueArg<std::string> alnFileArg( "a","align-file", "Path to the alignments file", true,"","string", cmd); TCLAP::ValueArg<std::string> seqFileArg( "s","seq-file", "Path to the sequences file", true,"","string", cmd); TCLAP::ValueArg<unsigned int> maxHitArg( "m","max-hit", "Maximum number of hits to pass to consensus", false,85,"uint", cmd); TCLAP::SwitchArg sortCovArg("x","coverage-sort", "Sort hits by coverage", cmd, false); TCLAP::SwitchArg properOvlArg("o","only-proper-overlaps", "Use only 'proper overlaps', i.e., align to the ends", cmd, false); TCLAP::SwitchArg verboseArg("v","verbose", "Turns on verbose logging", cmd, false); TCLAP::UnlabeledMultiArg<int> targetArgs( "targets", "Limit consensus to list of target ids", false, "list of ints", cmd); cmd.parse(argc, argv); popts.minCov = minCovArg.getValue(); popts.minLen = minLenArg.getValue(); popts.trim = trimArg.getValue(); popts.alnFile = alnFileArg.getValue(); popts.seqFile = seqFileArg.getValue(); popts.threads = threadArg.getValue(); popts.maxHits = maxHitArg.getValue(); popts.sortCov = sortCovArg.getValue(); popts.properOvls = properOvlArg.getValue(); std::vector<int> tgs = targetArgs.getValue(); popts.targets.insert(tgs.begin(), tgs.end()); } catch (TCLAP::ArgException& e) { std::cerr << "Error " << e.argId() << ": " << e.error() << std::endl; exit(1); } }
int main(int argc, char *argv[]) { // Command-line parsing ------------------------------------------------------ std::string inputFile; std::string outputFile; std::vector<std::string> models; try { TCLAP::CmdLine cmd("Decomposes the contours of the input PNG image into " "a set of DLL segments wrt. to the given DLL models.", ' ', "1.0"); TCLAP::UnlabeledValueArg<std::string> inputArg( "input", "The input PNG image.", true, "", "file" ); TCLAP::SwitchArg verboseArg( "v", "verbose", "Prints the DLL segments' inequations on the " "terminal's standard output.", false ); TCLAP::SwitchArg bgArg( "b", "black-background", "Specify that the image has a very dark background.", false ); TCLAP::MultiArg<std::string> dllArg( "d", "dll-model", "The underlying DLL model used for the decomposition.", false, "StraightLine | Circle | Conic" ); cmd.add(inputArg); cmd.add(verboseArg); cmd.add(bgArg); cmd.add(dllArg); cmd.parse(argc, argv); inputFile = inputArg.getValue(); verbose = verboseArg.getValue(); blackBackground = bgArg.getValue(); models = dllArg.getValue(); } catch (TCLAP::ArgException & e) { std::cerr << "Error: " << e.error() << " for arg " << e.argId() << std::endl; exit(EXIT_FAILURE); } // End of command-line parsing ----------------------------------------------- outputFile = "out_"; size_t startPos = inputFile.find_last_of("/\\"); if (startPos == std::string::npos) outputFile += inputFile; else outputFile += inputFile.substr(startPos + 1); png::image<png::gray_pixel> image(inputFile); // Binarization Utils::otsuThresholding(image); if (!blackBackground) Utils::binaryImageToNegative(image); // Contours extraction typedef Utils::BoundariesExtractor::Curve Curve; typedef Utils::BoundariesExtractor::Coordinates Coord; Utils::BoundariesExtractor be; std::vector<Curve> contours = be.extractBoundaries(image); png::image<png::rgb_pixel> output(image.get_width(), image.get_height()); if (models.empty()) { models.push_back("StraightLine"); models.push_back("Circle"); models.push_back("Conic"); } // Decompose into DLLs and save the result for (size_t i = 0; i < models.size(); ++i) { if (!blackBackground) Utils::fillImage(output, png::rgb_pixel(255,255,255)); if (models[i] == "StraightLine") { fillImageWithDecompostion<DLL::StraightLine>(contours, output); output.write("StraightLine_" + outputFile); } else if (models[i] == "Circle") { fillImageWithDecompostion<DLL::Circle>(contours, output); output.write("Circle_" + outputFile); } else if (models[i] == "Conic") { fillImageWithDecompostion<DLL::Conic>(contours, output); output.write("Conic_" + outputFile); } else std::cerr << "Unknown " << models[i] << " DLL model" << std::endl; } return EXIT_SUCCESS; }