int main(int argc, char const ** argv) { ArgumentParser parser("arg_parse_demo"); setShortDescription(parser, "Just a demo of the new seqan::ArgumentParser!"); setVersion(parser, "0.1"); setDate(parser, "Mar 2012"); addUsageLine(parser, "[\\fIOPTIONS\\fP] \\fIIN\\fP \\fIOUT\\fP "); addDescription(parser, "This is just a little demo to show what seqan::ArgumentParser is able to do."); addDescription(parser, "\\fIIN\\fP is a multi-FASTA input."); addDescription(parser, "\\fIOUT\\fP is a txt output."); addArgument(parser, ArgParseArgument(ArgParseArgument::INPUTFILE, "IN")); addArgument(parser, ArgParseArgument(ArgParseArgument::OUTPUTFILE, "OUT")); // allow only fasta files as input setValidValues(parser, 0, "FASTA fa"); setValidValues(parser, 1, "txt"); addSection(parser, "Important Tool Parameters"); addOption(parser, ArgParseOption("", "id", "Sequence identity between [0.0:1.0]", ArgParseArgument::DOUBLE, "ID")); setRequired(parser, "id", true); setMinValue(parser, "id", "0.0"); setMaxValue(parser, "id", "1.0"); addSection(parser, "Miscellaneous"); addOption(parser, ArgParseOption("v", "verbose", "Turn on verbose output.")); addOption(parser, ArgParseOption("H", "hidden", "Super mysterious flag that will not be shown in the help screen or man-page.")); hideOption(parser, "H"); addTextSection(parser, "References"); addText(parser, "http://www.seqan.de"); ArgumentParser::ParseResult res = parse(parser, argc, argv); if (res == ArgumentParser::PARSE_OK) { bool verbose = false; getOptionValue(verbose, parser, "verbose"); std::cout << "Verbose: " << (verbose ? "on" : "off") << std::endl; double identity = -1.0; getOptionValue(identity, parser, "id"); std::cout << "Identity: " << identity << std::endl; CharString inputFile, outputFile; getArgumentValue(inputFile, parser, 0); getArgumentValue(outputFile, parser, 1); std::cout << "Input-File: " << inputFile << std::endl; std::cout << "Output-File: " << outputFile << std::endl; return 0; } else { return res == ArgumentParser::PARSE_ERROR; // 1 on errors, 0 otherwise } }
int half_sw_banded(const Ts1 &s1, const Ts2 &s2, int match, int mismatch, int indel, const Tf &lizard_tail, int max_indels = 6) { using std::min; using std::max; using seqan::length; using std::vector; const int INF = 1005000; if (max_indels == 0) { return half_hamming(s1, s2, match, mismatch, lizard_tail); } int len1 = length(s1), len2 = length(s2); // Cache lengths because of length(s) computation maybe not O(1) e.g. for char*-strings vector<int> base(2*max_indels + 1, -INF); for (int i2 = max(0, len1 - max_indels); i2 <= min(len1 + max_indels, len2); ++i2) { int ind = i2 + max_indels - len1; base[ind] = lizard_tail(len2 - i2); } vector<int> new_base(2*max_indels + 1, -INF); for (int i1 = len1 - 1; i1 >= 0; --i1) { for (int i2 = i1 + max_indels; i2 >= i1 - max_indels; --i2) { int inx = max_indels + i2 - i1; if ((i2 < 0) || (i2 > len2)) { new_base[inx] = -INF; } else if (i2 == len2) { new_base[inx] = lizard_tail(len1 - i1); } else { int m = (s1[i1] == s2[i2]) ? match : mismatch; if (inx == 0) new_base[inx] = max( { m + base[inx], indel + new_base[inx + 1]} ); else if (inx == 2*max_indels) new_base[inx] = max( { m + base[inx], indel + base[inx - 1] } ); else new_base[inx] = max( { m + base[inx], indel + base[inx - 1], indel + new_base[inx + 1]} ); } } std::swap(base, new_base); } return max(-INF, base[max_indels]); // Score is always finite due to possibility to align using mismatches }
int half_hamming(const Ts1 &s1, const Ts2 &s2, int match, int mismatch, const Tf &lizard_tail) { int len1 = length(s1), len2 = length(s2); // Cache lengths because of length(s) computation maybe not O(1) e.g. for char*-strings size_t len = std::min<size_t>(len1, len2); size_t res = 0; for (size_t i = 0; i < len; ++i) { res += (s1[i] == s2[i]) ? match : mismatch; } res += lizard_tail(std::abs(len1 - len2)); return res; }
void add(const T &s, size_t id, const Tf &toIndex) { if (!root) { root.reset(new TrieNode); } typename TrieNode::pointer_type p = this->root.get(); for (size_t i = 0; i < length(s); ++i) { size_t el = toIndex(s[i]); assert((0 <= el) && (el < p->children.size())); if (!p->children[el]) { p->children[el] = new TrieNode(); } p = p->children[el]; } if (!p->ids) { p->ids = new std::vector<size_t>; } p->ids->push_back(id); }
int main(int argc, char const ** argv) { // Initialize ArgumentParser. ArgumentParser parser("arg_parse_demo"); setCategory(parser, "Demo"); setShortDescription(parser, "Just a demo of the new seqan::ArgumentParser!"); setVersion(parser, "0.1"); setDate(parser, "Mar 2012"); // Add use and description lines. addUsageLine(parser, "[\\fIOPTIONS\\fP] \\fIIN\\fP \\fIOUT\\fP "); addDescription( parser, "This is just a little demo to show what seqan::ArgumentParser is " "able to do. \\fIIN\\fP is a multi-FASTA input file. \\fIOUT\\fP is a " "txt output file."); // Add positional arguments and set their valid file types. addArgument(parser, ArgParseArgument(ArgParseArgument::INPUTFILE, "IN")); addArgument(parser, ArgParseArgument(ArgParseArgument::OUTPUTFILE, "OUT")); setValidValues(parser, 0, "FASTA fa"); setValidValues(parser, 1, "txt"); // Add a section with some options. addSection(parser, "Important Tool Parameters"); addOption(parser, ArgParseOption("", "id", "Sequence identity between [0.0:1.0]", ArgParseArgument::DOUBLE, "ID")); setRequired(parser, "id", true); setMinValue(parser, "id", "0.0"); setMaxValue(parser, "id", "1.0"); // Adding a verbose and a hidden option. addSection(parser, "Miscellaneous"); addOption(parser, ArgParseOption("v", "verbose", "Turn on verbose output.")); addOption(parser, ArgParseOption("H", "hidden", "Super mysterious flag that will not be shown in " "the help screen or man page.")); hideOption(parser, "H"); // Add a Reference section. addTextSection(parser, "References"); addText(parser, "http://www.seqan.de"); // Parse the arguments. ArgumentParser::ParseResult res = parse(parser, argc, argv); // Return if there was an error or a built-in command was triggered (e.g. help). if (res != ArgumentParser::PARSE_OK) return res == ArgumentParser::PARSE_ERROR; // 1 on errors, 0 otherwise // Extract and print the options. bool verbose = false; getOptionValue(verbose, parser, "verbose"); std::cout << "Verbose: " << (verbose ? "on" : "off") << std::endl; double identity = -1.0; getOptionValue(identity, parser, "id"); std::cout << "Identity: " << identity << std::endl; CharString inputFile, outputFile; getArgumentValue(inputFile, parser, 0); getArgumentValue(outputFile, parser, 1); std::cout << "Input-File: " << inputFile << std::endl; std::cout << "Output-File: " << outputFile << std::endl; return 0; }