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

[FIX] Ensure pipeline variables are returned from the graph in an aggregate query #349

Merged
merged 2 commits into from
Oct 10, 2024
Merged
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
17 changes: 7 additions & 10 deletions app/api/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ async def get(

response_obj = []
dataset_cols = ["dataset_uuid", "dataset_name"]
dataset_available_pipeline_info = {}
if not results_df.empty:
for (dataset_uuid, dataset_name), group in results_df.groupby(
by=dataset_cols
Expand Down Expand Up @@ -259,13 +258,11 @@ async def get(

subject_data = list(subject_data.to_dict("records"))

dataset_available_pipeline_info = (
group.groupby("pipeline_name", dropna=True)[
"pipeline_version"
]
.apply(lambda x: list(x.dropna().unique()))
.to_dict()
)
dataset_available_pipelines = (
group.groupby("pipeline_name", dropna=True)["pipeline_version"]
.apply(lambda x: list(x.dropna().unique()))
.to_dict()
)

response_obj.append(
CohortQueryResponse(
Expand All @@ -276,7 +273,7 @@ async def get(
],
dataset_portal_uri=(
group["dataset_portal_uri"].iloc[0]
if group["dataset_portal_uri"].notna().all()
if not group["dataset_portal_uri"].isna().any()
else None
),
num_matching_subjects=group["sub_id"].nunique(),
Expand All @@ -287,7 +284,7 @@ async def get(
group["image_modal"].notna()
].unique()
),
available_pipelines=dataset_available_pipeline_info,
available_pipelines=dataset_available_pipelines,
)
)

Expand Down
4 changes: 2 additions & 2 deletions app/api/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,11 +307,11 @@ def create_query(
query_string = (
textwrap.dedent(
"""
SELECT ?dataset_uuid ?dataset_name ?dataset_portal_uri ?sub_id ?image_modal
SELECT ?dataset_uuid ?dataset_name ?dataset_portal_uri ?sub_id ?image_modal ?pipeline_version ?pipeline_name
WHERE {"""
)
+ textwrap.indent(query_string, " ")
+ "} GROUP BY ?dataset_uuid ?dataset_name ?dataset_portal_uri ?sub_id ?image_modal"
+ "} GROUP BY ?dataset_uuid ?dataset_name ?dataset_portal_uri ?sub_id ?image_modal ?pipeline_version ?pipeline_name"
)

return "\n".join([create_context(), query_string])
Expand Down
27 changes: 24 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ def test_data():
"http://purl.org/nidash/nidm#T2Weighted",
],
"available_pipelines": {
"freesurfer": ["7.3.2", "2.8.2", "8.7.0-rc"]
"https://github.com/nipoppy/pipeline-catalog/tree/main/processing/freesurfer": [
"7.3.2",
"2.8.2",
"8.7.0-rc",
]
},
},
{
Expand All @@ -90,8 +94,15 @@ def test_data():
"http://purl.org/nidash/nidm#T1Weighted",
],
"available_pipelines": {
"freesurfer": ["7.3.2", "2.1.2"],
"fmriprep": ["23.1.3", "22.1.4", "v2.0.1"],
"https://github.com/nipoppy/pipeline-catalog/tree/main/processing/freesurfer": [
"7.3.2",
"2.1.2",
],
"https://github.com/nipoppy/pipeline-catalog/tree/main/processing/fmriprep": [
"23.1.3",
"22.1.4",
"v2.0.1",
],
},
},
]
Expand All @@ -110,6 +121,8 @@ def mockreturn(query, timeout=5.0):
"dataset_portal_uri",
"sub_id",
"image_modal",
"pipeline_name",
"pipeline_version",
]
},
"results": {
Expand Down Expand Up @@ -141,6 +154,14 @@ def mockreturn(query, timeout=5.0):
"type": "uri",
"value": "http://purl.org/nidash/nidm#T1Weighted",
},
"pipeline_version": {
"type": "literal",
"value": "7.3.2",
},
"pipeline_name": {
"type": "uri",
"value": "https://github.com/nipoppy/pipeline-catalog/tree/main/processing/freesurfer",
},
},
]
},
Expand Down