-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new sources for CiVIC Gene and OMIM Phenotypic series (#176)
- Loading branch information
Showing
5 changed files
with
100 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
"""Converter for CiVIC Genes.""" | ||
|
||
from typing import Iterable, Optional | ||
|
||
import pandas as pd | ||
|
||
from pyobo.struct import Obo, Reference, Term | ||
from pyobo.utils.path import ensure_df | ||
|
||
__all__ = [ | ||
"CIVICGeneGetter", | ||
] | ||
|
||
PREFIX = "civic.gid" | ||
URL = "https://civicdb.org/downloads/nightly/nightly-GeneSummaries.tsv" | ||
|
||
|
||
def _sort(_o, t): | ||
return int(t.identifier) | ||
|
||
|
||
class CIVICGeneGetter(Obo): | ||
"""An ontology representation of CiVIC's gene nomenclature.""" | ||
|
||
bioversions_key = ontology = PREFIX | ||
term_sort_key = _sort | ||
|
||
def iter_terms(self, force: bool = False) -> Iterable[Term]: | ||
"""Iterate over gene terms for CiVIC.""" | ||
yield from get_terms(self.data_version, force=force) | ||
|
||
|
||
def get_terms(version: Optional[str] = None, force: bool = False) -> Iterable[Term]: | ||
"""Get CIVIC terms.""" | ||
# if version is not None: | ||
# version_dt: datetime.date = dateutil.parser.parse(version) | ||
# else: | ||
# version_dt: datetime.date = datetime.today() | ||
# version = version_dt.strftime("01-%b-%Y") | ||
# version is like 01-Feb-2024 | ||
url = f"https://civicdb.org/downloads/{version}/{version}-GeneSummaries.tsv" | ||
df = ensure_df(prefix=PREFIX, url=url, sep="\t", force=force, dtype=str, version=version) | ||
for identifier, _, name, entrez_id, description, _last_review, _flag in df.values: | ||
term = Term( | ||
reference=Reference(prefix=PREFIX, identifier=identifier, name=name), | ||
definition=description if pd.notna(description) else None, | ||
) | ||
term.append_exact_match(Reference(prefix="ncbigene", identifier=entrez_id)) | ||
yield term | ||
|
||
|
||
if __name__ == "__main__": | ||
CIVICGeneGetter.cli() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
"""Converter for OMIM Phenotypic Series.""" | ||
|
||
import logging | ||
from typing import Iterable | ||
|
||
from bioversions.utils import get_soup | ||
|
||
from pyobo.struct import Obo, Term | ||
|
||
__all__ = [ | ||
"OMIMPSGetter", | ||
] | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
PREFIX = "omim.ps" | ||
URL = "https://omim.org/phenotypicSeriesTitles/all" | ||
|
||
|
||
class OMIMPSGetter(Obo): | ||
"""An ontology representation of OMIM Phenotypic Series.""" | ||
|
||
ontology = bioversions_key = PREFIX | ||
|
||
def iter_terms(self, force: bool = False) -> Iterable[Term]: | ||
"""Iterate over terms in the ontology.""" | ||
soup = get_soup(URL, user_agent="Mozilla/5.0") | ||
rows = soup.find(id="mimContent").find("table").find("tbody").find_all("tr") | ||
for row in rows: | ||
anchor = row.find("td").find("a") | ||
name = anchor.text.strip() | ||
identifier = anchor.attrs["href"][len("/phenotypicSeries/") :] | ||
yield Term.from_triple(PREFIX, identifier, name) | ||
|
||
|
||
if __name__ == "__main__": | ||
OMIMPSGetter.cli() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters