gtfparse 3.0.0__tar.gz → 3.0.4__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 (54) hide show
  1. gtfparse-3.0.4/PKG-INFO +101 -0
  2. gtfparse-3.0.4/README.md +68 -0
  3. {gtfparse-3.0.0 → gtfparse-3.0.4}/benchmarks/README.md +5 -2
  4. {gtfparse-3.0.0 → gtfparse-3.0.4}/benchmarks/compare_readers.py +2 -0
  5. gtfparse-3.0.4/benchmarks/compare_releases.py +139 -0
  6. gtfparse-3.0.4/benchmarks/optimization-results.json +7147 -0
  7. gtfparse-3.0.4/benchmarks/optimization.md +154 -0
  8. {gtfparse-3.0.0 → gtfparse-3.0.4}/gtfparse/__init__.py +1 -1
  9. {gtfparse-3.0.0 → gtfparse-3.0.4}/gtfparse/attribute_parsing.py +44 -50
  10. {gtfparse-3.0.0 → gtfparse-3.0.4}/gtfparse/create_missing_features.py +5 -2
  11. {gtfparse-3.0.0 → gtfparse-3.0.4}/gtfparse/read_gtf.py +60 -7
  12. gtfparse-3.0.4/gtfparse.egg-info/PKG-INFO +101 -0
  13. {gtfparse-3.0.0 → gtfparse-3.0.4}/gtfparse.egg-info/SOURCES.txt +4 -1
  14. gtfparse-3.0.4/tests/test_attribute_optimization.py +130 -0
  15. gtfparse-3.0.0/PKG-INFO +0 -157
  16. gtfparse-3.0.0/README.md +0 -124
  17. gtfparse-3.0.0/gtfparse.egg-info/PKG-INFO +0 -157
  18. {gtfparse-3.0.0 → gtfparse-3.0.4}/LICENSE +0 -0
  19. {gtfparse-3.0.0 → gtfparse-3.0.4}/MANIFEST.in +0 -0
  20. {gtfparse-3.0.0 → gtfparse-3.0.4}/benchmarks/results.json +0 -0
  21. {gtfparse-3.0.0 → gtfparse-3.0.4}/gtfparse/_polars.py +0 -0
  22. {gtfparse-3.0.0 → gtfparse-3.0.4}/gtfparse/_read_csv.py +0 -0
  23. {gtfparse-3.0.0 → gtfparse-3.0.4}/gtfparse/parsing_error.py +0 -0
  24. {gtfparse-3.0.0 → gtfparse-3.0.4}/gtfparse/write_gtf.py +0 -0
  25. {gtfparse-3.0.0 → gtfparse-3.0.4}/gtfparse.egg-info/dependency_links.txt +0 -0
  26. {gtfparse-3.0.0 → gtfparse-3.0.4}/gtfparse.egg-info/requires.txt +0 -0
  27. {gtfparse-3.0.0 → gtfparse-3.0.4}/gtfparse.egg-info/top_level.txt +0 -0
  28. {gtfparse-3.0.0 → gtfparse-3.0.4}/lint.sh +0 -0
  29. {gtfparse-3.0.0 → gtfparse-3.0.4}/pyproject.toml +0 -0
  30. {gtfparse-3.0.0 → gtfparse-3.0.4}/requirements.txt +0 -0
  31. {gtfparse-3.0.0 → gtfparse-3.0.4}/setup.cfg +0 -0
  32. {gtfparse-3.0.0 → gtfparse-3.0.4}/test.sh +0 -0
  33. {gtfparse-3.0.0 → gtfparse-3.0.4}/tests/__init__.py +0 -0
  34. {gtfparse-3.0.0 → gtfparse-3.0.4}/tests/data/B16.stringtie.head.gtf +0 -0
  35. {gtfparse-3.0.0 → gtfparse-3.0.4}/tests/data/ensembl_grch37.head.gtf +0 -0
  36. {gtfparse-3.0.0 → gtfparse-3.0.4}/tests/data/ensembl_grch37.head.gtf.gz +0 -0
  37. {gtfparse-3.0.0 → gtfparse-3.0.4}/tests/data/gencode.head.gtf +0 -0
  38. {gtfparse-3.0.0 → gtfparse-3.0.4}/tests/data/gencode.real.head.gtf +0 -0
  39. {gtfparse-3.0.0 → gtfparse-3.0.4}/tests/data/refseq.ucsc.small.gtf +0 -0
  40. {gtfparse-3.0.0 → gtfparse-3.0.4}/tests/data.py +0 -0
  41. {gtfparse-3.0.0 → gtfparse-3.0.4}/tests/test_attribute_values.py +0 -0
  42. {gtfparse-3.0.0 → gtfparse-3.0.4}/tests/test_create_missing_features.py +0 -0
  43. {gtfparse-3.0.0 → gtfparse-3.0.4}/tests/test_ensembl_gtf.py +0 -0
  44. {gtfparse-3.0.0 → gtfparse-3.0.4}/tests/test_expand_attribute_column_false.py +0 -0
  45. {gtfparse-3.0.0 → gtfparse-3.0.4}/tests/test_expand_attributes.py +0 -0
  46. {gtfparse-3.0.0 → gtfparse-3.0.4}/tests/test_gencode_gtf.py +0 -0
  47. {gtfparse-3.0.0 → gtfparse-3.0.4}/tests/test_multiple_values_for_tag_attribute.py +0 -0
  48. {gtfparse-3.0.0 → gtfparse-3.0.4}/tests/test_parse_gtf_lines.py +0 -0
  49. {gtfparse-3.0.0 → gtfparse-3.0.4}/tests/test_polars_compatibility.py +0 -0
  50. {gtfparse-3.0.0 → gtfparse-3.0.4}/tests/test_progress.py +0 -0
  51. {gtfparse-3.0.0 → gtfparse-3.0.4}/tests/test_read_stringtie_gtf.py +0 -0
  52. {gtfparse-3.0.0 → gtfparse-3.0.4}/tests/test_reader.py +0 -0
  53. {gtfparse-3.0.0 → gtfparse-3.0.4}/tests/test_refseq_gtf.py +0 -0
  54. {gtfparse-3.0.0 → gtfparse-3.0.4}/tests/test_write_gtf.py +0 -0
@@ -0,0 +1,101 @@
1
+ Metadata-Version: 2.4
2
+ Name: gtfparse
3
+ Version: 3.0.4
4
+ Summary: Parsing library for extracting data frames of genomic features from GTF files
5
+ Author-email: Alex Rubinsteyn <alex.rubinsteyn@unc.edu>
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/openvax/gtfparse
8
+ Project-URL: Bug Tracker, https://github.com/openvax/gtfparse/issues
9
+ Classifier: Development Status :: 4 - Beta
10
+ Classifier: Environment :: Console
11
+ Classifier: Operating System :: OS Independent
12
+ Classifier: Intended Audience :: Science/Research
13
+ Classifier: Programming Language :: Python
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.9
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
20
+ Requires-Python: >=3.9
21
+ Description-Content-Type: text/markdown
22
+ License-File: LICENSE
23
+ Requires-Dist: pyarrow>=18.0.0
24
+ Requires-Dist: pandas>=2.2.2
25
+ Provides-Extra: polars
26
+ Requires-Dist: polars>=0.20.31; extra == "polars"
27
+ Provides-Extra: dev
28
+ Requires-Dist: pytest; extra == "dev"
29
+ Requires-Dist: pytest-cov; extra == "dev"
30
+ Requires-Dist: ruff; extra == "dev"
31
+ Requires-Dist: coveralls; extra == "dev"
32
+ Dynamic: license-file
33
+
34
+ [![Tests](https://github.com/openvax/gtfparse/actions/workflows/tests.yml/badge.svg)](https://github.com/openvax/gtfparse/actions/workflows/tests.yml)
35
+ [![Coverage Status](https://coveralls.io/repos/openvax/gtfparse/badge.svg?branch=master&service=github)](https://coveralls.io/github/openvax/gtfparse?branch=master)
36
+ <a href="https://pypi.python.org/pypi/gtfparse/">
37
+ <img src="https://img.shields.io/pypi/v/gtfparse.svg?maxAge=1000" alt="PyPI" />
38
+ </a>
39
+
40
+ gtfparse
41
+ ========
42
+ Read GTF (gene transfer format) annotations into a pandas DataFrame, with one
43
+ row per feature and attribute values such as gene and transcript IDs expanded
44
+ into columns.
45
+
46
+ ## Install
47
+
48
+ ```sh
49
+ python -m pip install gtfparse
50
+ ```
51
+
52
+ Python 3.9 or later is required. For optional Polars output, install
53
+ `gtfparse[polars]`.
54
+
55
+ ## Read an annotation and find genes
56
+
57
+ This small artificial GTF runs without a download. Replace the stream with
58
+ your annotation filename when working with a real dataset.
59
+
60
+ ```python
61
+ from io import StringIO
62
+ from gtfparse import read_gtf
63
+
64
+ annotation = StringIO(
65
+ '1\texample\tgene\t101\t200\t.\t+\t.\tgene_id "g1"; gene_name "EXAMPLE";\n'
66
+ '1\texample\texon\t101\t150\t.\t+\t.\tgene_id "g1"; transcript_id "t1";\n'
67
+ )
68
+ features = read_gtf(annotation)
69
+ genes = features.loc[features["feature"] == "gene"]
70
+ print(genes["gene_name"].tolist())
71
+ for row in features.itertuples():
72
+ print(row.feature, row.seqname, row.start, row.end, row.gene_id)
73
+ ```
74
+
75
+ ```text
76
+ ['EXAMPLE']
77
+ gene 1 101 200 g1
78
+ exon 1 101 150 g1
79
+ ```
80
+
81
+ `feature` identifies the row type. `seqname` is the chromosome or contig name;
82
+ it is not the gene ID. The ninth GTF field supplies attributes such as
83
+ `gene_id`, `gene_name` and `transcript_id`.
84
+
85
+
86
+ <a id="version-3-migration"></a>
87
+ <a id="reporting-parsing-progress"></a>
88
+ <a id="example-usage"></a>
89
+ <a id="parsing-all-rows-of-a-gtf-file-into-a-pandas-dataframe"></a>
90
+ <a id="getting-gene-fpkm-values-from-a-stringtie-gtf-file"></a>
91
+
92
+ ## Documentation
93
+
94
+ - [Filter features, select chromosomes, write GTF and read numeric attributes](docs/guides/annotations.md)
95
+ - [Progress callbacks](docs/guides/progress.md)
96
+ - [Version 3 migration and optional Polars output](docs/guides/migration.md)
97
+ - [Complete API reference](docs/reference.md)
98
+
99
+ To build the documentation locally, run
100
+ `python -m pip install -r requirements-docs.txt` and `./docs.sh`.
101
+ `python scripts/check_docs_examples.py` checks the printed example output.
@@ -0,0 +1,68 @@
1
+ [![Tests](https://github.com/openvax/gtfparse/actions/workflows/tests.yml/badge.svg)](https://github.com/openvax/gtfparse/actions/workflows/tests.yml)
2
+ [![Coverage Status](https://coveralls.io/repos/openvax/gtfparse/badge.svg?branch=master&service=github)](https://coveralls.io/github/openvax/gtfparse?branch=master)
3
+ <a href="https://pypi.python.org/pypi/gtfparse/">
4
+ <img src="https://img.shields.io/pypi/v/gtfparse.svg?maxAge=1000" alt="PyPI" />
5
+ </a>
6
+
7
+ gtfparse
8
+ ========
9
+ Read GTF (gene transfer format) annotations into a pandas DataFrame, with one
10
+ row per feature and attribute values such as gene and transcript IDs expanded
11
+ into columns.
12
+
13
+ ## Install
14
+
15
+ ```sh
16
+ python -m pip install gtfparse
17
+ ```
18
+
19
+ Python 3.9 or later is required. For optional Polars output, install
20
+ `gtfparse[polars]`.
21
+
22
+ ## Read an annotation and find genes
23
+
24
+ This small artificial GTF runs without a download. Replace the stream with
25
+ your annotation filename when working with a real dataset.
26
+
27
+ ```python
28
+ from io import StringIO
29
+ from gtfparse import read_gtf
30
+
31
+ annotation = StringIO(
32
+ '1\texample\tgene\t101\t200\t.\t+\t.\tgene_id "g1"; gene_name "EXAMPLE";\n'
33
+ '1\texample\texon\t101\t150\t.\t+\t.\tgene_id "g1"; transcript_id "t1";\n'
34
+ )
35
+ features = read_gtf(annotation)
36
+ genes = features.loc[features["feature"] == "gene"]
37
+ print(genes["gene_name"].tolist())
38
+ for row in features.itertuples():
39
+ print(row.feature, row.seqname, row.start, row.end, row.gene_id)
40
+ ```
41
+
42
+ ```text
43
+ ['EXAMPLE']
44
+ gene 1 101 200 g1
45
+ exon 1 101 150 g1
46
+ ```
47
+
48
+ `feature` identifies the row type. `seqname` is the chromosome or contig name;
49
+ it is not the gene ID. The ninth GTF field supplies attributes such as
50
+ `gene_id`, `gene_name` and `transcript_id`.
51
+
52
+
53
+ <a id="version-3-migration"></a>
54
+ <a id="reporting-parsing-progress"></a>
55
+ <a id="example-usage"></a>
56
+ <a id="parsing-all-rows-of-a-gtf-file-into-a-pandas-dataframe"></a>
57
+ <a id="getting-gene-fpkm-values-from-a-stringtie-gtf-file"></a>
58
+
59
+ ## Documentation
60
+
61
+ - [Filter features, select chromosomes, write GTF and read numeric attributes](docs/guides/annotations.md)
62
+ - [Progress callbacks](docs/guides/progress.md)
63
+ - [Version 3 migration and optional Polars output](docs/guides/migration.md)
64
+ - [Complete API reference](docs/reference.md)
65
+
66
+ To build the documentation locally, run
67
+ `python -m pip install -r requirements-docs.txt` and `./docs.sh`.
68
+ `python scripts/check_docs_examples.py` checks the printed example output.
@@ -1,9 +1,12 @@
1
1
  # GTF reader backend comparison
2
2
 
3
- Version 3 uses PyArrow for fixed-column parsing and pandas for attribute
3
+ The 3.0.0 migration uses PyArrow for fixed-column parsing and pandas for attribute
4
4
  processing and writing. Polars is an optional output adapter. This directory
5
5
  contains the measurement harness and the evidence for that decision.
6
6
 
7
+ The follow-up [3.0.2 optimization report](optimization.md) compares the optimized
8
+ complete reader with both the 2.9.1 Polars and 3.0.0 Arrow/pandas releases.
9
+
7
10
  ## Reproduction
8
11
 
9
12
  The recorded runs use Python 3.12.6, NumPy 2.5.3, PyArrow 25.0.1, Polars 1.44.2,
@@ -54,7 +57,7 @@ include raw attributes, filtering, selection, aliases, version casts, biotype
54
57
  inference and converters; separate regressions cover streams, nullable fields,
55
58
  comments, malformed inputs and progress/cancellation semantics.
56
59
 
57
- ## Production results
60
+ ## 3.0.0 migration results
58
61
 
59
62
  The table shows three-run medians for equivalent pandas output. Complete load
60
63
  time includes fixed-column reading, attribute expansion, assembly and transforms.
@@ -17,6 +17,7 @@ import sys
17
17
  from pathlib import Path
18
18
  from time import perf_counter, process_time
19
19
 
20
+ import numpy as np
20
21
  import pandas as pd
21
22
  import pyarrow as pa
22
23
  import pyarrow.compute as pc
@@ -257,6 +258,7 @@ def main():
257
258
  "versions": {
258
259
  "gtfparse": __version__,
259
260
  "pandas": pd.__version__,
261
+ "numpy": np.__version__,
260
262
  "polars": pl.__version__ if pl is not None else None,
261
263
  "pyarrow": pa.__version__,
262
264
  "python": platform.python_version(),
@@ -0,0 +1,139 @@
1
+ """Repeat complete production reads sequentially in fresh processes.
2
+
3
+ Pass --baseline LABEL ROOT for each older checkout and --python PATH for each
4
+ interpreter. See optimization.md for the measured corpus and reproduction.
5
+ """
6
+
7
+ import argparse
8
+ import hashlib
9
+ import json
10
+ import os
11
+ import statistics
12
+ import subprocess
13
+ import sys
14
+ from datetime import datetime, timezone
15
+ from pathlib import Path
16
+
17
+
18
+ def summarize(records):
19
+ groups = {}
20
+ for record in records:
21
+ key = (
22
+ record["versions"]["pandas"],
23
+ record["path"],
24
+ record["release"],
25
+ tuple(sorted(record["versions"].items())),
26
+ )
27
+ groups.setdefault(key, []).append(record)
28
+ summaries = []
29
+ for (pandas, path, release, _versions), runs in groups.items():
30
+ summary = {"pandas": pandas, "input": path, "release": release, "runs": len(runs)}
31
+ summary["versions"] = runs[0]["versions"]
32
+ for name in ("wall_seconds", "cpu_seconds", "peak_rss_mib"):
33
+ values = [run[name] for run in runs]
34
+ summary[name] = {
35
+ "median": statistics.median(values),
36
+ "min": min(values),
37
+ "max": max(values),
38
+ }
39
+ summary["stage_medians"] = {
40
+ name: statistics.median(run["stages"][name] for run in runs)
41
+ for name in runs[0]["stages"]
42
+ }
43
+ summary["checksum"] = runs[0]["checksum"]
44
+ summaries.append(summary)
45
+ return summaries
46
+
47
+
48
+ def main():
49
+ parser = argparse.ArgumentParser(description=__doc__)
50
+ parser.add_argument("inputs", nargs="+", type=Path)
51
+ parser.add_argument(
52
+ "--baseline", nargs=2, action="append", default=[], metavar=("LABEL", "ROOT")
53
+ )
54
+ parser.add_argument("--python", action="append", dest="interpreters")
55
+ parser.add_argument("--repeats", type=int, default=3)
56
+ parser.add_argument("--threads", type=int, default=4)
57
+ parser.add_argument("--result-type", choices=["pandas", "polars"], default="pandas")
58
+ parser.add_argument("--features", nargs="+")
59
+ parser.add_argument("--usecols", nargs="+")
60
+ parser.add_argument("--output", required=True, type=Path)
61
+ args = parser.parse_args()
62
+ if args.repeats < 1 or args.threads < 1:
63
+ parser.error("repeats and threads must be positive")
64
+ if len({path.name for path in args.inputs}) != len(args.inputs):
65
+ parser.error("input basenames must be distinct")
66
+ script = Path(__file__).with_name("compare_readers.py")
67
+ releases = [*args.baseline, ("optimized", str(script.parent.parent))]
68
+ expected = {}
69
+ records = []
70
+ environment = dict(os.environ, POLARS_MAX_THREADS=str(args.threads))
71
+ with args.output.with_suffix(".jsonl").open("w") as raw:
72
+ for interpreter in args.interpreters or [sys.executable]:
73
+ for repeat in range(1, args.repeats + 1):
74
+ # Rotate reader order and reverse corpus order to distribute ordering effects.
75
+ offset = (repeat - 1) % len(releases)
76
+ order = releases[offset:] + releases[:offset]
77
+ paths = args.inputs if repeat % 2 else args.inputs[::-1]
78
+ for path in paths:
79
+ for label, root in order:
80
+ command = [
81
+ interpreter,
82
+ str(script),
83
+ str(path),
84
+ "--backend",
85
+ "production",
86
+ "--library-root",
87
+ root,
88
+ "--threads",
89
+ str(args.threads),
90
+ "--result-type",
91
+ args.result_type,
92
+ ]
93
+ for name in ("features", "usecols"):
94
+ value = getattr(args, name)
95
+ if value:
96
+ command.extend(["--" + name, *value])
97
+ run = subprocess.run(
98
+ command, env=environment, capture_output=True, text=True, check=True
99
+ )
100
+ record = json.loads(run.stdout)
101
+ key = path.name
102
+ content = record["checksum"], record["rows"], record["columns"]
103
+ if key in expected and expected[key] != content:
104
+ raise RuntimeError(
105
+ f"Reader results differ: {path}, {label}, {interpreter}"
106
+ )
107
+ expected[key] = content
108
+ record.update(path=path.name, release=label, repeat=repeat)
109
+ records.append(record)
110
+ raw.write(json.dumps(record, sort_keys=True) + "\n")
111
+ raw.flush()
112
+ print(
113
+ record["versions"]["pandas"],
114
+ repeat,
115
+ path.name,
116
+ label,
117
+ round(record["wall_seconds"], 3),
118
+ round(record["peak_rss_mib"]),
119
+ flush=True,
120
+ )
121
+ result = {
122
+ "description": "Complete production readers; imports/checksums outside wall time; sequential fresh processes",
123
+ "date": datetime.now(timezone.utc).isoformat(),
124
+ "threads": args.threads,
125
+ "inputs": {
126
+ path.name: {
127
+ "bytes": path.stat().st_size,
128
+ "sha256": hashlib.sha256(path.read_bytes()).hexdigest(),
129
+ }
130
+ for path in args.inputs
131
+ },
132
+ "summaries": summarize(records),
133
+ "measurements": records,
134
+ }
135
+ args.output.write_text(json.dumps(result, indent=2) + "\n")
136
+
137
+
138
+ if __name__ == "__main__":
139
+ main()