diff --git a/fluents/lib/nx_utils.py b/fluents/lib/nx_utils.py index 7fa8c5b..d61259c 100644 --- a/fluents/lib/nx_utils.py +++ b/fluents/lib/nx_utils.py @@ -8,10 +8,13 @@ from cx_utils import sorted_eig import numpy + + eps = numpy.finfo(float).eps.item() feps = numpy.finfo(numpy.single).eps.item() _array_precision = {'f': 0, 'd': 1, 'F': 0, 'D': 1,'i': 1} +class NXUTILSException(Exception): pass def xgraph_to_graph(G): """Convert an Xgraph to an ordinary graph. @@ -65,11 +68,12 @@ def get_affinity_matrix(G, data, ids, dist='e', mask=None, weight=None, t=0, out try: from Bio import Cluster as CLS except: - raise ValueError, "Need installed biopython" - nVar = len(data) - nSamp = len(data[data.keys()[0]]) + raise NXUTILSError("Import of Biopython failed") + n_var = len(data) + n_samp = len(data[data.keys()[0]]) X = zeros((nVar, nSamp),dtpye='1: - nghbrs = new_graph.neighbors(rx) - for i in nghbrs: - for j in nghbrs: - if i!=j: - if not new_graph.has_edge(i,j): - new_graph.add_edge(i,j,0.5) - - #update graph - new_graph.delete_nodes_from(list(bad_nodes)) - - return new_graph,new_node_data,new_pathways,new_data + A = NX.ad_matrix(G, nodelist=nodelist) + for i, node in enumerate(nodelist): + nei_i = A[i,:]==1 + vec_i = vec[nei_i] def weighted_laplacian(G,with_labels=False): """Return standard Laplacian of graph from a weighted adjacency matrix.""" @@ -418,10 +299,10 @@ def weighted_laplacian(G,with_labels=False): else: return L -def subnetworks(G, T2): +def grow_subnetworks(G, T2): """Return the highest scoring (T2-test) subgraph og G. - Use simulated annealing to identify highly scoring subgraphs. + Use simulated annealing to identify highly grow subgraphs. ref: -- Ideker et.al (Bioinformatics 18, 2002) -- Patil and Nielsen (PNAS 2006)