monarch-initiative / gpsea

A Python library for discovery of genotype-phenotype associations
https://monarch-initiative.github.io/gpsea/stable
MIT License
5 stars 1 forks source link

Simplify API for CohortViewable #262

Open pnrobinson opened 1 month ago

pnrobinson commented 1 month ago

Currently, we have this:

from gpsea.view import CohortViewable
cv = CohortViewable(hpo=hpo)
report = cv.process(cohort=cohort, transcript_id=POLR1A_MANE_transcript)
display(HTML(report))

but the report object is only used here. We could simplify the API by allowing something like this:

from gpsea.view import CohortViewable
display(HTML(CohortViewable.to_html(hpo=hpo, cohort=cohort, transcript_id=POLR1A_MANE_transcript)))

It would be great to reduce the number of lines of code for the Notebooks in general, this would help users!

ielis commented 1 month ago

Yeah, this could be turned into a free function that uses CohortViewable (CohortSummaryViewer would be a better name) under the hood.

So, instead of exporting CohortViewable from gpsea.view, there should be a function

def summarize_cohort(cohort: Cohort, hpo: hpotk.MinimalOntology, tx_id: str) -> str:
    # Implement!
    pass

which we should use as

from gpsea.view import summarize_cohort

summary = summarize_cohort(cohort, hpo, tx_id=POLR1A_MANE_transcript)
display(HTML(summary))