cdot 0.2.36__tar.gz → 0.2.38__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.
- {cdot-0.2.36 → cdot-0.2.38}/PKG-INFO +8 -8
- {cdot-0.2.36 → cdot-0.2.38}/README.md +6 -6
- {cdot-0.2.36 → cdot-0.2.38}/cdot/__init__.py +1 -1
- {cdot-0.2.36 → cdot-0.2.38}/cdot/data_release.py +5 -5
- {cdot-0.2.36 → cdot-0.2.38}/cdot/hgvs/dataproviders/fasta_seqfetcher.py +29 -1
- {cdot-0.2.36 → cdot-0.2.38}/cdot/hgvs/dataproviders/json_data_provider.py +68 -48
- {cdot-0.2.36 → cdot-0.2.38}/cdot/models.py +66 -6
- {cdot-0.2.36 → cdot-0.2.38}/cdot/pyhgvs/pyhgvs_transcript.py +1 -2
- {cdot-0.2.36 → cdot-0.2.38}/cdot.egg-info/PKG-INFO +8 -8
- {cdot-0.2.36 → cdot-0.2.38}/cdot.egg-info/SOURCES.txt +2 -0
- {cdot-0.2.36 → cdot-0.2.38}/cdot.egg-info/requires.txt +1 -1
- {cdot-0.2.36 → cdot-0.2.38}/pyproject.toml +2 -1
- cdot-0.2.38/tests/test_alt_alignments.py +101 -0
- {cdot-0.2.36 → cdot-0.2.38}/tests/test_cdot_json_merge.py +4 -0
- cdot-0.2.38/tests/test_ensembl_scaffolds.py +13 -0
- {cdot-0.2.36 → cdot-0.2.38}/tests/test_fasta_seqfetcher.py +71 -3
- {cdot-0.2.36 → cdot-0.2.38}/tests/test_gff_parser_golden.py +8 -4
- {cdot-0.2.36 → cdot-0.2.38}/tests/test_gff_parsers.py +32 -20
- {cdot-0.2.36 → cdot-0.2.38}/tests/test_uta_conversion.py +9 -3
- {cdot-0.2.36 → cdot-0.2.38}/LICENSE +0 -0
- {cdot-0.2.36 → cdot-0.2.38}/cdot/hgvs/__init__.py +0 -0
- {cdot-0.2.36 → cdot-0.2.38}/cdot/hgvs/_version_replacement_blocklist.py +0 -0
- {cdot-0.2.36 → cdot-0.2.38}/cdot/hgvs/clean.py +0 -0
- {cdot-0.2.36 → cdot-0.2.38}/cdot/hgvs/dataproviders/__init__.py +0 -0
- {cdot-0.2.36 → cdot-0.2.38}/cdot/hgvs/dataproviders/ensembl_tark_data_provider.py +0 -0
- {cdot-0.2.36 → cdot-0.2.38}/cdot/hgvs/dataproviders/seqfetcher.py +0 -0
- {cdot-0.2.36 → cdot-0.2.38}/cdot/hgvs/gene_hgvs.py +0 -0
- {cdot-0.2.36 → cdot-0.2.38}/cdot/hgvs/translation.py +0 -0
- {cdot-0.2.36 → cdot-0.2.38}/cdot/hgvs/version_safety.py +0 -0
- {cdot-0.2.36 → cdot-0.2.38}/cdot/pyhgvs/__init__.py +0 -0
- {cdot-0.2.36 → cdot-0.2.38}/cdot.egg-info/dependency_links.txt +0 -0
- {cdot-0.2.36 → cdot-0.2.38}/cdot.egg-info/top_level.txt +0 -0
- {cdot-0.2.36 → cdot-0.2.38}/setup.cfg +0 -0
- {cdot-0.2.36 → cdot-0.2.38}/tests/test_cdot_gene_info.py +0 -0
- {cdot-0.2.36 → cdot-0.2.38}/tests/test_cdot_json_gencode_hgnc.py +0 -0
- {cdot-0.2.36 → cdot-0.2.38}/tests/test_cdot_json_gene_info.py +0 -0
- {cdot-0.2.36 → cdot-0.2.38}/tests/test_check_new_sources.py +0 -0
- {cdot-0.2.36 → cdot-0.2.38}/tests/test_clean_hgvs.py +0 -0
- {cdot-0.2.36 → cdot-0.2.38}/tests/test_data_release.py +0 -0
- {cdot-0.2.36 → cdot-0.2.38}/tests/test_docs_in_sync.py +0 -0
- {cdot-0.2.36 → cdot-0.2.38}/tests/test_gene_hgvs.py +0 -0
- {cdot-0.2.36 → cdot-0.2.38}/tests/test_json_data_provider_ensembl.py +0 -0
- {cdot-0.2.36 → cdot-0.2.38}/tests/test_json_data_provider_refseq.py +0 -0
- {cdot-0.2.36 → cdot-0.2.38}/tests/test_json_loading.py +0 -0
- {cdot-0.2.36 → cdot-0.2.38}/tests/test_models.py +0 -0
- {cdot-0.2.36 → cdot-0.2.38}/tests/test_public_api.py +0 -0
- {cdot-0.2.36 → cdot-0.2.38}/tests/test_pyhgvs.py +0 -0
- {cdot-0.2.36 → cdot-0.2.38}/tests/test_quickstart.py +0 -0
- {cdot-0.2.36 → cdot-0.2.38}/tests/test_rest_data_provider_errors.py +0 -0
- {cdot-0.2.36 → cdot-0.2.38}/tests/test_rest_data_provider_prefetch.py +0 -0
- {cdot-0.2.36 → cdot-0.2.38}/tests/test_retrieve_many.py +0 -0
- {cdot-0.2.36 → cdot-0.2.38}/tests/test_struct_dict_compat.py +0 -0
- {cdot-0.2.36 → cdot-0.2.38}/tests/test_translation.py +0 -0
- {cdot-0.2.36 → cdot-0.2.38}/tests/test_version_safety.py +0 -0
- {cdot-0.2.36 → cdot-0.2.38}/tests/test_version_safety_real_records.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: cdot
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.38
|
|
4
4
|
Summary: Transcripts for HGVS libraries
|
|
5
5
|
Author-email: Dave Lawrence <davmlaw@gmail.com>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -36,7 +36,7 @@ Requires-Dist: msgspec; extra == "test"
|
|
|
36
36
|
Requires-Dist: pysam; extra == "test"
|
|
37
37
|
Provides-Extra: paper
|
|
38
38
|
Requires-Dist: snakemake; extra == "paper"
|
|
39
|
-
Requires-Dist: vibepaper; extra == "paper"
|
|
39
|
+
Requires-Dist: vibepaper==0.13.0; extra == "paper"
|
|
40
40
|
Requires-Dist: weasyprint; extra == "paper"
|
|
41
41
|
Dynamic: license-file
|
|
42
42
|
|
|
@@ -100,7 +100,7 @@ from hgvs.assemblymapper import AssemblyMapper
|
|
|
100
100
|
from cdot.hgvs.dataproviders import JSONDataProvider, RESTDataProvider
|
|
101
101
|
|
|
102
102
|
hdp = RESTDataProvider() # Uses API server at cdotlib.org
|
|
103
|
-
# hdp = JSONDataProvider(["./cdot-0.2.
|
|
103
|
+
# hdp = JSONDataProvider(["./cdot-0.2.37.refseq.GRCh37.json.gz"]) # Uses local JSON file
|
|
104
104
|
|
|
105
105
|
am = AssemblyMapper(hdp,
|
|
106
106
|
assembly_name='GRCh37',
|
|
@@ -136,7 +136,7 @@ from cdot.pyhgvs.pyhgvs_transcript import JSONPyHGVSTranscriptFactory, RESTPyHGV
|
|
|
136
136
|
|
|
137
137
|
genome = FastaFile("/data/annotation/fasta/GCF_000001405.25_GRCh37.p13_genomic.fna.gz")
|
|
138
138
|
factory = RESTPyHGVSTranscriptFactory()
|
|
139
|
-
# factory = JSONPyHGVSTranscriptFactory(["./cdot-0.2.
|
|
139
|
+
# factory = JSONPyHGVSTranscriptFactory(["./cdot-0.2.37.refseq.GRCh37.json.gz"]) # Uses local JSON file
|
|
140
140
|
pyhgvs.parse_hgvs_name('NM_001637.3:c.1582G>A', genome, get_transcript=factory.get_transcript_grch37)
|
|
141
141
|
```
|
|
142
142
|
|
|
@@ -207,7 +207,7 @@ on 500 variants). Reproduce with `paper/scripts/benchmark_resolution.py`.
|
|
|
207
207
|
|
|
208
208
|
## Q. Where can I download the JSON.gz files?
|
|
209
209
|
|
|
210
|
-
[Download from GitHub releases](https://github.com/SACGF/cdot/releases) - RefSeq (all builds) 96M, Ensembl (all builds) 132M, or one file per genome build (eg `cdot-0.2.
|
|
210
|
+
[Download from GitHub releases](https://github.com/SACGF/cdot/releases) - RefSeq (all builds) 96M, Ensembl (all builds) 132M, or one file per genome build (eg `cdot-0.2.37.refseq.GRCh38.json.gz`, 61M)
|
|
211
211
|
|
|
212
212
|
Details on what the files contain [here](https://github.com/SACGF/cdot/blob/main/docs/release_files.md)
|
|
213
213
|
|
|
@@ -219,8 +219,8 @@ and returns download URLs:
|
|
|
219
219
|
```python
|
|
220
220
|
from cdot.data_release import get_latest_release_version, get_latest_combo_file_urls
|
|
221
221
|
|
|
222
|
-
get_latest_release_version() # eg '0.2.
|
|
223
|
-
get_latest_combo_file_urls(["refseq"], ["GRCh38"]) # [".../cdot-0.2.
|
|
222
|
+
get_latest_release_version() # eg '0.2.37'
|
|
223
|
+
get_latest_combo_file_urls(["refseq"], ["GRCh38"]) # [".../cdot-0.2.37.refseq.GRCh38.json.gz"]
|
|
224
224
|
get_latest_combo_file_urls(["refseq", "ensembl"], ["all-builds"]) # the two all-builds files
|
|
225
225
|
```
|
|
226
226
|
|
|
@@ -244,7 +244,7 @@ You can also read the data with typed Python objects (no extra install required)
|
|
|
244
244
|
```python
|
|
245
245
|
from cdot import models
|
|
246
246
|
|
|
247
|
-
data = models.load("cdot-0.2.
|
|
247
|
+
data = models.load("cdot-0.2.37.refseq.GRCh38.json.gz")
|
|
248
248
|
tx = data.transcripts["NM_001637.3"]
|
|
249
249
|
print(tx.gene_name, tx.protein)
|
|
250
250
|
```
|
|
@@ -58,7 +58,7 @@ from hgvs.assemblymapper import AssemblyMapper
|
|
|
58
58
|
from cdot.hgvs.dataproviders import JSONDataProvider, RESTDataProvider
|
|
59
59
|
|
|
60
60
|
hdp = RESTDataProvider() # Uses API server at cdotlib.org
|
|
61
|
-
# hdp = JSONDataProvider(["./cdot-0.2.
|
|
61
|
+
# hdp = JSONDataProvider(["./cdot-0.2.37.refseq.GRCh37.json.gz"]) # Uses local JSON file
|
|
62
62
|
|
|
63
63
|
am = AssemblyMapper(hdp,
|
|
64
64
|
assembly_name='GRCh37',
|
|
@@ -94,7 +94,7 @@ from cdot.pyhgvs.pyhgvs_transcript import JSONPyHGVSTranscriptFactory, RESTPyHGV
|
|
|
94
94
|
|
|
95
95
|
genome = FastaFile("/data/annotation/fasta/GCF_000001405.25_GRCh37.p13_genomic.fna.gz")
|
|
96
96
|
factory = RESTPyHGVSTranscriptFactory()
|
|
97
|
-
# factory = JSONPyHGVSTranscriptFactory(["./cdot-0.2.
|
|
97
|
+
# factory = JSONPyHGVSTranscriptFactory(["./cdot-0.2.37.refseq.GRCh37.json.gz"]) # Uses local JSON file
|
|
98
98
|
pyhgvs.parse_hgvs_name('NM_001637.3:c.1582G>A', genome, get_transcript=factory.get_transcript_grch37)
|
|
99
99
|
```
|
|
100
100
|
|
|
@@ -165,7 +165,7 @@ on 500 variants). Reproduce with `paper/scripts/benchmark_resolution.py`.
|
|
|
165
165
|
|
|
166
166
|
## Q. Where can I download the JSON.gz files?
|
|
167
167
|
|
|
168
|
-
[Download from GitHub releases](https://github.com/SACGF/cdot/releases) - RefSeq (all builds) 96M, Ensembl (all builds) 132M, or one file per genome build (eg `cdot-0.2.
|
|
168
|
+
[Download from GitHub releases](https://github.com/SACGF/cdot/releases) - RefSeq (all builds) 96M, Ensembl (all builds) 132M, or one file per genome build (eg `cdot-0.2.37.refseq.GRCh38.json.gz`, 61M)
|
|
169
169
|
|
|
170
170
|
Details on what the files contain [here](https://github.com/SACGF/cdot/blob/main/docs/release_files.md)
|
|
171
171
|
|
|
@@ -177,8 +177,8 @@ and returns download URLs:
|
|
|
177
177
|
```python
|
|
178
178
|
from cdot.data_release import get_latest_release_version, get_latest_combo_file_urls
|
|
179
179
|
|
|
180
|
-
get_latest_release_version() # eg '0.2.
|
|
181
|
-
get_latest_combo_file_urls(["refseq"], ["GRCh38"]) # [".../cdot-0.2.
|
|
180
|
+
get_latest_release_version() # eg '0.2.37'
|
|
181
|
+
get_latest_combo_file_urls(["refseq"], ["GRCh38"]) # [".../cdot-0.2.37.refseq.GRCh38.json.gz"]
|
|
182
182
|
get_latest_combo_file_urls(["refseq", "ensembl"], ["all-builds"]) # the two all-builds files
|
|
183
183
|
```
|
|
184
184
|
|
|
@@ -202,7 +202,7 @@ You can also read the data with typed Python objects (no extra install required)
|
|
|
202
202
|
```python
|
|
203
203
|
from cdot import models
|
|
204
204
|
|
|
205
|
-
data = models.load("cdot-0.2.
|
|
205
|
+
data = models.load("cdot-0.2.37.refseq.GRCh38.json.gz")
|
|
206
206
|
tx = data.transcripts["NM_001637.3"]
|
|
207
207
|
print(tx.gene_name, tx.protein)
|
|
208
208
|
```
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
a client can read data whose schema (major.minor) is not newer than its own, see
|
|
14
14
|
:func:`get_data_schema_int`.
|
|
15
15
|
"""
|
|
16
|
-
__version__ = "0.2.
|
|
16
|
+
__version__ = "0.2.38"
|
|
17
17
|
# Data version is kept in generate_transcript_data/json_schema_version.py
|
|
18
18
|
|
|
19
19
|
def get_data_schema_int(version: str) -> int:
|
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
Find the latest cdot transcript data release on GitHub.
|
|
3
3
|
|
|
4
4
|
Data is released separately from the client code, as GitHub releases tagged ``data_v<version>``
|
|
5
|
-
(eg ``data_v0.2.
|
|
5
|
+
(eg ``data_v0.2.37``). These helpers query the GitHub releases API for the newest data release whose
|
|
6
6
|
schema version matches this client (see ``cdot.get_data_schema_int``), and return download URLs for
|
|
7
7
|
its assets.
|
|
8
8
|
|
|
9
9
|
Release asset names (current scheme)::
|
|
10
10
|
|
|
11
|
-
cdot-0.2.
|
|
12
|
-
cdot-0.2.
|
|
11
|
+
cdot-0.2.37.refseq.GRCh38.json.gz # one genome build
|
|
12
|
+
cdot-0.2.37.all-builds-refseq-grch37_grch38_t2t-chm13v2.0.json.gz # all genome builds in one file
|
|
13
13
|
|
|
14
14
|
Older releases (data_v0.2.25 and earlier) used lowercase builds (``cdot-0.2.25.refseq.grch38.json.gz``),
|
|
15
15
|
and early ones (eg v0.2.14) had a combined file named ``cdot-<version>.refseq.grch37_grch38.json.gz``.
|
|
@@ -31,7 +31,7 @@ _ALL_BUILDS_FILE_PATTERN = re.compile(r"cdot-(\d+\.\d+\.\d+)\.all-builds-(refseq
|
|
|
31
31
|
|
|
32
32
|
|
|
33
33
|
def get_latest_data_release_tag_name():
|
|
34
|
-
""" Tag name (eg 'data_v0.2.
|
|
34
|
+
""" Tag name (eg 'data_v0.2.37') of the latest data release compatible with this client, or None """
|
|
35
35
|
latest_data_release = get_latest_data_release()
|
|
36
36
|
return latest_data_release.get('tag_name')
|
|
37
37
|
|
|
@@ -76,7 +76,7 @@ def get_latest_data_release() -> dict:
|
|
|
76
76
|
|
|
77
77
|
|
|
78
78
|
def get_latest_release_version() -> Optional[str]:
|
|
79
|
-
""" Data version (eg '0.2.
|
|
79
|
+
""" Data version (eg '0.2.37') of the latest compatible data release, or None """
|
|
80
80
|
if latest_data_release := get_latest_data_release():
|
|
81
81
|
if tag_name := latest_data_release.get("tag_name"):
|
|
82
82
|
return _get_version_from_tag_name(tag_name, data_version=True)
|
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
:class:`FastaSeqFetcher` is the one to use: genomic contigs straight from the FASTA, transcript
|
|
4
4
|
sequences spliced together from their exons on it. See docs/fasta_seqfetcher.md. """
|
|
5
|
+
import os
|
|
5
6
|
import re
|
|
7
|
+
import threading
|
|
6
8
|
import warnings
|
|
7
9
|
from enum import Enum
|
|
8
10
|
|
|
@@ -24,12 +26,38 @@ __all__ = [
|
|
|
24
26
|
]
|
|
25
27
|
|
|
26
28
|
|
|
29
|
+
class _ThreadLocalFastaFile:
|
|
30
|
+
""" A pysam FastaFile opened once per thread and process. Reads through one shared handle from
|
|
31
|
+
several threads, or from both sides of a fork, corrupt it for every later read """
|
|
32
|
+
|
|
33
|
+
def __init__(self, fasta_filename):
|
|
34
|
+
self._local = threading.local()
|
|
35
|
+
fasta_file = self._open(fasta_filename)
|
|
36
|
+
self.filename = fasta_file.filename
|
|
37
|
+
self.references = fasta_file.references
|
|
38
|
+
|
|
39
|
+
def _open(self, fasta_filename):
|
|
40
|
+
self._local.fasta_file = FastaFile(fasta_filename)
|
|
41
|
+
self._local.pid = os.getpid()
|
|
42
|
+
return self._local.fasta_file
|
|
43
|
+
|
|
44
|
+
def fetch(self, *args, **kwargs):
|
|
45
|
+
if getattr(self._local, "pid", None) == os.getpid():
|
|
46
|
+
fasta_file = self._local.fasta_file
|
|
47
|
+
else:
|
|
48
|
+
fasta_file = self._open(self.filename)
|
|
49
|
+
return fasta_file.fetch(*args, **kwargs)
|
|
50
|
+
|
|
51
|
+
|
|
27
52
|
class GenomeFastaSeqFetcher:
|
|
53
|
+
""" Values of ``contig_fastas`` have ``fetch()`` and ``filename`` like a pysam FastaFile, but are
|
|
54
|
+
safe to share between threads and across a fork """
|
|
55
|
+
|
|
28
56
|
def __init__(self, *args):
|
|
29
57
|
self.source = "Local Fasta file reference"
|
|
30
58
|
self.contig_fastas = {}
|
|
31
59
|
for fasta_filename in args:
|
|
32
|
-
fasta_file =
|
|
60
|
+
fasta_file = _ThreadLocalFastaFile(fasta_filename)
|
|
33
61
|
for contig in fasta_file.references:
|
|
34
62
|
self.contig_fastas[contig] = fasta_file
|
|
35
63
|
|
|
@@ -36,6 +36,7 @@ __all__ = [
|
|
|
36
36
|
|
|
37
37
|
|
|
38
38
|
def _get_patch_assembly_name(assembly_name):
|
|
39
|
+
""" The bioutils assembly cdot uses for a genome build: the patch release, so it has every contig """
|
|
39
40
|
if assembly_name == "GRCh37":
|
|
40
41
|
assembly_name = 'GRCh37.p13' # Original build didn't have MT
|
|
41
42
|
elif assembly_name == "GRCh38":
|
|
@@ -167,8 +168,8 @@ class AbstractJSONDataProvider(Interface):
|
|
|
167
168
|
genome_build=genome_build, cited_position=cited_position)
|
|
168
169
|
|
|
169
170
|
def _get_transcript_coordinates_for_contig(self, transcript, alt_ac):
|
|
170
|
-
""" The transcript's
|
|
171
|
-
|
|
171
|
+
""" The transcript's alignment on contig ``alt_ac`` (see _get_first_alignment_by_contig), or None
|
|
172
|
+
if the transcript isn't on that contig.
|
|
172
173
|
|
|
173
174
|
Raises HGVSDataNotAvailableError if ``alt_ac`` is not a contig of any assembly this
|
|
174
175
|
provider was constructed with: the same error biocommons hgvs handles for any other
|
|
@@ -180,17 +181,23 @@ class AbstractJSONDataProvider(Interface):
|
|
|
180
181
|
f"Contig '{alt_ac}' not supported. Supported assemblies: {supported_assemblies}")
|
|
181
182
|
|
|
182
183
|
if build_data := transcript["genome_builds"].get(assembly):
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
184
|
+
return self._get_first_alignment_by_contig(build_data).get(alt_ac)
|
|
185
|
+
return None
|
|
186
|
+
|
|
187
|
+
@staticmethod
|
|
188
|
+
def _get_first_alignment_by_contig(build_data):
|
|
189
|
+
""" {contig: alignment} with one alignment per contig: the primary one on its contig, otherwise
|
|
190
|
+
the first of ``alt_alignments`` on that contig. This is the alignment get_tx_exons() uses. """
|
|
191
|
+
alignment_by_contig = {}
|
|
192
|
+
for contig, alignment in models.get_alignments(build_data):
|
|
193
|
+
alignment_by_contig.setdefault(contig, alignment)
|
|
194
|
+
return alignment_by_contig
|
|
186
195
|
|
|
187
196
|
@staticmethod
|
|
188
|
-
def
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
start
|
|
192
|
-
end = build_data["exons"][-1][1]
|
|
193
|
-
return contig, start, end, strand
|
|
197
|
+
def _get_start_end_strand(alignment):
|
|
198
|
+
strand = 1 if alignment["strand"] == "+" else -1
|
|
199
|
+
start, end = models.get_span(alignment)
|
|
200
|
+
return start, end, strand
|
|
194
201
|
|
|
195
202
|
def data_version(self):
|
|
196
203
|
return self.required_version
|
|
@@ -287,14 +294,20 @@ class AbstractJSONDataProvider(Interface):
|
|
|
287
294
|
}
|
|
288
295
|
tx_exons.append(exon_data)
|
|
289
296
|
|
|
290
|
-
# A partial alignment can leave
|
|
291
|
-
#
|
|
292
|
-
#
|
|
293
|
-
#
|
|
294
|
-
|
|
297
|
+
# A partial alignment can leave transcript bases unaligned, before the 5' exon or between two
|
|
298
|
+
# exons. biocommons builds transcript coordinates from the exon CIGARs starting at 0 and
|
|
299
|
+
# needs each exon to start where the previous one ends, so give those bases to the 5' exon
|
|
300
|
+
# as a leading transcript-only (D) op, and to the exon before a gap as a trailing one, as
|
|
301
|
+
# UTA does (CIGARs are in transcript order on both strands).
|
|
302
|
+
by_tx = sorted(tx_exons, key=lambda e: e["tx_start_i"])
|
|
303
|
+
first_exon = by_tx[0]
|
|
295
304
|
if unaligned := first_exon["tx_start_i"]:
|
|
296
305
|
first_exon["cigar"] = f"{unaligned}D" + first_exon["cigar"]
|
|
297
306
|
first_exon["tx_start_i"] = 0
|
|
307
|
+
for exon, next_exon in zip(by_tx, by_tx[1:]):
|
|
308
|
+
if unaligned := next_exon["tx_start_i"] - exon["tx_end_i"]:
|
|
309
|
+
exon["cigar"] += f"{unaligned}D"
|
|
310
|
+
exon["tx_end_i"] = next_exon["tx_start_i"]
|
|
298
311
|
|
|
299
312
|
self._tx_exons_cache[cache_key] = tx_exons
|
|
300
313
|
if len(self._tx_exons_cache) > self.TX_EXONS_CACHE_SIZE:
|
|
@@ -337,13 +350,12 @@ class AbstractJSONDataProvider(Interface):
|
|
|
337
350
|
self._check_alt_aln_method(alt_aln_method)
|
|
338
351
|
|
|
339
352
|
if transcript := self._get_transcript(tx_ac):
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
return tx_info
|
|
353
|
+
if self._get_transcript_coordinates_for_contig(transcript, alt_ac):
|
|
354
|
+
tx_info = self._get_transcript_info(transcript)
|
|
355
|
+
tx_info["tx_ac"] = tx_ac
|
|
356
|
+
tx_info["alt_ac"] = alt_ac
|
|
357
|
+
tx_info["alt_aln_method"] = self.NCBI_ALN_METHOD
|
|
358
|
+
return tx_info
|
|
347
359
|
|
|
348
360
|
raise HGVSDataNotAvailableError(
|
|
349
361
|
f"No tx_info for (tx_ac={tx_ac},alt_ac={alt_ac},alt_aln_method={alt_aln_method})"
|
|
@@ -353,12 +365,13 @@ class AbstractJSONDataProvider(Interface):
|
|
|
353
365
|
mapping_options = []
|
|
354
366
|
if transcript := self._get_transcript(tx_ac):
|
|
355
367
|
for build_coordinates in transcript["genome_builds"].values():
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
368
|
+
for contig in self._get_first_alignment_by_contig(build_coordinates):
|
|
369
|
+
mo = {
|
|
370
|
+
"tx_ac": tx_ac,
|
|
371
|
+
"alt_ac": contig,
|
|
372
|
+
"alt_aln_method": self.NCBI_ALN_METHOD,
|
|
373
|
+
}
|
|
374
|
+
mapping_options.append(mo)
|
|
362
375
|
return mapping_options
|
|
363
376
|
|
|
364
377
|
def get_acs_for_protein_seq(self, seq):
|
|
@@ -452,17 +465,18 @@ class LocalDataProvider(AbstractJSONDataProvider):
|
|
|
452
465
|
# JSONDataProvider) it equals transcript_id, so it's a no-op.
|
|
453
466
|
accession = transcript_data.get("id") or transcript_id
|
|
454
467
|
for build_data in transcript_data["genome_builds"].values():
|
|
455
|
-
contig,
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
468
|
+
for contig, alignment in self._get_first_alignment_by_contig(build_data).items():
|
|
469
|
+
tx_start, tx_end, _ = self._get_start_end_strand(alignment)
|
|
470
|
+
length = tx_end - tx_start
|
|
471
|
+
tx_data = {
|
|
472
|
+
"hgnc": gene,
|
|
473
|
+
"cds_start_i": cds_start_i,
|
|
474
|
+
"cds_end_i": cds_end_i,
|
|
475
|
+
"tx_ac": accession,
|
|
476
|
+
"alt_ac": contig,
|
|
477
|
+
"alt_aln_method": self.NCBI_ALN_METHOD,
|
|
478
|
+
}
|
|
479
|
+
tx_list.append((length, tx_data))
|
|
466
480
|
|
|
467
481
|
return [x[1] for x in sorted(tx_list, key=lambda x: x[0], reverse=True)]
|
|
468
482
|
|
|
@@ -563,10 +577,17 @@ class LocalDataProvider(AbstractJSONDataProvider):
|
|
|
563
577
|
tx_list = []
|
|
564
578
|
contig_iv_tree = self._get_contig_interval_tree(alt_ac)
|
|
565
579
|
transcript_ids = [interval.data for interval in contig_iv_tree[start_i:end_i+1]]
|
|
580
|
+
assembly = self.assembly_by_contig.get(alt_ac)
|
|
566
581
|
for transcript_id, transcript_data in self._get_transcripts(transcript_ids).items():
|
|
567
|
-
build_data
|
|
568
|
-
|
|
569
|
-
|
|
582
|
+
if not (build_data := transcript_data["genome_builds"].get(assembly)):
|
|
583
|
+
continue
|
|
584
|
+
# Each alignment on the contig that overlaps the region (a transcript can be on a contig twice)
|
|
585
|
+
for contig, alignment in models.get_alignments(build_data):
|
|
586
|
+
if contig != alt_ac:
|
|
587
|
+
continue
|
|
588
|
+
tx_start, tx_end, strand = self._get_start_end_strand(alignment)
|
|
589
|
+
if tx_start > end_i or tx_end <= start_i:
|
|
590
|
+
continue
|
|
570
591
|
tx_list.append({
|
|
571
592
|
"alt_ac": alt_ac,
|
|
572
593
|
"alt_aln_method": self.NCBI_ALN_METHOD,
|
|
@@ -589,10 +610,9 @@ class LocalDataProvider(AbstractJSONDataProvider):
|
|
|
589
610
|
tx_by_gene[gene_name].add(transcript_id)
|
|
590
611
|
|
|
591
612
|
for build_data in transcript_data["genome_builds"].values():
|
|
592
|
-
contig
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
tx_intervals[contig][tx_start:tx_end] = transcript_id
|
|
613
|
+
for contig, alignment in models.get_alignments(build_data):
|
|
614
|
+
tx_start, tx_end = models.get_span(alignment)
|
|
615
|
+
tx_intervals[contig][tx_start:tx_end] = transcript_id
|
|
596
616
|
return tx_by_gene, tx_intervals
|
|
597
617
|
|
|
598
618
|
@staticmethod
|
|
@@ -624,7 +644,7 @@ class JSONDataProvider(LocalDataProvider):
|
|
|
624
644
|
from hgvs.assemblymapper import AssemblyMapper
|
|
625
645
|
from cdot.hgvs.dataproviders import JSONDataProvider
|
|
626
646
|
|
|
627
|
-
hdp = JSONDataProvider(["cdot-0.2.
|
|
647
|
+
hdp = JSONDataProvider(["cdot-0.2.37.refseq.GRCh38.json.gz"])
|
|
628
648
|
am = AssemblyMapper(hdp, assembly_name="GRCh38", alt_aln_method="splign")
|
|
629
649
|
|
|
630
650
|
:param file_or_filename_list: cdot JSON files to load, each a filename (``.json`` or
|
|
@@ -139,24 +139,42 @@ class GenomeMismatch(_DictAccessStruct, forbid_unknown_fields=False):
|
|
|
139
139
|
``pct_coverage``. Data schema >= 0.2.36."""
|
|
140
140
|
|
|
141
141
|
|
|
142
|
+
class AltAlignment(_DictAccessStruct, forbid_unknown_fields=False):
|
|
143
|
+
"""Another alignment of the transcript on a genome build (``GenomeBuild.alt_alignments``). Has the
|
|
144
|
+
alignment fields of ``GenomeBuild``, the contig being its key in ``alt_alignments``. Data schema >= 0.2.37."""
|
|
145
|
+
strand: str
|
|
146
|
+
"""``'+'`` or ``'-'``."""
|
|
147
|
+
exons: List[Exon]
|
|
148
|
+
cds_start: Optional[int] = None
|
|
149
|
+
"""0-based genomic CDS start on the contig (coding transcripts only)."""
|
|
150
|
+
cds_end: Optional[int] = None
|
|
151
|
+
"""0-based genomic CDS end on the contig (coding transcripts only)."""
|
|
152
|
+
start: Optional[int] = None
|
|
153
|
+
"""0-based genomic start of the alignment on the contig."""
|
|
154
|
+
stop: Optional[int] = None
|
|
155
|
+
"""0-based genomic end of the alignment on the contig (exclusive)."""
|
|
156
|
+
|
|
157
|
+
|
|
142
158
|
class GenomeBuild(_DictAccessStruct, forbid_unknown_fields=False):
|
|
143
|
-
"""A transcript's coordinates on one genome build (e.g. ``GRCh38``).
|
|
159
|
+
"""A transcript's coordinates on one genome build (e.g. ``GRCh38``). ``contig``, ``strand``, ``exons`` and
|
|
160
|
+
``cds_start``/``cds_end`` are the primary alignment, any others are in ``alt_alignments``."""
|
|
144
161
|
contig: str
|
|
145
|
-
"""Chromosome/contig accession, e.g. ``'NC_000007.14'``.
|
|
162
|
+
"""Chromosome/contig accession, e.g. ``'NC_000007.14'``. A chromosome (``NC_``) when the transcript is on one,
|
|
163
|
+
chrX for a pseudoautosomal transcript."""
|
|
146
164
|
strand: str
|
|
147
165
|
"""``'+'`` or ``'-'``."""
|
|
148
166
|
exons: List[Exon]
|
|
149
167
|
url: Optional[str] = None
|
|
150
168
|
"""Source annotation file the transcript was extracted from."""
|
|
151
|
-
# cds_* / start / stop are absent for non-coding transcripts and some sources
|
|
152
169
|
cds_start: Optional[int] = None
|
|
153
170
|
"""0-based genomic CDS start on the contig (coding transcripts only)."""
|
|
154
171
|
cds_end: Optional[int] = None
|
|
155
172
|
"""0-based genomic CDS end on the contig (coding transcripts only)."""
|
|
156
173
|
start: Optional[int] = None
|
|
157
|
-
"""0-based genomic start of the transcript on the contig.
|
|
174
|
+
"""0-based genomic start of the transcript on the contig. Data schema >= 0.2.37, ``get_span()`` works it
|
|
175
|
+
out from the exons when absent."""
|
|
158
176
|
stop: Optional[int] = None
|
|
159
|
-
"""0-based genomic end of the transcript on the contig."""
|
|
177
|
+
"""0-based genomic end of the transcript on the contig (exclusive). Data schema >= 0.2.37, as ``start``."""
|
|
160
178
|
tag: Optional[str] = None
|
|
161
179
|
"""Comma-separated tags (e.g. ``'MANE_Select,Ensembl_canonical'``), verbatim from the source
|
|
162
180
|
GTF/GFF. Spelling differs by consortium: RefSeq uses spaces (``'MANE Select'``, ``'RefSeq Select'``)
|
|
@@ -165,7 +183,14 @@ class GenomeBuild(_DictAccessStruct, forbid_unknown_fields=False):
|
|
|
165
183
|
spelling before comparison."""
|
|
166
184
|
note: Optional[str] = None
|
|
167
185
|
other_chroms: Optional[List[str]] = None
|
|
168
|
-
"""Other contigs this transcript also aligns to (e.g. PAR/alt loci)
|
|
186
|
+
"""Deprecated, use ``alt_alignments``. Other contigs this transcript also aligns to (e.g. PAR/alt loci),
|
|
187
|
+
the contigs of ``alt_alignments`` other than ``contig``. Kept for older readers, and will be removed in the
|
|
188
|
+
next breaking schema change."""
|
|
189
|
+
alt_alignments: Optional[Dict[str, List[AltAlignment]]] = None
|
|
190
|
+
"""The transcript's other alignments on this build: contig -> alignments on it, in genomic order. These are
|
|
191
|
+
the chrY copy of a pseudoautosomal (PAR) transcript, alignments to alt loci (``NT_``) and fix/novel patches
|
|
192
|
+
(``NW_``), and a second copy on a contig (including ``contig``). Mostly RefSeq. Absent when there are none.
|
|
193
|
+
Data schema >= 0.2.37."""
|
|
169
194
|
source: Optional[Union[str, List[str]]] = None
|
|
170
195
|
"""Annotation source (GTF/GFF column 2, e.g. ``'BestRefSeq'``); data schema >= 0.2.32.
|
|
171
196
|
A single string in early 0.2.32 data, a list (e.g. ``['BestRefSeq']``) from 0.2.33 on."""
|
|
@@ -229,6 +254,17 @@ class Transcript(_DictAccessStruct, forbid_unknown_fields=False):
|
|
|
229
254
|
every genome build. Absent when the source has nothing to add. Data schema >= 0.2.35."""
|
|
230
255
|
|
|
231
256
|
|
|
257
|
+
class GeneExtent(_DictAccessStruct, forbid_unknown_fields=False):
|
|
258
|
+
"""Where a gene is on one contig and strand (``Gene.genome_builds``). Data schema >= 0.2.37."""
|
|
259
|
+
contig: str
|
|
260
|
+
strand: str
|
|
261
|
+
"""``'+'`` or ``'-'``."""
|
|
262
|
+
start: int
|
|
263
|
+
"""0-based genomic start, the lowest start of the gene's transcripts on this contig and strand."""
|
|
264
|
+
stop: int
|
|
265
|
+
"""0-based genomic end (exclusive), the highest end of the gene's transcripts on this contig and strand."""
|
|
266
|
+
|
|
267
|
+
|
|
232
268
|
class Gene(_DictAccessStruct, forbid_unknown_fields=False):
|
|
233
269
|
"""Gene-level metadata (present when the source provided gene info)."""
|
|
234
270
|
gene_symbol: Optional[str] = None
|
|
@@ -246,6 +282,10 @@ class Gene(_DictAccessStruct, forbid_unknown_fields=False):
|
|
|
246
282
|
source: Optional[List[str]] = None
|
|
247
283
|
transcripts: Optional[List[str]] = None
|
|
248
284
|
"""Transcript accessions belonging to this gene (when provided)."""
|
|
285
|
+
genome_builds: Optional[Dict[str, List[GeneExtent]]] = None
|
|
286
|
+
"""Build name -> where the gene is on it: one entry per contig and strand its transcripts are on (eg chrX
|
|
287
|
+
and chrY for a pseudoautosomal gene), sorted by contig. The union of all alignments (including
|
|
288
|
+
``alt_alignments``) of the gene's transcripts in this file. Data schema >= 0.2.37."""
|
|
249
289
|
|
|
250
290
|
def __post_init__(self):
|
|
251
291
|
# Convert the legacy comma-separated str biotype (<= 0.2.19) to a list so
|
|
@@ -303,3 +343,23 @@ def transcript_from_dict(d: dict) -> Transcript:
|
|
|
303
343
|
def gene_from_dict(d: dict) -> Gene:
|
|
304
344
|
"""Build a typed :class:`Gene` from a plain cdot gene dict."""
|
|
305
345
|
return msgspec.convert(d, Gene)
|
|
346
|
+
|
|
347
|
+
|
|
348
|
+
def get_alignments(build):
|
|
349
|
+
"""(contig, alignment) for the primary alignment of a ``GenomeBuild`` (or its dict), then for each of
|
|
350
|
+
its ``alt_alignments``"""
|
|
351
|
+
yield build["contig"], build
|
|
352
|
+
for contig, alignments in (build.get("alt_alignments") or {}).items():
|
|
353
|
+
for alignment in alignments:
|
|
354
|
+
yield contig, alignment
|
|
355
|
+
|
|
356
|
+
|
|
357
|
+
def get_span(alignment) -> tuple[int, int]:
|
|
358
|
+
"""(start, stop) of a ``GenomeBuild`` or ``AltAlignment`` (or its dict), 0-based half-open. Its
|
|
359
|
+
``start``/``stop``, else the start of its first exon and end of its last (exons are in genomic order)"""
|
|
360
|
+
start = alignment.get("start")
|
|
361
|
+
stop = alignment.get("stop")
|
|
362
|
+
if start is None or stop is None:
|
|
363
|
+
exons = alignment["exons"]
|
|
364
|
+
start, stop = exons[0][0], exons[-1][1]
|
|
365
|
+
return start, stop
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: cdot
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.38
|
|
4
4
|
Summary: Transcripts for HGVS libraries
|
|
5
5
|
Author-email: Dave Lawrence <davmlaw@gmail.com>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -36,7 +36,7 @@ Requires-Dist: msgspec; extra == "test"
|
|
|
36
36
|
Requires-Dist: pysam; extra == "test"
|
|
37
37
|
Provides-Extra: paper
|
|
38
38
|
Requires-Dist: snakemake; extra == "paper"
|
|
39
|
-
Requires-Dist: vibepaper; extra == "paper"
|
|
39
|
+
Requires-Dist: vibepaper==0.13.0; extra == "paper"
|
|
40
40
|
Requires-Dist: weasyprint; extra == "paper"
|
|
41
41
|
Dynamic: license-file
|
|
42
42
|
|
|
@@ -100,7 +100,7 @@ from hgvs.assemblymapper import AssemblyMapper
|
|
|
100
100
|
from cdot.hgvs.dataproviders import JSONDataProvider, RESTDataProvider
|
|
101
101
|
|
|
102
102
|
hdp = RESTDataProvider() # Uses API server at cdotlib.org
|
|
103
|
-
# hdp = JSONDataProvider(["./cdot-0.2.
|
|
103
|
+
# hdp = JSONDataProvider(["./cdot-0.2.37.refseq.GRCh37.json.gz"]) # Uses local JSON file
|
|
104
104
|
|
|
105
105
|
am = AssemblyMapper(hdp,
|
|
106
106
|
assembly_name='GRCh37',
|
|
@@ -136,7 +136,7 @@ from cdot.pyhgvs.pyhgvs_transcript import JSONPyHGVSTranscriptFactory, RESTPyHGV
|
|
|
136
136
|
|
|
137
137
|
genome = FastaFile("/data/annotation/fasta/GCF_000001405.25_GRCh37.p13_genomic.fna.gz")
|
|
138
138
|
factory = RESTPyHGVSTranscriptFactory()
|
|
139
|
-
# factory = JSONPyHGVSTranscriptFactory(["./cdot-0.2.
|
|
139
|
+
# factory = JSONPyHGVSTranscriptFactory(["./cdot-0.2.37.refseq.GRCh37.json.gz"]) # Uses local JSON file
|
|
140
140
|
pyhgvs.parse_hgvs_name('NM_001637.3:c.1582G>A', genome, get_transcript=factory.get_transcript_grch37)
|
|
141
141
|
```
|
|
142
142
|
|
|
@@ -207,7 +207,7 @@ on 500 variants). Reproduce with `paper/scripts/benchmark_resolution.py`.
|
|
|
207
207
|
|
|
208
208
|
## Q. Where can I download the JSON.gz files?
|
|
209
209
|
|
|
210
|
-
[Download from GitHub releases](https://github.com/SACGF/cdot/releases) - RefSeq (all builds) 96M, Ensembl (all builds) 132M, or one file per genome build (eg `cdot-0.2.
|
|
210
|
+
[Download from GitHub releases](https://github.com/SACGF/cdot/releases) - RefSeq (all builds) 96M, Ensembl (all builds) 132M, or one file per genome build (eg `cdot-0.2.37.refseq.GRCh38.json.gz`, 61M)
|
|
211
211
|
|
|
212
212
|
Details on what the files contain [here](https://github.com/SACGF/cdot/blob/main/docs/release_files.md)
|
|
213
213
|
|
|
@@ -219,8 +219,8 @@ and returns download URLs:
|
|
|
219
219
|
```python
|
|
220
220
|
from cdot.data_release import get_latest_release_version, get_latest_combo_file_urls
|
|
221
221
|
|
|
222
|
-
get_latest_release_version() # eg '0.2.
|
|
223
|
-
get_latest_combo_file_urls(["refseq"], ["GRCh38"]) # [".../cdot-0.2.
|
|
222
|
+
get_latest_release_version() # eg '0.2.37'
|
|
223
|
+
get_latest_combo_file_urls(["refseq"], ["GRCh38"]) # [".../cdot-0.2.37.refseq.GRCh38.json.gz"]
|
|
224
224
|
get_latest_combo_file_urls(["refseq", "ensembl"], ["all-builds"]) # the two all-builds files
|
|
225
225
|
```
|
|
226
226
|
|
|
@@ -244,7 +244,7 @@ You can also read the data with typed Python objects (no extra install required)
|
|
|
244
244
|
```python
|
|
245
245
|
from cdot import models
|
|
246
246
|
|
|
247
|
-
data = models.load("cdot-0.2.
|
|
247
|
+
data = models.load("cdot-0.2.37.refseq.GRCh38.json.gz")
|
|
248
248
|
tx = data.transcripts["NM_001637.3"]
|
|
249
249
|
print(tx.gene_name, tx.protein)
|
|
250
250
|
```
|
|
@@ -22,6 +22,7 @@ cdot/hgvs/dataproviders/json_data_provider.py
|
|
|
22
22
|
cdot/hgvs/dataproviders/seqfetcher.py
|
|
23
23
|
cdot/pyhgvs/__init__.py
|
|
24
24
|
cdot/pyhgvs/pyhgvs_transcript.py
|
|
25
|
+
tests/test_alt_alignments.py
|
|
25
26
|
tests/test_cdot_gene_info.py
|
|
26
27
|
tests/test_cdot_json_gencode_hgnc.py
|
|
27
28
|
tests/test_cdot_json_gene_info.py
|
|
@@ -30,6 +31,7 @@ tests/test_check_new_sources.py
|
|
|
30
31
|
tests/test_clean_hgvs.py
|
|
31
32
|
tests/test_data_release.py
|
|
32
33
|
tests/test_docs_in_sync.py
|
|
34
|
+
tests/test_ensembl_scaffolds.py
|
|
33
35
|
tests/test_fasta_seqfetcher.py
|
|
34
36
|
tests/test_gene_hgvs.py
|
|
35
37
|
tests/test_gff_parser_golden.py
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
""" #251 - A transcript with more than one alignment on a build (PAR chrY, alt loci, twice on one contig) """
|
|
2
|
+
import io
|
|
3
|
+
import json
|
|
4
|
+
import os
|
|
5
|
+
import unittest
|
|
6
|
+
|
|
7
|
+
from hgvs.exceptions import HGVSDataNotAvailableError
|
|
8
|
+
|
|
9
|
+
from cdot import models
|
|
10
|
+
from cdot.hgvs.dataproviders import JSONDataProvider
|
|
11
|
+
from generate_transcript_data.cdot_json import get_gene_extents
|
|
12
|
+
from generate_transcript_data.json_schema_version import JSON_SCHEMA_VERSION
|
|
13
|
+
|
|
14
|
+
GOLDEN_DIR = os.path.join(os.path.dirname(__file__), "test_data", "gff_parser_golden")
|
|
15
|
+
CHRX, CHRY, CHR1 = "NC_000023.11", "NC_000024.10", "NC_000001.11"
|
|
16
|
+
PARX = "NM_900001.1" # Synthetic, on X and Y
|
|
17
|
+
CAPN8 = "NM_001143962.1" # Twice on chr1: 223541608-223558167 (primary) and 223609152-223665734
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def _make_provider(goldens=("refseq_test.par_and_unplaced_codon.gff.json", "refseq_test.GRCh38.106.CAPN8.gff.json")):
|
|
21
|
+
""" JSONDataProvider for GRCh38 golden parser outputs """
|
|
22
|
+
transcripts = {}
|
|
23
|
+
genes = {}
|
|
24
|
+
for golden in goldens:
|
|
25
|
+
with open(os.path.join(GOLDEN_DIR, golden)) as f:
|
|
26
|
+
data = json.load(f)
|
|
27
|
+
transcripts.update(data["transcripts"])
|
|
28
|
+
genes.update(data["genes"])
|
|
29
|
+
cdot_data = {"cdot_version": JSON_SCHEMA_VERSION, "genome_builds": ["GRCh38"],
|
|
30
|
+
"transcripts": transcripts, "genes": genes}
|
|
31
|
+
return JSONDataProvider([io.BytesIO(json.dumps(cdot_data).encode())])
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class TestAltAlignments(unittest.TestCase):
|
|
35
|
+
@classmethod
|
|
36
|
+
def setUpClass(cls):
|
|
37
|
+
cls.hdp = _make_provider()
|
|
38
|
+
|
|
39
|
+
def test_get_tx_exons(self):
|
|
40
|
+
x_exons = self.hdp.get_tx_exons(PARX, CHRX, "splign")
|
|
41
|
+
self.assertEqual([e["alt_start_i"] for e in x_exons], [1000, 2000, 3000])
|
|
42
|
+
y_exons = self.hdp.get_tx_exons(PARX, CHRY, "splign")
|
|
43
|
+
self.assertEqual([e["alt_start_i"] for e in y_exons], [5000, 6000, 7000])
|
|
44
|
+
self.assertEqual({e["alt_ac"] for e in y_exons}, {CHRY})
|
|
45
|
+
self.assertEqual([e["tx_start_i"] for e in y_exons], [e["tx_start_i"] for e in x_exons])
|
|
46
|
+
with self.assertRaises(HGVSDataNotAvailableError):
|
|
47
|
+
self.hdp.get_tx_exons(PARX, CHR1, "splign")
|
|
48
|
+
|
|
49
|
+
def test_get_tx_exons_twice_on_contig(self):
|
|
50
|
+
""" Only the primary alignment can be asked for on its contig """
|
|
51
|
+
exons = self.hdp.get_tx_exons(CAPN8, CHR1, "splign")
|
|
52
|
+
self.assertEqual(exons[0]["alt_start_i"], 223541608)
|
|
53
|
+
|
|
54
|
+
def test_get_tx_exons_alt_locus(self):
|
|
55
|
+
exons = self.hdp.get_tx_exons("NR_900003.1", "NT_187361.1", "splign")
|
|
56
|
+
self.assertEqual([e["alt_start_i"] for e in exons], [500, 800])
|
|
57
|
+
|
|
58
|
+
def test_get_tx_info(self):
|
|
59
|
+
self.assertEqual(self.hdp.get_tx_info(PARX, CHRY, "splign")["alt_ac"], CHRY)
|
|
60
|
+
with self.assertRaises(HGVSDataNotAvailableError):
|
|
61
|
+
self.hdp.get_tx_info(PARX, CHR1, "splign")
|
|
62
|
+
|
|
63
|
+
def test_get_tx_mapping_options(self):
|
|
64
|
+
self.assertEqual([mo["alt_ac"] for mo in self.hdp.get_tx_mapping_options(PARX)], [CHRX, CHRY])
|
|
65
|
+
self.assertEqual([mo["alt_ac"] for mo in self.hdp.get_tx_mapping_options(CAPN8)], [CHR1])
|
|
66
|
+
|
|
67
|
+
def test_get_tx_for_gene(self):
|
|
68
|
+
self.assertEqual([tx["alt_ac"] for tx in self.hdp.get_tx_for_gene("PARX")], [CHRX, CHRY])
|
|
69
|
+
self.assertEqual([tx["alt_ac"] for tx in self.hdp.get_tx_for_gene("CAPN8")], [CHR1])
|
|
70
|
+
|
|
71
|
+
def test_get_tx_for_region(self):
|
|
72
|
+
[tx] = self.hdp.get_tx_for_region(CHRY, "splign", 6000, 6050)
|
|
73
|
+
self.assertEqual((tx["tx_ac"], tx["start_i"], tx["end_i"]), (PARX, 5000, 7100))
|
|
74
|
+
self.assertEqual(self.hdp.get_tx_for_region(CHRY, "splign", 1000, 1100), [])
|
|
75
|
+
|
|
76
|
+
def test_get_tx_for_region_twice_on_contig(self):
|
|
77
|
+
""" The region query reports the copy that overlaps """
|
|
78
|
+
[tx] = self.hdp.get_tx_for_region(CHR1, "splign", 223620000, 223620100)
|
|
79
|
+
self.assertEqual((tx["tx_ac"], tx["start_i"], tx["end_i"]), (CAPN8, 223609152, 223665734))
|
|
80
|
+
txs = self.hdp.get_tx_for_region(CHR1, "splign", 223550000, 223610000)
|
|
81
|
+
self.assertEqual([(tx["start_i"], tx["end_i"]) for tx in txs],
|
|
82
|
+
[(223541608, 223558167), (223609152, 223665734)])
|
|
83
|
+
|
|
84
|
+
def test_get_gene_extents(self):
|
|
85
|
+
""" #246 - one extent per contig, including alt_alignments, a gene twice on a contig gets one """
|
|
86
|
+
extents = get_gene_extents(self.hdp.transcripts)
|
|
87
|
+
self.assertEqual(extents["90001"]["GRCh38"], [
|
|
88
|
+
{"contig": CHRX, "strand": "+", "start": 1000, "stop": 3100},
|
|
89
|
+
{"contig": CHRY, "strand": "+", "start": 5000, "stop": 7100}])
|
|
90
|
+
self.assertEqual(extents["388743"]["GRCh38"], [
|
|
91
|
+
{"contig": CHR1, "strand": "-", "start": 223541608, "stop": 223665734}])
|
|
92
|
+
|
|
93
|
+
def test_get_span_without_start_stop(self):
|
|
94
|
+
""" #246 - files without start/stop use the exons """
|
|
95
|
+
alignment = {"strand": "+", "exons": [[100, 200, 0, 1, 100, None], [300, 400, 1, 101, 200, None]]}
|
|
96
|
+
self.assertEqual(models.get_span(alignment), (100, 400))
|
|
97
|
+
self.assertEqual(models.get_span(alignment | {"start": 90, "stop": 410}), (90, 410))
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
if __name__ == "__main__":
|
|
101
|
+
unittest.main()
|
|
@@ -349,6 +349,9 @@ class TestCdotJsonMerge(unittest.TestCase):
|
|
|
349
349
|
# Gene data from the latest file, genes without transcripts dropped
|
|
350
350
|
self.assertEqual(sorted(merged["genes"]), ["672", "861"])
|
|
351
351
|
self.assertEqual(merged["genes"]["672"]["summary"], "new summary")
|
|
352
|
+
# Gene extents are recalculated from the merged transcripts
|
|
353
|
+
self.assertEqual(merged["genes"]["672"]["genome_builds"],
|
|
354
|
+
{"GRCh38": [{"contig": "NC_000017.11", "strand": "-", "start": 100, "stop": 300}]})
|
|
352
355
|
self.assertEqual(merged["genome_builds"], ["GRCh38"])
|
|
353
356
|
self.assertEqual(merged["metadata"]["method"], "Merge historical")
|
|
354
357
|
self.assertEqual(merged["metadata"]["input_files"], input_filenames)
|
|
@@ -395,6 +398,7 @@ class TestCdotJsonMerge(unittest.TestCase):
|
|
|
395
398
|
self.assertEqual(list(mismatch["genome_builds"]), ["GRCh38"])
|
|
396
399
|
same = combined["transcripts"]["NM_001754.4"]
|
|
397
400
|
self.assertEqual(sorted(same["genome_builds"]), ["GRCh37", "GRCh38"])
|
|
401
|
+
self.assertEqual(sorted(combined["genes"]["1"]["genome_builds"]), ["GRCh37", "GRCh38"])
|
|
398
402
|
self.assertEqual(combined["metadata"]["url_counts"], {grch38_url: 2, grch37_url: 1})
|
|
399
403
|
self.assertIn("Some transcripts were removed as they had different coding coordinates from latest", stdout)
|
|
400
404
|
self.assertIn(f"{grch37_url}: NM_007294.3", stdout)
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
""" #255 - Ensembl scaffold (GenBank accession) and patch ('CHR_' name) contigs are converted to RefSeq """
|
|
2
|
+
import unittest
|
|
3
|
+
|
|
4
|
+
from tests.test_alt_alignments import _make_provider
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class TestEnsemblScaffolds(unittest.TestCase):
|
|
8
|
+
def test_get_tx_exons(self):
|
|
9
|
+
hdp = _make_provider(["ensembl_test.GRCh38.116.scaffolds.gtf.json"])
|
|
10
|
+
for tx_ac, alt_ac in [("ENST00000900002.1", "NT_187361.1"), # KI270706.1
|
|
11
|
+
("ENST00000900003.1", "NT_187515.1")]: # CHR_HSCHR1_1_CTG3
|
|
12
|
+
exons = hdp.get_tx_exons(tx_ac, alt_ac, "splign")
|
|
13
|
+
self.assertEqual([e["alt_start_i"] for e in exons], [1000, 2000])
|
|
@@ -5,15 +5,20 @@ Uses a tiny synthetic genome and transcripts. The genome_mismatch values are fro
|
|
|
5
5
|
in #115: EGR2 NM_000399.3 (1 indel) and PTEN NM_000314.4 (1 substitution, 1 indel)
|
|
6
6
|
"""
|
|
7
7
|
import json
|
|
8
|
+
import os
|
|
9
|
+
import random
|
|
10
|
+
import threading
|
|
8
11
|
import warnings
|
|
12
|
+
from unittest import mock
|
|
9
13
|
|
|
14
|
+
from bioutils.sequences import reverse_complement
|
|
10
15
|
import pysam
|
|
11
16
|
import pytest
|
|
12
17
|
from hgvs.exceptions import HGVSDataNotAvailableError
|
|
13
18
|
|
|
14
19
|
from cdot.hgvs.dataproviders import ChainedSeqFetcher, JSONDataProvider
|
|
15
20
|
from cdot.hgvs.dataproviders.fasta_seqfetcher import FastaSeqFetcher, ExonsFromGenomeFastaSeqFetcher, \
|
|
16
|
-
GenomeMismatchError, GenomeMismatchPolicy, GenomeMismatchWarning
|
|
21
|
+
GenomeFastaSeqFetcher, GenomeMismatchError, GenomeMismatchPolicy, GenomeMismatchWarning
|
|
17
22
|
|
|
18
23
|
CONTIG = "NC_000011.9" # GRCh37 chr11
|
|
19
24
|
GENOME = "ACGTTGCAAC" * 10
|
|
@@ -162,6 +167,9 @@ PADDED_TRANSCRIPTS = {
|
|
|
162
167
|
"NM_000002.1": ("-", [[10, 30, 0, 1, 22, "M5 I2 M15"]]),
|
|
163
168
|
"NM_000003.1": ("+", [[10, 30, 0, 4, 23, None]]),
|
|
164
169
|
"NM_000004.1": ("-", [[10, 30, 0, 4, 23, None]]),
|
|
170
|
+
# Transcript bases 21-23 align nowhere, between the two exons
|
|
171
|
+
"NM_000005.1": ("+", [[10, 30, 0, 1, 20, None], [40, 60, 1, 24, 43, None]]),
|
|
172
|
+
"NM_000006.1": ("-", [[10, 30, 1, 24, 43, None], [40, 60, 0, 1, 20, None]]),
|
|
165
173
|
}
|
|
166
174
|
|
|
167
175
|
|
|
@@ -245,9 +253,11 @@ def test_indel_normalized_into_padding_raises(padded_files):
|
|
|
245
253
|
@pytest.mark.parametrize("ac, n_pos, g_pos", [
|
|
246
254
|
("NM_000003.1", 4, 11), ("NM_000003.1", 23, 30),
|
|
247
255
|
("NM_000004.1", 4, 30), ("NM_000004.1", 23, 11),
|
|
256
|
+
("NM_000005.1", 20, 30), ("NM_000005.1", 24, 41), ("NM_000005.1", 43, 60),
|
|
257
|
+
("NM_000006.1", 20, 41), ("NM_000006.1", 24, 30), ("NM_000006.1", 43, 11),
|
|
248
258
|
])
|
|
249
|
-
def
|
|
250
|
-
"""
|
|
259
|
+
def test_unaligned_transcript_bases_map(padded_files, ac, n_pos, g_pos):
|
|
260
|
+
""" Unaligned transcript bases (n.1_3 at the start, n.21_23 between exons) are skipped """
|
|
251
261
|
from hgvs.alignmentmapper import AlignmentMapper
|
|
252
262
|
from hgvs.parser import Parser
|
|
253
263
|
_, json_filename = padded_files
|
|
@@ -255,3 +265,61 @@ def test_unaligned_transcript_start_maps(padded_files, ac, n_pos, g_pos):
|
|
|
255
265
|
interval = Parser().parse_n_interval(str(n_pos))
|
|
256
266
|
g_interval = AlignmentMapper(hdp, ac, CONTIG, "splign").n_to_g(interval)
|
|
257
267
|
assert (g_interval.start.base, g_interval.end.base) == (g_pos, g_pos)
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
@pytest.mark.parametrize("ac, seq", [
|
|
271
|
+
("NM_000005.1", PADDED_GENOME[10:30] + "NNN" + PADDED_GENOME[40:60]),
|
|
272
|
+
("NM_000006.1", reverse_complement(PADDED_GENOME[40:60]) + "NNN" + reverse_complement(PADDED_GENOME[10:30])),
|
|
273
|
+
])
|
|
274
|
+
def test_unaligned_bases_between_exons_padded(padded_files, ac, seq):
|
|
275
|
+
fasta_filename, json_filename = padded_files
|
|
276
|
+
hdp = _hdp(json_filename, FastaSeqFetcher(fasta_filename))
|
|
277
|
+
with pytest.warns(GenomeMismatchWarning, match=f"{ac} n.21_23"):
|
|
278
|
+
assert hdp.seqfetcher.fetch_seq(ac) == seq
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
@pytest.fixture(scope="module")
|
|
282
|
+
def bgzipped_genome(tmp_path_factory):
|
|
283
|
+
""" 2 Mb, so reads land in many different bgzf blocks """
|
|
284
|
+
tmp_path = tmp_path_factory.mktemp("bgzip")
|
|
285
|
+
rng = random.Random(42)
|
|
286
|
+
genome = "".join(rng.choice("ACGT") for _ in range(2_000_000))
|
|
287
|
+
fasta_filename = str(tmp_path / "genome.fa")
|
|
288
|
+
with open(fasta_filename, "w") as f:
|
|
289
|
+
f.write(f">{CONTIG}\n{genome}\n")
|
|
290
|
+
pysam.tabix_compress(fasta_filename, fasta_filename + ".gz")
|
|
291
|
+
pysam.faidx(fasta_filename + ".gz")
|
|
292
|
+
return fasta_filename + ".gz", genome
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
def test_fetch_from_several_threads(bgzipped_genome):
|
|
296
|
+
fasta_filename, genome = bgzipped_genome
|
|
297
|
+
seqfetcher = GenomeFastaSeqFetcher(fasta_filename)
|
|
298
|
+
errors = []
|
|
299
|
+
|
|
300
|
+
def fetch_random(seed):
|
|
301
|
+
rng = random.Random(seed)
|
|
302
|
+
for _ in range(300):
|
|
303
|
+
pos = rng.randrange(len(genome) - 10)
|
|
304
|
+
try:
|
|
305
|
+
assert seqfetcher.fetch_seq(CONTIG, pos, pos + 10) == genome[pos:pos + 10]
|
|
306
|
+
except Exception as e:
|
|
307
|
+
errors.append(e)
|
|
308
|
+
|
|
309
|
+
threads = [threading.Thread(target=fetch_random, args=(seed,)) for seed in range(4)]
|
|
310
|
+
for thread in threads:
|
|
311
|
+
thread.start()
|
|
312
|
+
for thread in threads:
|
|
313
|
+
thread.join()
|
|
314
|
+
assert not errors
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
def test_forked_process_opens_own_handle(bgzipped_genome):
|
|
318
|
+
fasta_filename, genome = bgzipped_genome
|
|
319
|
+
seqfetcher = GenomeFastaSeqFetcher(fasta_filename)
|
|
320
|
+
fasta_file = seqfetcher.contig_fastas[CONTIG]
|
|
321
|
+
assert seqfetcher.fetch_seq(CONTIG, 0, 10) == genome[:10]
|
|
322
|
+
parent_handle = fasta_file._local.fasta_file
|
|
323
|
+
with mock.patch("os.getpid", return_value=os.getpid() + 1):
|
|
324
|
+
assert seqfetcher.fetch_seq(CONTIG, 0, 10) == genome[:10]
|
|
325
|
+
assert fasta_file._local.fasta_file is not parent_handle
|
|
@@ -51,14 +51,18 @@ FIXTURES = [
|
|
|
51
51
|
("refseq_test.RS_2025_08.ribosomal_slippage.gff", GFF3Parser, "GRCh38", {}),
|
|
52
52
|
("refseq_test.GRCh37.105.20220307.ACTN3.gff", GFF3Parser, "GRCh37", {}),
|
|
53
53
|
("refseq_test.RS_2025_08.ACTN3.gff", GFF3Parser, "GRCh38", {}),
|
|
54
|
-
#
|
|
55
|
-
|
|
56
|
-
#
|
|
54
|
+
# The same transcript twice on one contig (alt_alignments on the primary contig)
|
|
55
|
+
("refseq_test.GRCh38.106.CAPN8.gff", GFF3Parser, "GRCh38", {}),
|
|
56
|
+
# Synthetic: PAR gene on X and Y (alt_alignments), CDS starting outside the exons (codons_unplaced),
|
|
57
|
+
# gene on an NT_ scaffold. Parsed again without contig conversion, for a genome build that has no
|
|
58
|
+
# bioutils assembly
|
|
57
59
|
("refseq_test.par_and_unplaced_codon.gff", GFF3Parser, "GRCh38", {}),
|
|
58
60
|
("refseq_test.par_and_unplaced_codon.gff", GFF3Parser, "CustomBuild",
|
|
59
61
|
{"no_contig_conversion": True, "discard_contigs_with_underscores": False}, "no_contig_conversion"),
|
|
60
|
-
# Synthetic: Ensembl GRCh37 GTFs repeat PAR genes on Y with the same IDs (
|
|
62
|
+
# Synthetic: Ensembl GRCh37 GTFs repeat PAR genes on Y with the same IDs (alt_alignments)
|
|
61
63
|
("ensembl_test.GRCh37.87.par.gtf", GTFParser, "GRCh37", {}),
|
|
64
|
+
# Synthetic: Ensembl scaffold (GenBank accession) and patch ('CHR_' name) contigs convert to RefSeq
|
|
65
|
+
("ensembl_test.GRCh38.116.scaffolds.gtf", GTFParser, "GRCh38", {}),
|
|
62
66
|
]
|
|
63
67
|
|
|
64
68
|
|
|
@@ -9,7 +9,7 @@ import unittest
|
|
|
9
9
|
from generate_transcript_data.cdot_json import add_gencode_hgnc, combine_builds, write_cdot_json
|
|
10
10
|
from generate_transcript_data.annotation_consortium import RefSeq, detect_annotation_consortium
|
|
11
11
|
from generate_transcript_data.gff_parser import GTFParser, GFF3Parser
|
|
12
|
-
from generate_transcript_data.transcript_builder import TranscriptBuilder
|
|
12
|
+
from generate_transcript_data.transcript_builder import TranscriptBuilder, AlignmentFeatures
|
|
13
13
|
from generate_transcript_data.transcript_coordinates import get_transcript_range_start, get_transcript_range_end, \
|
|
14
14
|
transcript_position_to_genomic
|
|
15
15
|
|
|
@@ -501,12 +501,13 @@ class Test(unittest.TestCase):
|
|
|
501
501
|
|
|
502
502
|
builder = TranscriptBuilder("GRCh38", self.FAKE_URL, {})
|
|
503
503
|
perfect = {"num_mismatch": "0", "gap_count": "0", "pct_identity_gap": "100", "pct_coverage": "100"}
|
|
504
|
-
|
|
505
|
-
|
|
504
|
+
alignment = AlignmentFeatures("NC_000013.11", "+", 0, 100)
|
|
505
|
+
RefSeq()._add_alignment_stats(alignment, Feature(**perfect), builder)
|
|
506
|
+
self.assertEqual(alignment.genome_mismatch, {})
|
|
506
507
|
|
|
507
508
|
substitution = {**perfect, "num_mismatch": "1", "pct_identity_gap": "99.9"}
|
|
508
|
-
RefSeq()._add_alignment_stats(
|
|
509
|
-
self.assertEqual(
|
|
509
|
+
RefSeq()._add_alignment_stats(alignment, Feature(**substitution), builder)
|
|
510
|
+
self.assertEqual(alignment.genome_mismatch["alignment"],
|
|
510
511
|
{"num_mismatch": 1, "gap_count": 0, "pct_identity_gap": 99.9, "pct_coverage": 100})
|
|
511
512
|
|
|
512
513
|
def test_transcript_position_across_coordinate_hole(self):
|
|
@@ -692,17 +693,21 @@ class Test(unittest.TestCase):
|
|
|
692
693
|
|
|
693
694
|
def test_refseq_gff3_other_chroms(self):
|
|
694
695
|
""" RefSeq annotates the Y copy of a PAR transcript under the same accession. The transcript keeps
|
|
695
|
-
the
|
|
696
|
+
the X coordinates, and the Y alignment goes in alt_alignments """
|
|
696
697
|
genome_build = "GRCh38"
|
|
697
698
|
parser = GFF3Parser(self.REFSEQ_GFF3_FILENAME_PAR, genome_build, self.FAKE_URL)
|
|
698
699
|
with self.assertLogs(level="WARNING"): # The UNPL start codon
|
|
699
700
|
genes, transcripts = parser.get_genes_and_transcripts()
|
|
700
701
|
build_data = transcripts["NM_900001.1"]["genome_builds"][genome_build]
|
|
701
702
|
self.assertEqual(build_data["contig"], "NC_000023.11")
|
|
702
|
-
self.assertEqual(build_data["other_chroms"], {"
|
|
703
|
+
self.assertEqual(build_data["other_chroms"], {"NC_000024.10"})
|
|
703
704
|
self.assertEqual([(e[0], e[1]) for e in build_data["exons"]], [(1000, 1100), (2000, 2100), (3000, 3100)])
|
|
705
|
+
[y_alignment] = build_data["alt_alignments"]["NC_000024.10"]
|
|
706
|
+
self.assertEqual([(e[0], e[1]) for e in y_alignment["exons"]], [(5000, 5100), (6000, 6100), (7000, 7100)])
|
|
707
|
+
self.assertEqual((y_alignment["cds_start"], y_alignment["cds_end"]), (5050, 7030))
|
|
704
708
|
self.assertEqual(transcripts["NM_900001.1"]["protein"], "NP_900001.1")
|
|
705
|
-
self.assertEqual(
|
|
709
|
+
self.assertEqual(transcripts["NM_900001.1"]["start_codon"], 50)
|
|
710
|
+
self.assertEqual(list(genes), ["90001", "90002", "90003"]) # One gene for both copies
|
|
706
711
|
|
|
707
712
|
def test_gtf_other_chroms(self):
|
|
708
713
|
""" Ensembl GRCh37 GTFs repeat PAR genes on Y with the same gene/transcript IDs """
|
|
@@ -713,8 +718,10 @@ class Test(unittest.TestCase):
|
|
|
713
718
|
transcript = transcripts["ENST00000900001.1"]
|
|
714
719
|
build_data = transcript["genome_builds"][genome_build]
|
|
715
720
|
self.assertEqual(build_data["contig"], "NC_000023.10")
|
|
716
|
-
self.assertEqual(build_data["other_chroms"], {"
|
|
721
|
+
self.assertEqual(build_data["other_chroms"], {"NC_000024.9"})
|
|
717
722
|
self.assertEqual([(e[0], e[1]) for e in build_data["exons"]], [(60000, 60100), (61000, 62000)])
|
|
723
|
+
[y_alignment] = build_data["alt_alignments"]["NC_000024.9"]
|
|
724
|
+
self.assertEqual([(e[0], e[1]) for e in y_alignment["exons"]], [(10000, 10100), (11000, 12000)])
|
|
718
725
|
self.assertEqual(transcript["start_codon"], 50)
|
|
719
726
|
self.assertEqual(transcript["stop_codon"], 600)
|
|
720
727
|
|
|
@@ -735,25 +742,30 @@ class Test(unittest.TestCase):
|
|
|
735
742
|
self.assertIn("mRNA", transcript["biotype"])
|
|
736
743
|
|
|
737
744
|
def test_discard_contigs_with_underscores(self):
|
|
738
|
-
"""
|
|
745
|
+
""" RefSeq alt locus / scaffold accessions (eg NT_187361.1) are kept, other contig names with an
|
|
746
|
+
underscore that don't convert to one are dropped unless discard_contigs_with_underscores=False """
|
|
739
747
|
parser = GFF3Parser(self.REFSEQ_GFF3_FILENAME_PAR, "GRCh38", self.FAKE_URL)
|
|
740
|
-
with self.assertLogs(level="WARNING"):
|
|
741
|
-
genes, transcripts = parser.get_genes_and_transcripts()
|
|
742
|
-
self.assertEqual(dict(parser.discarded_contigs), {"NT_187361.1": 4}) # gene, lnc_RNA, 2 exons
|
|
743
|
-
self.assertNotIn("90003", genes)
|
|
744
|
-
self.assertNotIn("NR_900003.1", transcripts)
|
|
745
|
-
|
|
746
|
-
parser = GFF3Parser(self.REFSEQ_GFF3_FILENAME_PAR, "GRCh38", self.FAKE_URL,
|
|
747
|
-
discard_contigs_with_underscores=False)
|
|
748
748
|
with self.assertLogs(level="WARNING"):
|
|
749
749
|
genes, transcripts = parser.get_genes_and_transcripts()
|
|
750
750
|
self.assertEqual(dict(parser.discarded_contigs), {})
|
|
751
751
|
self.assertEqual(genes["90003"]["gene_symbol"], "SCAF")
|
|
752
752
|
build_data = transcripts["NR_900003.1"]["genome_builds"]["GRCh38"]
|
|
753
|
-
self.assertEqual(build_data["contig"], "NT_187361.1")
|
|
753
|
+
self.assertEqual(build_data["contig"], "NT_187361.1")
|
|
754
754
|
self.assertEqual(build_data["strand"], "-")
|
|
755
755
|
self.assertEqual([(e[0], e[1]) for e in build_data["exons"]], [(500, 600), (800, 1000)])
|
|
756
756
|
|
|
757
|
+
with open(self.REFSEQ_GFF3_FILENAME_PAR) as f:
|
|
758
|
+
gff = f.read().replace("NT_187361.1", "unknown_scaffold_1")
|
|
759
|
+
with tempfile.NamedTemporaryFile("w", suffix=".gff") as f:
|
|
760
|
+
f.write(gff)
|
|
761
|
+
f.flush()
|
|
762
|
+
for discard, expected_discarded in [(True, {"unknown_scaffold_1": 4}), (False, {})]:
|
|
763
|
+
parser = GFF3Parser(f.name, "GRCh38", self.FAKE_URL, discard_contigs_with_underscores=discard)
|
|
764
|
+
with self.assertLogs(level="WARNING"):
|
|
765
|
+
_, transcripts = parser.get_genes_and_transcripts()
|
|
766
|
+
self.assertEqual(dict(parser.discarded_contigs), expected_discarded)
|
|
767
|
+
self.assertEqual("NR_900003.1" in transcripts, not discard)
|
|
768
|
+
|
|
757
769
|
def test_no_contig_conversion(self):
|
|
758
770
|
""" Genome builds without a bioutils assembly can only be used with no_contig_conversion, which
|
|
759
771
|
leaves contig names as they are in the file """
|
|
@@ -766,7 +778,7 @@ class Test(unittest.TestCase):
|
|
|
766
778
|
_, transcripts = parser.get_genes_and_transcripts()
|
|
767
779
|
build_data = transcripts["NM_900001.1"]["genome_builds"][genome_build]
|
|
768
780
|
self.assertEqual(build_data["contig"], "X")
|
|
769
|
-
self.assertEqual(build_data["other_chroms"], {"Y"})
|
|
781
|
+
self.assertEqual(build_data["other_chroms"], {"Y"}) # Not converted either
|
|
770
782
|
|
|
771
783
|
def test_gtf_row_without_gene_id(self):
|
|
772
784
|
""" Every GTF row needs a gene_id, the error names the row """
|
|
@@ -138,6 +138,7 @@ class UTAToJSONTestCase(unittest.TestCase):
|
|
|
138
138
|
self.assertEqual(build_data["strand"], "+")
|
|
139
139
|
self.assertEqual(build_data["exons"], [[1000, 1100, 0, 1, 100, None], [2000, 2100, 1, 101, 200, None]])
|
|
140
140
|
self.assertEqual((build_data["cds_start"], build_data["cds_end"]), (2001, 2060))
|
|
141
|
+
self.assertEqual((build_data["start"], build_data["stop"]), (1000, 2100))
|
|
141
142
|
|
|
142
143
|
runx1 = data["transcripts"]["NM_001754.5"]
|
|
143
144
|
build_data = runx1["genome_builds"]["GRCh38"]
|
|
@@ -152,10 +153,15 @@ class UTAToJSONTestCase(unittest.TestCase):
|
|
|
152
153
|
self.assertNotIn(key, ncrna)
|
|
153
154
|
self.assertNotIn("cds_start", ncrna["genome_builds"]["GRCh38"])
|
|
154
155
|
|
|
155
|
-
# Fake genes (not real accessions, so merge_historical swaps them for real ones) list their transcripts
|
|
156
|
+
# Fake genes (not real accessions, so merge_historical swaps them for real ones) list their transcripts.
|
|
157
|
+
# Extents are the union of the transcripts written, so BADCDS (skipped) has none
|
|
156
158
|
self.assertEqual(data["genes"], {
|
|
157
|
-
"_BRCA2": {"gene_symbol": "BRCA2", "transcripts": ["NM_000059.4", "NR_000001.1"], "url": self.URL
|
|
158
|
-
|
|
159
|
+
"_BRCA2": {"gene_symbol": "BRCA2", "transcripts": ["NM_000059.4", "NR_000001.1"], "url": self.URL,
|
|
160
|
+
"genome_builds": {"GRCh38": [{"contig": "NC_000013.11", "strand": "+",
|
|
161
|
+
"start": 1000, "stop": 5100}]}},
|
|
162
|
+
"_RUNX1": {"gene_symbol": "RUNX1", "transcripts": ["NM_001754.5"], "url": self.URL,
|
|
163
|
+
"genome_builds": {"GRCh38": [{"contig": "NC_000021.9", "strand": "-",
|
|
164
|
+
"start": 1000, "stop": 3100}]}},
|
|
159
165
|
"_BADCDS": {"gene_symbol": "BADCDS", "transcripts": ["NM_000002.1"], "url": self.URL},
|
|
160
166
|
})
|
|
161
167
|
self.assertTrue(any(p.startswith("Warning: Skipped NM_000002.1") for p in self.printed), self.printed)
|
|
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
|
|
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
|