seqmat 1.2.0__tar.gz → 1.2.2__tar.gz
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.
- {seqmat-1.2.0/seqmat.egg-info → seqmat-1.2.2}/PKG-INFO +1 -1
- {seqmat-1.2.0 → seqmat-1.2.2}/seqmat/__init__.py +1 -1
- {seqmat-1.2.0 → seqmat-1.2.2}/seqmat/seqmat.py +48 -50
- {seqmat-1.2.0 → seqmat-1.2.2}/seqmat/transcript.py +3 -16
- {seqmat-1.2.0 → seqmat-1.2.2/seqmat.egg-info}/PKG-INFO +1 -1
- {seqmat-1.2.0 → seqmat-1.2.2}/setup.py +1 -1
- {seqmat-1.2.0 → seqmat-1.2.2}/LICENSE +0 -0
- {seqmat-1.2.0 → seqmat-1.2.2}/MANIFEST.in +0 -0
- {seqmat-1.2.0 → seqmat-1.2.2}/README.md +0 -0
- {seqmat-1.2.0 → seqmat-1.2.2}/examples/basic_usage.py +0 -0
- {seqmat-1.2.0 → seqmat-1.2.2}/examples/data_inspection.py +0 -0
- {seqmat-1.2.0 → seqmat-1.2.2}/requirements.txt +0 -0
- {seqmat-1.2.0 → seqmat-1.2.2}/seqmat/cli.py +0 -0
- {seqmat-1.2.0 → seqmat-1.2.2}/seqmat/config.py +0 -0
- {seqmat-1.2.0 → seqmat-1.2.2}/seqmat/gene.py +0 -0
- {seqmat-1.2.0 → seqmat-1.2.2}/seqmat/lmdb_store.py +0 -0
- {seqmat-1.2.0 → seqmat-1.2.2}/seqmat/sqlite_store.py +0 -0
- {seqmat-1.2.0 → seqmat-1.2.2}/seqmat/utils.py +0 -0
- {seqmat-1.2.0 → seqmat-1.2.2}/seqmat.egg-info/SOURCES.txt +0 -0
- {seqmat-1.2.0 → seqmat-1.2.2}/seqmat.egg-info/dependency_links.txt +0 -0
- {seqmat-1.2.0 → seqmat-1.2.2}/seqmat.egg-info/entry_points.txt +0 -0
- {seqmat-1.2.0 → seqmat-1.2.2}/seqmat.egg-info/requires.txt +0 -0
- {seqmat-1.2.0 → seqmat-1.2.2}/seqmat.egg-info/top_level.txt +0 -0
- {seqmat-1.2.0 → seqmat-1.2.2}/setup.cfg +0 -0
- {seqmat-1.2.0 → seqmat-1.2.2}/tests/__init__.py +0 -0
- {seqmat-1.2.0 → seqmat-1.2.2}/tests/bench_gene_creation.py +0 -0
- {seqmat-1.2.0 → seqmat-1.2.2}/tests/test_gene.py +0 -0
- {seqmat-1.2.0 → seqmat-1.2.2}/tests/test_seqmat.py +0 -0
|
@@ -18,6 +18,13 @@ from .config import get_organism_config
|
|
|
18
18
|
|
|
19
19
|
Mutation = Tuple[int, str, str]
|
|
20
20
|
|
|
21
|
+
# Byte lookup table for complement: A<->T, C<->G, everything else identity
|
|
22
|
+
_COMPLEMENT_LUT = np.arange(256, dtype=np.uint8)
|
|
23
|
+
_COMPLEMENT_LUT[ord('A')] = ord('T')
|
|
24
|
+
_COMPLEMENT_LUT[ord('T')] = ord('A')
|
|
25
|
+
_COMPLEMENT_LUT[ord('C')] = ord('G')
|
|
26
|
+
_COMPLEMENT_LUT[ord('G')] = ord('C')
|
|
27
|
+
|
|
21
28
|
|
|
22
29
|
@lru_cache(maxsize=8)
|
|
23
30
|
def _fetch_fasta_region(fasta_path: str, chrom: str, start: int, end: int) -> str:
|
|
@@ -78,9 +85,9 @@ class SeqMat:
|
|
|
78
85
|
|
|
79
86
|
# Prepare sequence
|
|
80
87
|
if isinstance(nucleotides, str):
|
|
81
|
-
nts = np.
|
|
88
|
+
nts = np.frombuffer(nucleotides.encode('ascii'), dtype='S1')
|
|
82
89
|
else:
|
|
83
|
-
nts = np.
|
|
90
|
+
nts = np.asarray(nucleotides, dtype='S1')
|
|
84
91
|
L = len(nts)
|
|
85
92
|
|
|
86
93
|
# Indices default to 1-based
|
|
@@ -125,7 +132,6 @@ class SeqMat:
|
|
|
125
132
|
arr['mut_type'] = b''
|
|
126
133
|
arr['valid'] = arr['nt'] != b'-'
|
|
127
134
|
self.seq_array = arr
|
|
128
|
-
self._refresh_mutation_state()
|
|
129
135
|
|
|
130
136
|
@classmethod
|
|
131
137
|
def from_fasta(
|
|
@@ -281,8 +287,9 @@ class SeqMat:
|
|
|
281
287
|
new.mutations = copy.deepcopy(self.mutations)
|
|
282
288
|
new.mutated_positions = set(self.mutated_positions)
|
|
283
289
|
if start is not None or end is not None:
|
|
284
|
-
lo = start
|
|
285
|
-
hi = end
|
|
290
|
+
lo = start if start is not None else self.index.min()
|
|
291
|
+
hi = end if end is not None else self.index.max()
|
|
292
|
+
lo, hi = min(lo, hi), max(lo, hi)
|
|
286
293
|
mask = (self.seq_array['index'] >= lo) & (self.seq_array['index'] <= hi)
|
|
287
294
|
new.seq_array = self.seq_array[mask].copy()
|
|
288
295
|
new._cow = False
|
|
@@ -489,77 +496,51 @@ class SeqMat:
|
|
|
489
496
|
self.seq_array['valid'][mask] = False
|
|
490
497
|
self.seq_array['mut_type'][mask] = b'del'
|
|
491
498
|
|
|
499
|
+
@staticmethod
|
|
500
|
+
def _complement_nt(nt_field: np.ndarray) -> np.ndarray:
|
|
501
|
+
"""Complement nucleotide bytes via single-pass LUT (A<->T, C<->G)."""
|
|
502
|
+
return _COMPLEMENT_LUT[nt_field.view(np.uint8)].view('S1')
|
|
503
|
+
|
|
492
504
|
def complement(self, copy: bool = False) -> SeqMat:
|
|
493
505
|
"""
|
|
494
506
|
Complement the sequence (A<->T, C<->G) in-place or return a copy.
|
|
495
|
-
|
|
507
|
+
|
|
496
508
|
Args:
|
|
497
509
|
copy: If True, return a new SeqMat object instead of modifying in-place
|
|
498
|
-
|
|
510
|
+
|
|
499
511
|
Returns:
|
|
500
512
|
Self (for chaining) or new SeqMat if copy=True
|
|
501
513
|
"""
|
|
502
514
|
if copy:
|
|
503
515
|
new = self.clone()
|
|
504
516
|
new._ensure_writable()
|
|
505
|
-
|
|
506
|
-
temp_array = new.seq_array['nt'].copy()
|
|
507
|
-
temp_array[new.seq_array['nt'] == b'A'] = b'T'
|
|
508
|
-
temp_array[new.seq_array['nt'] == b'T'] = b'A'
|
|
509
|
-
temp_array[new.seq_array['nt'] == b'C'] = b'G'
|
|
510
|
-
temp_array[new.seq_array['nt'] == b'G'] = b'C'
|
|
511
|
-
# N and - stay the same
|
|
512
|
-
new.seq_array['nt'] = temp_array
|
|
517
|
+
new.seq_array['nt'] = self._complement_nt(new.seq_array['nt'])
|
|
513
518
|
return new
|
|
514
519
|
else:
|
|
515
|
-
# In-place modification
|
|
516
520
|
self._ensure_writable()
|
|
517
|
-
|
|
518
|
-
temp_array[self.seq_array['nt'] == b'A'] = b'T'
|
|
519
|
-
temp_array[self.seq_array['nt'] == b'T'] = b'A'
|
|
520
|
-
temp_array[self.seq_array['nt'] == b'C'] = b'G'
|
|
521
|
-
temp_array[self.seq_array['nt'] == b'G'] = b'C'
|
|
522
|
-
# N and - stay the same
|
|
523
|
-
self.seq_array['nt'] = temp_array
|
|
521
|
+
self.seq_array['nt'] = self._complement_nt(self.seq_array['nt'])
|
|
524
522
|
return self
|
|
525
523
|
|
|
526
524
|
def reverse_complement(self, copy: bool = False) -> SeqMat:
|
|
527
525
|
"""
|
|
528
526
|
Reverse-complement the sequence in-place or return a copy.
|
|
529
|
-
|
|
527
|
+
|
|
530
528
|
Args:
|
|
531
529
|
copy: If True, return a new SeqMat object instead of modifying in-place
|
|
532
|
-
|
|
530
|
+
|
|
533
531
|
Returns:
|
|
534
532
|
Self (for chaining) or new SeqMat if copy=True
|
|
535
533
|
"""
|
|
536
534
|
if copy:
|
|
537
535
|
new = self.clone()
|
|
538
536
|
new._ensure_writable()
|
|
539
|
-
|
|
540
|
-
temp_array = new.seq_array['nt'].copy()
|
|
541
|
-
temp_array[new.seq_array['nt'] == b'A'] = b'T'
|
|
542
|
-
temp_array[new.seq_array['nt'] == b'T'] = b'A'
|
|
543
|
-
temp_array[new.seq_array['nt'] == b'C'] = b'G'
|
|
544
|
-
temp_array[new.seq_array['nt'] == b'G'] = b'C'
|
|
545
|
-
new.seq_array['nt'] = temp_array
|
|
546
|
-
|
|
547
|
-
# Reverse the sequence
|
|
537
|
+
new.seq_array['nt'] = self._complement_nt(new.seq_array['nt'])
|
|
548
538
|
new.seq_array = new.seq_array[::-1].copy()
|
|
549
539
|
new.rev = not new.rev
|
|
550
540
|
return new
|
|
551
541
|
else:
|
|
552
|
-
# In-place modification
|
|
553
542
|
self._ensure_writable()
|
|
554
|
-
|
|
555
|
-
temp_array = self.seq_array['nt'].copy()
|
|
556
|
-
temp_array[self.seq_array['nt'] == b'A'] = b'T'
|
|
557
|
-
temp_array[self.seq_array['nt'] == b'T'] = b'A'
|
|
558
|
-
temp_array[self.seq_array['nt'] == b'C'] = b'G'
|
|
559
|
-
temp_array[self.seq_array['nt'] == b'G'] = b'C'
|
|
560
|
-
self.seq_array['nt'] = temp_array
|
|
561
|
-
|
|
562
|
-
# Reverse the sequence
|
|
543
|
+
self.seq_array['nt'] = self._complement_nt(self.seq_array['nt'])
|
|
563
544
|
self.seq_array = self.seq_array[::-1].copy()
|
|
564
545
|
self.rev = not self.rev
|
|
565
546
|
return self
|
|
@@ -567,19 +548,36 @@ class SeqMat:
|
|
|
567
548
|
def remove_regions(self, regions: List[Tuple[int, int]]) -> SeqMat:
|
|
568
549
|
"""
|
|
569
550
|
Excise given genomic intervals (inclusive).
|
|
570
|
-
|
|
551
|
+
|
|
571
552
|
Args:
|
|
572
553
|
regions: List of (start, end) tuples to remove
|
|
573
|
-
|
|
554
|
+
|
|
574
555
|
Returns:
|
|
575
556
|
New SeqMat with regions removed
|
|
576
557
|
"""
|
|
577
558
|
new = self.clone()
|
|
578
|
-
|
|
559
|
+
indices = new.seq_array['index']
|
|
560
|
+
n = len(indices)
|
|
561
|
+
remove = np.zeros(n, dtype=bool)
|
|
562
|
+
|
|
563
|
+
# Detect monotonic order for searchsorted fast path
|
|
564
|
+
ascending = n < 2 or indices[0] <= indices[-1]
|
|
565
|
+
if ascending:
|
|
566
|
+
sorted_idx = indices
|
|
567
|
+
else:
|
|
568
|
+
sorted_idx = indices[::-1] # view, no copy
|
|
569
|
+
|
|
579
570
|
for lo, hi in regions:
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
571
|
+
lo, hi = min(lo, hi), max(lo, hi)
|
|
572
|
+
i = np.searchsorted(sorted_idx, lo)
|
|
573
|
+
j = np.searchsorted(sorted_idx, hi, side='right')
|
|
574
|
+
if ascending:
|
|
575
|
+
remove[i:j] = True
|
|
576
|
+
else:
|
|
577
|
+
# Map back to original order
|
|
578
|
+
remove[n - j:n - i] = True
|
|
579
|
+
|
|
580
|
+
new.seq_array = new.seq_array[~remove].copy()
|
|
583
581
|
return new
|
|
584
582
|
|
|
585
583
|
def summary(self) -> str:
|
|
@@ -320,23 +320,10 @@ class Transcript:
|
|
|
320
320
|
print("Cannot create protein without set TIS and TTS values.")
|
|
321
321
|
return self
|
|
322
322
|
|
|
323
|
-
# Extract ORF region from mature mRNA
|
|
323
|
+
# Extract ORF region from mature mRNA via clone (no string re-parse)
|
|
324
324
|
if hasattr(self, 'mature_mrna') and self.mature_mrna is not None:
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
orf_end_idx = np.where(self.mature_mrna.index == self.TTS)[0]
|
|
328
|
-
|
|
329
|
-
if len(orf_start_idx) > 0 and len(orf_end_idx) > 0:
|
|
330
|
-
# Extract the subsequence using the found indices
|
|
331
|
-
start_idx = orf_start_idx[0]
|
|
332
|
-
end_idx = orf_end_idx[0] + 1 # +1 for inclusive end
|
|
333
|
-
|
|
334
|
-
# Create new SeqMat with the ORF sequence
|
|
335
|
-
orf_seq = self.mature_mrna.seq[start_idx:end_idx]
|
|
336
|
-
orf_indices = self.mature_mrna.index[start_idx:end_idx]
|
|
337
|
-
|
|
338
|
-
return SeqMat(orf_seq, indices=orf_indices)
|
|
339
|
-
|
|
325
|
+
return self.mature_mrna.clone(self.TIS, self.TTS)
|
|
326
|
+
|
|
340
327
|
return self
|
|
341
328
|
|
|
342
329
|
def generate_protein(self, inplace: bool = True) -> Union['Transcript', str]:
|
|
@@ -8,7 +8,7 @@ long_description = (this_directory / "README.md").read_text()
|
|
|
8
8
|
|
|
9
9
|
setup(
|
|
10
10
|
name="seqmat",
|
|
11
|
-
version="1.2.
|
|
11
|
+
version="1.2.2",
|
|
12
12
|
author="Nicolas Lynn Vila",
|
|
13
13
|
author_email="nicolasalynn@gmail.com",
|
|
14
14
|
description="Lightning-fast gene manipulation and analysis library.",
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|