Skip to content

Commit

Permalink
Split tarjan_scc to its own header
Browse files Browse the repository at this point in the history
  • Loading branch information
gmarcais committed Jan 21, 2024
1 parent 351e5b9 commit 1391a26
Show file tree
Hide file tree
Showing 10 changed files with 217 additions and 712 deletions.
224 changes: 0 additions & 224 deletions MDS-ILP.py

This file was deleted.

5 changes: 0 additions & 5 deletions Tupfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,3 @@ PROGS += fms2mds optimize_rem_path_len mykkeltveit_set find_longest_path
PROGS += champarnaud_set sketch_components syncmer_set syncmer_sketch frac_set
PROGS += create_seed sketch_histo old_champarnaud_set
run ./rules.sh $(PROGS)

# MDS ilp
ifdef ILP_PYTHON
: MDS-ILP.py |> echo '#!/bin/bash\nTQDM_DISABLE=1 exec "@(ILP_PYTHON)"' "`realpath %f`" @(ALPHA) @(K) "\$((2*@(K)*@(K)*@(K)))" '"$@"' > %o; chmod a+rx %o |> ilp_set
endif
69 changes: 69 additions & 0 deletions compact_utilities.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
def transposition_table(*pairs):
X = ''.join(pairs)
Y = ''.join(pair[::-1] for pair in pairs)

return str.maketrans(X, Y)


def kmer_formatter(b: int, k: int):
"""
Returns a string formatting function for base b kmers.
"""

def kmer(x: int):
d = b ** k

digits = []
for i in range(k):
d //= b
xi, x = divmod(x, d)
digits.append(str(xi))

return ''.join(digits)

return kmer


def DBG_walk_maps(b: int, k: int):
"""
Returns the In and Out maps for the base b, order k De Bruijn graph.
"""

p = b ** (k - 1)
s = b ** k

def In(x):
base = (x // b) % p
return [
base + i * p for i in range(b)
]

def Out(x):
base = (x * b) % s
return [
base + i for i in range(b)
]

return In, Out


def PCR(b: int, k: int):
"""
Produces an iterator over the PCRs of the (b, k) De Bruijn graph.
The PCR follows xS --> Sx, continuing until returning to XS.
"""

kmer = kmer_formatter(b, k)

seen = set()
for x in range(b ** k):
if x in seen:
continue

x = kmer(x)
y, cycle = x, [int(x, b)]
while (y := y[1:] + y[0]) != x:
cycle.append(int(y, b))

yield cycle
seen.update(cycle)
Loading

0 comments on commit 1391a26

Please sign in to comment.