Skip to content

Commit

Permalink
build: require >=3.10 (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsstevenson authored and bencap committed May 31, 2024
1 parent 090fca0 commit e5a9703
Show file tree
Hide file tree
Showing 15 changed files with 137 additions and 146 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ classifiers = [
"Intended Audience :: Science/Research",
"Topic :: Scientific/Engineering :: Bio-Informatics",
]
requires-python = ">=3.8"
requires-python = ">=3.10"
dependencies = [
"requests",
"biopython",
Expand Down
9 changes: 4 additions & 5 deletions src/dcd_mapping/align.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import subprocess
import tempfile
from pathlib import Path
from typing import List, Optional
from urllib.parse import urlparse

import requests
Expand Down Expand Up @@ -39,7 +38,7 @@ class AlignmentError(Exception):
"""Raise when errors encountered during alignment."""


def _write_query_file(file: Path, lines: List[str]) -> None:
def _write_query_file(file: Path, lines: list[str]) -> None:
"""Write lines to query file. This method is broken out to enable easy mocking while
testing.
Expand All @@ -65,7 +64,7 @@ def _build_query_file(scoreset_metadata: ScoresetMetadata, query_file: Path) ->


def get_ref_genome_file(
silent: bool = True, dcd_mapping_dir: Optional[Path] = None
silent: bool = True, dcd_mapping_dir: Path | None = None
) -> Path:
"""Acquire reference genome file in 2bit format from UCSC.
Expand Down Expand Up @@ -174,7 +173,7 @@ def _get_blat_output(metadata: ScoresetMetadata, silent: bool) -> QueryResult:
return output


def _get_best_hit(output: QueryResult, urn: str, chromosome: Optional[str]) -> Hit:
def _get_best_hit(output: QueryResult, urn: str, chromosome: str | None) -> Hit:
"""Get best hit from BLAT output.
First, try to return hit corresponding to expected chromosome taken from scoreset
Expand Down Expand Up @@ -223,7 +222,7 @@ def _get_best_hit(output: QueryResult, urn: str, chromosome: Optional[str]) -> H
return best_score_hit


def _get_best_hsp(hit: Hit, urn: str, gene_location: Optional[GeneLocation]) -> HSP:
def _get_best_hsp(hit: Hit, urn: str, gene_location: GeneLocation | None) -> HSP:
"""Retrieve preferred HSP from BLAT Hit object.
If gene location data is available, prefer the HSP with the least distance
Expand Down
29 changes: 14 additions & 15 deletions src/dcd_mapping/annotate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import json
import logging
from pathlib import Path
from typing import Dict, List, Optional

import hgvs.edit
import hgvs.location
Expand Down Expand Up @@ -179,7 +178,7 @@ def get_vod_postmapped(allele: dict) -> dict:
}


def get_vod_haplotype(allele_list: List[dict]) -> dict:
def get_vod_haplotype(allele_list: list[dict]) -> dict:
"""Define VOD model for haplotype
:param allele_list: A list of VRS allele dictionaries
Expand All @@ -191,7 +190,7 @@ def get_vod_haplotype(allele_list: List[dict]) -> dict:
def get_computed_reference_sequence(
ss: str,
layer: AnnotationLayer,
tx_output: Optional[TxSelectResult] = None,
tx_output: TxSelectResult | None = None,
) -> ComputedReferenceSequence:
"""Report the computed reference sequence for a score set
Expand All @@ -218,8 +217,8 @@ def get_computed_reference_sequence(

def get_mapped_reference_sequence(
layer: AnnotationLayer,
tx_output: Optional[TxSelectResult] = None,
align_result: Optional[AlignmentResult] = None,
tx_output: TxSelectResult | None = None,
align_result: AlignmentResult | None = None,
) -> MappedReferenceSequence:
"""Report the mapped reference sequence for a score set
Expand Down Expand Up @@ -248,7 +247,7 @@ def get_mapped_reference_sequence(
)


def _set_layer(ss: str, mappings: List[VrsObject1_x]) -> AnnotationLayer:
def _set_layer(ss: str, mappings: list[VrsObject1_x]) -> AnnotationLayer:
if ss.startswith("urn:mavedb:00000097"):
return AnnotationLayer.PROTEIN
for var in mappings:
Expand All @@ -257,7 +256,7 @@ def _set_layer(ss: str, mappings: List[VrsObject1_x]) -> AnnotationLayer:
return AnnotationLayer.PROTEIN


def _format_score_mapping(var: VrsObject1_x, layer: AnnotationLayer) -> Optional[Dict]:
def _format_score_mapping(var: VrsObject1_x, layer: AnnotationLayer) -> dict | None:
if var and var.layer == layer:
if "members" in var.pre_mapped_variants:
pre_mapped_members = []
Expand All @@ -283,10 +282,10 @@ def _format_score_mapping(var: VrsObject1_x, layer: AnnotationLayer) -> Optional

def save_mapped_output_json(
ss: str,
mappings: List[VrsObject1_x],
mappings: list[VrsObject1_x],
align_result: AlignmentResult,
tx_output: Optional[TxSelectResult] = None,
output_path: Optional[Path] = None,
tx_output: TxSelectResult | None = None,
output_path: Path | None = None,
) -> None:
"""Save mapping output for a score set in a JSON file
Expand Down Expand Up @@ -316,15 +315,15 @@ def save_mapped_output_json(
mapped_scores.append(formatted_score_mapping)
mapped_ss_output["mapped_scores"] = mapped_scores

ss = ss.strip("urn:mavedb:") # noqa: B005
ss = ss.removeprefix("urn:mavedb:")
if not output_path:
output_path = LOCAL_STORE_PATH / f"{ss}_mapping.json"

with output_path.open("w") as file:
json.dump(mapped_ss_output, file, indent=4)


def _format_start_end(ss: str, start: int, end: int) -> List[int]:
def _format_start_end(ss: str, start: int, end: int) -> list[int]:
"""Format start and end coordinates for vrs_ref_allele_seq for known edge cases
:param ss: score set
Expand All @@ -346,10 +345,10 @@ def _format_start_end(ss: str, start: int, end: int) -> List[int]:


def annotate(
tx_select_results: Optional[TxSelectResult],
vrs_results: List[VrsObject1_x],
tx_select_results: TxSelectResult | None,
vrs_results: list[VrsObject1_x],
metadata: ScoresetMetadata,
) -> List[VrsObject1_x]:
) -> list[VrsObject1_x]:
"""TODO"""
sr = get_seqrepo()
for var in vrs_results:
Expand Down
3 changes: 1 addition & 2 deletions src/dcd_mapping/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import asyncio
import logging
from pathlib import Path
from typing import Optional

import click

Expand Down Expand Up @@ -32,7 +31,7 @@
default=None,
help="Desired location at which output file should be saved",
)
def cli(urn: str, debug: bool, output: Optional[Path]) -> None:
def cli(urn: str, debug: bool, output: Path | None) -> None:
"""Get VRS mapping on preferred transcript for URN.
For example:
Expand Down
35 changes: 17 additions & 18 deletions src/dcd_mapping/lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import logging
import os
from pathlib import Path
from typing import List, Optional

import polars as pl
import requests
Expand Down Expand Up @@ -78,7 +77,7 @@ def __new__(cls) -> CoolSeqTool:
"""

class _AugmentedSeqRepoAccess(SeqRepoAccess):
def derive_refget_accession(self, ac: str) -> Optional[str]:
def derive_refget_accession(self, ac: str) -> str | None:
if ac is None:
return None

Expand All @@ -104,7 +103,7 @@ def __init__(
lrg_refseqgene_path: Path = LRG_REFSEQGENE_PATH,
mane_data_path: Path = MANE_SUMMARY_PATH,
db_url: str = UTA_DB_URL,
sr: Optional[SeqRepo] = None,
sr: SeqRepo | None = None,
) -> None:
if not sr:
sr = SeqRepo(root_dir=SEQREPO_ROOT_DIR)
Expand Down Expand Up @@ -184,7 +183,7 @@ def __new__(cls, data_proxy: SeqRepoDataProxy) -> AlleleTranslator:
# ----------------------------------- UTA ----------------------------------- #


async def get_protein_accession(transcript: str) -> Optional[str]:
async def get_protein_accession(transcript: str) -> str | None:
"""Retrieve protein accession for a transcript.
:param transcript: transcript accession, e.g. ``"NM_002529.3"``
Expand All @@ -203,7 +202,7 @@ async def get_protein_accession(transcript: str) -> Optional[str]:

async def get_transcripts(
gene_symbol: str, chromosome_ac: str, start: int, end: int
) -> List[str]:
) -> list[str]:
"""Get transcript accessions matching given parameters (excluding non-coding RNA).
TODO: may be able to successfully query with only one of gene symbol/chromosome ac.
Expand Down Expand Up @@ -233,7 +232,7 @@ async def get_transcripts(
# ------------------------------ Gene Normalizer ------------------------------ #


def _get_hgnc_symbol(term: str) -> Optional[str]:
def _get_hgnc_symbol(term: str) -> str | None:
"""Fetch HGNC symbol from gene term.
:param term: gene referent
Expand All @@ -248,7 +247,7 @@ def _get_hgnc_symbol(term: str) -> Optional[str]:
return None


def get_gene_symbol(metadata: ScoresetMetadata) -> Optional[str]:
def get_gene_symbol(metadata: ScoresetMetadata) -> str | None:
"""Acquire HGNC gene symbol given provided metadata from scoreset.
Right now, we use two sources for normalizing:
Expand All @@ -271,7 +270,7 @@ def get_gene_symbol(metadata: ScoresetMetadata) -> Optional[str]:
return None


def _normalize_gene(term: str) -> Optional[Gene]:
def _normalize_gene(term: str) -> Gene | None:
"""Fetch normalizer response for gene term.
:param term: gene name or referent to normalize
Expand All @@ -286,7 +285,7 @@ def _normalize_gene(term: str) -> Optional[Gene]:

def _get_normalized_gene_response(
metadata: ScoresetMetadata,
) -> Optional[Gene]:
) -> Gene | None:
"""Fetch best normalized concept given available scoreset metadata.
:param metadata: salient scoreset metadata items
Expand All @@ -308,8 +307,8 @@ def _get_normalized_gene_response(


def _get_genomic_interval(
extensions: List[Extension], src_name: str
) -> Optional[GeneLocation]:
extensions: list[Extension], src_name: str
) -> GeneLocation | None:
"""Extract start/end coords from extension list. Extensions in normalized genes
can be of several different types, but we only want SequenceLocation data.
Expand All @@ -332,7 +331,7 @@ def _get_genomic_interval(
return None


def get_gene_location(metadata: ScoresetMetadata) -> Optional[GeneLocation]:
def get_gene_location(metadata: ScoresetMetadata) -> GeneLocation | None:
"""Acquire gene location data from gene normalizer using metadata provided by
scoreset.
Expand Down Expand Up @@ -404,7 +403,7 @@ def get_ucsc_chromosome_name(chromosome: str) -> str:
raise KeyError from e


def get_chromosome_identifier_from_vrs_id(sequence_id: str) -> Optional[str]:
def get_chromosome_identifier_from_vrs_id(sequence_id: str) -> str | None:
"""Get NC_ identifier given a VRS sequence ID.
:param sequence_id: identifier a la ``ga4gh:SQ.XXXXXX``
Expand All @@ -420,7 +419,7 @@ def get_chromosome_identifier_from_vrs_id(sequence_id: str) -> Optional[str]:
return sorted_results[-1]


def get_vrs_id_from_identifier(sequence_id: str) -> Optional[str]:
def get_vrs_id_from_identifier(sequence_id: str) -> str | None:
"""Get GA4GH SQ identifier given an NP_ sequence id:
:param: GA4GH SQ digest
:raise KeyError: if unable to retrieve identifier
Expand All @@ -436,8 +435,8 @@ def get_vrs_id_from_identifier(sequence_id: str) -> Optional[str]:

def get_sequence(
sequence_id: str,
start: Optional[int] = None,
end: Optional[int] = None,
start: int | None = None,
end: int | None = None,
) -> str:
"""Get reference sequence given a sequence identifier.
Expand Down Expand Up @@ -490,7 +489,7 @@ def translate_hgvs_to_vrs(hgvs: str) -> Allele:
# ----------------------------------- MANE ----------------------------------- #


def get_mane_transcripts(transcripts: List[str]) -> List[ManeDescription]:
def get_mane_transcripts(transcripts: list[str]) -> list[ManeDescription]:
"""Get corresponding MANE data for transcripts. Results given in order of
transcript preference.
Expand Down Expand Up @@ -542,7 +541,7 @@ def _sort_mane_result(description: ManeDescription) -> int:
# ---------------------------------- Misc. ---------------------------------- #


def get_uniprot_sequence(uniprot_id: str) -> Optional[str]:
def get_uniprot_sequence(uniprot_id: str) -> str | None:
"""Get sequence directly from UniProt.
:param uniprot_id: ID provided with target info
Expand Down
7 changes: 3 additions & 4 deletions src/dcd_mapping/main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Provide core MaveDB mapping methods."""
import logging
from pathlib import Path
from typing import List, Optional

import click

Expand All @@ -21,9 +20,9 @@

async def map_scoreset(
metadata: ScoresetMetadata,
records: List[ScoreRow],
records: list[ScoreRow],
silent: bool = True,
output_path: Optional[Path] = None,
output_path: Path | None = None,
) -> None:
"""Given information about a MAVE experiment, map to VRS and save output as JSON.
Expand Down Expand Up @@ -62,7 +61,7 @@ async def map_scoreset(


async def map_scoreset_urn(
urn: str, silent: bool = True, output_path: Optional[Path] = None
urn: str, silent: bool = True, output_path: Path | None = None
) -> None:
"""Perform end-to-end mapping for a scoreset.
Expand Down
Loading

0 comments on commit e5a9703

Please sign in to comment.