Commit 5e05d845 authored by Yoann Dufresne's avatar Yoann Dufresne
Browse files

refactor directories

parent a8692cf4
......@@ -48,5 +48,5 @@ Config parameters:
snakemake -s Snakefile_data_simu --config n=10000 m=[4,6,8,10,12] m_dev=[0,0.5,1,2,3]
snakemake -s Snakefile_d2 --config input=[snakemake -s Snakefile_d2 --config input=[snake_exec/simu_bar_n10000_d5_m10-dev0.5.gexf,snake_exec/simu_bar_n10000_d5_m10-dev0.gexf,snake_exec/simu_bar_n10000_d5_m10-dev1.gexf,snake_exec/simu_bar_n10000_d5_m10-dev2.gexf,snake_exec/simu_bar_n10000_d5_m10-dev3.gexf,snake_exec/simu_bar_n10000_d5_m12-dev0.5.gexf,snake_exec/simu_bar_n10000_d5_m12-dev0.gexf,snake_exec/simu_bar_n10000_d5_m12-dev1.gexf,snake_exec/simu_bar_n10000_d5_m12-dev2.gexf,snake_exec/simu_bar_n10000_d5_m12-dev3.gexf,snake_exec/simu_bar_n10000_d5_m4-dev0.5.gexf,snake_exec/simu_bar_n10000_d5_m4-dev0.gexf,snake_exec/simu_bar_n10000_d5_m4-dev1.gexf,snake_exec/simu_bar_n10000_d5_m4-dev2.gexf,snake_exec/simu_bar_n10000_d5_m4-dev3.gexf,snake_exec/simu_bar_n10000_d5_m6-dev0.5.gexf,snake_exec/simu_bar_n10000_d5_m6-dev0.gexf,snake_exec/simu_bar_n10000_d5_m6-dev1.gexf,snake_exec/simu_bar_n10000_d5_m6-dev2.gexf,snake_exec/simu_bar_n10000_d5_m6-dev3.gexf,snake_exec/simu_bar_n10000_d5_m8-dev0.5.gexf,snake_exec/simu_bar_n10000_d5_m8-dev0.gexf,snake_exec/simu_bar_n10000_d5_m8-dev1.gexf,snake_exec/simu_bar_n10000_d5_m8-dev2.gexf,snake_exec/simu_bar_n10000_d5_m8-dev3.gexf]]
snakemake -s Snakefile_d2 --config input=[snake_exec/simu_bar_n10000_d5_m10-dev0.5.gexf,snake_exec/simu_bar_n10000_d5_m10-dev0.gexf,snake_exec/simu_bar_n10000_d5_m10-dev1.gexf,snake_exec/simu_bar_n10000_d5_m10-dev2.gexf,snake_exec/simu_bar_n10000_d5_m10-dev3.gexf,snake_exec/simu_bar_n10000_d5_m12-dev0.5.gexf,snake_exec/simu_bar_n10000_d5_m12-dev0.gexf,snake_exec/simu_bar_n10000_d5_m12-dev1.gexf,snake_exec/simu_bar_n10000_d5_m12-dev2.gexf,snake_exec/simu_bar_n10000_d5_m12-dev3.gexf,snake_exec/simu_bar_n10000_d5_m4-dev0.5.gexf,snake_exec/simu_bar_n10000_d5_m4-dev0.gexf,snake_exec/simu_bar_n10000_d5_m4-dev1.gexf,snake_exec/simu_bar_n10000_d5_m4-dev2.gexf,snake_exec/simu_bar_n10000_d5_m4-dev3.gexf,snake_exec/simu_bar_n10000_d5_m6-dev0.5.gexf,snake_exec/simu_bar_n10000_d5_m6-dev0.gexf,snake_exec/simu_bar_n10000_d5_m6-dev1.gexf,snake_exec/simu_bar_n10000_d5_m6-dev2.gexf,snake_exec/simu_bar_n10000_d5_m6-dev3.gexf,snake_exec/simu_bar_n10000_d5_m8-dev0.5.gexf,snake_exec/simu_bar_n10000_d5_m8-dev0.gexf,snake_exec/simu_bar_n10000_d5_m8-dev1.gexf,snake_exec/simu_bar_n10000_d5_m8-dev2.gexf,snake_exec/simu_bar_n10000_d5_m8-dev3.gexf]
import networkx as nx
from itertools import combinations
from d2_path import Path, Unitig
from d2graph.d2_path import Unitig
""" Remove unnecessary transitions
......@@ -3,7 +3,7 @@ import itertools
from bidict import bidict
import sys
from d_graph import Dgraph, compute_all_max_d_graphs, filter_dominated, list_domination_filter
from dgraph.d_graph import Dgraph, compute_all_max_d_graphs, list_domination_filter
class D2Graph(nx.Graph):
......@@ -56,7 +56,6 @@ class D2Graph(nx.Graph):
def construct_from_barcodes(self, index_size=3, verbose=True, debug=False, clique_mode=None):
import debug_disct as dd
# Compute all the d-graphs
if verbose:
print("Computing the unit d-graphs..")
......@@ -79,7 +78,7 @@ class D2Graph(nx.Graph):
# Index all the d-graphs
if verbose:
print("Compute the dmer index")
print("Compute the dmer dgraph")
self.index = self.create_index_from_tuples(index_size, verbose=verbose)
self.filter_dominated_in_index(tuple_size=index_size, verbose=verbose)
# Compute node distances for pair of dgraphs that share at least 1 dmer.
......@@ -209,7 +208,7 @@ class D2Graph(nx.Graph):
to_remove = set()
if verbose:
print("\tFilter dominated in index")
print("\tFilter dominated in dgraph")
# Find dominated
for dmer_idx, item in enumerate(self.index.items()):
......@@ -242,7 +241,7 @@ class D2Graph(nx.Graph):
# Remove dominated in index
# Remove dominated in dgraph
for dmer in itertools.combinations(r_dg.to_sorted_list(), tuple_size):
if r_dg in self.index[dmer]:
self.index[dmer] = list(filter(lambda x: x!=r_dg, self.index[dmer]))
......@@ -4,8 +4,7 @@ import networkx as nx
import argparse
import sys
import d2_graph as d2
import d2_algorithms as d2a
from d2graph import d2_algorithms as d2a, d2_graph as d2
def parse_arguments():
import networkx as nx
from d2_path import Path
from d2graph.d2_path import Path
""" Greedy algorithm. Start with th most probable unitig (ie lowest normalized penalty first and largest unitig for
equalities). Then extends on both side to the nearest interesting unitig.
import random
from d2_path import Path
from d2graph.d2_path import Path
import networkx as nx
def save(dict, filename):
with open(filename, "w") as fp:
for key, array in dict.items():
fp.write(str(len(array)) + " " + key + "\n")
fp.write('\n'.join([str(sorted(x.nodes)) for x in array]) + "\n")
print(filename, "saved")
def load(filename):
d = {}
with open(filename) as fp:
value = None
nb_vals = 0
for line in fp:
line = line.strip()
if value == None:
first_space = line.find(' ')
nb_vals = int(line[:first_space])
value = line[first_space+1:]
d[value] = []
nb_vals -= 1
if nb_vals == 0:
value = None
print(filename, "loaded")
return d
def compare(d1, d2):
remaining = set(d2.keys())
for key in d1:
if key not in d2:
print(key, "not present in d2")
l1 = sorted([str(sorted(x.nodes)) for x in d1[key]])
l2 = sorted([str(x) for x in d2[key]])
if l1 != l2:
print(f"{key}: disimilar lists:")
s1 = set(l1)
s2 = set(l2)
print(s1 - s2)
print(s2 - s1)
for key in remaining:
print(key, "not present in d1")
from itertools import combinations
class AbstractDGIndex(dict):
def __init__(self, fixed_size=False, size=3):
""" This class represent a d_graph dgraph.
Each key in the dgraph is a set of barcodes and each value a list of dgraphs containing these barcodes.
:param fixed_size: True if the keys in the dgraph have a fixed size.
:param size: The size of the key sets if fixed size, the min size otherwise.
super(AbstractDGIndex, self).__init__()
self.fixed_size = fixed_size
self.size = size
def _add_value(self, key_set, dgraph):
""" Add the couple key (set of barcodes) and value (dgraph) at the right place in the dict
# Test the key size
if self.fixed_size and len(key_set) != self.size:
raise ValueError("Wrong set size in the dgraph")
elif (not self.fixed_size) and len(key_set) < len(dgraph.node_set) - self.size:
raise ValueError("Wrong set size in the dgraph")
key_set = frozenset(key_set)
# Add the key if not already present
if key_set not in self:
self[key_set] = set()
# Associate the value with the key
def add_dgraph(self, dg):
""" Generate all the set needed for keys in the dgraph and push the d-graph as value.
For fixed size of the dgraph all the sets of this size will be generated as key.
Otherwise, all the set of size at least len(dg) - size will be generated.
barcodes = dg.node_set
if self.fixed_size:
for tup in combinations(barcodes, self.size):
self._add_value(frozenset(tup), dg)
for size in range(len(barcodes)-self.size, len(barcodes)+1):
for tup in combinations(barcodes, size):
self._add_value(frozenset(tup), dg)
def __contains__(self, key):
key = frozenset(key)
return super(AbstractDGIndex, self).__contains__(key)
def __getitem__(self, key):
return super(AbstractDGIndex, self).__getitem__(self.__keytransform__(key))
def __keytransform__(self, key):
return frozenset(key)
#!/usr/bin/env python3
import networkx as nx
import path_optimization as po
import argparse
import sys
import d2_graph as d2
from d2graph import d2_graph as d2, path_optimization as po
def parse_arguments():
......@@ -6,8 +6,6 @@ import argparse
from termcolor import colored
import networkx as nx
from d2_graph import D2Graph
def parse_args():
parser = argparse.ArgumentParser(description='Process some integers.')
......@@ -4,7 +4,7 @@ import networkx as nx
import random
import argparse
import graph_manipulator as gm
from dgraph import graph_manipulator as gm
def parse_arguments():
......@@ -2,7 +2,7 @@
import argparse
import graph_manipulator as gm
from dgraph import graph_manipulator as gm
def parse_arguments():
......@@ -4,7 +4,7 @@ import networkx as nx
import argparse
import sys
import d2_graph as d2
from d2graph import d2_graph as d2
def parse_arguments():
import unittest
from random import randint
from dgraph.AbstractDGIndex import AbstractDGIndex
from dgraph.d_graph import Dgraph
from dgraph.graph_manipulator import generate_d_graph_chain
class TestIndex(unittest.TestCase):
def test_construction(self):
for _ in range(10):
size = randint(1, 50)
index = AbstractDGIndex(size=size)
self.assertEqual(len(index), 0)
self.assertEqual(index.size, size)
def test_wrong_size_filling(self):
index = AbstractDGIndex(fixed_size=True, size=3)
key = frozenset({'A', 'B'})
val = "Test"
with self.assertRaises(ValueError):
index._add_value(key, val)
def test_fill_static(self):
index = AbstractDGIndex(fixed_size=True, size=3)
key = frozenset({'A', 'B', 'C'})
val = "Test"
index._add_value(key, val)
self.assertEqual(len(index), 1)
self.assertTrue(key in index)
self.assertEqual(index[key], {val})
def test_fixed_size(self):
dg = _generate_dg(2)
index = AbstractDGIndex(fixed_size=True, size=2)
print("\n".join([str(k) for k in index.keys()]))
self.assertEqual(len(index), 10)
def test_variable_size(self):
dg = _generate_dg(2)
index = AbstractDGIndex(fixed_size=False, size=2)
print("\n".join([str(k) for k in index.keys()]))
self.assertEqual(len(index), 16)
def _generate_dg(d):
# nx graph construction
G = generate_d_graph_chain(2*d+1, d)
center = d
h1 = list(G.subgraph([x for x in range(d)]).nodes())
h2 = list(G.subgraph([2*d-x for x in range(d)]).nodes())
# d-graph construction
dg = Dgraph(center)
dg.put_halves(h1, h2, G)
return dg
if __name__ == "__main__":
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment