diff --git a/handler/ezBIDS_core/ezBIDS_core.py b/handler/ezBIDS_core/ezBIDS_core.py index dbe29c3e..f1bea8fa 100755 --- a/handler/ezBIDS_core/ezBIDS_core.py +++ b/handler/ezBIDS_core/ezBIDS_core.py @@ -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]) @@ -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 diff --git a/handler/find_img_data.py b/handler/find_img_data.py index a047f6a5..5f54cd55 100755 --- a/handler/find_img_data.py +++ b/handler/find_img_data.py @@ -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] diff --git a/handler/preprocess.sh b/handler/preprocess.sh index 6d24eca1..bb4815f8 100755 --- a/handler/preprocess.sh +++ b/handler/preprocess.sh @@ -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 @@ -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" @@ -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 diff --git a/ui/src/Upload.vue b/ui/src/Upload.vue index 848cd232..4c94c122 100644 --- a/ui/src/Upload.vue +++ b/ui/src/Upload.vue @@ -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 (dlevitas@iu.edu).</el-alert + >ezBIDS failed.. Please check the Debug logs and contact the ezBIDS team + (dlevitas@iu.edu).</el-alert > <br /> <pre class="status">{{ session.status_msg }}</pre> @@ -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 (dlevitas@iu.edu) or https://github.com/brainlife/ezbids/issues for + ezBIDS team (dlevitas@iu.edu or https://github.com/brainlife/ezbids/issues) for support</el-alert > </div> @@ -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