Skip to content

Commit

Permalink
Deploying to gh-pages from @ cfff1ba 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
ielis committed Dec 5, 2023
1 parent 7bf938b commit 07bb067
Show file tree
Hide file tree
Showing 9 changed files with 130 additions and 48 deletions.
6 changes: 3 additions & 3 deletions stable/_modules/hpotk/validate/_model.html
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,11 @@ <h1>Source code for hpotk.validate._model</h1><div class="highlight"><pre>
<span class="sd"> The runner applies a sequence of rule validators on items and packs the results</span>
<span class="sd"> into :class:`ValidationResults`.</span>

<span class="sd"> :param validators: a sequence of :class:`RuleValidator`\ s to apply.</span>
<span class="sd"> :param validators: an iterable of :class:`RuleValidator`\ s to apply.</span>
<span class="sd"> &quot;&quot;&quot;</span>

<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">validators</span><span class="p">:</span> <span class="n">typing</span><span class="o">.</span><span class="n">Sequence</span><span class="p">[</span><span class="n">RuleValidator</span><span class="p">]):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_validators</span> <span class="o">=</span> <span class="n">validators</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">validators</span><span class="p">:</span> <span class="n">typing</span><span class="o">.</span><span class="n">Iterable</span><span class="p">[</span><span class="n">RuleValidator</span><span class="p">]):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_validators</span> <span class="o">=</span> <span class="nb">tuple</span><span class="p">(</span><span class="n">validators</span><span class="p">)</span>

<div class="viewcode-block" id="ValidationRunner.validate_all">
<a class="viewcode-back" href="../../../apidocs/hpotk.validate.html#hpotk.validate.ValidationRunner.validate_all">[docs]</a>
Expand Down
49 changes: 30 additions & 19 deletions stable/_sources/user-guide/load-ontology.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,35 @@ JSON file which is available for download from the `HPO website <https://hpo.jax
Minimal ontology
^^^^^^^^^^^^^^^^

Let's load HPO:
Let's load the HPO version released on Oct 9th, 2023:

.. doctest:: load-minimal-ontology

>>> import hpotk

>>> hpo = hpotk.load_minimal_ontology('data/hp.toy.json')
>>> hpo.version
'2022-10-05'
>>> url = 'https://github.com/obophenotype/human-phenotype-ontology/releases/download/v2023-10-09/hp.json'
>>> hpo = hpotk.load_minimal_ontology(url)

We load the ontology from a toy Obographs JSON file and we check the version of the data.
The loader fetches the Obographs JSON file and loads the data into :class:`hpotk.ontology.MinimalOntology`.

.. note::

The loader can fetch the HPO from a URL, and it transparently handles gzipped files
if the file name ends with `.gz` suffix.

Now, we can check that the toy HPO has 393 primary terms:
Having `MinimalOntology`, we can do several checks. We can check the HPO version:

.. doctest:: load-minimal-ontology

>>> hpo.version
'2023-10-09'

check that the Oct 9th release has *17,664* terms:

.. doctest:: load-minimal-ontology

>>> len(hpo)
393
17664

check that `HP:0001250` is/was a valid identifier:

Expand All @@ -54,18 +60,22 @@ or print names of its children in alphabetical order:

.. doctest:: load-minimal-ontology

>>> children_names = sorted(
... map(lambda ch: hpo.get_term(ch).name,
... hpo.graph.get_children(seizure)))
>>> for child in children_names:
>>> for child in sorted(hpo.get_term_name(child)
... for child in hpo.graph.get_children(seizure)):
... print(child)
Bilateral tonic-clonic seizure
Dialeptic seizure
Focal-onset seizure
Generalized-onset seizure
Infection-related seizure
Maternal seizure
Motor seizure

.. note::

The toy HPO is a subset of the full HPO and Seizure only 2 child terms in the toy file. There are more children
in the real-life ("production") HPO.
Neonatal seizure
Nocturnal seizures
Non-motor seizure
Reflex seizure
Status epilepticus
Symptomatic seizures

The terms of :class:`hpotk.ontology.MinimalOntology` are instances of :class:`hpotk.model.MinimalTerm` and contain a subset
of the term metadata such as identifier, labels, and alternative IDs. The simplified are useful for tasks that
Expand All @@ -80,12 +90,13 @@ loader function:
.. testsetup:: load-ontology

import hpotk
url = 'https://github.com/obophenotype/human-phenotype-ontology/releases/download/v2023-10-09/hp.json'

.. doctest:: load-ontology

>>> hpo = hpotk.load_ontology('data/hp.toy.json')
>>> hpo = hpotk.load_ontology(url)
>>> hpo.version
'2022-10-05'
'2023-10-09'

Same as above, the loader parses the Obographs JSON file and returns an ontology. However, this time
it is an instance :class:`hpotk.ontology.Ontology` with :class:`hpotk.model.Term` - the term with full metadata.
Expand All @@ -104,9 +115,9 @@ or check out seizure's synonyms:

>>> for synonym in seizure.synonyms:
... print(synonym.name)
Epileptic seizure
Seizures
Epilepsy
Epileptic seizure

.. note::

Expand Down
10 changes: 9 additions & 1 deletion stable/_sources/user-guide/sort-term-ids.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,15 @@ And sort the HPO terms:
>>> indices = sorting.argsort(term_ids)
>>> ordered = tuple(term_ids[idx] for idx in indices)

Now let's look at the order:
Now let's look at the order. Originally, the HPO terms were ordered as follows::

'HP:0001744' # Splenomegaly
'HP:0020221' # Clonic seizure
'HP:0001238' # Slender finger
'HP:0011153' # Focal motor seizure
'HP:0002240' # Hepatomegaly

When sorted, we get this order:

.. doctest:: sort-term-ids

Expand Down
26 changes: 25 additions & 1 deletion stable/_sources/user-guide/validate-phenotypic-features.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,28 @@ There seems to an issue. Let's break it down:
The validator points out that *Seizure* is an ancestor of *Focal clonic seizure* and should, therefore, not be used
as an annotation of the individual.

That's it for now. There are more validators to come!
Validation pipeline
^^^^^^^^^^^^^^^^^^^

For greater convenience, the validators can be integrated and run on the input at the same time:

.. doctest:: check-consistency

>>> from hpotk.validate import ValidationRunner

>>> # Create a validation runner
>>> runner = ValidationRunner(validators=(obs_val, pa_val, ap_val))

>>> # Validate the input features
>>> vr = runner.validate_all(term_ids)
>>> vr.is_ok()
False

>>> for validation_result in vr.results:
... print(validation_result)
ValidationResult(level=<ValidationLevel.WARNING: 1>, category='obsolete_term_id_is_used', message='Using the obsolete HP:0001505 instead of HP:0001166 for Arachnodactyly')
ValidationResult(level=<ValidationLevel.ERROR: 2>, category='annotation_propagation', message='Terms should not contain both present Focal clonic seizure [HP:0002266] and its present or excluded ancestor Seizure [HP:0001250]')

:class:`hpotk.validate.ValidationRunner` applies several validators and aggregates the issues into
:class:`hpotk.validate.ValidationResults`. We can check if the input passed the validation and if not, we can go through
the issues.
4 changes: 2 additions & 2 deletions stable/apidocs/hpotk.validate.html
Original file line number Diff line number Diff line change
Expand Up @@ -290,13 +290,13 @@

<dl class="py class">
<dt class="sig sig-object py" id="hpotk.validate.ValidationRunner">
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">hpotk.validate.</span></span><span class="sig-name descname"><span class="pre">ValidationRunner</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">validators</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Sequence" title="(in Python v3.12)"><span class="pre">Sequence</span></a><span class="p"><span class="pre">[</span></span><a class="reference internal" href="#hpotk.validate.RuleValidator" title="hpotk.validate._model.RuleValidator"><span class="pre">RuleValidator</span></a><span class="p"><span class="pre">]</span></span></span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/hpotk/validate/_model.html#ValidationRunner"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#hpotk.validate.ValidationRunner" title="Link to this definition"></a></dt>
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">hpotk.validate.</span></span><span class="sig-name descname"><span class="pre">ValidationRunner</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">validators</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Iterable" title="(in Python v3.12)"><span class="pre">Iterable</span></a><span class="p"><span class="pre">[</span></span><a class="reference internal" href="#hpotk.validate.RuleValidator" title="hpotk.validate._model.RuleValidator"><span class="pre">RuleValidator</span></a><span class="p"><span class="pre">]</span></span></span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/hpotk/validate/_model.html#ValidationRunner"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#hpotk.validate.ValidationRunner" title="Link to this definition"></a></dt>
<dd><p>Bases: <a class="reference external" href="https://docs.python.org/3/library/functions.html#object" title="(in Python v3.12)"><code class="xref py py-class docutils literal notranslate"><span class="pre">object</span></code></a></p>
<p>The runner applies a sequence of rule validators on items and packs the results
into <a class="reference internal" href="#hpotk.validate.ValidationResults" title="hpotk.validate.ValidationResults"><code class="xref py py-class docutils literal notranslate"><span class="pre">ValidationResults</span></code></a>.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><p><strong>validators</strong>a sequence of <a class="reference internal" href="#hpotk.validate.RuleValidator" title="hpotk.validate.RuleValidator"><code class="xref py py-class docutils literal notranslate"><span class="pre">RuleValidator</span></code></a>s to apply.</p>
<dd class="field-odd"><p><strong>validators</strong>an iterable of <a class="reference internal" href="#hpotk.validate.RuleValidator" title="hpotk.validate.RuleValidator"><code class="xref py py-class docutils literal notranslate"><span class="pre">RuleValidator</span></code></a>s to apply.</p>
</dd>
</dl>
<dl class="py method">
Expand Down
2 changes: 1 addition & 1 deletion stable/searchindex.js

Large diffs are not rendered by default.

46 changes: 27 additions & 19 deletions stable/user-guide/load-ontology.html
Original file line number Diff line number Diff line change
Expand Up @@ -98,23 +98,27 @@
JSON file which is available for download from the <a class="reference external" href="https://hpo.jax.org/app/data/ontology">HPO website</a>.</p>
<section id="minimal-ontology">
<h2>Minimal ontology<a class="headerlink" href="#minimal-ontology" title="Link to this heading"></a></h2>
<p>Let’s load HPO:</p>
<p>Let’s load the HPO version released on Oct 9th, 2023:</p>
<div class="highlight-pycon notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">hpotk</span>

<span class="gp">&gt;&gt;&gt; </span><span class="n">hpo</span> <span class="o">=</span> <span class="n">hpotk</span><span class="o">.</span><span class="n">load_minimal_ontology</span><span class="p">(</span><span class="s1">&#39;data/hp.toy.json&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">hpo</span><span class="o">.</span><span class="n">version</span>
<span class="go">&#39;2022-10-05&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">url</span> <span class="o">=</span> <span class="s1">&#39;https://github.com/obophenotype/human-phenotype-ontology/releases/download/v2023-10-09/hp.json&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">hpo</span> <span class="o">=</span> <span class="n">hpotk</span><span class="o">.</span><span class="n">load_minimal_ontology</span><span class="p">(</span><span class="n">url</span><span class="p">)</span>
</pre></div>
</div>
<p>We load the ontology from a toy Obographs JSON file and we check the version of the data.</p>
<p>The loader fetches the Obographs JSON file and loads the data into <a class="reference internal" href="../apidocs/hpotk.ontology.html#hpotk.ontology.MinimalOntology" title="hpotk.ontology.MinimalOntology"><code class="xref py py-class docutils literal notranslate"><span class="pre">hpotk.ontology.MinimalOntology</span></code></a>.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>The loader can fetch the HPO from a URL, and it transparently handles gzipped files
if the file name ends with <cite>.gz</cite> suffix.</p>
</div>
<p>Now, we can check that the toy HPO has 393 primary terms:</p>
<p>Having <cite>MinimalOntology</cite>, we can do several checks. We can check the HPO version:</p>
<div class="highlight-pycon notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">hpo</span><span class="o">.</span><span class="n">version</span>
<span class="go">&#39;2023-10-09&#39;</span>
</pre></div>
</div>
<p>check that the Oct 9th release has <em>17,664</em> terms:</p>
<div class="highlight-pycon notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="nb">len</span><span class="p">(</span><span class="n">hpo</span><span class="p">)</span>
<span class="go">393</span>
<span class="go">17664</span>
</pre></div>
</div>
<p>check that <cite>HP:0001250</cite> is/was a valid identifier:</p>
Expand All @@ -129,20 +133,24 @@ <h2>Minimal ontology<a class="headerlink" href="#minimal-ontology" title="Link t
</pre></div>
</div>
<p>or print names of its children in alphabetical order:</p>
<div class="highlight-pycon notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">children_names</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">(</span>
<span class="gp">... </span> <span class="nb">map</span><span class="p">(</span><span class="k">lambda</span> <span class="n">ch</span><span class="p">:</span> <span class="n">hpo</span><span class="o">.</span><span class="n">get_term</span><span class="p">(</span><span class="n">ch</span><span class="p">)</span><span class="o">.</span><span class="n">name</span><span class="p">,</span>
<span class="gp">... </span> <span class="n">hpo</span><span class="o">.</span><span class="n">graph</span><span class="o">.</span><span class="n">get_children</span><span class="p">(</span><span class="n">seizure</span><span class="p">)))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">for</span> <span class="n">child</span> <span class="ow">in</span> <span class="n">children_names</span><span class="p">:</span>
<div class="highlight-pycon notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="k">for</span> <span class="n">child</span> <span class="ow">in</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">hpo</span><span class="o">.</span><span class="n">get_term_name</span><span class="p">(</span><span class="n">child</span><span class="p">)</span>
<span class="gp">... </span> <span class="k">for</span> <span class="n">child</span> <span class="ow">in</span> <span class="n">hpo</span><span class="o">.</span><span class="n">graph</span><span class="o">.</span><span class="n">get_children</span><span class="p">(</span><span class="n">seizure</span><span class="p">)):</span>
<span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="n">child</span><span class="p">)</span>
<span class="go">Bilateral tonic-clonic seizure</span>
<span class="go">Dialeptic seizure</span>
<span class="go">Focal-onset seizure</span>
<span class="go">Generalized-onset seizure</span>
<span class="go">Infection-related seizure</span>
<span class="go">Maternal seizure</span>
<span class="go">Motor seizure</span>
<span class="go">Neonatal seizure</span>
<span class="go">Nocturnal seizures</span>
<span class="go">Non-motor seizure</span>
<span class="go">Reflex seizure</span>
<span class="go">Status epilepticus</span>
<span class="go">Symptomatic seizures</span>
</pre></div>
</div>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>The toy HPO is a subset of the full HPO and Seizure only 2 child terms in the toy file. There are more children
in the real-life (“production”) HPO.</p>
</div>
<p>The terms of <a class="reference internal" href="../apidocs/hpotk.ontology.html#hpotk.ontology.MinimalOntology" title="hpotk.ontology.MinimalOntology"><code class="xref py py-class docutils literal notranslate"><span class="pre">hpotk.ontology.MinimalOntology</span></code></a> are instances of <a class="reference internal" href="../apidocs/hpotk.model.html#hpotk.model.MinimalTerm" title="hpotk.model.MinimalTerm"><code class="xref py py-class docutils literal notranslate"><span class="pre">hpotk.model.MinimalTerm</span></code></a> and contain a subset
of the term metadata such as identifier, labels, and alternative IDs. The simplified are useful for tasks that
use the ontology hierarchy. However, the tasks that need the full term metadata should use <cite>Ontology</cite>.</p>
Expand All @@ -151,9 +159,9 @@ <h2>Minimal ontology<a class="headerlink" href="#minimal-ontology" title="Link t
<h2>Ontology<a class="headerlink" href="#ontology" title="Link to this heading"></a></h2>
<p>Unsurprisingly, loading ontology is very similar to loading minimal ontology. We use <cite>hpotk.load_ontology</cite>
loader function:</p>
<div class="highlight-pycon notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">hpo</span> <span class="o">=</span> <span class="n">hpotk</span><span class="o">.</span><span class="n">load_ontology</span><span class="p">(</span><span class="s1">&#39;data/hp.toy.json&#39;</span><span class="p">)</span>
<div class="highlight-pycon notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">hpo</span> <span class="o">=</span> <span class="n">hpotk</span><span class="o">.</span><span class="n">load_ontology</span><span class="p">(</span><span class="n">url</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">hpo</span><span class="o">.</span><span class="n">version</span>
<span class="go">&#39;2022-10-05&#39;</span>
<span class="go">&#39;2023-10-09&#39;</span>
</pre></div>
</div>
<p>Same as above, the loader parses the Obographs JSON file and returns an ontology. However, this time
Expand All @@ -167,9 +175,9 @@ <h2>Ontology<a class="headerlink" href="#ontology" title="Link to this heading">
<p>or check out seizure’s synonyms:</p>
<div class="highlight-pycon notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="k">for</span> <span class="n">synonym</span> <span class="ow">in</span> <span class="n">seizure</span><span class="o">.</span><span class="n">synonyms</span><span class="p">:</span>
<span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="n">synonym</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
<span class="go">Epileptic seizure</span>
<span class="go">Seizures</span>
<span class="go">Epilepsy</span>
<span class="go">Epileptic seizure</span>
</pre></div>
</div>
<div class="admonition note">
Expand Down
Loading

0 comments on commit 07bb067

Please sign in to comment.