Skip to content

Commit

Permalink
[ENH] miscellaneous small changes and minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Levitas committed Feb 16, 2024
1 parent 83f771a commit 5f8c637
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 15 deletions.
12 changes: 8 additions & 4 deletions handler/ezBIDS_core/ezBIDS_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,9 +504,11 @@ def modify_uploaded_dataset_list(uploaded_img_list):
elif any(x.endswith(tuple(['.v', '.v.gz'])) for x in grouped_files):
grouped_files = [x for x in grouped_files if not x.endswith(tuple(['.v', '.v.gz']))]

# If imaging file comes with additional data (JSON, bval/bvec) add them to list for processing
if len(grouped_files) > 1:
uploaded_files_list.append(grouped_files)
# Don't want this section is we're allowing only NIfTI files to be uploaded (group length will only be 1).
# # If imaging file comes with additional data (JSON, bval/bvec) add them to list for processing
# if len(grouped_files) > 1:
# uploaded_files_list.append(grouped_files)
uploaded_files_list.append(grouped_files)

# Flatten uploaded_files_list
uploaded_files_list = natsorted([file for sublist in uploaded_files_list for file in sublist])
Expand Down Expand Up @@ -913,7 +915,9 @@ def generate_dataset_list(uploaded_files_list, exclude_data):
for img_file in img_list:
# Find file extension
if img_file.endswith('.nii.gz'):
ext = 'nii.gz'
ext = '.nii.gz'
elif img_file.endswith('.v.gz'):
ext = '.v.gz'
else:
ext = Path(img_file).suffix

Expand Down
2 changes: 1 addition & 1 deletion handler/find_img_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ def find_img_data(dir):


# PET
# TODO - These two lines take several seconds to complete, maybe can be sped up?
pet_folders = [str(folder) for folder in is_pet.pet_folder(Path(root).resolve())]

pet_folders = [os.path.relpath(x, root) for x in pet_folders if x != '']

pet_folders = [os.path.join('.', x) for x in pet_folders]
Expand Down
46 changes: 38 additions & 8 deletions handler/preprocess.sh
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,13 @@ if [ $bids_compliant == "true" ]; then

touch $root/dcm2niix_output
touch $root/dcm2niix_error

touch $root/pet2bids_output
touch $root/pet2bids_error

# find products (NIfTI files)
(cd $root && find . -maxdepth 9 -type f \( -name "*.nii.gz" \) > list)
(cd $root && find . -maxdepth 9 -type f \( -name "*.nii.gz" \) > $root/list)
(cd $root && find . -maxdepth 9 -type f \( -name "*blood.json" \) >> $root/list)

echo "running ezBIDS_core (may take several minutes, depending on size of data)"
python3 "./ezBIDS_core/ezBIDS_core.py" $root
Expand Down Expand Up @@ -142,13 +146,15 @@ else

# determine which uploaded files/folders are PET directories or ECAT files
echo "Finding imaging directories and files"
if [ ! -f $root/list]; then
mkdir -p $root/list
if [ ! -f $root/list ]; then
touch $root/list
fi
./find_img_data.py $root

# sort $root/pet2bids_dcm.list, $root/pet2bids_ecat.list, and $root/dcm2niix.list for comm.
# Then, remove pet directories from dcm2niix list
touch $root/pet2bids_output

if [ -f $root/pet2bids_dcm.list ]; then
sort -o $root/pet2bids_dcm.list $root/pet2bids_dcm.list
echo "Removing PET directories from dcm2niix list"
Expand Down Expand Up @@ -216,17 +222,41 @@ else
done
fi

# Let's add the transformed raw data (i.e. to NIfTI or MEG formats) to the list file

(cd $root && find . -maxdepth 9 -type f \( -name "*.nii.gz" \) > list)
(cd $root && find . -maxdepth 9 -type f \( -name "*blood.json" \) >> list)
# Check for pet2bids errors
if [[ $PET2BIDS_RUN -eq "true" ]]; then
# pull pet2bids error information to log file
{ grep -B 1 --group-separator=$'\n\n' Error $root/pet2bids_output || true; } > $root/pet2bids_error
# # remove error message(s) about not finding any DICOMs in folder
line_nums=$(grep -n 'Error: Unable to find any DICOM images' $root/pet2bids_error | cut -d: -f1)

for line_num in ${line_nums[*]}
do
sed -i "$((line_num-1)), $((line_num+1))d" $root/pet2bids_error
done
fi

# Add all transformed data (e.g. NIfTI or MEG formats) to the list file
(cd $root && find . -maxdepth 9 -type f \( -name "*.nii.gz" \) > $root/list)
(cd $root && find . -maxdepth 9 -type f \( -name "*blood.json" \) >> $root/list)

if [ -f $root/meg.list ]; then
cat $root/meg.list >> $root/list
fi

if [ ! -s $root/list ]; then
echo "Could not find any MRI, PET, or MEG imaging files in upload, aborting"
err_file=''
if [ `grep 'Error' $root/dcm2niix_error | wc -l` -ne 0 ]; then
err_file='dcm2niix_error'
fi

if [ `grep 'Error' $root/pet2bids_error | wc -l` -ne 0 ]; then
err_file='pet2bids_error'
fi

echo ""
echo "Error: Could not find any MRI, PET, or MEG imaging files in upload."
echo "Please click the Debug section below and select Download ${err_file}"
echo "We recommend reaching out to the dcm2niix team for assistance: https://github.com/rordenlab/dcm2niix/issues"
exit 1
fi

Expand Down
8 changes: 6 additions & 2 deletions ui/src/Upload.vue
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@

<div v-if="session.status == 'failed'">
<el-alert type="error"
>ezBIDS failed.. Please check the Debug logs and contact ezBIDS team ([email protected]).</el-alert
>ezBIDS failed.. Please check the Debug logs and contact the ezBIDS team
([email protected]).</el-alert
>
<br />
<pre class="status">{{ session.status_msg }}</pre>
Expand Down Expand Up @@ -190,7 +191,7 @@
<div v-if="!ezbids.notLoaded && !ezbids.objects.length">
<el-alert type="error"
>We couldn't find any objects. Please upload data that contains at least 1 object. Contact the
ezBIDS team ([email protected]) or https://github.com/brainlife/ezbids/issues for
ezBIDS team ([email protected] or https://github.com/brainlife/ezbids/issues) for
support</el-alert
>
</div>
Expand All @@ -213,6 +214,9 @@
<el-button type="warning" size="mini" @click="downloadFile('dcm2niix_error')"
>Download dcm2niix_error</el-button
>
<el-button type="warning" size="mini" @click="downloadFile('pet2bids_error')"
>Download pet2bids_error</el-button
>
<el-button type="warning" size="mini" @click="downloadFile('list')">Download list</el-button>
<el-button type="warning" size="mini" @click="downloadFile('ezBIDS_core.json')"
>Download ezBIDS_core.json</el-button
Expand Down

0 comments on commit 5f8c637

Please sign in to comment.