Skip to content

Commit

Permalink
ref
Browse files Browse the repository at this point in the history
  • Loading branch information
katerinakazantseva committed Aug 12, 2024
1 parent 2fa6a7a commit 1607df0
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 27 deletions.
2 changes: 1 addition & 1 deletion strainy/clustering/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from strainy.clustering import build_data as build_data
from strainy.clustering import build_adj_matrix as matrix
from strainy.params import *
import strainy.gfa_operations.gfa_ops as gfa_ops
import strainy.graph_operations.gfa_ops as gfa_ops


logger = logging.getLogger()
Expand Down
2 changes: 1 addition & 1 deletion strainy/clustering/cluster_postprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from strainy.clustering.community_detection import find_communities
from strainy.clustering import build_adj_matrix as matrix
from strainy.clustering import build_data
from strainy.gfa_operations import gfa_ops
from strainy.graph_operations import gfa_ops
from strainy.params import *

logger = logging.getLogger()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
from strainy.gfa_operations import gfa_ops
from strainy.graph_operations import gfa_ops
from strainy.unitig_statistics import utg_stats
from strainy.clustering import build_data
from strainy.params import *
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import pygraphviz as gv
from collections import Counter, deque, defaultdict
import logging
from strainy.gfa_operations import gfa_ops
from strainy.gfa_operations import asm_graph_ops
from strainy.graph_operations import gfa_ops
from strainy.graph_operations import asm_graph_ops
from strainy.params import *


Expand All @@ -18,26 +18,26 @@
"""


def build_paths_graph(cons, full_paths_roots, full_paths_leafs, cluster_distances):
"""
Create an "overlap" graph for clusters within a unitig, based on flye distance
"""
M = cluster_distances
G = gfa_ops.from_pandas_adjacency_notinplace(M, create_using = nx.DiGraph)
G.remove_edges_from(list(nx.selfloop_edges(G)))
G = remove_nested(G, cons)
try:
G.remove_node(0)
except:
pass
#todo move it to parental function
G, full_paths_roots, full_paths_leafs = \
remove_leaf_root_subnodes(G,full_paths_roots,full_paths_leafs)
G = remove_nested(G, cons)
G = remove_transitive(G)
return G




def remove_transitive(G):
path_remove = []
for node in G.nodes():
Expand All @@ -47,35 +47,43 @@ def remove_transitive(G):
if len(n_path) == 3:
path_remove.append(n_path)
for n_path in path_remove:
try:
G.remove_edge(n_path[0], n_path[1])
except:
continue
try:
G.remove_edge(n_path[0], n_path[1])
except:
continue
return G




def remove_leaf_root_subnodes(G,full_paths_roots,full_paths_leafs):
node_remove = []
for node in full_paths_leafs+full_paths_roots:
if node in full_paths_leafs:
neighbors = list(full_paths_leafs)
else:
neighbors = list(full_paths_roots)
for node in full_paths_leafs:
neighbors = list(full_paths_leafs)
for neighbor in list(neighbors):
for n_path in nx.algorithms.all_simple_paths(G, node, neighbor, cutoff = 2):
for n_path in nx.algorithms.all_simple_paths(G, node, neighbor, cutoff=2):
print(n_path)
if len(n_path) == 2:
node_remove.append(neighbor)
for node in full_paths_roots:
neighbors = list(full_paths_roots)
for neighbor in list(neighbors):
for n_path in nx.algorithms.all_simple_paths(G, neighbor,node, cutoff = 2):
print(n_path)
if len(n_path) == 2:
node_remove.append(neighbor)
for node in node_remove:
try:
try:
G.remove_node(node)
logger.debug("REMOVE " + str(node))
full_paths_roots.remove(node)
full_paths_leafs.remove(node)
except:
continue
except:
continue
return (G,full_paths_roots,full_paths_leafs)



def remove_bubbles(graph, source_nodes):
for node in source_nodes:
neighbors = list(source_nodes)
Expand All @@ -99,7 +107,6 @@ def find_full_paths(G, paths_roots, paths_leafs):
pass
for path in list(paths_nx):
paths.append(path)

return paths


Expand Down
10 changes: 5 additions & 5 deletions strainy/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
from strainy.clustering import build_adj_matrix as matrix
from strainy.clustering import cluster_postprocess as postprocess
from strainy.simplification import simplify_links as smpl
from strainy.gfa_operations import gfa_ops
from strainy.gfa_operations import asm_graph_ops
from strainy.gfa_operations import overlap_graph_ops
from strainy.graph_operations import gfa_ops
from strainy.graph_operations import asm_graph_ops
from strainy.graph_operations import overlap_graph_ops
from strainy.unitig_statistics import utg_stats
from strainy.flye_consensus import FlyeConsensus
from strainy.clustering import build_data
Expand All @@ -27,11 +27,11 @@
from strainy.reports.call_variants import produce_strainy_vcf
from strainy.preprocessing import gfa_to_fasta
from strainy.phase import color_bam

from dataclasses import dataclass
logger = logging.getLogger()


from dataclasses import dataclass




Expand Down

0 comments on commit 1607df0

Please sign in to comment.