-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathreconstruct_genome_string.py
More file actions
34 lines (28 loc) · 1.34 KB
/
Copy pathreconstruct_genome_string.py
File metadata and controls
34 lines (28 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from algorithms.eulerian_cycle import eulerian_path
from algorithms.sequencing_graph import kmers_to_debruijn
from algorithms.four_russians_binary_encoding import Sequence
from algorithms.eulerian_cycle import eulerian_cycle
from algorithms.sequencing_graph import paired_kmers_to_debruijn
def reconstruct_from_genome_path(genome_path:list):
k = len(genome_path[0])
genome_string = str(genome_path[0]).strip()
for i in range(1,len(genome_path)):
node:str = genome_path[i]
genome_string += str(genome_path[i]).strip()[-1]
return genome_string
def reconstruct_from_kmers(kmers:list):
graph = kmers_to_debruijn(kmers)
genome_path = eulerian_path(graph)
return reconstruct_from_genome_path(genome_path)
def construct_k_universal_circular_string(k:int):
kmers = list(Sequence(["0","1"],k))
graph = kmers_to_debruijn(kmers)
genome_path = eulerian_cycle(graph)
const = reconstruct_from_genome_path(genome_path)[:-(k-1)]
return const
def reconstruct_from_paired_kmers(paired_kmers:list,k:int,d:int):
graph = paired_kmers_to_debruijn(paired_kmers)
genome_path = eulerian_path(graph)
upper_path = reconstruct_from_genome_path(list(map(lambda x:x[0],genome_path)))
lower_path = reconstruct_from_genome_path(list(map(lambda x:x[1],genome_path)))
return upper_path + lower_path[-(k+d):]