Skip to content

Commit

Permalink
Fix rendering of method parameters (#51)
Browse files Browse the repository at this point in the history
* Fix rendering of method parameters

* ibis 0.6 compat
  • Loading branch information
ivirshup authored Sep 20, 2023
1 parent 5bcc2a4 commit d7b7311
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 22 deletions.
4 changes: 4 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ help:

.PHONY: help Makefile

clean:
@$(SPHINXBUILD) -M clean "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
rm -r "generated"

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ urls.Documentation = "https://genomic-features.readthedocs.io/"
urls.Source = "https://github.com/scverse/genomic-features"
urls.Home-page = "https://github.com/scverse/genomic-features"
dependencies = [
"ibis-framework[sqlite]",
"ibis-framework[sqlite]>0.6",
"pooch",
"pandas",
"pyarrow",
Expand Down
82 changes: 61 additions & 21 deletions src/genomic_features/ensembl/ensembldb.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
TIMESTAMP_URL = "https://annotationhub.bioconductor.org/metadata/database_timestamp"


def annotation(species: str, version: str | int):
def annotation(species: str, version: str | int) -> EnsemblDB:
"""Get an annotation database for a species and version.
Parameters
Expand All @@ -43,8 +43,12 @@ def annotation(species: str, version: str | int):
Returns
-------
EnsemblDB
The annotation database.
The annotation database.
Usage
-----
>>> gf.ensembl.annotation("Hsapiens", "108")
"""
try:
ensdb = EnsemblDB(
Expand Down Expand Up @@ -75,8 +79,12 @@ def list_ensdb_annotations(species: None | str | list[str] = None) -> DataFrame:
Returns
-------
DataFrame
A table of available species and annotation versions in EnsDb.
A table of available species and annotation versions in EnsDb.
Usage
-----
>>> gf.ensembl.list_ensdb_annotations("Mmusculus")
"""
# Get latest AnnotationHub timestamp
db_path = Path(retrieve_annotation(ANNOTATION_HUB_URL))
Expand Down Expand Up @@ -126,7 +134,7 @@ def __init__(self, connection: ibis.BaseBackend):

@cached_property
def metadata(self) -> dict:
"""Metadata for the database (e.g. who built it, when, with what resource)."""
"""Metadata for the database as a dict (e.g. who built it, when, with what resource)."""
metadata_tbl = self.db.table("metadata").execute()
return dict(zip(metadata_tbl["name"], metadata_tbl["value"]))

Expand All @@ -140,7 +148,23 @@ def genes(
filter: _filters.AbstractFilterExpr = filters.EmptyFilter(),
join_type: Literal["inner", "left"] = "inner",
) -> DataFrame:
"""Get the genes table."""
"""Get gene annotations.
Parameters
----------
cols
Which columns to retrieve from the database. Can be from other tables.
Returns all gene columns if None.
filters
Filters to apply to the query.
join_type
How to perform joins during the query (if cols or filters requires them).
Usage
-----
>>> ensdb.genes(cols=["gene_id", "gene_name", "tx_id"])
"""
table: Final = "gene"
if cols is None:
# TODO: check why R adds entrezid
Expand All @@ -159,17 +183,22 @@ def transcripts(
filter: _filters.AbstractFilterExpr = filters.EmptyFilter(),
join_type: Literal["inner", "left"] = "inner",
) -> DataFrame:
"""Get transcripts table.
"""Get transcript annotations.
Params
------
Parameters
----------
cols
Columns to return, can be from other tables. Returns all transcript columns
if None.
filter
Filter to apply to the query.
Which columns to retrieve from the database. Can be from other tables.
Returns all transcript columns if None.
filters
Filters to apply to the query.
join_type
Type of join to use for the query.
How to perform joins during the query (if cols or filters requires them).
Usage
-----
>>> ensdb.transcripts(cols=["tx_id", "tx_name", "gene_id"])
"""
table: Final = "tx"
if cols is None:
Expand All @@ -194,15 +223,20 @@ def exons(
) -> DataFrame:
"""Get exons table.
Params
------
Parameters
----------
cols
Columns to return, can be from other tables. Returns all exon columns if
None.
Which columns to retrieve from the database. Can be from other tables.
Returns all exon columns if None.
filter
Filter to apply to the query.
join_type
Type of join to use for the query.
Usage
-----
>>> ensdb.exons()
"""
table: Final = "exon"
if cols is None:
Expand All @@ -227,7 +261,12 @@ def _execute_query(self, query: IbisTable) -> DataFrame:
return query.distinct().execute()

def chromosomes(self) -> DataFrame:
"""Get chromosome information."""
"""Get chromosome information (seq_name, length, etc.).
Usage
-----
>>> ensdb.chromosomes()
"""
return self.db.table("chromosome").execute()

def _build_query(
Expand Down Expand Up @@ -306,7 +345,8 @@ def _join_query(
t2,
predicates=[key],
how="left",
suffixes=("", "_y"),
rname="{name}_y",
# suffixes=("", "_y"),
)
query = query.drop(f"{key}_y") # drop duplicate columns
else:
Expand Down

0 comments on commit d7b7311

Please sign in to comment.