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.
Files changed (28) hide show
  1. {seqmat-1.2.0/seqmat.egg-info → seqmat-1.2.1}/PKG-INFO +1 -1
  2. {seqmat-1.2.0 → seqmat-1.2.1}/seqmat/__init__.py +1 -1
  3. {seqmat-1.2.0 → seqmat-1.2.1}/seqmat/seqmat.py +45 -48
  4. {seqmat-1.2.0 → seqmat-1.2.1}/seqmat/transcript.py +3 -16
  5. {seqmat-1.2.0 → seqmat-1.2.1/seqmat.egg-info}/PKG-INFO +1 -1
  6. {seqmat-1.2.0 → seqmat-1.2.1}/setup.py +1 -1
  7. {seqmat-1.2.0 → seqmat-1.2.1}/LICENSE +0 -0
  8. {seqmat-1.2.0 → seqmat-1.2.1}/MANIFEST.in +0 -0
  9. {seqmat-1.2.0 → seqmat-1.2.1}/README.md +0 -0
  10. {seqmat-1.2.0 → seqmat-1.2.1}/examples/basic_usage.py +0 -0
  11. {seqmat-1.2.0 → seqmat-1.2.1}/examples/data_inspection.py +0 -0
  12. {seqmat-1.2.0 → seqmat-1.2.1}/requirements.txt +0 -0
  13. {seqmat-1.2.0 → seqmat-1.2.1}/seqmat/cli.py +0 -0
  14. {seqmat-1.2.0 → seqmat-1.2.1}/seqmat/config.py +0 -0
  15. {seqmat-1.2.0 → seqmat-1.2.1}/seqmat/gene.py +0 -0
  16. {seqmat-1.2.0 → seqmat-1.2.1}/seqmat/lmdb_store.py +0 -0
  17. {seqmat-1.2.0 → seqmat-1.2.1}/seqmat/sqlite_store.py +0 -0
  18. {seqmat-1.2.0 → seqmat-1.2.1}/seqmat/utils.py +0 -0
  19. {seqmat-1.2.0 → seqmat-1.2.1}/seqmat.egg-info/SOURCES.txt +0 -0
  20. {seqmat-1.2.0 → seqmat-1.2.1}/seqmat.egg-info/dependency_links.txt +0 -0
  21. {seqmat-1.2.0 → seqmat-1.2.1}/seqmat.egg-info/entry_points.txt +0 -0
  22. {seqmat-1.2.0 → seqmat-1.2.1}/seqmat.egg-info/requires.txt +0 -0
  23. {seqmat-1.2.0 → seqmat-1.2.1}/seqmat.egg-info/top_level.txt +0 -0
  24. {seqmat-1.2.0 → seqmat-1.2.1}/setup.cfg +0 -0
  25. {seqmat-1.2.0 → seqmat-1.2.1}/tests/__init__.py +0 -0
  26. {seqmat-1.2.0 → seqmat-1.2.1}/tests/bench_gene_creation.py +0 -0
  27. {seqmat-1.2.0 → seqmat-1.2.1}/tests/test_gene.py +0 -0
  28. {seqmat-1.2.0 → seqmat-1.2.1}/tests/test_seqmat.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: seqmat
3
- Version: 1.2.0
3
+ Version: 1.2.1
4
4
  Summary: Lightning-fast gene manipulation and analysis library.
5
5
  Home-page: https://github.com/nicolasalynn/seqmat
6
6
  Author: Nicolas Lynn Vila
@@ -5,7 +5,7 @@ A comprehensive Python library for genomic sequence analysis with full mutation
5
5
  splicing analysis, and sequence manipulation.
6
6
  """
7
7
 
8
- __version__ = "1.2.0"
8
+ __version__ = "1.2.1"
9
9
  __author__ = "Nicolas Lynn Vila"
10
10
  __email__ = "nicolasalynn@gmail.com"
11
11
 
@@ -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.array(list(nucleotides), dtype='S1')
88
+ nts = np.frombuffer(nucleotides.encode('ascii'), dtype='S1')
82
89
  else:
83
- nts = np.array(nucleotides, dtype='S1')
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
- # Use a temporary placeholder to avoid double replacement
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
- temp_array = self.seq_array['nt'].copy()
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
- # Apply complement mapping using temporary array
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
- # Apply complement mapping in place using temporary array
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
- mask = np.ones(len(new.seq_array), bool)
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
- mask &= ~((new.seq_array['index'] >= min(lo, hi)) &
581
- (new.seq_array['index'] <= max(lo, hi)))
582
- new.seq_array = new.seq_array[mask].copy()
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
- # Find the positions in the mature mRNA
326
- orf_start_idx = np.where(self.mature_mrna.index == self.TIS)[0]
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]:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: seqmat
3
- Version: 1.2.0
3
+ Version: 1.2.1
4
4
  Summary: Lightning-fast gene manipulation and analysis library.
5
5
  Home-page: https://github.com/nicolasalynn/seqmat
6
6
  Author: Nicolas Lynn Vila
@@ -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.0",
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