Commit f78f16f2 authored by Yoann Dufresne's avatar Yoann Dufresne

refactoring of the code to match package tree

parent dd190fee
......@@ -2,6 +2,16 @@
Trying to deconvolve single tag assignment for multiple molecules
## Installation
Install the package from the root directory.
```bash
# For users
pip install . --user
# For developers
pip install -e . --user
```
## Scripts
For the majority of the scripts, argparse is used.
......
import networkx as nx
from d2graph.d2_path import Unitig
from deconvolution.d2graph.d2_path import Unitig
""" Remove unnecessary transitions
......
......@@ -3,8 +3,8 @@ import itertools
from bidict import bidict
import sys
from dgraph.FixedDGIndex import FixedDGIndex
from dgraph.d_graph import Dgraph, compute_all_max_d_graphs, list_domination_filter
from deconvolution.dgraph.FixedDGIndex import FixedDGIndex
from deconvolution.dgraph.d_graph import Dgraph, compute_all_max_d_graphs
class D2Graph(nx.Graph):
......
......@@ -4,7 +4,8 @@ import networkx as nx
import argparse
import sys
from d2graph import d2_algorithms as d2a, d2_graph as d2
from deconvolution.d2graph import d2_graph as d2
from deconvolution.d2graph import d2_algorithms as d2a
def parse_arguments():
......
from d2graph.d2_path import Path
from deconvolution.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 d2graph.d2_path import Path
import networkx as nx
from deconvolution.d2graph.d2_path import Path
class Optimizer:
......
from dgraph.AbstractDGIndex import AbstractDGIndex
from itertools import combinations
from deconvolution.dgraph.AbstractDGIndex import AbstractDGIndex
class FixedDGIndex(AbstractDGIndex):
......
from dgraph.AbstractDGIndex import AbstractDGIndex
from itertools import combinations
from deconvolution.dgraph.AbstractDGIndex import AbstractDGIndex
class VariableDGIndex(AbstractDGIndex):
......
import networkx as nx
from functools import total_ordering
import community # pip install python-louvain
import community # pip install python-louvain TODO: Ajouter dans les requirements !!!
from dgraph.FixedDGIndex import FixedDGIndex
from deconvolution.dgraph.FixedDGIndex import FixedDGIndex
@total_ordering
......@@ -312,92 +312,92 @@ def compute_all_max_d_graphs(graph, debug=False, clique_mode=None):
return d_graphs
""" Add the new dg in the dgs list. If dg is dominated by another dg in the list, then it's
dropped. If any dg in the list is dominated by the dg to add, then, the new dg is added and
all the dominated dg are removed from the list.
@param dg A new dg to add/filter.
@param undominated_dgs_list A list of dg where any of them is dominated by another one.
@return The updated undominated list.
"""
def add_new_dg_regarding_domination(dg, undominated_dgs_list):
to_remove = []
dominated = False
# Search for domination relations
for u_dg in undominated_dgs_list:
if not dominated and dg.is_dominated(u_dg):
dominated = True
if u_dg.is_dominated(dg):
to_remove.append(u_dg)
# Remove dominated values
size = len(undominated_dgs_list)
for dg2 in to_remove:
undominated_dgs_list.remove(dg2)
# Add the new dg
if not dominated:
undominated_dgs_list.append(dg)
return undominated_dgs_list
def filter_dominated(d_graphs, overall=False, in_place=True):
if not overall:
return local_domination_filter(d_graphs, in_place)
all_d_graphs = []
for dgs in d_graphs.values():
all_d_graphs.extend(dgs)
all_d_graphs = list_domination_filter(all_d_graphs)
return d_graphs
""" Filter the d-graphs by node. In a list of d-graph centered on a node n, if a d-graph is
completely included in another and have a highest distance score to the optimal, then it is
filtered out.
@param d_graphs All the d-graphs to filter, sorted by central node.
@param in_place If true, modify the content of d_graph with the filtered version. If False,
copy all the content in a new dictionary.
@return The filtered dictionary of d-graph per node.
"""
def local_domination_filter(d_graphs, in_place=True):
filtered = d_graphs if in_place else {}
# Filter node by node
for node, d_graph_list in d_graphs.items():
lst = str(sorted([str(x) for x in d_graph_list]))
filtered[node] = brutal_list_domination_filter(d_graph_list, node_name=str(node))
return filtered
""" Filter the input d-graphs list. In the list of d-graph centered on a node n, if a d-graph is
completely included in another and have a highest distance score to the optimal, then it is
filtered out.
@param d_graphs All the d-graphs to filter.
@return The filtered dictionary of d-graph per node.
"""
def list_domination_filter(d_graphs):
filtered = []
# Filter d-graph by d-graph
for dg in d_graphs:
add_new_dg_regarding_domination(dg, filtered)
return set(filtered)
def brutal_list_domination_filter(d_graphs, node_name=""):
undominated = set(d_graphs)
to_remove = set()
for dg1 in d_graphs:
for dg2 in d_graphs:
if dg1.is_dominated(dg2):
to_remove.add(dg1)
break
return undominated - to_remove
# """ Add the new dg in the dgs list. If dg is dominated by another dg in the list, then it's
# dropped. If any dg in the list is dominated by the dg to add, then, the new dg is added and
# all the dominated dg are removed from the list.
# @param dg A new dg to add/filter.
# @param undominated_dgs_list A list of dg where any of them is dominated by another one.
# @return The updated undominated list.
# """
# def add_new_dg_regarding_domination(dg, undominated_dgs_list):
# to_remove = []
# dominated = False
#
# # Search for domination relations
# for u_dg in undominated_dgs_list:
# if not dominated and dg.is_dominated(u_dg):
# dominated = True
# if u_dg.is_dominated(dg):
# to_remove.append(u_dg)
#
# # Remove dominated values
# size = len(undominated_dgs_list)
# for dg2 in to_remove:
# undominated_dgs_list.remove(dg2)
#
# # Add the new dg
# if not dominated:
# undominated_dgs_list.append(dg)
#
# return undominated_dgs_list
#
#
#
# def filter_dominated(d_graphs, overall=False, in_place=True):
# if not overall:
# return local_domination_filter(d_graphs, in_place)
#
# all_d_graphs = []
# for dgs in d_graphs.values():
# all_d_graphs.extend(dgs)
#
# all_d_graphs = list_domination_filter(all_d_graphs)
#
# return d_graphs
#
#
# """ Filter the d-graphs by node. In a list of d-graph centered on a node n, if a d-graph is
# completely included in another and have a highest distance score to the optimal, then it is
# filtered out.
# @param d_graphs All the d-graphs to filter, sorted by central node.
# @param in_place If true, modify the content of d_graph with the filtered version. If False,
# copy all the content in a new dictionary.
# @return The filtered dictionary of d-graph per node.
# """
# def local_domination_filter(d_graphs, in_place=True):
# filtered = d_graphs if in_place else {}
#
# # Filter node by node
# for node, d_graph_list in d_graphs.items():
# lst = str(sorted([str(x) for x in d_graph_list]))
# filtered[node] = brutal_list_domination_filter(d_graph_list, node_name=str(node))
#
# return filtered
#
#
# """ Filter the input d-graphs list. In the list of d-graph centered on a node n, if a d-graph is
# completely included in another and have a highest distance score to the optimal, then it is
# filtered out.
# @param d_graphs All the d-graphs to filter.
# @return The filtered dictionary of d-graph per node.
# """
# def list_domination_filter(d_graphs):
# filtered = []
#
# # Filter d-graph by d-graph
# for dg in d_graphs:
# add_new_dg_regarding_domination(dg, filtered)
#
# return set(filtered)
#
# def brutal_list_domination_filter(d_graphs, node_name=""):
# undominated = set(d_graphs)
# to_remove = set()
#
# for dg1 in d_graphs:
# for dg2 in d_graphs:
# if dg1.is_dominated(dg2):
# to_remove.add(dg1)
# break
#
# return undominated - to_remove
......@@ -4,7 +4,7 @@ import networkx as nx
import argparse
import sys
from d2graph import d2_graph as d2, path_optimization as po
from deconvolution.d2graph import d2_graph as d2, path_optimization as po
def parse_arguments():
......
#!/usr/bin/env python3
import networkx as nx
import networkx as nx
import random
import argparse
from dgraph import graph_manipulator as gm
import deconvolution.dgraph.graph_manipulator as gm
def parse_arguments():
......
......@@ -2,7 +2,7 @@
import argparse
from dgraph import graph_manipulator as gm
from deconvolution.dgraph import graph_manipulator as gm
def parse_arguments():
......
......@@ -4,7 +4,7 @@ import networkx as nx
import argparse
import sys
from d2graph import d2_graph as d2
from deconvolution.d2graph import d2_graph as d2
def parse_arguments():
......
from distutils.core import setup
setup(
name='10X-deconvolve',
version='0.1dev',
packages=['deconvolution.d2graph', 'deconvolution.dgraph', 'deconvolution.main'],
license='AGPL V3',
long_description=open('README.md').read(),
)
import unittest
from random import randint
from dgraph.FixedDGIndex import FixedDGIndex
from dgraph.VariableDGIndex import VariableDGIndex
from dgraph.d_graph import Dgraph
from dgraph.graph_manipulator import generate_d_graph_chain
from deconvolution.dgraph.FixedDGIndex import FixedDGIndex
from deconvolution.dgraph.VariableDGIndex import VariableDGIndex
from deconvolution.dgraph.d_graph import Dgraph
from deconvolution.dgraph.graph_manipulator import generate_d_graph_chain
class TestIndex(unittest.TestCase):
......
......@@ -3,10 +3,8 @@ import tempfile
import networkx as nx
from scipy.special import comb
from d2graph.d2_graph import D2Graph
from dgraph import graph_manipulator as gm
from d_graph_data import complete_graph
from deconvolution.d2graph.d2_graph import D2Graph
from deconvolution.dgraph import graph_manipulator as gm
class TestD2Graph(unittest.TestCase):
......
import unittest
from d_graph_data import unit_d_graph
from dgraph.d_graph import Dgraph
from dgraph import graph_manipulator as gm
from deconvolution.dgraph.d_graph import Dgraph
from deconvolution.dgraph import graph_manipulator as gm
class TestDGraph(unittest.TestCase):
......
import unittest
from dgraph import graph_manipulator as gm
from deconvolution.dgraph import graph_manipulator as gm
class TestGraphManipulation(unittest.TestCase):
......
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