Skip to content

Commit

Permalink
test: failing doctest in different python version (#320)
Browse files Browse the repository at this point in the history
* test: issue on test with different python version

* refactor: value error instead of assertion
  • Loading branch information
d0choa authored Dec 12, 2023
1 parent e0297cb commit bbd9df4
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/otg/datasource/gwas_catalog/summary_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@


def filename_to_study_identifier(path: str) -> str:
r"""Extract GWAS Catalog study identifier from path.
"""Extract GWAS Catalog study identifier from path.
There's an expectation that the filename has to have the GCST accession of the study.
Expand All @@ -28,20 +28,24 @@ def filename_to_study_identifier(path: str) -> str:
Returns:
str: GWAS Catalog stuy accession.
Raises:
ValueError: If the path does not contain the GWAS Catalog study identifier.
Examples:
>>> filename_to_study_identifier("http://ftp.ebi.ac.uk/pub/databases/gwas/summary_statistics/GCST006001-GCST007000/GCST006090/harmonised/29895819-GCST006090-HP_0000975.h.tsv.gz")
'GCST006090'
>>> filename_to_study_identifier("wrong/path")
Traceback (most recent call last):
...
AssertionError: Path ("wrong/path") does not contain GWAS Catalog study identifier.
...
ValueError: Path ("wrong/path") does not contain GWAS Catalog study identifier.
"""
file_name = path.split("/")[-1]
study_id_matches = re.search(r"(GCST\d+)", file_name)

assert (
study_id_matches is not None
), f'Path ("{path}") does not contain GWAS Catalog study identifier.'
if not study_id_matches:
raise ValueError(
f'Path ("{path}") does not contain GWAS Catalog study identifier.'
)

return study_id_matches[0]

Expand Down

0 comments on commit bbd9df4

Please sign in to comment.