geney 1.4.22__py2.py3-none-any.whl → 1.4.23__py2.py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of geney might be problematic. Click here for more details.
geney/utils/SeqMats.py
CHANGED
|
@@ -159,37 +159,66 @@ class SeqMat:
|
|
|
159
159
|
new.seq_array['valid_mask'] = new.seq_array['nt'] != b'-'
|
|
160
160
|
return new
|
|
161
161
|
|
|
162
|
+
# def apply_mutations(
|
|
163
|
+
# self,
|
|
164
|
+
# mutations: Union[Tuple[float, str, str], List[Tuple[float, str, str]]],
|
|
165
|
+
# only_snps: bool = False
|
|
166
|
+
# ) -> SeqMat:
|
|
167
|
+
|
|
162
168
|
def apply_mutations(
|
|
163
169
|
self,
|
|
164
|
-
mutations: Union[Tuple[float, str, str], List[Tuple[float, str, str]]],
|
|
170
|
+
mutations: Union[Tuple[float, str, str], List[Tuple[float, str, str]]] = None,
|
|
171
|
+
*,
|
|
172
|
+
pos: Optional[float] = None,
|
|
173
|
+
ref: Optional[str] = None,
|
|
174
|
+
alt: Optional[str] = None,
|
|
165
175
|
only_snps: bool = False
|
|
166
|
-
|
|
176
|
+
) -> SeqMat:
|
|
167
177
|
"""
|
|
168
178
|
Apply one or a batch of mutations (pos, ref, alt) efficiently:
|
|
169
179
|
- Supports a single tuple or a list of tuples
|
|
170
180
|
- Assumes mutations sorted by position for vectorized searchsorted
|
|
171
181
|
"""
|
|
172
182
|
# Normalize to list
|
|
173
|
-
if isinstance(mutations, tuple) and len(mutations) == 3:
|
|
183
|
+
# if isinstance(mutations, tuple) and len(mutations) == 3:
|
|
184
|
+
# mutations = [mutations]
|
|
185
|
+
# elif not isinstance(mutations, list):
|
|
186
|
+
# raise TypeError("mutations must be a tuple or list of tuples")
|
|
187
|
+
# Input normalization
|
|
188
|
+
if mutations is None:
|
|
189
|
+
if pos is None or ref is None or alt is None:
|
|
190
|
+
raise ValueError("Either `mutations` or `pos, ref, alt` must be provided")
|
|
191
|
+
mutations = [(pos, ref, alt)]
|
|
192
|
+
elif isinstance(mutations, tuple) and len(mutations) == 3:
|
|
174
193
|
mutations = [mutations]
|
|
175
194
|
elif not isinstance(mutations, list):
|
|
176
|
-
raise TypeError("mutations must be a tuple or list of tuples")
|
|
177
|
-
|
|
178
|
-
# Left-normalize and bucket
|
|
195
|
+
raise TypeError("`mutations` must be a tuple or list of tuples")
|
|
196
|
+
|
|
197
|
+
# # Left-normalize and bucket
|
|
198
|
+
# subs, ins, dels = [], [], []
|
|
199
|
+
# for pos, ref, alt in mutations:
|
|
200
|
+
# while ref and alt and ref[0] == alt[0]:
|
|
201
|
+
# pos += 1
|
|
202
|
+
# ref = ref[1:] or '-'
|
|
203
|
+
# alt = alt[1:] or '-'
|
|
204
|
+
# if ref != '-' and alt != '-':
|
|
205
|
+
# subs.append((pos, ref, alt))
|
|
206
|
+
# elif ref == '-' and alt != '-' and not only_snps:
|
|
207
|
+
# ins.append((pos, alt))
|
|
208
|
+
# elif alt == '-' and ref != '-' and not only_snps:
|
|
209
|
+
# dels.append((pos, ref))
|
|
210
|
+
# else:
|
|
211
|
+
# raise ValueError(f"Unsupported mutation {pos}:{ref}:{alt}.")
|
|
212
|
+
# Bucket mutations
|
|
179
213
|
subs, ins, dels = [], [], []
|
|
180
|
-
for
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
ins.append((pos, alt))
|
|
189
|
-
elif alt == '-' and ref != '-' and not only_snps:
|
|
190
|
-
dels.append((pos, ref))
|
|
191
|
-
else:
|
|
192
|
-
raise ValueError(f"Unsupported mutation {pos}:{ref}:{alt}.")
|
|
214
|
+
for p, r, a in mutations:
|
|
215
|
+
# left-normalize
|
|
216
|
+
while r and a and r[0] == a[0]:
|
|
217
|
+
p += 1; r = r[1:] or '-'; a = a[1:] or '-'
|
|
218
|
+
if r != '-' and a != '-': subs.append((p, r, a))
|
|
219
|
+
elif r == '-' and a != '-' and not only_snps: ins.append((p, a))
|
|
220
|
+
elif a == '-' and r != '-' and not only_snps: dels.append((p, r))
|
|
221
|
+
else: raise ValueError(f"Unsupported mutation {p}:{r}:{a}")
|
|
193
222
|
|
|
194
223
|
# Ensure seq_array indices sorted
|
|
195
224
|
coords = self.seq_array['index']
|
|
@@ -37,7 +37,7 @@ geney/translation_initiation/tis_utils.py,sha256=AF3siFjuQH-Rs44EV-80zHdbxRMvN4w
|
|
|
37
37
|
geney/translation_initiation/resources/kozak_pssm.json,sha256=pcd0Olziutq-6H3mFWDCD9cujQ_AlZO-iiOvBl82hqE,1165
|
|
38
38
|
geney/translation_initiation/resources/tis_regressor_model.joblib,sha256=IXb4DUDhJ5rBDKcqMk9zE3ECTZZcdj7Jixz3KpoZ7OA,2592025
|
|
39
39
|
geney/utils/Fasta_segment.py,sha256=weB5NJ65P0XiyAJCiCHx4T9sHC1pWLpuQeOy0B85gyg,11364
|
|
40
|
-
geney/utils/SeqMats.py,sha256=
|
|
40
|
+
geney/utils/SeqMats.py,sha256=4NJMXNDw6XQAaKVpNuEIft1Xa1sSxPSFwnIeMzjI3eE,17058
|
|
41
41
|
geney/utils/SeqMatsOld.py,sha256=syRU5DAuTh3xUfGW_qP9wlcBO5pHsG_y5PlrfXTIxUY,18502
|
|
42
42
|
geney/utils/TranscriptLibrary.py,sha256=ma_ZVPgglxXDDneEvdqxxeqxG8eSFL-zgLUXyC6BqY8,2070
|
|
43
43
|
geney/utils/__init__.py,sha256=-nJ-DMx1JzP-ZCe_QuQCeM0ZYIT_16jxoXDhUaO_4Oc,714
|
|
@@ -46,7 +46,7 @@ geney/utils/pangolin_utils.py,sha256=JQSPbWxdzqGFYfWQktkfLMaMSGR28eGQhNzO7MLMe5M
|
|
|
46
46
|
geney/utils/spliceai_utils.py,sha256=VtrIbjyQxk_3lw86eWjftRYyal9OzxArJ0GV5u_ymTg,2721
|
|
47
47
|
geney/utils/splicing_utils.py,sha256=vPCGnCPR1ooEZEHR79yFHLmRQXEJHXEQjjxpBR-YWOs,20635
|
|
48
48
|
geney/utils/utils.py,sha256=m51Vd0cEbrcIHo6_8BAuI9YSPcKRs22e5LfVd2Qj6Is,2181
|
|
49
|
-
geney-1.4.
|
|
50
|
-
geney-1.4.
|
|
51
|
-
geney-1.4.
|
|
52
|
-
geney-1.4.
|
|
49
|
+
geney-1.4.23.dist-info/METADATA,sha256=cRWawSdfae-X2F-k7AFedHrQd_OhD2zBLjkA2zzNLrs,990
|
|
50
|
+
geney-1.4.23.dist-info/WHEEL,sha256=AHX6tWk3qWuce7vKLrj7lnulVHEdWoltgauo8bgCXgU,109
|
|
51
|
+
geney-1.4.23.dist-info/top_level.txt,sha256=O-FuNUMb5fn9dhZ-dYCgF0aZtfi1EslMstnzhc5IIVo,6
|
|
52
|
+
geney-1.4.23.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|