Guest User

Untitled

a guest
Sep 19th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.73 KB | None | 0 0
  1. include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <seqan3/argument_parser/argument_parser.hpp>
  5. #include <seqan3/io/sequence_file/input.hpp>
  6. #include <seqan3/io/stream/debug_stream.hpp>
  7. #include <seqan3/search/all.hpp>
  8. #include <seqan3/range/all.hpp>
  9. #include <seqan3/range/view/convert.hpp>
  10. #include <seqan3/range/view/get.hpp>
  11. #include <range/v3/action/slice.hpp>
  12.  
  13. using namespace std;
  14. using namespace seqan3;
  15. using namespace seqan3::search_cfg;
  16.  
  17. int main(int argc, const char** argv) {
  18. argument_parser parser("simple_read_mapper", argc, argv);
  19. string genomeFName;
  20. string readsFName;
  21. string outFName;
  22. int maxError = 42;
  23. parser.add_option(maxError, 'm', "max_error", "Maximum error tolerance");
  24. parser.add_positional_option(genomeFName, "Genome filename");
  25. parser.add_positional_option(readsFName, "Reads filename");
  26. parser.add_positional_option(outFName, "Output filename");
  27. try {
  28. parser.parse();
  29. } catch (parser_invalid_argument const& e) {
  30. cerr << "You provided an invalid argument: " << e.what() << endl;
  31. return 1;
  32. } catch (parser_interruption const& e) {
  33. cerr << "I see you have interrupted the parser. Be careful!" << endl;
  34. return 0; // SeqAn has already printed --help output or whatever
  35. }
  36. cout << "The maximum error tolerance is " << maxError << endl;
  37.  
  38. // Read in the input files
  39. sequence_file_input genomeFile { genomeFName, fields<field::SEQ>{} };
  40. vector<dna5> genomeSeq = get<field::SEQ>(*begin(genomeFile));
  41. debug_stream << "First 10 characters of the genome are <" << view::take(genomeSeq, 10) << '>' << '\n';
  42.  
  43. // Build an index on the genome
  44. seqan3::detail::configuration indexCfg = max_error(total { maxError }, substitution { maxError }, insertion { maxError }, deletion { maxError }) | mode(best);
  45. fm_index index(genomeSeq);
  46.  
  47. sequence_file_input readsFile { readsFName, fields<field::SEQ_QUAL>{} };
  48. for (auto& rec : readsFile) {
  49. vector<dna5q> x = get<field::SEQ_QUAL>(rec);
  50. debug_stream << "First read sequence: <" << x << ">\n";
  51. vector<dna5> y = (x | view::convert<dna5>); // (1)
  52. //auto y = (x | view::convert<dna5>); // (2)
  53. auto results = search(index, y, indexCfg);
  54. for (size_t position: results)
  55. {
  56. debug_stream << "FROM THE GENOME: " << (genomeSeq | ::ranges::view::slice(position, position + x.size() + maxError)) << '\n';
  57. }
  58. debug_stream << results << '\n';
  59. }
  60.  
  61. return 0;
  62. }
Add Comment
Please, Sign In to add comment