Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ exclude: |
| gget/constants/
| tests/fixtures/
| tests/pytest_results.*\.txt
| \.github/badges/.*\.json
)
repos:
- repo: https://github.com/biomejs/pre-commit
Expand Down
70 changes: 66 additions & 4 deletions gget/gget_8cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import io
import json as json_package
from typing import Any
from typing import Any, Literal, overload

import pandas as pd
import requests
Expand Down Expand Up @@ -54,12 +54,30 @@ def _normalize_gene_list(gene_list: list[str] | tuple[str, ...]) -> list[str]:
# --------------------------------------------------------------------
# 1. SPECIFICITY
# --------------------------------------------------------------------
@overload
def specificity(
gene_list: list[str] | tuple[str, ...],
json: Literal[False] = False,
save: bool = False,
verbose: bool = True,
) -> pd.DataFrame: ...


@overload
def specificity(
gene_list: list[str] | tuple[str, ...],
json: Literal[True],
save: bool = False,
verbose: bool = True,
) -> list[dict[str, Any]]: ...


def specificity(
gene_list: list[str] | tuple[str, ...],
json: bool = False,
save: bool = False,
verbose: bool = True,
) -> Any:
) -> pd.DataFrame | list[dict[str, Any]]:
"""Retrieve gene-level specificity statistics from the 8cubeDB.

(https://eightcubedb.onrender.com/).
Expand Down Expand Up @@ -126,14 +144,36 @@ def specificity(
# --------------------------------------------------------------------
# 2. PSI BLOCK
# --------------------------------------------------------------------
@overload
def psi_block(
gene_list: list[str] | tuple[str, ...],
analysis_level: str,
analysis_type: str,
json: Literal[False] = False,
save: bool = False,
verbose: bool = True,
) -> pd.DataFrame: ...


@overload
def psi_block(
gene_list: list[str] | tuple[str, ...],
analysis_level: str,
analysis_type: str,
json: Literal[True],
save: bool = False,
verbose: bool = True,
) -> list[dict[str, Any]]: ...


def psi_block(
gene_list: list[str] | tuple[str, ...],
analysis_level: str,
analysis_type: str,
json: bool = False,
save: bool = False,
verbose: bool = True,
) -> Any:
) -> pd.DataFrame | list[dict[str, Any]]:
"""Retrieve ψ_block (psi-block) specificity scores from the 8cubeDB.

ψ_block quantifies the specificity of a gene to a particular block
Expand Down Expand Up @@ -194,14 +234,36 @@ def psi_block(
# --------------------------------------------------------------------
# 3. GENE EXPRESSION
# --------------------------------------------------------------------
@overload
def gene_expression(
gene_list: list[str] | tuple[str, ...],
analysis_level: str,
analysis_type: str,
json: Literal[False] = False,
save: bool = False,
verbose: bool = True,
) -> pd.DataFrame: ...


@overload
def gene_expression(
gene_list: list[str] | tuple[str, ...],
analysis_level: str,
analysis_type: str,
json: Literal[True],
save: bool = False,
verbose: bool = True,
) -> list[dict[str, Any]]: ...


def gene_expression(
gene_list: list[str] | tuple[str, ...],
analysis_level: str,
analysis_type: str,
json: bool = False,
save: bool = False,
verbose: bool = True,
) -> Any:
) -> pd.DataFrame | list[dict[str, Any]]:
"""Retrieve normalized gene expression values from 8cubeDB.

This endpoint returns mean and variance of normalized expression for the
Expand Down
28 changes: 27 additions & 1 deletion gget/gget_archs4.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import io
import json as json_package
from typing import Any
from typing import Any, Literal, overload

import pandas as pd
import requests
Expand All @@ -17,6 +17,32 @@
from .gget_info import info # noqa: E402


@overload
def archs4(
gene: str,
ensembl: bool = False,
which: str = "correlation",
gene_count: int = 100,
species: str = "human",
json: Literal[True] = ...,
save: bool = False,
verbose: bool = True,
) -> list[dict[str, Any]] | None: ...


@overload
def archs4(
gene: str,
ensembl: bool = False,
which: str = "correlation",
gene_count: int = 100,
species: str = "human",
json: Literal[False] = False,
save: bool = False,
verbose: bool = True,
) -> pd.DataFrame | None: ...


def archs4(
gene: str,
ensembl: bool = False,
Expand Down
32 changes: 30 additions & 2 deletions gget/gget_bgee.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import json as json_
from importlib.metadata import PackageNotFoundError, version
from typing import TYPE_CHECKING, Any
from typing import TYPE_CHECKING, Any, Literal, overload

from .utils import dig, http_json, json_list_to_df, set_up_logger

Expand Down Expand Up @@ -180,13 +180,41 @@ def _bgee_expression(gene_id: str | list[str], json: bool = False, verbose: bool
return df


@overload
def bgee(
gene_id: str | list[str],
type: str,
json: Literal[True],
verbose: bool = ...,
) -> list[dict[str, Any]]: ...


@overload
def bgee(
gene_id: str | list[str],
type: str = ...,
*,
json: Literal[True],
verbose: bool = ...,
) -> list[dict[str, Any]]: ...


@overload
def bgee(
gene_id: str | list[str],
type: str = ...,
json: Literal[False] = False,
verbose: bool = ...,
) -> pd.DataFrame: ...


# noinspection PyShadowingBuiltins
def bgee(
gene_id: str | list[str],
type: str = "orthologs",
json: bool = False,
verbose: bool = True,
) -> pd.DataFrame | Any:
) -> pd.DataFrame | list[dict[str, Any]]:
"""Get orthologs/expression data for a gene from Bgee (https://www.bgee.org/).

Args:
Expand Down
35 changes: 34 additions & 1 deletion gget/gget_blast.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import json as json_package
import time
from io import StringIO
from typing import Any
from typing import Any, Literal, overload
from urllib.parse import urlencode

# Using urllib instead of requests here because requests does not
Expand All @@ -25,6 +25,39 @@
)


@overload
def blast(
sequence: str,
program: str = "default",
database: str = "default",
limit: int = 50,
expect: float = 10.0,
low_comp_filt: bool = False,
megablast: bool = True,
verbose: bool = True,
wrap_text: bool = False,
*,
json: Literal[True],
save: bool = False,
) -> list[dict[str, Any]] | None: ...


@overload
def blast(
sequence: str,
program: str = "default",
database: str = "default",
limit: int = 50,
expect: float = 10.0,
low_comp_filt: bool = False,
megablast: bool = True,
verbose: bool = True,
wrap_text: bool = False,
json: Literal[False] = False,
save: bool = False,
) -> pd.DataFrame | None: ...


def blast(
sequence: str,
program: str = "default",
Expand Down
26 changes: 24 additions & 2 deletions gget/gget_blat.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import json as json_package
import time
from json.decoder import JSONDecodeError
from typing import Any
from typing import Any, Literal, overload
from urllib import request
from urllib.error import HTTPError, URLError

Expand All @@ -18,6 +18,28 @@
_BLAT_BACKOFF_BASE_SECONDS = 1.5


@overload
def blat(
sequence: str,
seqtype: str = ...,
assembly: str = ...,
json: Literal[True] = ...,
save: bool = ...,
verbose: bool = ...,
) -> list[dict[str, Any]] | None: ...


@overload
def blat(
sequence: str,
seqtype: str = ...,
assembly: str = ...,
json: Literal[False] = ...,
save: bool = ...,
verbose: bool = ...,
) -> pd.DataFrame | None: ...


def blat(
sequence: str,
seqtype: str = "default",
Expand Down Expand Up @@ -133,7 +155,7 @@ def blat(

## Build data frame to resemble BLAT web search results
# Define dataframe from dictionary
df_dict = {}
df_dict: dict[str, list[Any]] = {}

for field in results["fields"]:
df_dict.update({field: []})
Expand Down
51 changes: 49 additions & 2 deletions gget/gget_cosmic.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import shutil
import subprocess
import tarfile
from typing import Any
from typing import Any, Literal, overload

import pandas as pd

Expand Down Expand Up @@ -315,6 +315,53 @@ def match_and_limit(mask, extract_fn):
return results


@overload
def cosmic(
searchterm: str | None,
cosmic_tsv_path: str | None = None,
limit: int = 100,
*,
json: Literal[True],
download_cosmic: bool = False,
cosmic_project: str | None = None,
cosmic_version: int | None = None,
grch_version: int = 37,
email: str | None = None,
password: str | None = None,
gget_mutate: bool = False,
keep_genome_info: bool = False,
remove_duplicates: bool = False,
seq_id_column: str = "seq_ID",
mutation_column: str = "mutation",
mut_id_column: str = "mutation_id",
out: str | None = None,
verbose: bool = True,
) -> list[dict[str, Any]] | None: ...


@overload
def cosmic(
searchterm: str | None,
cosmic_tsv_path: str | None = None,
limit: int = 100,
json: Literal[False] = False,
download_cosmic: bool = False,
cosmic_project: str | None = None,
cosmic_version: int | None = None,
grch_version: int = 37,
email: str | None = None,
password: str | None = None,
gget_mutate: bool = False,
keep_genome_info: bool = False,
remove_duplicates: bool = False,
seq_id_column: str = "seq_ID",
mutation_column: str = "mutation",
mut_id_column: str = "mutation_id",
out: str | None = None,
verbose: bool = True,
) -> pd.DataFrame | None: ...


def cosmic(
searchterm: str | None,
cosmic_tsv_path: str | None = None,
Expand All @@ -334,7 +381,7 @@ def cosmic(
mut_id_column: str = "mutation_id",
out: str | None = None,
verbose: bool = True,
) -> Any:
) -> pd.DataFrame | list[dict[str, Any]] | None:
"""Search for genes, mutations, etc associated with cancers using the COSMIC database.

(Catalogue Of Somatic Mutations In Cancer) database
Expand Down
Loading
Loading