seqmat 1.2.0__tar.gz → 1.2.1__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.1}/PKG-INFO +1 -1
- {seqmat-1.2.0 → seqmat-1.2.1}/seqmat/__init__.py +1 -1
- {seqmat-1.2.0 → seqmat-1.2.1}/seqmat/seqmat.py +45 -48
- {seqmat-1.2.0 → seqmat-1.2.1}/seqmat/transcript.py +3 -16
- {seqmat-1.2.0 → seqmat-1.2.1/seqmat.egg-info}/PKG-INFO +1 -1
- {seqmat-1.2.0 → seqmat-1.2.1}/setup.py +1 -1
- {seqmat-1.2.0 → seqmat-1.2.1}/LICENSE +0 -0
- {seqmat-1.2.0 → seqmat-1.2.1}/MANIFEST.in +0 -0
- {seqmat-1.2.0 → seqmat-1.2.1}/README.md +0 -0
- {seqmat-1.2.0 → seqmat-1.2.1}/examples/basic_usage.py +0 -0
- {seqmat-1.2.0 → seqmat-1.2.1}/examples/data_inspection.py +0 -0
- {seqmat-1.2.0 → seqmat-1.2.1}/requirements.txt +0 -0
- {seqmat-1.2.0 → seqmat-1.2.1}/seqmat/cli.py +0 -0
- {seqmat-1.2.0 → seqmat-1.2.1}/seqmat/config.py +0 -0
- {seqmat-1.2.0 → seqmat-1.2.1}/seqmat/gene.py +0 -0
- {seqmat-1.2.0 → seqmat-1.2.1}/seqmat/lmdb_store.py +0 -0
- {seqmat-1.2.0 → seqmat-1.2.1}/seqmat/sqlite_store.py +0 -0
- {seqmat-1.2.0 → seqmat-1.2.1}/seqmat/utils.py +0 -0
- {seqmat-1.2.0 → seqmat-1.2.1}/seqmat.egg-info/SOURCES.txt +0 -0
- {seqmat-1.2.0 → seqmat-1.2.1}/seqmat.egg-info/dependency_links.txt +0 -0
- {seqmat-1.2.0 → seqmat-1.2.1}/seqmat.egg-info/entry_points.txt +0 -0
- {seqmat-1.2.0 → seqmat-1.2.1}/seqmat.egg-info/requires.txt +0 -0
- {seqmat-1.2.0 → seqmat-1.2.1}/seqmat.egg-info/top_level.txt +0 -0
- {seqmat-1.2.0 → seqmat-1.2.1}/setup.cfg +0 -0
- {seqmat-1.2.0 → seqmat-1.2.1}/tests/__init__.py +0 -0
- {seqmat-1.2.0 → seqmat-1.2.1}/tests/bench_gene_creation.py +0 -0
- {seqmat-1.2.0 → seqmat-1.2.1}/tests/test_gene.py +0 -0
- {seqmat-1.2.0 → seqmat-1.2.1}/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(
|
|
@@ -489,77 +495,51 @@ class SeqMat:
|
|
|
489
495
|
self.seq_array['valid'][mask] = False
|
|
490
496
|
self.seq_array['mut_type'][mask] = b'del'
|
|
491
497
|
|
|
498
|
+
@staticmethod
|
|
499
|
+
def _complement_nt(nt_field: np.ndarray) -> np.ndarray:
|
|
500
|
+
"""Complement nucleotide bytes via single-pass LUT (A<->T, C<->G)."""
|
|
501
|
+
return _COMPLEMENT_LUT[nt_field.view(np.uint8)].view('S1')
|
|
502
|
+
|
|
492
503
|
def complement(self, copy: bool = False) -> SeqMat:
|
|
493
504
|
"""
|
|
494
505
|
Complement the sequence (A<->T, C<->G) in-place or return a copy.
|
|
495
|
-
|
|
506
|
+
|
|
496
507
|
Args:
|
|
497
508
|
copy: If True, return a new SeqMat object instead of modifying in-place
|
|
498
|
-
|
|
509
|
+
|
|
499
510
|
Returns:
|
|
500
511
|
Self (for chaining) or new SeqMat if copy=True
|
|
501
512
|
"""
|
|
502
513
|
if copy:
|
|
503
514
|
new = self.clone()
|
|
504
515
|
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
|
|
516
|
+
new.seq_array['nt'] = self._complement_nt(new.seq_array['nt'])
|
|
513
517
|
return new
|
|
514
518
|
else:
|
|
515
|
-
# In-place modification
|
|
516
519
|
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
|
|
520
|
+
self.seq_array['nt'] = self._complement_nt(self.seq_array['nt'])
|
|
524
521
|
return self
|
|
525
522
|
|
|
526
523
|
def reverse_complement(self, copy: bool = False) -> SeqMat:
|
|
527
524
|
"""
|
|
528
525
|
Reverse-complement the sequence in-place or return a copy.
|
|
529
|
-
|
|
526
|
+
|
|
530
527
|
Args:
|
|
531
528
|
copy: If True, return a new SeqMat object instead of modifying in-place
|
|
532
|
-
|
|
529
|
+
|
|
533
530
|
Returns:
|
|
534
531
|
Self (for chaining) or new SeqMat if copy=True
|
|
535
532
|
"""
|
|
536
533
|
if copy:
|
|
537
534
|
new = self.clone()
|
|
538
535
|
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
|
|
536
|
+
new.seq_array['nt'] = self._complement_nt(new.seq_array['nt'])
|
|
548
537
|
new.seq_array = new.seq_array[::-1].copy()
|
|
549
538
|
new.rev = not new.rev
|
|
550
539
|
return new
|
|
551
540
|
else:
|
|
552
|
-
# In-place modification
|
|
553
541
|
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
|
|
542
|
+
self.seq_array['nt'] = self._complement_nt(self.seq_array['nt'])
|
|
563
543
|
self.seq_array = self.seq_array[::-1].copy()
|
|
564
544
|
self.rev = not self.rev
|
|
565
545
|
return self
|
|
@@ -567,19 +547,36 @@ class SeqMat:
|
|
|
567
547
|
def remove_regions(self, regions: List[Tuple[int, int]]) -> SeqMat:
|
|
568
548
|
"""
|
|
569
549
|
Excise given genomic intervals (inclusive).
|
|
570
|
-
|
|
550
|
+
|
|
571
551
|
Args:
|
|
572
552
|
regions: List of (start, end) tuples to remove
|
|
573
|
-
|
|
553
|
+
|
|
574
554
|
Returns:
|
|
575
555
|
New SeqMat with regions removed
|
|
576
556
|
"""
|
|
577
557
|
new = self.clone()
|
|
578
|
-
|
|
558
|
+
indices = new.seq_array['index']
|
|
559
|
+
n = len(indices)
|
|
560
|
+
remove = np.zeros(n, dtype=bool)
|
|
561
|
+
|
|
562
|
+
# Detect monotonic order for searchsorted fast path
|
|
563
|
+
ascending = n < 2 or indices[0] <= indices[-1]
|
|
564
|
+
if ascending:
|
|
565
|
+
sorted_idx = indices
|
|
566
|
+
else:
|
|
567
|
+
sorted_idx = indices[::-1] # view, no copy
|
|
568
|
+
|
|
579
569
|
for lo, hi in regions:
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
570
|
+
lo, hi = min(lo, hi), max(lo, hi)
|
|
571
|
+
i = np.searchsorted(sorted_idx, lo)
|
|
572
|
+
j = np.searchsorted(sorted_idx, hi, side='right')
|
|
573
|
+
if ascending:
|
|
574
|
+
remove[i:j] = True
|
|
575
|
+
else:
|
|
576
|
+
# Map back to original order
|
|
577
|
+
remove[n - j:n - i] = True
|
|
578
|
+
|
|
579
|
+
new.seq_array = new.seq_array[~remove].copy()
|
|
583
580
|
return new
|
|
584
581
|
|
|
585
582
|
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.1",
|
|
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
|