From bf4c30a98771495ed1ff8f27e81d7b33036242a8 Mon Sep 17 00:00:00 2001 From: leggettr Date: Wed, 20 Apr 2016 15:35:52 +0100 Subject: [PATCH] Added multiple subgraph contigs option. --- include/cortex/cmd_line.h | 3 ++- include/cortex/metagraphs.h | 2 +- src/cortex/cmd_line.c | 8 ++++++-- src/cortex/metacortex.c | 4 ++-- src/cortex/metagraphs.c | 24 +++++++++++++----------- 5 files changed, 24 insertions(+), 17 deletions(-) diff --git a/include/cortex/cmd_line.h b/include/cortex/cmd_line.h index 8b59baa..f6b9edd 100755 --- a/include/cortex/cmd_line.h +++ b/include/cortex/cmd_line.h @@ -81,7 +81,8 @@ typedef struct boolean graphviz; boolean print_uncertain_as_n; boolean output_log; - boolean output_kmer_coverage_know ; + boolean output_kmer_coverage_know; + boolean multiple_subgraph_contigs; //----------- //parameters diff --git a/include/cortex/metagraphs.h b/include/cortex/metagraphs.h index a8b0714..d382884 100644 --- a/include/cortex/metagraphs.h +++ b/include/cortex/metagraphs.h @@ -48,4 +48,4 @@ typedef struct { */ //int grow_graph_from_node(dBNode* start_node, dBNode** best_node, dBGraph* graph, Queue* graph_queue); -void metacortex_find_subgraphs(dBGraph* graph, char* consensus_contigs_filename, int min_subgraph_kmers, int min_contig_length); +void metacortex_find_subgraphs(dBGraph* graph, char* consensus_contigs_filename, int min_subgraph_kmers, int min_contig_length, boolean multiple_subgraph_contigs); diff --git a/src/cortex/cmd_line.c b/src/cortex/cmd_line.c index d514f90..a9d255a 100644 --- a/src/cortex/cmd_line.c +++ b/src/cortex/cmd_line.c @@ -94,6 +94,7 @@ int default_opts(CmdLine * c) c->low_coverage_node_clip = false; c->remove_low_coverage_supernodes = false; c->remove_spurious_links = false; + c->multiple_subgraph_contigs = false; //output c->dump_binary = false; @@ -190,6 +191,7 @@ CmdLine parse_cmdline(int argc, char *argv[], int unit_size) {"input_reference", required_argument, NULL, 'H'}, {"output_kmer_coverage", required_argument, NULL, 'J'}, {"remove_spurious_links",required_argument,NULL,'L'}, + {"multiple_subgraph_contigs",no_argument,NULL,'M'}, {"hash_output_file", required_argument, NULL, 'O'}, {"tip_clip_iterations", required_argument, NULL, 'P'}, {"graph_stats", no_argument, NULL, 'S'}, @@ -198,7 +200,7 @@ CmdLine parse_cmdline(int argc, char *argv[], int unit_size) }; while ((opt = getopt_long(argc, argv, - "ab:c:d:ef:g:hi:jk:l:m:n:o:p:q:s:t:uvw:x:z:A:B:C:D:E:FG:H:I:J:K:L:N:O:P:STZ:", + "ab:c:d:ef:g:hi:jk:l:m:n:o:p:q:s:t:uvw:x:z:A:B:C:D:E:FG:H:I:J:K:L:MN:O:P:STZ:", long_options, &longopt_index)) > 0) { //Parse the default options @@ -501,10 +503,12 @@ CmdLine parse_cmdline(int argc, char *argv[], int unit_size) } } break; + case 'M': + cmd_line.multiple_subgraph_contigs = true; + break; case 'N': cmd_line.print_uncertain_as_n = false; break; - case 'O': cmd_line.dump_hash = true; if (strlen(optarg) < LENGTH_FILENAME) { diff --git a/src/cortex/metacortex.c b/src/cortex/metacortex.c index 0f1b81a..f7feae9 100755 --- a/src/cortex/metacortex.c +++ b/src/cortex/metacortex.c @@ -456,7 +456,7 @@ int main(int argc, char **argv) break; case METACORTEX_CONSENSUS: log_and_screen_printf("\nDumping subgraph consensus contigs: %s\n", cmd_line.output_fasta_filename); - metacortex_find_subgraphs(db_graph, cmd_line.output_fasta_filename, cmd_line.min_subgraph_size, cmd_line.min_contig_length); + metacortex_find_subgraphs(db_graph, cmd_line.output_fasta_filename, cmd_line.min_subgraph_size, cmd_line.min_contig_length, cmd_line.multiple_subgraph_contigs); break; case GRAPH_STATS: @@ -470,7 +470,7 @@ int main(int argc, char **argv) //db_graph_walk_branches(cmd_line.output_fasta_filename, total_max_length, db_graph->kmer_size * 10 + 1, bubble_max_depth, db_graph); //db_graph_walk_branches(char *filename, int total_max_length, int bubble_max_length, int bubble_max_depth, dBGraph * db_graph) - //metacortex_find_subgraphs(db_graph, cmd_line.output_fasta_filename, cmd_line.min_subgraph_size, cmd_line.min_contig_length); + //metacortex_find_subgraphs(db_graph, cmd_line.output_fasta_filename, cmd_line.min_subgraph_size, cmd_line.min_contig_length, cmd_line.multiple_subgraph_contigs); break; default: log_and_screen_printf("Algorithm not implemented \n"); diff --git a/src/cortex/metagraphs.c b/src/cortex/metagraphs.c index 393cd99..fe753d0 100755 --- a/src/cortex/metagraphs.c +++ b/src/cortex/metagraphs.c @@ -172,7 +172,7 @@ int grow_graph_from_node(dBNode* start_node, dBNode** best_node, dBGraph* graph, return current_graph_size; } -void metacortex_find_subgraphs(dBGraph* graph, char* consensus_contigs_filename, int min_subgraph_kmers, int min_contig_length) +void metacortex_find_subgraphs(dBGraph* graph, char* consensus_contigs_filename, int min_subgraph_kmers, int min_contig_length, boolean multiple_subgraph_contigs) { FILE* fp_analysis; FILE* fp_contigs; @@ -260,17 +260,19 @@ void metacortex_find_subgraphs(dBGraph* graph, char* consensus_contigs_filename, } else { log_printf("Didn't write path of size %d\n", final_path->length); } + + if (multiple_subgraph_contigs) { + /* Now clear visited flags for subgraph */ + while (graph_queue->number_of_items > 0) { + queue_node = (dBNode*)queue_pop(graph_queue); + db_node_action_unset_flag(queue_node, VISITED); + } - /* Now clear visited flags for subgraph */ - while (graph_queue->number_of_items > 0) { - queue_node = (dBNode*)queue_pop(graph_queue); - db_node_action_unset_flag(queue_node, VISITED); - } - - /* Now disconnect path from other nodes and mark path as visited, so it's not visited again */ - for (pi=0; pilength; pi++) { - cleaning_prune_db_node(final_path->nodes[pi], graph); - db_node_action_set_flag(final_path->nodes[pi], VISITED); + /* Now disconnect path from other nodes and mark path as visited, so it's not visited again */ + for (pi=0; pilength; pi++) { + cleaning_prune_db_node(final_path->nodes[pi], graph); + db_node_action_set_flag(final_path->nodes[pi], VISITED); + } } /* Reset paths */