diff --git a/gnomad/resources/grch37/gnomad.py b/gnomad/resources/grch37/gnomad.py index cf933ed68..9c9ab1a99 100644 --- a/gnomad/resources/grch37/gnomad.py +++ b/gnomad/resources/grch37/gnomad.py @@ -104,6 +104,37 @@ def _liftover_data_path(data_type: str, version: str) -> str: return f"gs://gnomad-public-requester-pays/release/{version}/liftover_grch38/ht/{data_type}/gnomad.{data_type}.r{version}.sites.liftover_grch38.ht" +def _public_constraint_ht_path() -> str: + """ + Get public gene constraint Table path. + + :return: Path to constraint Table. + """ + return "gs://gnomad-public-requester-pays/release/2.1.1/constraint/gnomad.v2.1.1.lof_metrics.by_transcript.ht" + + +def _public_pext_path(pext_type: str = "base_level") -> str: + """ + Get public proportion expressed across transcripts (pext) data. + + :param pext_type: One of "annotation_level" or "base_level". Default is "base_level". + :return: Path to pext data. + :raises DataException: If the provided pext_type is invalid. + """ + pext_paths = { + "annotation_level": "gs://gnomad-public-requester-pays/papers/2019-tx-annotation/pre_computed/all.possible.snvs.tx_annotated.021520.ht", + "base_level": "gs://gnomad-public-requester-pays/papers/2019-tx-annotation/gnomad_browser/all.baselevel.021620.ht", + } + + if pext_type not in pext_paths: + valid_types = list(pext_paths.keys()) + raise DataException( + f"Invalid pext_type: '{pext_type}'. Valid options are {valid_types}." + ) + + return pext_paths[pext_type] + + def public_release(data_type: str) -> VersionedTableResource: """ Retrieve publicly released versioned table resource. @@ -219,3 +250,22 @@ def release_vcf_path(data_type: str, version: str, contig: str) -> str: contig = f".{contig}" if contig else "" return f"gs://gcp-public-data--gnomad/release/{version}/vcf/{data_type}/gnomad.{data_type}.r{version}.sites{contig}.vcf.bgz" + + +def pext(pext_type: str = "base_level") -> GnomadPublicTableResource: + """ + Retrieve proportion expressed across transcripts (pext) data. + + :param pext_type: One of "annotation_level" or "base_level". Default is "base_level". + :return: Pext Table. + """ + return GnomadPublicTableResource(path=_public_pext_path(pext_type)) + + +def constraint() -> GnomadPublicTableResource: + """ + Retrieve gene constraint table. + + :return: Gene constraint Table. + """ + return GnomadPublicTableResource(path=_public_constraint_ht_path()) diff --git a/gnomad/resources/grch38/gnomad.py b/gnomad/resources/grch38/gnomad.py index 62cb950bb..3403a1d14 100644 --- a/gnomad/resources/grch38/gnomad.py +++ b/gnomad/resources/grch38/gnomad.py @@ -46,7 +46,6 @@ MAJOR_RELEASES = ["v3", "v4"] CURRENT_MAJOR_RELEASE = MAJOR_RELEASES[-1] - GENOME_POPS = ["AFR", "AMI", "AMR", "ASJ", "EAS", "FIN", "NFE", "SAS", "OTH"] SUBSETS = { "v3": [ @@ -365,6 +364,33 @@ def _public_an_ht_path(data_type: str, version: str) -> str: return f"gs://gnomad-public-requester-pays/release/{version}/ht/{data_type}/gnomad.{data_type}.v{version}.allele_number_all_sites.ht" +def _public_pext_ht_path(pext_type: str = "base_level") -> str: + """ + Get public proportion expressed across transcripts (pext) data. + + :param pext_type: One of "base_level" or "annotation_level". Default is "base_level". + :return: Path to pext Table. + """ + valid_types = ["base_level", "annotation_level"] + + if pext_type not in valid_types: + raise DataException( + f"Invalid pext_type: '{pext_type}'. Valid options are {valid_types}." + ) + + return f"gs://gnomad-public-requester-pays/release/4.1/pext/gnomad.pext.gtex_v10.{pext_type}.ht" + + +def _public_constraint_ht_path(version: str) -> str: + """ + Get public constraint table path. + + :param version: One of the release versions of gnomAD on GRCh38. + :return: Path to gene constraint Table. + """ + return f"gs://gnomad-public-requester-pays/release/{version}/constraint/gnomad.v{version}.constraint_metrics.ht" + + def public_release(data_type: str) -> VersionedTableResource: """ Retrieve publicly released versioned table resource. @@ -701,3 +727,35 @@ def gnomad_gks( outputs.append(out) return outputs + + +def pext(pext_type: str = "base_level") -> GnomadPublicTableResource: + """ + Retrieve pext table by type. + + :param pext_type: One of "base_level" or "annotation_level". Default is "base_level". + :return: Pext Table. + """ + return GnomadPublicTableResource(path=_public_pext_ht_path(pext_type)) + + +def constraint(version: str = CURRENT_EXOME_RELEASE) -> VersionedTableResource: + """ + Retrieve gene constraint Table. + + :param version: One of the release versions of gnomAD on GRCh38. Default is the current exome release. + :return: Gene constraint Table. + :raises ValueError: If the version is not a valid release. + """ + if version not in EXOME_RELEASES: + raise ValueError( + f"Invalid version: {version}. Must be one of {EXOME_RELEASES}." + ) + + return VersionedTableResource( + CURRENT_EXOME_RELEASE, + { + release: GnomadPublicTableResource(path=_public_constraint_ht_path(release)) + for release in EXOME_RELEASES + }, + )