Class: Bio::FinishM::PathCounter
- Inherits:
-
Object
- Object
- Bio::FinishM::PathCounter
- Includes:
- Logging
- Defined in:
- lib/finishm/path_counter.rb
Instance Method Summary collapse
- #add_options(optparse_object, options) ⇒ Object
- #count_paths_through_graph(finishm_graph, initial_onodes, options = {}) ⇒ Object
- #get_leash_start_nodes(finishm_graph, nodes_within_leash) ⇒ Object
- #run(options, argv) ⇒ Object
- #validate_options(options, argv) ⇒ Object
Methods included from Logging
Instance Method Details
#add_options(optparse_object, options) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/finishm/path_counter.rb', line 4 def (optparse_object, ) .merge! Bio::FinishM::Visualise::DEFAULT_OPTIONS optparse_object. = "\nUsage: finishm count_paths --assembly-??? Count paths through assembly graph \n\n" optparse_object.separator "Input genome information" optparse_object.separator "\nIf an assembly is to be done, there must be some definition of reads:\n\n" #TODO improve this help Bio::FinishM::ReadInput.new.(optparse_object, ) optparse_object.separator "\nOptional graph-exploration arguments:\n\n" Bio::FinishM::Visualise.new.(optparse_object, ) optparse_object.separator "\nOptional graph-related arguments:\n\n" Bio::FinishM::GraphGenerator.new.(optparse_object, ) end |
#count_paths_through_graph(finishm_graph, initial_onodes, options = {}) ⇒ Object
81 82 83 84 85 86 87 88 89 |
# File 'lib/finishm/path_counter.rb', line 81 def count_paths_through_graph(finishm_graph, initial_onodes, ={}) height_finder = Bio::AssemblyGraphAlgorithms::HeightFinder.new by_height, = height_finder.traverse(finishm_graph.graph, initial_onodes, ) min_paths_through = height_finder.min_paths_through(by_height) max_paths_through = height_finder.max_paths_through(by_height) puts "Minimum number of distinct sequences to explain graph, assuming no errors: #{min_paths_through}." puts "Maximum number of distinct sequences allowed by graph: #{max_paths_through}." end |
#get_leash_start_nodes(finishm_graph, nodes_within_leash) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/finishm/path_counter.rb', line 67 def get_leash_start_nodes(finishm_graph, nodes_within_leash) log.info "Finding nodes from which to begin search.." start_onodes, = Bio::AssemblyGraphAlgorithms::HeightFinder.new.find_oriented_edge_of_range(finishm_graph.graph, nodes_within_leash) if start_onodes.empty? #possible with a completely cyclic graph, choose any node to begin onode = Bio::Velvet::Graph::OrientedNodeTrail::OrientedNode finishm_graph.graph.nodes[1], true start_onodes = [onode] log.info "Graph appears to be a self-contained loop, so chose an arbitrary node" else log.info "Found #{start_onodes.length} nodes" end return start_onodes end |
#run(options, argv) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/finishm/path_counter.rb', line 31 def run(, argv) read_input = Bio::FinishM::ReadInput.new read_input. visualise = Bio::FinishM::Visualise.new if [:interesting_probes] or [:interesting_probe_names] finishm_graph, interesting_node_ids, = visualise.generate_graph_from_probes(read_input, ) if [:probe_to_node_map] # Output probe map if asked visualise.write_probe_to_node_map([:probe_to_node_map], finishm_graph, [:interesting_probes]) end elsif [:interesting_nodes] finishm_graph = visualise.generate_graph_from_nodes(read_input, ) interesting_nodes = [:interesting_nodes] elsif [:assembly_files] finishm_graph, interesting_node_ids, = visualise.generate_graph_from_assembly(read_input, ) else finishm_graph = Bio::FinishM::GraphGenerator.new.generate_graph([], read_input, ) end if [:graph_search_leash_length] # get a list of the nodes to be visualised given the leash length nodes_within_leash, node_ids_at_leash = visualise.get_nodes_within_leash(finishm_graph, interesting_node_ids, ) log.info "Found #{node_ids_at_leash.length} nodes at the end of the #{[:graph_search_leash_length] }bp leash" else nodes_within_leash = finishm_graph.graph.nodes end initial_onodes = get_leash_start_nodes(finishm_graph, nodes_within_leash) log.info "Counting paths through assembly graph.." count_paths_through_graph(finishm_graph, initial_onodes, :range => nodes_within_leash ) end |
#validate_options(options, argv) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/finishm/path_counter.rb', line 22 def (, argv) #TODO: give a better description of the error that has occurred #TODO: require reads options visualise = Bio::FinishM::Visualise.new return visualise.validate_argv_length(argv) || visualise.() || visualise.() end |