static pathStep *get_next_step(pathStep * current_step, pathStep * next_step, pathStep * reverse_step, dBGraph * db_graph) { pathStep *step = db_graph_get_next_step(current_step, next_step, reverse_step, db_graph); assert(step != NULL); step->label = Undefined; Nucleotide n; // TODO: If this works, then there's possibly a bug to fix for the multi-colour situation if (next_step->node == NULL) { next_step->label = Undefined; return next_step; } if (db_node_has_precisely_one_edge_all_colours(next_step->node, next_step->orientation, &n)) { next_step->label = n; } if (!db_node_has_precisely_one_edge_all_colours(next_step->node, opposite_orientation(next_step->orientation), &n)) { next_step->label = Undefined; } return next_step; }
int perfect_path_get_path_with_callback_with_args(dBNode * node, Orientation orientation, void (*node_action) (dBNode * , void *), void * node_args, void (*path_action) (Path * , void *), void * path_args,dBGraph * db_graph) { WalkingFunctions wf; perfect_path_get_funtions(&wf); pathStep first; first.node = node; //first.orientation = orientation == undefined? reverse: orientation; first.orientation = orientation; first.label = Undefined; if (orientation != undefined) { db_node_has_precisely_one_edge_all_colours(node, orientation, &first.label); wf.get_starting_step = &get_first_step_identity; } //wf.find_first_node = &find_first; db_graph_add_node_action_with_args (&wf, node_action, node_args); db_graph_add_path_callback_with_args (&wf, path_action, path_args); Path *path = path_get_buffer_path(); int ret = db_graph_generic_walk(&first, path, &wf, db_graph); path_free_buffer_path(path); return ret; }
static pathStep *get_next_step(pathStep * current_step, pathStep * next_step, pathStep * reverse_step, dBGraph * db_graph) { pathStep *step = db_graph_get_next_step(current_step, next_step, reverse_step, db_graph); assert(step != NULL); if (step->node != NULL) { step->label = Undefined; Nucleotide n; if (db_node_has_precisely_one_edge_all_colours (next_step->node, next_step->orientation, &n)) { next_step->label = n; }else{ next_step->label = path_step_get_unvisited_edge_all_colours(next_step); } } return next_step; }
static pathStep *get_first_step(pathStep * first_step, dBGraph * db_graph) { //printf("|"); WalkingFunctions wf; pathStep tmp_step; Nucleotide n; path_step_assign(&tmp_step, first_step); if(tmp_step.orientation == undefined){ tmp_step.orientation = reverse; //This will allow, when reversing the walk, to walk in the forward direction, which "naturally" appends the bases to the end of the path. }else{ return first_step; } /* Check if forward node has one edge, if not that reverse node does. While we're at it, assign label to n. */ if (db_node_has_precisely_one_edge_all_colours(tmp_step.node, tmp_step.orientation, &n)) { } else if (db_node_has_precisely_one_edge_all_colours(tmp_step.node, opposite_orientation(tmp_step.orientation), &n)) { tmp_step.orientation = opposite_orientation(tmp_step.orientation); } else { return NULL; } tmp_step.label = n; /* If it's a blunt node in the opposite orientation, then we can't get a better starting step */ if (db_node_is_blunt_end_all_colours(first_step->node, opposite_orientation(tmp_step.orientation))) { path_step_assign(first_step, &tmp_step); return first_step; } //printf("#"); /* Otherwise, do a perfect path walk to try and get a better start step */ //Path * temp_path = path_new(limit, db_graph->kmer_size); Path *temp_path = path_get_buffer_path(); temp_path->id = -2; db_node_has_precisely_one_edge_all_colours(tmp_step.node, tmp_step.orientation, &tmp_step.label); wf.get_starting_step = &get_first_step_identity; wf.continue_backwards = &clean_path; wf.post_step_action = &path_step_do_nothing; wf.pre_step_action = &path_step_do_nothing; wf.step_action = &path_step_do_nothing; wf.continue_traversing = &continue_traversing; wf.get_next_step = &get_next_step; wf.output_callback = &path_do_nothing; wf.node_callbacks.used = 0; wf.step_actions.used = 0; wf.path_callbacks.used = 0 ; db_graph_add_path_callback_with_args(&wf, &store_last, (void *) first_step); if (DEBUG) { printf("[get_first_step]Orientation: %s\n", tmp_step.orientation == forward ? "forward" : "reverse"); printf("[get_first_step] (%d):", path_get_edges_count(temp_path)); path_step_print(first_step, db_graph->kmer_size, stdout); printf("\n"); } db_graph_generic_walk(&tmp_step, temp_path, &wf, db_graph); path_free_buffer_path(temp_path); return first_step; }