Skip to content

Commit

Permalink
Merge commit 'ded3f2feb257b1be2bf9310f5d8ba88f136f5fa7'
Browse files Browse the repository at this point in the history
  • Loading branch information
Matis Alias-Bagarre committed Jan 9, 2025
2 parents 4dfad56 + ded3f2f commit 2547470
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 66 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/python-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ jobs:
pip install seaborn==0.13.2
pip install plotly==5.24.1
pip install pytest==8.3.4
pip3 install pybind11-global
pip install pybind11-global
- name: Clean up existing libbdsg directory
run: |
rm -rf libbdsg
- name: Install libbdsg
run: |
sudo apt-get install -y --no-install-recommends libjansson-dev doxygen
Expand Down
110 changes: 46 additions & 64 deletions stoat/list_snarl_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,6 @@ def nreversed(self):
# counts how many nodes are traversed in reverse
return (sum(['<' == orient for orient in self.orients]))

def split_paths(path) :
return re.findall(r'\d+', path)

def length_node(pg, node_id) :
return pg.get_length(node_id)

def calcul_type_variant(list_list_length_paths) :
"""
Calcul type variant of a tested snarl
Expand Down Expand Up @@ -127,7 +121,6 @@ def add_to_path(next_child) :
# Case where we find a loop
if stree.net_handle_as_string(i) == stree.net_handle_as_string(next_child) :
return False

paths.append([])
for net in path:
paths[-1].append(net)
Expand Down Expand Up @@ -191,7 +184,7 @@ def fill_pretty_paths(stree, pg, finished_paths) :
for net in path :
if stree.is_sentinel(net) :
net = stree.get_node_from_sentinel(net)

# case node : get the node length
if stree.is_node(net) :
ppath.addNodeHandle(net, stree)
Expand Down Expand Up @@ -224,73 +217,62 @@ def fill_pretty_paths(stree, pg, finished_paths) :
assert len(type_variants) == len(pretty_paths)
return pretty_paths, type_variants

def write_header_output(output_file) :
with open(output_file, 'w') as outf:
outf.write('snarl\tpaths\ttype\tchr\tpos\n')

def write_output(output_file, snarl_id, pretty_paths, type_variants, chr, pos) :
with open(output_file, 'a') as outf:
outf.write('{}\t{}\t{}\t{}\t{}\n'.format(snarl_id, ','.join(pretty_paths), ','.join(type_variants), chr, pos))

def write_header_output_not_analyse(output_file) :
with open(output_file, 'w') as outf:
outf.write('snarl\treason\n')

def write_output_not_analyse(output_file, snarl_id, reason) :
with open(output_file, 'a') as outf:
outf.write('{}\t{}\n'.format(snarl_id, reason))

def loop_over_snarls_write(stree, snarls, pg, output_file, output_snarl_not_analyse, children_treshold=50, bool_return=True) :

write_header_output(output_file)
write_header_output_not_analyse(output_snarl_not_analyse)
with open(output_file, 'w') as out_snarl, open(output_snarl_not_analyse, 'w') as out_fail:
out_snarl.write('snarl\tpaths\ttype\tchr\tpos\n')
out_fail.write('snarl\treason\n')

snarl_paths = []
paths_number_analysis = 0
time_threshold = 2 # 2s max per snarl analysis

snarl_paths = {}
paths_number_analysis = 0
time_threshold = 2 # 2s max per snarl analysis
children = [0]
def count_children(net):
children[0] += 1
return (True)

children = [0]
def count_children(net):
children[0] += 1
return (True)
# for each snarl, lists paths through the netgraph and write to output TSV
for snarl, chr, pos in snarls:

# for each snarl, lists paths through the netgraph and write to output TSV
for snarl, chr, pos in snarls:
snarl_time = time.time()
snarl_id = find_snarl_id(stree, snarl)
not_break = True
children = [0]

snarl_time = time.time()
snarl_id = find_snarl_id(stree, snarl)
not_break = True
children = [0]
stree.for_each_child(snarl, count_children)
if children[0] > children_treshold :
out_fail.write('{}\t{}\n'.format(snarl_id, "too_many_children"))
continue

# we'll traverse the netgraph starting at the left boundary
# init unfinished paths to the first boundary node
paths = [[stree.get_bound(snarl, False, True)]]
finished_paths = []
while len(paths) > 0 :
path = paths.pop()

if time.time() - snarl_time > time_threshold :
out_fail.write('{}\t{}\n'.format(snarl_id, "time_calculation_out"))
not_break = False
break

stree.for_each_child(snarl, count_children)
if children[0] > children_treshold :
write_output_not_analyse(output_snarl_not_analyse, snarl_id, "too_many_children")
continue

# we'll traverse the netgraph starting at the left boundary
# init unfinished paths to the first boundary node
paths = [[stree.get_bound(snarl, False, True)]]
finished_paths = []
while len(paths) > 0 :
path = paths.pop()

if time.time() - snarl_time > time_threshold :
write_output_not_analyse(output_snarl_not_analyse, snarl_id, "time_calculation_out")
not_break = False
break

follow_edges(stree, finished_paths, path, paths, pg)

if not_break :

# prepare path list to output and write each path directly to the file
pretty_paths, type_variants = fill_pretty_paths(stree, pg, finished_paths)
write_output(output_file, snarl_id, pretty_paths, type_variants, chr, pos)

if bool_return :
snarl_paths[snarl_id] = (pretty_paths, ','.join(type_variants), chr, pos)

paths_number_analysis += len(pretty_paths)
follow_edges(stree, finished_paths, path, paths, pg)

if not_break :

# prepare path list to output and write each path directly to the file
pretty_paths, type_variants = fill_pretty_paths(stree, pg, finished_paths)
out_snarl.write('{}\t{}\t{}\t{}\t{}\n'.format(snarl_id, ','.join(pretty_paths), ','.join(type_variants), chr, pos))

if bool_return :
snarl_paths.append(snarl_id, pretty_paths, ','.join(type_variants), chr, pos)

paths_number_analysis += len(pretty_paths)

return snarl_paths, paths_number_analysis

Expand Down

0 comments on commit 2547470

Please sign in to comment.