Skip to content

Commit

Permalink
Merge branch 'master' into BTP-16-add-ezbids-landing-page
Browse files Browse the repository at this point in the history
  • Loading branch information
Ubuntu committed Oct 3, 2023
2 parents 06ba089 + 2855ce2 commit 067c1c1
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 23 deletions.
36 changes: 36 additions & 0 deletions handler/ezBIDS_core/ezBIDS_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1203,6 +1203,7 @@ def finalized_configuration(dataset_list_unique_series, subjects_information, co
participants_column_info = config_data["participantsColumn"]
subjects_sessions_info = config_data["subjects"]
config_dataset_list_unique_series = config_data["series"]
config_dataset_list_objects = config_data["objects"]

# Try to determine subject (and session) mapping from what's in the configuration
match_start_index = None
Expand All @@ -1214,6 +1215,20 @@ def finalized_configuration(dataset_list_unique_series, subjects_information, co
ref_subject_id = ref_subject_info["subject"]
ref_patient_info = ref_subject_info["PatientInfo"][-1] # Get most recent information

anonymized_sidecar_fields = [
"SeriesInstanceUID",
"StudyInstanceUID",
"ReferringPhysicianName",
"StudyID",
"PatientName",
"PatientID",
"AccessionNumber",
"PatientBirthDate",
"PatientSex",
"PatientWeight",
"AcquisitionDateTime"
]

for sub_info in subjects_information:
sub = sub_info["subject"]
for key in ref_patient_info.keys():
Expand Down Expand Up @@ -1258,6 +1273,7 @@ def finalized_configuration(dataset_list_unique_series, subjects_information, co
et = unique_dic["EchoTime"]
rt = unique_dic["RepetitionTime"]
it = unique_dic["ImageType"]
sidecar = unique_dic["sidecar"]

"""
Don't use series_idx as identifier because the uploaded data might not contain the same data as
Expand All @@ -1278,6 +1294,7 @@ def finalized_configuration(dataset_list_unique_series, subjects_information, co
ref_B0FieldIdentifier = config_series_ref["B0FieldIdentifier"]
ref_B0FieldSource = config_series_ref["B0FieldSource"]
ref_message = config_series_ref["message"]
ref_series_idx = config_series_ref["series_idx"]

unique_dic["type"] = ref_type
unique_dic["entities"] = ref_entities
Expand All @@ -1292,6 +1309,24 @@ def finalized_configuration(dataset_list_unique_series, subjects_information, co
else:
unique_dic["message"] = "Datatype, suffix, and entity information was determined based on match "\
"with corresponding data in ezBIDS configuration (finalized.json) file. Please modify if incorrect"

"""
If metadata information was added in, find it and add to the json file.
"""
ref_object = [
x for x in config_dataset_list_objects
if "series_idx" in x.keys()
and x["series_idx"] == ref_series_idx
]
if len(ref_object): # If len > 1, just take the 1st instance
ref_sidecar = [x["sidecar"] for x in ref_object[0]["items"] if x["name"] == "json"][0]
for field in ref_sidecar:
value = ref_sidecar[field]
if field not in sidecar and field not in anonymized_sidecar_fields:
sidecar[field] = value

unique_dic["sidecar"] = sidecar

"""
If events.tsv files (for func/bold) are referenced in the configuration, grab this information and display
it on the Events page if user uploads event timing data again.
Expand Down Expand Up @@ -2491,6 +2526,7 @@ def extract_series_info(dataset_list_unique_series):
if config is True:
readme, dataset_description_dic, participants_column_info, dataset_list_unique_series, subjects_information, events = \
finalized_configuration(dataset_list_unique_series, subjects_information, config_file)

else:
# README
readme = generate_readme(DATA_DIR, bids_compliant)
Expand Down
2 changes: 1 addition & 1 deletion ui/src/Finalize.vue
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ export default defineComponent({
//things that convert.ts uses
objects: this.ezbids.objects, //most important thing that convert.ts needs
events: this.events,
events: this.ezbids.events,
entityMappings, //helps with convert
datasetDescription: this.ezbids.datasetDescription,
readme: this.ezbids.readme,
Expand Down
19 changes: 12 additions & 7 deletions ui/src/Objects.vue
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
</el-form-item>
</div>

<div v-if="so._type.startsWith('fmap/')" class="border-top">
<div v-if="so._type.startsWith('fmap/') || so._type === 'perf/m0scan'" class="border-top">
<br>
<el-form-item label="IntendedFor">
<el-select v-model="so.IntendedFor" multiple placeholder="Select Object" style="width: 100%" @change="update(so)">
Expand Down Expand Up @@ -360,7 +360,7 @@
if(!o) return;
this.$emit("updateObject", o);
},
isValid(cb: (err?: string)=>void) {
this.$emit("mapObjects");
this.validateAll();
Expand Down Expand Up @@ -470,13 +470,18 @@
}
}
if(o._type.startsWith("fmap/")) {
if(!o.IntendedFor) o.IntendedFor = []; //TODO can't think of a better place to do this
if(o._type.startsWith("fmap/") || o._type === "perf/m0scan") {
if(!o.IntendedFor) o.IntendedFor = [];
if(o.IntendedFor.length == 0) {
let warningMessage = "It is recommended that field map (fmap) images have IntendedFor set to at least 1 object. This is necessary if you plan on using processing BIDS-apps such as fMRIPrep"
if (!o.validationWarnings.includes(warningMessage)) {
o.validationWarnings.push(warningMessage);
if(o._type.startsWith("fmap/")) {
o.validationWarnings.push("It is recommended that field map (fmap) images have IntendedFor set to at least 1 series ID. This is necessary if you plan on using processing BIDS-apps such as fMRIPrep");
} else if (o.type === "perf/m0scan") {
o.validationErrors.push("It is required that perfusion m0scan images have IntendedFor set to at least 1 series ID.");
}
// let warningMessage = "It is recommended that these images have IntendedFor set to at least 1 object. This is necessary if you plan on using processing BIDS-apps such as fMRIPrep"
// if (!o.validationWarnings.includes(warningMessage)) {
// o.validationWarnings.push(warningMessage);
// }
}
//Ensure other fmap series aren't included in the IntendedFor mapping
Expand Down
18 changes: 11 additions & 7 deletions ui/src/SeriesPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
</p> -->
</div>

<div v-if="ss.type && ss.type.startsWith('fmap/')">
<div v-if="ss.type && (ss.type.startsWith('fmap/') || ss.type === 'perf/m0scan')">
<el-form-item label="IntendedFor">
<el-select v-model="ss.IntendedFor" required multiple filterable
placeholder="Please select Series" size="small"
Expand All @@ -92,7 +92,7 @@
</el-option>
</el-select>
<p style="margin-top: 0">
<small>* <b>Recommended</b>: select Series that this field map should be applied to. Helpful is planning on using BIDS-apps for processing (e.g., fMRIPrep).</small>
<small>* <b>Recommended (Required if perf/m0scan)</b>: select Series that this sequence should be applied to.</small>
</p>
</el-form-item>
</div>
Expand Down Expand Up @@ -130,7 +130,7 @@
</p>
</el-form-item>
<br/>
<el-form-item v-if="ss.type=='perf/asl'" label="Edit Modalities">
<el-form-item v-if="ss.type == 'perf/asl' || ss.type == 'perf/m0scan'" label="Relevant Metadata">
<ModalityForm :ss="ss" :ezbids="ezbids"
@form-submitted="submitForm"/>
</el-form-item>
Expand Down Expand Up @@ -310,15 +310,19 @@ export default defineComponent({
}
}
if(s.type.startsWith("fmap/")) {
if(s.type.startsWith("fmap/") || s.type === "perf/m0scan") {
if(!s.IntendedFor) s.IntendedFor = [];
if(s.IntendedFor.length == 0) {
s.validationWarnings.push("It is recommended that field map (fmap) images have IntendedFor set to at least 1 series ID. This is necessary if you plan on using processing BIDS-apps such as fMRIPrep");
if(s.type.startsWith("fmap/")) {
s.validationWarnings.push("It is recommended that field map (fmap) images have IntendedFor set to at least 1 series ID. This is necessary if you plan on using processing BIDS-apps such as fMRIPrep");
} else if (s.type === "perf/m0scan") {
s.validationErrors.push("It is required that perfusion m0scan images have IntendedFor set to at least 1 series ID.");
}
}
//Ensure other fmap series aren't included in the IntendedFor mapping
//Ensure other fmap or perf/m0scan series aren't included in the IntendedFor mapping
if(s.IntendedFor.length > 0) {
s.IntendedFor.forEach(i=>{
if(this.ezbids.series[i].type.startsWith("fmap/")) {
if(this.ezbids.series[i].type.startsWith("fmap/") || this.ezbids.series[i].type === "perf/m0scan") {
s.validationErrors.push("The selected series (#"+i+") appears to be a field map (fmap), which isn't allowed in the IntendedFor mapping. Please remove this series, or, if it isn't a field map, please correct it.")
}
})
Expand Down
6 changes: 3 additions & 3 deletions ui/src/components/modalityForm.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<el-button @click="initForm()">Edit Modality</el-button>
<el-dialog v-model="showDialog" title="Edit Modalities">
<el-button @click="initForm()">Edit Metadata</el-button>
<el-dialog v-model="showDialog" title="Relevant Metadata">
<el-form ref="form" :model="formData" label-position="top" label-width="500px" :inline="true" :rules="rules">
<el-row>
<el-col :span="8">
Expand Down Expand Up @@ -297,7 +297,7 @@ export default defineComponent({
// console.log("petYaml", petYaml);
// fileObject = petYaml;
// }
if(type == 'perf/asl') fileObject = aslYaml;
if(type == 'perf/asl' || 'perf/m0scan') fileObject = aslYaml;
let result = {
required: [],
Expand Down
28 changes: 27 additions & 1 deletion ui/src/libUnsafe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ export function setRun($root:IEzbids) {
let initialGrouping = sesGroup.objects.filter(e=>e._type !== "exclude" &&
!e._exclude &&
e._type === obj._type &&
e._type !== "func/events" && // let users specify the run number for func/events files
deepEqual(Object.fromEntries(Object.entries(e._entities).filter(([key])=>key !== "part" && key !== "run" && key !== "echo")), targetEntities)
)

Expand Down Expand Up @@ -438,6 +439,31 @@ export function setIntendedFor($root:IEzbids) {
});
}
}
// if (obj._type.startsWith("fmap/") || obj._type === "perf/m0scan") {
// if (!obj.IntendedFor) {
// Object.assign(obj, {IntendedFor: []})
// }

// let correspindingSeriesIntendedFor = $root.series[obj.series_idx].IntendedFor
// if (correspindingSeriesIntendedFor !== undefined && correspindingSeriesIntendedFor !== null) {
// correspindingSeriesIntendedFor.forEach((i:number) => {
// let IntendedForIDs = section.filter(o=>o.series_idx === i && o._type !== "func/events").map(o=>o.idx)
// if (obj.IntendedFor !== undefined) {
// IntendedForIDs.forEach((IntendedForID:number) => {
// if (!obj.IntendedFor?.includes(IntendedForID)) {
// obj.IntendedFor = obj.IntendedFor?.concat(IntendedForIDs)
// }

// let IntendedForObj = sesGroup.objects.filter(e=>e.idx === IntendedForID)[0]
// console.log(IntendedForObj)
// if (IntendedForObj._exclude || IntendedForObj._type === "exclude") {
// obj.IntendedFor = obj.IntendedFor?.filter(e=>e === IntendedForID)
// }
// })
// }
// });
// }
// }

// check B0FieldIdentifier and B0FieldSource information
if (obj._type && !obj._type.includes('exclude') && !obj._type.includes('events')) {
Expand Down Expand Up @@ -1361,4 +1387,4 @@ export function validateParticipantsInfo($root:IEzbids) {
})
})
return errors
}
}
8 changes: 4 additions & 4 deletions ui/src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,24 +394,24 @@ const state = {
//these are just for typescript definitions.
//real initial values should come from mapEventColumns()

onsetLogic: "",
onsetLogic: "eq",
onset: null, //will be set to column name in event
onset2: null, //will be set to column name in event
onsetUnit: "sec",

durationLogic: "",
durationLogic: "eq",
duration: null,
duration2: null, //used in case durationLogic is "subtract" or "add"
durationUnit: "sec",

sampleLogic: "",
sampleLogic: "eq",
sample: null,
sample2: null,
sampleUnit: "samples",

trialType: null,

responseTimeLogic: "",
responseTimeLogic: "eq",
responseTime: null,
responseTime2: null,
responseTimeUnit: "sec",
Expand Down

0 comments on commit 067c1c1

Please sign in to comment.