Skip to content

Commit

Permalink
building up dataset query
Browse files Browse the repository at this point in the history
  • Loading branch information
apdavison committed Mar 4, 2024
1 parent 1a04e7d commit 024bed2
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 32 deletions.
26 changes: 14 additions & 12 deletions apps/nar-v3/src/components/DatasetCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ function SubjectCard(props) {
)}
</Stack>
<Box sx={styles.entity} component={Paper} variant="outlined">
<h2>Subject {subject.label}</h2>
<h2>Subject {subject.lookupLabel}</h2>
<p>
({props.index + 1} of {props.subjects.length})
</p>
Expand Down Expand Up @@ -343,11 +343,13 @@ function DataFileCard(props) {

function DatasetCard(props) {
const dataset = props.dataset;
const subjects = dataset.studiedSpecimen;

const [subjectIndex, _setSubjectIndex] = useState(0);
const [sliceIndex, _setSliceIndex] = useState(0);

const setSubjectIndex = (index) => {
if (index >= 0 && index < dataset.subjects.length) {
if (index >= 0 && index < subjects.length) {
_setSubjectIndex(index);
setSliceIndex(0);
}
Expand All @@ -357,7 +359,7 @@ function DatasetCard(props) {
if (
index >= 0 &&
index <
dataset.subjects[subjectIndex].states[0].slicePreparation[0].slices
subjects[subjectIndex].states[0].slicePreparation[0].slices
.length
) {
_setSliceIndex(index);
Expand All @@ -379,15 +381,15 @@ function DatasetCard(props) {
</Link>
</h2>

{dataset.subjects ? (
{subjects ? (
<Stack
direction="column"
alignItems="center"
spacing={2}
sx={{ marginBottom: 5 }}
>
<SubjectCard
subjects={dataset.subjects}
subjects={subjects}
index={subjectIndex}
setIndex={setSubjectIndex}
/>
Expand All @@ -396,15 +398,15 @@ function DatasetCard(props) {

<SlicePreparationCard
activity={
dataset.subjects[subjectIndex].states[0].slicePreparation[0]
subjects[subjectIndex].states[0].slicePreparation[0]
}
/>

<Connection />

<SliceCard
slices={
dataset.subjects[subjectIndex].states[0].slicePreparation[0]
subjects[subjectIndex].states[0].slicePreparation[0]
.slices
}
index={sliceIndex}
Expand All @@ -415,7 +417,7 @@ function DatasetCard(props) {

<CellPatchingCard
activity={
dataset.subjects[subjectIndex].states[0].slicePreparation[0]
subjects[subjectIndex].states[0].slicePreparation[0]
.slices[sliceIndex].cellPatching[0]
}
/>
Expand All @@ -424,7 +426,7 @@ function DatasetCard(props) {

<PatchedCellCard
cell={
dataset.subjects[subjectIndex].states[0].slicePreparation[0]
subjects[subjectIndex].states[0].slicePreparation[0]
.slices[sliceIndex].cellPatching[0].patchedCells[0]
}
/>
Expand All @@ -433,12 +435,12 @@ function DatasetCard(props) {

<RecordingCard
recording={
dataset.subjects[subjectIndex].states[0].slicePreparation[0]
subjects[subjectIndex].states[0].slicePreparation[0]
.slices[sliceIndex].cellPatching[0].patchedCells[0]
.recordingActivity[0]
}
stimulation={
dataset.subjects[subjectIndex].states[0].slicePreparation[0]
subjects[subjectIndex].states[0].slicePreparation[0]
.slices[sliceIndex].cellPatching[0].patchedCells[0]
.stimulationActivity[0]
}
Expand All @@ -448,7 +450,7 @@ function DatasetCard(props) {

<DataFileCard
fileObj={
dataset.subjects[subjectIndex].states[0].slicePreparation[0]
subjects[subjectIndex].states[0].slicePreparation[0]
.slices[sliceIndex].cellPatching[0].patchedCells[0]
.recordingActivity[0].files[0]
}
Expand Down
28 changes: 14 additions & 14 deletions apps/nar-v3/src/example_data/example_patch_clamp_dataset.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
"@type": [
"https://openminds.ebrains.eu/core/DatasetVersion"
],
"subjects": [
"studiedSpecimen": [
{
"label": "AD-Ctrl_s95",
"lookupLabel": "AD-Ctrl_s95",
"@type": [
"https://openminds.ebrains.eu/core/Subject"
],
Expand Down Expand Up @@ -1937,7 +1937,7 @@
]
},
{
"label": "AD-Ctrl_s86",
"lookupLabel": "AD-Ctrl_s86",
"@type": [
"https://openminds.ebrains.eu/core/Subject"
],
Expand Down Expand Up @@ -2947,7 +2947,7 @@
]
},
{
"label": "AD-Ctrl_s76",
"lookupLabel": "AD-Ctrl_s76",
"@type": [
"https://openminds.ebrains.eu/core/Subject"
],
Expand Down Expand Up @@ -4417,7 +4417,7 @@
]
},
{
"label": "AD-Ctrl_s75",
"lookupLabel": "AD-Ctrl_s75",
"@type": [
"https://openminds.ebrains.eu/core/Subject"
],
Expand Down Expand Up @@ -5197,7 +5197,7 @@
]
},
{
"label": "AD-Ctrl-s27",
"lookupLabel": "AD-Ctrl-s27",
"@type": [
"https://openminds.ebrains.eu/core/Subject"
],
Expand Down Expand Up @@ -5747,7 +5747,7 @@
]
},
{
"label": "AD-Ctrl-s31",
"lookupLabel": "AD-Ctrl-s31",
"@type": [
"https://openminds.ebrains.eu/core/Subject"
],
Expand Down Expand Up @@ -6987,7 +6987,7 @@
]
},
{
"label": "AD-Ctrl-s24",
"lookupLabel": "AD-Ctrl-s24",
"@type": [
"https://openminds.ebrains.eu/core/Subject"
],
Expand Down Expand Up @@ -8457,7 +8457,7 @@
]
},
{
"label": "APPPS_s96",
"lookupLabel": "APPPS_s96",
"@type": [
"https://openminds.ebrains.eu/core/Subject"
],
Expand Down Expand Up @@ -10161,7 +10161,7 @@
]
},
{
"label": "APPPS_s87",
"lookupLabel": "APPPS_s87",
"@type": [
"https://openminds.ebrains.eu/core/Subject"
],
Expand Down Expand Up @@ -12095,7 +12095,7 @@
]
},
{
"label": "APPPS_s77",
"lookupLabel": "APPPS_s77",
"@type": [
"https://openminds.ebrains.eu/core/Subject"
],
Expand Down Expand Up @@ -13799,7 +13799,7 @@
]
},
{
"label": "APPPS_s26",
"lookupLabel": "APPPS_s26",
"@type": [
"https://openminds.ebrains.eu/core/Subject"
],
Expand Down Expand Up @@ -14353,7 +14353,7 @@
]
},
{
"label": "APPPS_s22",
"lookupLabel": "APPPS_s22",
"@type": [
"https://openminds.ebrains.eu/core/Subject"
],
Expand Down Expand Up @@ -15827,7 +15827,7 @@
]
},
{
"label": "APPPS_s23",
"lookupLabel": "APPPS_s23",
"@type": [
"https://openminds.ebrains.eu/core/Subject"
],
Expand Down
15 changes: 13 additions & 2 deletions apps/nar-v3/src/queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@ function linkProperty(name, structure, options) {
const defaultOptions = {
expectSingle: true,
filter: "",
required: false
required: false,
type: null
}
const {expectSingle, filter, required} = {...defaultOptions, ...options}
const {expectSingle, filter, required, type} = {...defaultOptions, ...options}
let prop = simpleProperty(name);

if (expectSingle) {
Expand All @@ -70,6 +71,16 @@ function linkProperty(name, structure, options) {
if (structure && structure.length > 0) {
prop.structure = structure
}
if (type) {
if (typeof prop.path === 'string') {
prop.path = [{
"@id": prop.path
}]
}
prop.path[0].typeFilter = {
"@id": `https://openminds.ebrains.eu/${type}`
}
}
if (filter) {
prop.filter = {
op: "CONTAINS",
Expand Down
35 changes: 33 additions & 2 deletions apps/nar-v3/src/routes/dataset.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import React from "react";
import { Await, defer, useLoaderData } from "react-router-dom";

import { buildKGQuery, simpleProperty as S, linkProperty as L, reverseLinkProperty as R } from "../queries";
import {
buildKGQuery,
simpleProperty as S,
linkProperty as L,
reverseLinkProperty as R,
} from "../queries";
import { datastore } from "../datastore";
import { uuidFromUri } from "../utility.js";
import Navigation from "../components/Navigation";
Expand All @@ -19,6 +24,29 @@ const query = buildKGQuery("core/DatasetVersion", [
S("description"),
S("shortName"),
]),
L(
"studiedSpecimen",
[
S("lookupLabel"),
L(
"studiedState",
[
L("age", [
S("value"),
S("minValue"),
S("maxValue"),
L("unit/name"),
L("minValueUnit/name"),
L("maxValueUnit/name"),
]),
L("ageCategory/name"),
L("pathology", [], { expectSingle: false }),
],
{ expectSingle: false }
),
],
{ type: "core/Subject", expectSingle: false }
),
]);

export async function loader({ params }) {
Expand Down Expand Up @@ -47,7 +75,10 @@ function Dataset(props) {
return (
<>
<Navigation
location={["Datasets", uuidFromUri(dataset.id || dataset["@id"])]}
location={[
"Datasets",
uuidFromUri(dataset.id || dataset["@id"]),
]}
/>
<DatasetCard dataset={dataset} />
</>
Expand Down
4 changes: 2 additions & 2 deletions apps/nar-v3/tmp/build_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@
QP("@type"),
QP(
f"{vocab}studiedSpecimen",
name="subjects",
name="studiedSpecimen",
type_filter=omcore.Subject.type_[0],
properties=[
QP(f"{vocab}lookupLabel", name="label"),
QP(f"{vocab}lookupLabel", name="lookupLabel"),
QP("@type"),
QP(
f"{vocab}studiedState",
Expand Down

0 comments on commit 024bed2

Please sign in to comment.