seqmat 0.1.51__tar.gz → 0.1.53__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-0.1.51/seqmat.egg-info → seqmat-0.1.53}/PKG-INFO +2 -3
  2. seqmat-0.1.53/requirements.txt +9 -0
  3. {seqmat-0.1.51 → seqmat-0.1.53}/seqmat/__init__.py +1 -1
  4. {seqmat-0.1.51 → seqmat-0.1.53}/seqmat/seqmat.py +5 -3
  5. {seqmat-0.1.51 → seqmat-0.1.53}/seqmat/utils.py +56 -14
  6. {seqmat-0.1.51 → seqmat-0.1.53/seqmat.egg-info}/PKG-INFO +2 -3
  7. {seqmat-0.1.51 → seqmat-0.1.53}/seqmat.egg-info/requires.txt +1 -2
  8. {seqmat-0.1.51 → seqmat-0.1.53}/setup.py +3 -4
  9. seqmat-0.1.51/requirements.txt +0 -9
  10. {seqmat-0.1.51 → seqmat-0.1.53}/LICENSE +0 -0
  11. {seqmat-0.1.51 → seqmat-0.1.53}/MANIFEST.in +0 -0
  12. {seqmat-0.1.51 → seqmat-0.1.53}/README.md +0 -0
  13. {seqmat-0.1.51 → seqmat-0.1.53}/examples/basic_usage.py +0 -0
  14. {seqmat-0.1.51 → seqmat-0.1.53}/examples/data_inspection.py +0 -0
  15. {seqmat-0.1.51 → seqmat-0.1.53}/seqmat/cli.py +0 -0
  16. {seqmat-0.1.51 → seqmat-0.1.53}/seqmat/config.py +0 -0
  17. {seqmat-0.1.51 → seqmat-0.1.53}/seqmat/gene.py +0 -0
  18. {seqmat-0.1.51 → seqmat-0.1.53}/seqmat/lmdb_store.py +0 -0
  19. {seqmat-0.1.51 → seqmat-0.1.53}/seqmat/sqlite_store.py +0 -0
  20. {seqmat-0.1.51 → seqmat-0.1.53}/seqmat/transcript.py +0 -0
  21. {seqmat-0.1.51 → seqmat-0.1.53}/seqmat.egg-info/SOURCES.txt +0 -0
  22. {seqmat-0.1.51 → seqmat-0.1.53}/seqmat.egg-info/dependency_links.txt +0 -0
  23. {seqmat-0.1.51 → seqmat-0.1.53}/seqmat.egg-info/entry_points.txt +0 -0
  24. {seqmat-0.1.51 → seqmat-0.1.53}/seqmat.egg-info/top_level.txt +0 -0
  25. {seqmat-0.1.51 → seqmat-0.1.53}/setup.cfg +0 -0
  26. {seqmat-0.1.51 → seqmat-0.1.53}/tests/__init__.py +0 -0
  27. {seqmat-0.1.51 → seqmat-0.1.53}/tests/test_gene.py +0 -0
  28. {seqmat-0.1.51 → seqmat-0.1.53}/tests/test_seqmat.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: seqmat
3
- Version: 0.1.51
3
+ Version: 0.1.53
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
@@ -18,12 +18,11 @@ Description-Content-Type: text/markdown
18
18
  License-File: LICENSE
19
19
  Requires-Dist: numpy<3,>=1.20.0
20
20
  Requires-Dist: pandas<3,>=2.2.0
21
- Requires-Dist: pyarrow>=14.0.0
21
+ Requires-Dist: pyarrow>=15.0.0
22
22
  Requires-Dist: pysam>=0.19.0
23
23
  Requires-Dist: requests>=2.26.0
24
24
  Requires-Dist: tqdm>=4.62.0
25
25
  Requires-Dist: biopython>=1.79
26
- Requires-Dist: gtfparse>=1.2.0
27
26
  Requires-Dist: platformdirs>=3.0.0
28
27
  Provides-Extra: lmdb
29
28
  Requires-Dist: lmdb>=1.4.0; extra == "lmdb"
@@ -0,0 +1,9 @@
1
+ # NumPy 2 and pandas 2.x supported; pyarrow>=15 works with NumPy 2 (gtfparse removed)
2
+ numpy>=1.20.0,<3
3
+ pandas>=2.2.0,<3
4
+ pyarrow>=15.0.0
5
+ pysam>=0.19.0
6
+ requests>=2.26.0
7
+ tqdm>=4.62.0
8
+ biopython>=1.79
9
+ platformdirs>=3.0.0
@@ -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__ = "0.1.51"
8
+ __version__ = "0.1.53"
9
9
  __author__ = "Nicolas Lynn Vila"
10
10
  __email__ = "nicolasalynn@gmail.com"
11
11
 
@@ -5,12 +5,14 @@ import copy
5
5
  from collections import defaultdict
6
6
  from dataclasses import dataclass, field
7
7
  from pathlib import Path
8
- from typing import Any, Dict, List, Optional, Tuple, Union
8
+ from typing import TYPE_CHECKING, Any, Dict, List, Optional, Tuple, Union
9
9
 
10
10
  import numpy as np
11
- import pandas as pd
12
11
  import pysam
13
12
 
13
+ if TYPE_CHECKING:
14
+ import pandas as pd
15
+
14
16
  from .config import get_organism_config
15
17
 
16
18
  Mutation = Tuple[int, str, str]
@@ -37,7 +39,7 @@ class SeqMat:
37
39
  mutations: List[Dict[str, Any]] = field(default_factory=list, init=False, repr=False)
38
40
  mutated_positions: set[int] = field(default_factory=set, init=False, repr=False)
39
41
  rev: bool = field(default=False, init=False, repr=False)
40
- predicted_splicing: Optional[pd.DataFrame] = field(default=None, init=False, repr=False)
42
+ predicted_splicing: Optional["pd.DataFrame"] = field(default=None, init=False, repr=False)
41
43
 
42
44
  def __init__(
43
45
  self,
@@ -1,23 +1,29 @@
1
1
  """Utility functions for SeqMat package"""
2
+ from __future__ import annotations
3
+
2
4
  import pickle
3
5
  import json
6
+ import re
4
7
  import sqlite3
5
8
  from concurrent.futures import ProcessPoolExecutor, as_completed
6
9
  from multiprocessing import cpu_count
7
10
  import numpy as np
8
11
  from pathlib import Path
9
- from typing import Any, Union, List, Optional, Dict, Tuple
10
- import pandas as pd
12
+ from typing import TYPE_CHECKING, Any, Union, List, Optional, Dict, Tuple
11
13
  from tqdm import tqdm
14
+
15
+ if TYPE_CHECKING:
16
+ import pandas as pd
17
+ else:
18
+ def _get_pd():
19
+ import pandas as pd
20
+ return pd
12
21
  import requests
13
22
  import gzip
14
23
  import shutil
15
24
 
16
- try:
17
- from gtfparse import read_gtf
18
- GTFPARSE_AVAILABLE = True
19
- except ImportError:
20
- GTFPARSE_AVAILABLE = False
25
+ # GTF reading: we use a pandas-based reader so we don't depend on gtfparse (which pins pyarrow<14.1).
26
+ # That allows seqmat to require pyarrow>=15 and NumPy 2.
21
27
 
22
28
  try:
23
29
  import polars as pl
@@ -34,9 +40,48 @@ _GTF_COLS = [
34
40
  ]
35
41
  _FEATURE_FILTER = {'gene', 'transcript', 'exon', 'CDS'}
36
42
 
43
+ _GTF_FIXED_COLS = ['seqname', 'source', 'feature', 'start', 'end', 'score', 'strand', 'frame', 'attributes']
44
+ _GTF_ATTR_KEYS = ['gene_id', 'transcript_id', 'gene_name', 'gene_biotype', 'transcript_biotype', 'tag', 'protein_id']
45
+
46
+
47
+ def _parse_gtf_attributes(attr_str: str) -> Dict[str, str]:
48
+ """Parse GTF attributes column (key "value"; key2 "value2"; ...) into a dict."""
49
+ out: Dict[str, str] = {}
50
+ if not isinstance(attr_str, str) or not attr_str.strip():
51
+ return out
52
+ for m in re.finditer(r'(\w+)\s+"([^"]*)"', attr_str):
53
+ out[m.group(1)] = m.group(2)
54
+ return out
55
+
56
+
57
+ def _read_gtf_pandas(annotations_file: Union[Path, str]) -> "pd.DataFrame":
58
+ """Read a GTF file into a pandas DataFrame with columns needed for annotation processing.
59
+ Does not require gtfparse, so we can use pyarrow>=15 and NumPy 2.
60
+ """
61
+ pd = _get_pd()
62
+ path = Path(annotations_file)
63
+ df = pd.read_csv(
64
+ path,
65
+ sep='\t',
66
+ comment='#',
67
+ header=None,
68
+ names=_GTF_FIXED_COLS,
69
+ dtype={'seqname': str, 'source': str, 'feature': str, 'strand': str, 'frame': str, 'attributes': str},
70
+ on_bad_lines='warn',
71
+ )
72
+ # Parse attributes into columns
73
+ attr_rows = df['attributes'].map(_parse_gtf_attributes)
74
+ for key in _GTF_ATTR_KEYS:
75
+ df[key] = attr_rows.map(lambda d, k=key: d.get(k, ''))
76
+ df = df.drop(columns=['attributes'])
77
+ df['start'] = pd.to_numeric(df['start'], errors='coerce').astype('Int64')
78
+ df['end'] = pd.to_numeric(df['end'], errors='coerce').astype('Int64')
79
+ return df
80
+
37
81
 
38
82
  def _process_gene_chunk(args: Tuple[Any, Optional[Dict], Any]) -> List[Tuple[str, str, str, bytes]]:
39
83
  """Process a subset of annotations (one chunk by gene_id). Returns list of (gene_name, gene_id, biotype, blob)."""
84
+ pd = _get_pd()
40
85
  chunk_df, cons_data, gtex_df = args
41
86
  if chunk_df.empty:
42
87
  return []
@@ -165,9 +210,10 @@ def download_and_ungzip(external_url: str, local_path: Path, skip_existing: bool
165
210
  return output_file
166
211
 
167
212
 
168
- def process_transcript(transcript_df: pd.DataFrame, rev: bool, chrm: str,
213
+ def process_transcript(transcript_df: "pd.DataFrame", rev: bool, chrm: str,
169
214
  cons_data: Optional[Dict[str, Any]]) -> Optional[Dict[str, Any]]:
170
215
  """Process transcript data from GTF dataframe."""
216
+ pd = _get_pd()
171
217
  if transcript_df.empty:
172
218
  return None
173
219
 
@@ -244,8 +290,7 @@ def retrieve_and_parse_ensembl_annotations(
244
290
  n_jobs: int = 1,
245
291
  ) -> None:
246
292
  """Parse Ensembl GTF annotations and create genes.db. Use n_jobs > 1 to parallelize (faster)."""
247
- if not GTFPARSE_AVAILABLE:
248
- raise ImportError("gtfparse is required for genomics data setup. Install with: pip install seqmat[genomics]")
293
+ pd = _get_pd()
249
294
 
250
295
  # Load GTEx expression data if available
251
296
  if gtex_file and gtex_file.exists():
@@ -257,10 +302,7 @@ def retrieve_and_parse_ensembl_annotations(
257
302
  gtex_df = pd.DataFrame()
258
303
 
259
304
  print("Reading GTF annotations...")
260
- annotations = read_gtf(annotations_file)
261
-
262
- if POLARS_AVAILABLE and hasattr(annotations, '__module__') and 'polars' in annotations.__module__:
263
- annotations = annotations.to_pandas()
305
+ annotations = _read_gtf_pandas(annotations_file)
264
306
 
265
307
  required_columns = ['gene_id', 'gene_biotype', 'seqname', 'strand', 'feature']
266
308
  missing_columns = [col for col in required_columns if col not in annotations.columns]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: seqmat
3
- Version: 0.1.51
3
+ Version: 0.1.53
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
@@ -18,12 +18,11 @@ Description-Content-Type: text/markdown
18
18
  License-File: LICENSE
19
19
  Requires-Dist: numpy<3,>=1.20.0
20
20
  Requires-Dist: pandas<3,>=2.2.0
21
- Requires-Dist: pyarrow>=14.0.0
21
+ Requires-Dist: pyarrow>=15.0.0
22
22
  Requires-Dist: pysam>=0.19.0
23
23
  Requires-Dist: requests>=2.26.0
24
24
  Requires-Dist: tqdm>=4.62.0
25
25
  Requires-Dist: biopython>=1.79
26
- Requires-Dist: gtfparse>=1.2.0
27
26
  Requires-Dist: platformdirs>=3.0.0
28
27
  Provides-Extra: lmdb
29
28
  Requires-Dist: lmdb>=1.4.0; extra == "lmdb"
@@ -1,11 +1,10 @@
1
1
  numpy<3,>=1.20.0
2
2
  pandas<3,>=2.2.0
3
- pyarrow>=14.0.0
3
+ pyarrow>=15.0.0
4
4
  pysam>=0.19.0
5
5
  requests>=2.26.0
6
6
  tqdm>=4.62.0
7
7
  biopython>=1.79
8
- gtfparse>=1.2.0
9
8
  platformdirs>=3.0.0
10
9
 
11
10
  [dev]
@@ -8,7 +8,7 @@ long_description = (this_directory / "README.md").read_text()
8
8
 
9
9
  setup(
10
10
  name="seqmat",
11
- version="0.1.51",
11
+ version="0.1.53",
12
12
  author="Nicolas Lynn Vila",
13
13
  author_email="nicolasalynn@gmail.com",
14
14
  description="Lightning-fast gene manipulation and analysis library.",
@@ -29,13 +29,12 @@ setup(
29
29
  python_requires=">=3.10",
30
30
  install_requires=[
31
31
  "numpy>=1.20.0,<3",
32
- "pandas>=2.2.0,<3", # 2.x: avoid pandas 3 + pyarrow ABI issues with NumPy 2
33
- "pyarrow>=14.0.0", # parquet (for save_seqmat); use 14.x with pandas 2.x
32
+ "pandas>=2.2.0,<3",
33
+ "pyarrow>=15.0.0",
34
34
  "pysam>=0.19.0",
35
35
  "requests>=2.26.0",
36
36
  "tqdm>=4.62.0",
37
37
  "biopython>=1.79",
38
- "gtfparse>=1.2.0",
39
38
  "platformdirs>=3.0.0",
40
39
  ],
41
40
  extras_require={
@@ -1,9 +0,0 @@
1
- # Core dependencies (NumPy 2 and pandas 2.x; avoid pandas 3 for ABI compatibility)
2
- numpy>=1.20.0,<3
3
- pandas>=2.2.0,<3
4
- pysam>=0.19.0
5
- requests>=2.26.0
6
- tqdm>=4.62.0
7
- biopython>=1.79
8
- gtfparse>=1.2.0
9
- platformdirs>=3.0.0
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