Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding example 02 #16

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/_static/test-data/subjects_case01.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"subject_ID", "species", "age_category", "imaged_while"
"sub-01", "Mus musculus", "adult", "awake; asleep"
"sub-02", "Rattus norvegicus", "adult", "awake"
"sub-03", "Felis catus", "adult", "awake; asleep"
"sub-04", "Macaca mulatta", "adult", "awake"
"sub-05", "Ovis aries", "adult", "awake; asleep"
6 changes: 6 additions & 0 deletions docs/_static/test-data/subjects_case02.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"subject_ID", "weight_infant", "weight_juvenile", "weight_adult", "weight_unit"
"sub-A", 0.403, 1.300, 5.512, "kg"
"sub-B", 0.465, 1.415, 5.324, "kg"
"sub-C", 0.500, 1.555, 7.113, "kg"
"sub-D", 0.512, 1.612, 6.478, "kg"
"sub-E", 0.550, 1.835, 7.985, "kg"
2 changes: 2 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# -- General configuration

extensions = [
'IPython.sphinxext.ipython_console_highlighting',
'IPython.sphinxext.ipython_directive',
'sphinx.ext.duration',
'sphinx.ext.doctest',
'sphinx.ext.autodoc',
Expand Down
90 changes: 90 additions & 0 deletions docs/shared/supportive_tooling/example-02.rst
Original file line number Diff line number Diff line change
@@ -1,2 +1,92 @@
Example-02
==========

Let us become more scientific in our next example and demonstrate for two fictional case scenarios how information on research subjects stored in a tabular format (e.g., as CSV) can be extracted into openMINDS compliant graph structured metadata instances.

For the first case scenario, we assume that five adult research subjects, each of a different species, were imaged once while awake, and (at least for some) were imaged a second time while asleep. The metadata structurally describing this information is stored in the following CSV file:

.. csv-table:: subjects_case01.csv
:file: ../../_static/test-data/subjects_case01.csv
:widths: 10, 10, 10, 10, 10
:header-rows: 1

Based on this information, we know that we will have to create five "Subject" instances and one to two "SubjectState" instances. In addition, we know that we will not have to create instances for defining the species, the age category or the subject attribute describing the state of the subject when it was imaged, because these instances are already available through the openMINDS libraries.

Translating this tabular information into a graph structured openMINDS metadata collection using Python could look like this:

.. code-block:: python

# import packages
from openminds import Collection
import csv
import openminds.latest.core as omcore

# Create an empty metadata collection
collection = Collection()

# read csv file to a list of dictionaries
with open('subjects_case01.csv', 'r') as f:
csv_reader = csv.DictReader(f)
data = [row for row in csv_reader]
f.close()

# create subject instances with their respective states
subjects = {}
for d in data:
subjects[d["subject_ID"]] = omcore.Subject(
internal_identifier = d["subject_ID"]
)

# adding instances to collection
# (remember: linked instances are automatically added)
for s in subjects:
collection.add(s)

failures = collection.validate()

if not failures:
collection.save("my_collection.jsonld")

For the second case scenario, we assume that another five adult research subjects, where we pretend to have the general knowledge that all subjects are rhesus macaques (Macaca mulatta), and participated in a behavioral experiment while being an infant, a juvenile and an adult. Instead of the exact age of each monkey, the body weight was measured before each behavioral experiment:

.. csv-table:: subjects_case02.csv
:file: ../../_static/test-data/subjects_case02.csv
:widths: 10, 10, 10, 10, 10
:header-rows: 1

Based on this information, we know that we will have again to create five "Subject" instances, each with three "SubjectState" instances. In addition, we know that we will not have to create instances for defining the species, the age category or the unit of measurement of the subject's body weight, because these instances are already available through the openMINDS libraries.

Translating this tabular information into a graph structured openMINDS metadata collection using Python could look like this:

.. code-block:: python

# import packages
from openminds import Collection
import csv
import openminds.latest.core as omcore

# Create an empty metadata collection
collection = Collection()

# read csv file to a list of dictionaries
with open('subjects_case02.csv', 'r') as f:
csv_reader = csv.DictReader(f)
data = [row for row in csv_reader]
f.close()

# create subject instances with their respective states
subjects = {}
for d in data:
subjects[d["subject_ID"]] = omcore.Subject(
internal_identifier = d["subject_ID"]
)

# adding instances to collection
# (remember: linked instances are automatically added)
for s in subjects:
collection.add(s)

failures = collection.validate()

if not failures:
collection.save("my_collection.jsonld")
5 changes: 0 additions & 5 deletions docs/shared/supportive_tooling/persons.csv

This file was deleted.