added functions std, path_average_weight, remove_paths

master
nicolas-zimmermann 2019-10-22 17:43:50 +02:00
parent 1d75d1417c
commit d0c28884ed
1 changed files with 50 additions and 7 deletions

View File

@ -2,6 +2,7 @@
Small assembly module based on de bruijn graphs Small assembly module based on de bruijn graphs
""" """
import os import os
import statistics
import networkx as nx import networkx as nx
from networkx import algorithms from networkx import algorithms
@ -83,8 +84,15 @@ def get_starting_nodes(graph):
return starting_nodes return starting_nodes
def std(): def std(values):
pass """
Arguments:
values, list: list of values
Returns :
standard deviation of the 'values' data list
"""
return stdev(float(values))
def get_sink_nodes(graph): def get_sink_nodes(graph):
@ -103,12 +111,47 @@ def get_sink_nodes(graph):
return sink_nodes return sink_nodes
def path_average_weight(): def path_average_weight(graph, path):
pass """
Arguments:
graph, nx.DiGraph: a de bruijn graph
path, list of str(nodes): list of nodes constituing a path
Return:
mean weight, float: the mean weight of the path
"""
weight = 0
for i in range(len(path)-1):
weight += graph[path[i][i+i][weight]
return weight/(len(path)-1)
def remove_paths():
pass def remove_paths(graph, paths, delete_entry_node=False, delete_sink_node=False):
"""
Removes paths in 'paths' list from 'graph' object. Don't delete entry and
sink nodes unless specified.
Arguments:
graph, nd.DiGraph(): de bruijn graph
paths, list of string lists: list of paths composed of nodes
delete_entry_node, boolean: Delete entry if True
delete_sink_node, boolean: Delete sink node if True
Return:
graph, nd.DiGraph(): de bruijn graph with deletes paths.
"""
entry = 1
sink = -1
if delete_entry_node == True:
entry = 0
if delete_sink_node == True:
sink = None
for path in paths:
graph.remove_nodes_from(path[entry:sink])
return graph
def select_best_path(): def select_best_path():
@ -153,7 +196,7 @@ def get_contigs(graph, starting_nodes, sink_nodes):
for i in range(len(path)-1): for i in range(len(path)-1):
contig += path[i+1][-1] contig += path[i+1][-1]
contigs.append((contig, len(contig))) contigs.append((contig, len(contig)))
return contigs return contigs
def solve_bubble(): def solve_bubble():