cdot 0.2.37__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.
Files changed (55) hide show
  1. {cdot-0.2.37 → cdot-0.2.38}/PKG-INFO +8 -8
  2. {cdot-0.2.37 → cdot-0.2.38}/README.md +6 -6
  3. {cdot-0.2.37 → cdot-0.2.38}/cdot/__init__.py +1 -1
  4. {cdot-0.2.37 → cdot-0.2.38}/cdot/data_release.py +5 -5
  5. {cdot-0.2.37 → cdot-0.2.38}/cdot/hgvs/dataproviders/json_data_provider.py +57 -43
  6. {cdot-0.2.37 → cdot-0.2.38}/cdot/models.py +66 -6
  7. {cdot-0.2.37 → cdot-0.2.38}/cdot/pyhgvs/pyhgvs_transcript.py +1 -2
  8. {cdot-0.2.37 → cdot-0.2.38}/cdot.egg-info/PKG-INFO +8 -8
  9. {cdot-0.2.37 → cdot-0.2.38}/cdot.egg-info/SOURCES.txt +2 -0
  10. {cdot-0.2.37 → cdot-0.2.38}/cdot.egg-info/requires.txt +1 -1
  11. {cdot-0.2.37 → cdot-0.2.38}/pyproject.toml +2 -1
  12. cdot-0.2.38/tests/test_alt_alignments.py +101 -0
  13. {cdot-0.2.37 → cdot-0.2.38}/tests/test_cdot_json_merge.py +4 -0
  14. cdot-0.2.38/tests/test_ensembl_scaffolds.py +13 -0
  15. {cdot-0.2.37 → cdot-0.2.38}/tests/test_gff_parser_golden.py +8 -4
  16. {cdot-0.2.37 → cdot-0.2.38}/tests/test_gff_parsers.py +32 -20
  17. {cdot-0.2.37 → cdot-0.2.38}/tests/test_uta_conversion.py +9 -3
  18. {cdot-0.2.37 → cdot-0.2.38}/LICENSE +0 -0
  19. {cdot-0.2.37 → cdot-0.2.38}/cdot/hgvs/__init__.py +0 -0
  20. {cdot-0.2.37 → cdot-0.2.38}/cdot/hgvs/_version_replacement_blocklist.py +0 -0
  21. {cdot-0.2.37 → cdot-0.2.38}/cdot/hgvs/clean.py +0 -0
  22. {cdot-0.2.37 → cdot-0.2.38}/cdot/hgvs/dataproviders/__init__.py +0 -0
  23. {cdot-0.2.37 → cdot-0.2.38}/cdot/hgvs/dataproviders/ensembl_tark_data_provider.py +0 -0
  24. {cdot-0.2.37 → cdot-0.2.38}/cdot/hgvs/dataproviders/fasta_seqfetcher.py +0 -0
  25. {cdot-0.2.37 → cdot-0.2.38}/cdot/hgvs/dataproviders/seqfetcher.py +0 -0
  26. {cdot-0.2.37 → cdot-0.2.38}/cdot/hgvs/gene_hgvs.py +0 -0
  27. {cdot-0.2.37 → cdot-0.2.38}/cdot/hgvs/translation.py +0 -0
  28. {cdot-0.2.37 → cdot-0.2.38}/cdot/hgvs/version_safety.py +0 -0
  29. {cdot-0.2.37 → cdot-0.2.38}/cdot/pyhgvs/__init__.py +0 -0
  30. {cdot-0.2.37 → cdot-0.2.38}/cdot.egg-info/dependency_links.txt +0 -0
  31. {cdot-0.2.37 → cdot-0.2.38}/cdot.egg-info/top_level.txt +0 -0
  32. {cdot-0.2.37 → cdot-0.2.38}/setup.cfg +0 -0
  33. {cdot-0.2.37 → cdot-0.2.38}/tests/test_cdot_gene_info.py +0 -0
  34. {cdot-0.2.37 → cdot-0.2.38}/tests/test_cdot_json_gencode_hgnc.py +0 -0
  35. {cdot-0.2.37 → cdot-0.2.38}/tests/test_cdot_json_gene_info.py +0 -0
  36. {cdot-0.2.37 → cdot-0.2.38}/tests/test_check_new_sources.py +0 -0
  37. {cdot-0.2.37 → cdot-0.2.38}/tests/test_clean_hgvs.py +0 -0
  38. {cdot-0.2.37 → cdot-0.2.38}/tests/test_data_release.py +0 -0
  39. {cdot-0.2.37 → cdot-0.2.38}/tests/test_docs_in_sync.py +0 -0
  40. {cdot-0.2.37 → cdot-0.2.38}/tests/test_fasta_seqfetcher.py +0 -0
  41. {cdot-0.2.37 → cdot-0.2.38}/tests/test_gene_hgvs.py +0 -0
  42. {cdot-0.2.37 → cdot-0.2.38}/tests/test_json_data_provider_ensembl.py +0 -0
  43. {cdot-0.2.37 → cdot-0.2.38}/tests/test_json_data_provider_refseq.py +0 -0
  44. {cdot-0.2.37 → cdot-0.2.38}/tests/test_json_loading.py +0 -0
  45. {cdot-0.2.37 → cdot-0.2.38}/tests/test_models.py +0 -0
  46. {cdot-0.2.37 → cdot-0.2.38}/tests/test_public_api.py +0 -0
  47. {cdot-0.2.37 → cdot-0.2.38}/tests/test_pyhgvs.py +0 -0
  48. {cdot-0.2.37 → cdot-0.2.38}/tests/test_quickstart.py +0 -0
  49. {cdot-0.2.37 → cdot-0.2.38}/tests/test_rest_data_provider_errors.py +0 -0
  50. {cdot-0.2.37 → cdot-0.2.38}/tests/test_rest_data_provider_prefetch.py +0 -0
  51. {cdot-0.2.37 → cdot-0.2.38}/tests/test_retrieve_many.py +0 -0
  52. {cdot-0.2.37 → cdot-0.2.38}/tests/test_struct_dict_compat.py +0 -0
  53. {cdot-0.2.37 → cdot-0.2.38}/tests/test_translation.py +0 -0
  54. {cdot-0.2.37 → cdot-0.2.38}/tests/test_version_safety.py +0 -0
  55. {cdot-0.2.37 → 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.37
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.36.refseq.GRCh37.json.gz"]) # Uses local JSON file
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.36.refseq.GRCh37.json.gz"]) # Uses local JSON file
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.36.refseq.GRCh38.json.gz`, 61M)
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.36'
223
- get_latest_combo_file_urls(["refseq"], ["GRCh38"]) # [".../cdot-0.2.36.refseq.GRCh38.json.gz"]
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.36.refseq.GRCh38.json.gz")
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.36.refseq.GRCh37.json.gz"]) # Uses local JSON file
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.36.refseq.GRCh37.json.gz"]) # Uses local JSON file
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.36.refseq.GRCh38.json.gz`, 61M)
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.36'
181
- get_latest_combo_file_urls(["refseq"], ["GRCh38"]) # [".../cdot-0.2.36.refseq.GRCh38.json.gz"]
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.36.refseq.GRCh38.json.gz")
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.37"
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.36``). These helpers query the GitHub releases API for the newest data release whose
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.36.refseq.GRCh38.json.gz # one genome build
12
- cdot-0.2.36.all-builds-refseq-grch37_grch38_t2t-chm13v2.0.json.gz # all genome builds in one file
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.36') of the latest data release compatible with this client, or None """
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.36') of the latest compatible data release, or None """
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)
@@ -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 coordinates (its ``genome_builds`` entry) on contig ``alt_ac``, or
171
- None if the transcript isn't on that contig.
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
- if build_data["contig"] != alt_ac:
184
- return None
185
- return build_data
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 _get_contig_start_end_strand(build_data):
189
- contig = build_data["contig"]
190
- strand = 1 if build_data["strand"] == "+" else -1
191
- start = build_data["exons"][0][0]
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
@@ -343,13 +350,12 @@ class AbstractJSONDataProvider(Interface):
343
350
  self._check_alt_aln_method(alt_aln_method)
344
351
 
345
352
  if transcript := self._get_transcript(tx_ac):
346
- for build_data in transcript["genome_builds"].values():
347
- if alt_ac == build_data["contig"]:
348
- tx_info = self._get_transcript_info(transcript)
349
- tx_info["tx_ac"] = tx_ac
350
- tx_info["alt_ac"] = alt_ac
351
- tx_info["alt_aln_method"] = self.NCBI_ALN_METHOD
352
- 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
353
359
 
354
360
  raise HGVSDataNotAvailableError(
355
361
  f"No tx_info for (tx_ac={tx_ac},alt_ac={alt_ac},alt_aln_method={alt_aln_method})"
@@ -359,12 +365,13 @@ class AbstractJSONDataProvider(Interface):
359
365
  mapping_options = []
360
366
  if transcript := self._get_transcript(tx_ac):
361
367
  for build_coordinates in transcript["genome_builds"].values():
362
- mo = {
363
- "tx_ac": tx_ac,
364
- "alt_ac": build_coordinates["contig"],
365
- "alt_aln_method": self.NCBI_ALN_METHOD,
366
- }
367
- mapping_options.append(mo)
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)
368
375
  return mapping_options
369
376
 
370
377
  def get_acs_for_protein_seq(self, seq):
@@ -458,17 +465,18 @@ class LocalDataProvider(AbstractJSONDataProvider):
458
465
  # JSONDataProvider) it equals transcript_id, so it's a no-op.
459
466
  accession = transcript_data.get("id") or transcript_id
460
467
  for build_data in transcript_data["genome_builds"].values():
461
- contig, tx_start, tx_end, _ = self._get_contig_start_end_strand(build_data)
462
- length = tx_end - tx_start
463
- tx_data = {
464
- "hgnc": gene,
465
- "cds_start_i": cds_start_i,
466
- "cds_end_i": cds_end_i,
467
- "tx_ac": accession,
468
- "alt_ac": contig,
469
- "alt_aln_method": self.NCBI_ALN_METHOD,
470
- }
471
- tx_list.append((length, tx_data))
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))
472
480
 
473
481
  return [x[1] for x in sorted(tx_list, key=lambda x: x[0], reverse=True)]
474
482
 
@@ -569,10 +577,17 @@ class LocalDataProvider(AbstractJSONDataProvider):
569
577
  tx_list = []
570
578
  contig_iv_tree = self._get_contig_interval_tree(alt_ac)
571
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)
572
581
  for transcript_id, transcript_data in self._get_transcripts(transcript_ids).items():
573
- build_data = self._get_transcript_coordinates_for_contig(transcript_data, alt_ac)
574
- contig, tx_start, tx_end, strand = self._get_contig_start_end_strand(build_data)
575
- if contig == alt_ac:
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
576
591
  tx_list.append({
577
592
  "alt_ac": alt_ac,
578
593
  "alt_aln_method": self.NCBI_ALN_METHOD,
@@ -595,10 +610,9 @@ class LocalDataProvider(AbstractJSONDataProvider):
595
610
  tx_by_gene[gene_name].add(transcript_id)
596
611
 
597
612
  for build_data in transcript_data["genome_builds"].values():
598
- contig = build_data["contig"]
599
- tx_start = build_data["exons"][0][0]
600
- tx_end = build_data["exons"][-1][1]
601
- 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
602
616
  return tx_by_gene, tx_intervals
603
617
 
604
618
  @staticmethod
@@ -630,7 +644,7 @@ class JSONDataProvider(LocalDataProvider):
630
644
  from hgvs.assemblymapper import AssemblyMapper
631
645
  from cdot.hgvs.dataproviders import JSONDataProvider
632
646
 
633
- hdp = JSONDataProvider(["cdot-0.2.36.refseq.GRCh38.json.gz"])
647
+ hdp = JSONDataProvider(["cdot-0.2.37.refseq.GRCh38.json.gz"])
634
648
  am = AssemblyMapper(hdp, assembly_name="GRCh38", alt_aln_method="splign")
635
649
 
636
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
@@ -38,8 +38,7 @@ class AbstractPyHGVSTranscriptFactory(abc.ABC):
38
38
  return {}
39
39
 
40
40
  exons = build_coords['exons']
41
- start = exons[0][0]
42
- end = exons[-1][1]
41
+ start, end = models.get_span(build_coords)
43
42
 
44
43
  pyhgvs_data = {
45
44
  "id": transcript_json["id"],
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cdot
3
- Version: 0.2.37
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.36.refseq.GRCh37.json.gz"]) # Uses local JSON file
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.36.refseq.GRCh37.json.gz"]) # Uses local JSON file
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.36.refseq.GRCh38.json.gz`, 61M)
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.36'
223
- get_latest_combo_file_urls(["refseq"], ["GRCh38"]) # [".../cdot-0.2.36.refseq.GRCh38.json.gz"]
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.36.refseq.GRCh38.json.gz")
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
@@ -17,7 +17,7 @@ pysam
17
17
 
18
18
  [paper]
19
19
  snakemake
20
- vibepaper
20
+ vibepaper==0.13.0
21
21
  weasyprint
22
22
 
23
23
  [test]
@@ -54,7 +54,8 @@ test = [
54
54
  # weasyprint provides the optional PDF toolchain (vibepaper --pdf / the `pdf` rule).
55
55
  paper = [
56
56
  "snakemake",
57
- "vibepaper",
57
+ # Keep CI's pin (.github/workflows/tests.yml) in step.
58
+ "vibepaper==0.13.0",
58
59
  "weasyprint",
59
60
  ]
60
61
 
@@ -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])
@@ -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
- # Synthetic: PAR gene on X and Y (other_chroms), CDS starting outside the exons (codons_unplaced),
55
- # gene on an NT_ scaffold (discarded by default). Parsed again keeping that scaffold and without
56
- # contig conversion, for a genome build that has no bioutils assembly
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 (other_chroms)
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
- RefSeq()._add_alignment_stats("NM_000059.4", Feature(**perfect), builder)
505
- self.assertNotIn("NM_000059.4", builder.transcript_genome_mismatch)
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("NM_001754.5", Feature(**substitution), builder)
509
- self.assertEqual(builder.transcript_genome_mismatch["NM_001754.5"]["alignment"],
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 first (X) coordinates and records the other chromosome """
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"], {"Y"})
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(list(genes), ["90001", "90002"]) # One gene for both copies, scaffold gene discarded
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"], {"Y"})
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
- """ Rows on contigs with an underscore (unplaced scaffolds, eg NT_187361.1) are dropped by default """
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") # Not a chromosome name, so left as is
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
- "_RUNX1": {"gene_symbol": "RUNX1", "transcripts": ["NM_001754.5"], "url": self.URL},
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