Ejemplo n.º 1
0
void perfect_path_base_callback(Path * p)
{
	pathStep p1, p2;
	path_get_last_step(&p1, p);
	path_get_step_at_index(0, &p2, p);
	
	//Remove the repeated node in a cycle
	if (path_is_cycle(p)) {
		
		if (path_step_equals
		    (&p1,
		     &p2)) {
				p1.label = Undefined;
				path_remove_last(p);
				path_add_node(&p1, p);
			}
	}
	
	int n_fwd = db_node_edges_count_all_colours(p2.node, p2.orientation);
    int n_rev = db_node_edges_count_all_colours(p2.node, opposite_orientation(p2.orientation));
    
    int n_fwd_f = db_node_edges_count_all_colours(p1.node, p1.orientation);
    int n_rev_f = db_node_edges_count_all_colours(p1.node, opposite_orientation(p1.orientation));
    
        
    if (n_fwd == 0) {
        path_add_stop_reason(FIRST, PATH_FLAG_STOP_BLUNT_END, p);
    }
    if (n_fwd > 1) {
        path_add_stop_reason(FIRST, PATH_FLAG_DIVERGING_PATHS, p);
    }
    
    if (n_rev > 1) {
        path_add_stop_reason(FIRST, PATH_FLAG_CONVERGING_PATHS, p);
    }
        
	if(n_rev  > 1 && n_fwd_f > 1 ){
		path_add_stop_reason(FIRST, PATH_FLAG_IS_DOUBLE_Y,p);
	}
    
    if(n_rev_f > 1){
        path_add_stop_reason(LAST, PATH_FLAG_CONVERGING_PATHS, p);
    }
    
    if(n_fwd_f > 1){
        path_add_stop_reason(LAST, PATH_FLAG_DIVERGING_PATHS, p);
    }
	
	
}
Ejemplo n.º 2
0
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;
}
Ejemplo n.º 3
0
static boolean continue_traversing(pathStep * current_step,
                                   pathStep * next_step,
                                   pathStep * reverse_step, Path * temp_path,
                                   dBGraph * db_graph)
{
	pathStep first;
	
	boolean cont;
    cont = current_step->label != Undefined;
    //cont = cont && db_node_has_precisely_one_edge_all_colours(current_step->node, current_step->orientation, &n);
    path_get_step_at_index(0, &first, temp_path);
    int n_fwd, n_rev;
    /* We don't do these checks for the first node - in case it's a Y node */
    if(temp_path->length > 1) {
        if (db_node_check_for_any_flag(next_step->node, next_step->orientation == forward? VISITED_FORWARD:VISITED_REVERSE)) {
            cont = false;
        }
        
        /* Check for a cycle - as this is a perfect path, we only need to check the first node. If we come
           back in at one of the other nodes, then it will result in two edges in one orientation */
        
        if (path_step_equals_without_label(&first, current_step)) {
            path_add_stop_reason(LAST, PATH_FLAG_IS_CYCLE, temp_path);
            cont = false;
        }
        /* Now check for more than one edge in either direction */
        n_fwd = db_node_edges_count_all_colours(current_step->node, current_step->orientation);
        n_rev = db_node_edges_count_all_colours(current_step->node, opposite_orientation(current_step->orientation));
        
        if (n_fwd == 0) {
            path_add_stop_reason(LAST, PATH_FLAG_STOP_BLUNT_END, temp_path);
            cont = false;
        }
        if (n_fwd > 1) {
            path_add_stop_reason(LAST, PATH_FLAG_DIVERGING_PATHS, temp_path);
            cont = false;
        }
        if (n_rev > 1) {
            path_add_stop_reason(LAST, PATH_FLAG_CONVERGING_PATHS, temp_path);
            cont = false;
        }
        if (!path_has_space(temp_path)) {
            path_add_stop_reason(LAST, PATH_FLAG_LONGER_THAN_BUFFER, temp_path);
            cont = false;
        }      
    }
                                                  
    
    
	return cont;
}
Ejemplo n.º 4
0
static boolean continue_traversing(pathStep * current_step,
								   pathStep * next_step,
								   pathStep * reverse_step, Path * temp_path,
								   dBGraph * db_graph)
{
	pathStep first;
	
	boolean cont = true;
    cont = current_step->label != Undefined;
    //cont = cont && db_node_has_precisely_one_edge(current_step->node, current_step->orientation, &n);
    path_get_step_at_index(0, &first, temp_path);
    int n_fwd, n_rev;
    /* We don't do these checks for the first node - in case it's a Y node */
    if(temp_path->length > 1) {
        if (db_node_check_for_any_flag(next_step->node, next_step->orientation == forward? VISITED_FORWARD:VISITED_REVERSE)) {
            cont = false;
        }
        
        if (path_step_equals_without_label(&first, current_step) || path_has_in_step(next_step, temp_path)) {
            path_add_stop_reason(LAST, PATH_FLAG_IS_CYCLE, temp_path);
            cont = false;
        }
        /* Now check for more than one edge in either direction */
        n_fwd = db_node_edges_count_all_colours(current_step->node, current_step->orientation);
        n_rev = db_node_edges_count_all_colours(current_step->node, opposite_orientation(current_step->orientation));
        
        if (n_fwd == 0) {
            path_add_stop_reason(LAST, PATH_FLAG_STOP_BLUNT_END, temp_path);
            cont = false;
        }
       
    }
    
    if(path_get_length(temp_path) >= path_get_limit(temp_path)){
        cont = false;
        path_add_stop_reason(LAST, PATH_FLAG_LONGER_THAN_BUFFER, temp_path);
    }
    
    if(temp_path->in_nodes_count > db_graph->max_double_y_complexity && temp_path->out_nodes_count > db_graph->max_double_y_complexity){
        cont = false;
        path_add_stop_reason(LAST, PATH_TOO_COMPEX, temp_path);
    }
    
    
	return cont;
}
Ejemplo n.º 5
0
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;
}