-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSVSignature.py
More file actions
141 lines (118 loc) · 5.18 KB
/
SVSignature.py
File metadata and controls
141 lines (118 loc) · 5.18 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import logging
class Signature:
"""Signature class for basic signatures of structural variants. An signature is always detected from a single read.
"""
def __init__(self, contig, start, end, signature, read):
self.contig = contig
self.start = start
self.end = end
self.signature = signature
self.read = read
self.type = None
self.data = None
self.svlen = self.end - self.start
if self.end < self.start:
logging.warning("Signature with invalid coordinates (end < start): " + self.as_string())
def get_source(self):
return (self.contig, self.start, self.end)
def get_key(self):
contig, start, end = self.get_source()
return (self.type, contig, end)
def downstream_distance_to(self, signature2):
"""Return distance >= 0 between this signature's end and the start of signature2."""
this_contig, this_start, this_end = self.get_source()
other_contig, other_start, other_end = signature2.get_source()
if self.type == signature2.type and this_contig == other_contig:
return max(0, other_start - this_end)
else:
return float("inf")
class SignatureDeletion(Signature):
"""SV Signature: a region (contig:start-end) has been deleted and is not present in sample"""
def __init__(self, contig, start, end, signature, read):
self.contig = contig
assert end >= start
# 0-based start of the deletion (first deleted base)
self.start = start
# 0-based end of the deletion (one past the last deleted base)
self.end = end
self.signature = signature
self.read = read
self.type = "DEL"
self.svlen = self.end - self.start
class SignatureInsertion(Signature):
"""SV Signature: a region of length end-start has been inserted at contig:start"""
def __init__(self, contig, start, end, signature, read, insert_sequence):
self.contig = contig
assert end >= start
# 0-based start of the insertion (base after the insertion)
self.start = start
# 0-based start of the insertion (base after the insertion) + length of the insertion
self.end = end
self.signature = signature
self.read = read
self.type = "INS"
self.svlen = self.end - self.start
self.alt_sequence = insert_sequence
def get_key(self):
contig, start, end = self.get_source()
return (self.type, contig, start)
def downstream_distance_to(self, signature2):
"""Return distance >= 0 between this signature's end and the start of signature2."""
this_contig, this_start, this_end = self.get_source()
other_contig, other_start, other_end = signature2.get_source()
if self.type == signature2.type and this_contig == other_contig:
return max(0, other_start - this_start)
else:
return float("inf")
class SignatureInversion(Signature):
"""SV Signature: a region (contig:start-end) has been inverted in the sample"""
def __init__(self, contig, start, end, signature, read, direction):
self.contig = contig
assert end >= start
# 0-based start of the inversion (first inverted base)
self.start = start
# 0-based end of the inversion (one past the last inverted base)
self.end = end
self.signature = signature
self.read = read
self.type = "INV"
self.direction = direction
self.svlen = self.end - self.start
class SignatureDuplicationTandem(Signature):
"""SV Signature: a region (contig:start-end) has been tandemly duplicated"""
def __init__(self, contig, start, end, signature, read):
self.contig = contig
assert end >= start
# 0-based start of the region (first copied base)
self.start = start
# 0-based end of the region (one past the last copied base)
self.end = end
self.signature = signature
self.read = read
self.type = "DUP"
self.svlen = self.end - self.start
class SignatureTranslocation(Signature):
"""SV Signature: two positions (contig1:pos1 and contig2:pos2) are connected in the sample"""
def __init__(self, contig1, pos1, direction1, contig2, pos2, direction2, signature, read):
if contig1 < contig2 or (contig1 == contig2 and pos1 < pos2):
self.contig1 = contig1
# 0-based source of the translocation (first base before the translocation)
self.pos1 = pos1
self.source_direction = direction1
self.contig2 = contig2
# 0-based destination of the translocation (first base after the translocation)
self.pos2 = pos2
self.dest_direction = direction2
else:
print('translocation error')
self.contig = contig1
self.signature = signature
self.read = read
self.type = "BND"
self.svlen = None
def get_source(self):
return (self.contig1, self.pos1, self.pos1 + 1)
def get_destination(self):
return (self.contig2, self.pos2, self.pos2 + 1)
def get_key(self):
return (self.type, self.contig1, self.pos1)