Skip to content

Commit 5f0ad99

Browse files
committed
fix up some docs
1 parent 4cfd4ff commit 5f0ad99

3 files changed

Lines changed: 46 additions & 24 deletions

File tree

src/cool_seq_tool/mappers/exon_genomic_coords.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,7 @@ def check_errors(cls, values: dict) -> dict: # noqa: N805
105105
"""Ensure that fields are (un)set depending on errors
106106
107107
:param values: Values in model
108-
:raises ValueError: If `seg`, `genomic_ac` and `tx_ac` are not
109-
provided when there are no errors
108+
:raises ValueError: If `seg`, `genomic_ac` and `tx_ac` are not provided when there are no errors
110109
:return: Values in model
111110
"""
112111
if not values.get("errors") and not all(

src/cool_seq_tool/resources/status.py

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@
1212
from cool_seq_tool.handlers.seqrepo_access import SEQREPO_ROOT_DIR, SeqRepoAccess
1313
from cool_seq_tool.mappers.liftover import LiftOver
1414
from cool_seq_tool.resources.data_files import DataFile, get_data_file
15-
from cool_seq_tool.sources.uta_database import UTA_DB_URL, ParseResult, UtaDatabase
15+
from cool_seq_tool.sources.uta_database import (
16+
DEFAULT_UTA_DB_URL,
17+
ParseResult,
18+
UtaDatabase,
19+
create_uta_connection_pool,
20+
)
1621

1722
_logger = logging.getLogger(__name__)
1823

@@ -35,7 +40,7 @@ async def check_status(
3540
transcript_file_path: Path | None = None,
3641
lrg_refseqgene_path: Path | None = None,
3742
mane_data_path: Path | None = None,
38-
db_url: str = UTA_DB_URL,
43+
db_url: str | None = None,
3944
sr: SeqRepo | None = None,
4045
chain_file_37_to_38: str | None = None,
4146
chain_file_38_to_37: str | None = None,
@@ -120,24 +125,31 @@ async def check_status(
120125
else:
121126
status["liftover"] = True
122127

123-
parsed_result = ParseResult(urlparse(db_url))
124-
sanitized_url = parsed_result.sanitized_url
125-
try:
126-
await UtaDatabase.create(db_url)
127-
except ValueError:
128-
_logger.exception("Database URL is not valid")
129-
except (OSError, InvalidCatalogNameError, UndefinedTableError):
130-
_logger.exception(
131-
"Encountered error instantiating UTA at URI %s", sanitized_url
132-
)
133-
except Exception as e:
134-
_logger.critical(
135-
"Encountered unexpected error instantiating UTA from URI %s: %s",
136-
sanitized_url,
137-
e,
138-
)
128+
uta_pool = await create_uta_connection_pool(db_url)
129+
uta_db = UtaDatabase(uta_pool)
130+
if db_url:
131+
sanitized_url = ParseResult(urlparse(db_url)).sanitized_url
139132
else:
140-
status["uta"] = True
133+
sanitized_url = DEFAULT_UTA_DB_URL
134+
135+
async with uta_db.repository() as uta:
136+
try:
137+
cursor = await uta.execute_query("SELECT 1 FROM transcript LIMIT 1;")
138+
await cursor.fetchone()
139+
except ValueError:
140+
_logger.exception("Database URL is not valid: %s", sanitized_url)
141+
except (OSError, InvalidCatalogNameError, UndefinedTableError):
142+
_logger.exception(
143+
"Encountered error instantiating UTA at URI %s", sanitized_url
144+
)
145+
except Exception as e:
146+
_logger.critical(
147+
"Encountered unexpected error instantiating UTA from URI %s: %s",
148+
sanitized_url,
149+
e,
150+
)
151+
else:
152+
status["uta"] = True
141153

142154
try:
143155
if not sr:

src/cool_seq_tool/sources/uta_database.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414
True
1515
1616
The class breakdown in this module is intended to reflect a *repository pattern*, where
17-
query/data transformation logic is separated from connection lifespan management. See the
18-
following example for how you might employ this in a FastAPI app:
17+
query/data transformation logic is defined in :py:class:`~cool_seq_tool.uta_database.UtaRepository`,
18+
and connection management/state/etc is defined in :py:class:`~cool_seq_tool.uta_database.UtaDatabase`.
19+
20+
The following is an example of how you might employ this in a FastAPI app:
1921
2022
.. code-block:: python
2123
@@ -52,6 +54,15 @@ async def check_gene_exists(
5254
):
5355
return await uta.gene_exists(gene)
5456
57+
The connection class also provides a ``repository()`` method, which returns a context
58+
manager, for convenience:
59+
60+
.. code-block:: python
61+
62+
uta_db: UtaDatabase # assume this exists
63+
async with uta_db.repository() as uta:
64+
print(await uta.gene_exists("BRAF"))
65+
5566
"""
5667

5768
import ast
@@ -342,7 +353,7 @@ async def gene_exists(self, gene: str) -> bool:
342353
"""Return whether or not a gene symbol exists in UTA gene table
343354
344355
:param gene: Gene symbol
345-
:return ``True`` if gene symbol exists in UTA, ``False`` if not
356+
:return: ``True`` if gene symbol exists in UTA, ``False`` if not
346357
"""
347358
query = """
348359
SELECT EXISTS(

0 commit comments

Comments
 (0)