-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e3c3604
commit f4eb902
Showing
4 changed files
with
71 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/bin/bash | ||
|
||
# Function to handle renaming for a given direction | ||
rename_fmapdup() { | ||
local DIRECTION="$1" | ||
local RUN_NUM_ORIG="$2" | ||
local RUN_NUM_NEW="$3" | ||
|
||
# Construct original and new JSON filenames based on direction and run numbers | ||
local DUPJSON="./sub-0057/ses-01/fmap/sub-0057_ses-01_acq-mb8_dir-${DIRECTION}_run-${RUN_NUM_ORIG}_epi__dup-01.json" | ||
local RENAMEJSON="./sub-0057/ses-01/fmap/sub-0057_ses-01_acq-mb8_dir-${DIRECTION}_run-${RUN_NUM_NEW}_epi.json" | ||
|
||
# Rename the JSON file | ||
datalad run ../../../code/rename_file "${DUPJSON}" "${RENAMEJSON}" | ||
|
||
# Construct the corresponding .nii.gz filenames | ||
local ORIGINAL_NII_GZ="${DUPJSON%.json}.nii.gz" | ||
local NEW_NII_GZ="${RENAMEJSON%.json}.nii.gz" | ||
|
||
# Check if the original .nii.gz file exists before attempting to rename | ||
if [ -f "$ORIGINAL_NII_GZ" ]; then | ||
# Rename the .nii.gz file | ||
git mv "$ORIGINAL_NII_GZ" "$NEW_NII_GZ" | ||
echo "Renamed $ORIGINAL_NII_GZ to $NEW_NII_GZ" | ||
else | ||
echo "File $ORIGINAL_NII_GZ does not exist, skipping..." | ||
fi | ||
} | ||
|
||
# Run the renaming for both directions | ||
# Adjust RUN_NUM_ORIG and RUN_NUM_NEW as needed for each case | ||
rename_fmapdup "ap" "02" "03" | ||
rename_fmapdup "pa" "02" "03" # Update RUN_NUM_ORIG and RUN_NUM_NEW as per your requirements for the pa direction |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#NEED TO REMOVE PRIMARY and rename DUP as PRIMARY | ||
# PRIMARYJSON="sub-0122_ses-03_acq-mb8_dir-ap_run-01_epi.json" | ||
DUPJSON="./sub-0122/ses-03/fmapsub-0122_ses-03_acq-mb8_dir-ap_run-01_epi__dup-01.json" | ||
DUPJSON_TR=$(jq '.AcquisitionTime' "${DUPJSON}") | ||
PRIMARYJSON=$(echo "${DUPJSON}" | sed 's/__dup-[0-9]*//') | ||
PRIMARYJSON_TR=$(jq '.AcquisitionTime' "${PRIMARYJSON}") | ||
if [[ "$PRIMARYJSON_TR" == "null" || "$PRIMARYJSON_TR" =~ "error" ]]; then | ||
echo "$PRIMARYJSON: Error extracting TR value." >> "$error_log" | ||
continue | ||
fi | ||
PRIMARYJSON_NODEC=${PRIMARYJSON_TR%%.*} | ||
DUPJSON_NODEC=${DUPJSON_TR%%.*} | ||
PRIMARYJSON_SEC=$(echo $PRIMARYJSON_NODEC | tr -d '"'| awk -F: '{ print ($1 * 3600) + ($2 * 60) + $3 }') | ||
DUPJSON_SEC=$(echo $DUPJSON_NODEC | tr -d '"' | awk -F: '{ print ($1 * 3600) + ($2 * 60) + $3 }') | ||
|
||
if [ "$PRIMARYJSON_SEC" -lt "$DUPJSON_SEC" ]; then | ||
echo -e "\n${DUPJSON}\nPRIMARYJSON acquisition time is earlier." >> $LOG_FILE | ||
# echo -e "\n>>>>> ERROR: PRIMARYJSON ${PRIMARYJSON_NODEC} ${PRIMARYJSON_SEC} has an earlier time than DUPJSON ${DUPJSON_NODEC} ${DUPJSON_SEC}\n\n" >> $LOG_FILE | ||
|
||
# SWAP DUP AND PRIMARY, THEN DELETED | ||
PRIMARYGZ=${PRIMARYJSON} | ||
DUPGZ=${DUPJSON} #TODO remove file extension | ||
# RENAME JSON primary is crap, keep dup | ||
$(dirname "$0")/rename_file "${PRIMARYJSON}" CRAPJSON; | ||
$(dirname "$0")/rename_file "${DUPJSON}" "${PRIMARYJSON}"; | ||
$(dirname "$0")/rename_file CRAPJSON "${DUPJSON}" | ||
# # RENAME fmap | ||
$(dirname "$0")/rename_file "${PRIMARYGZ}" CRAPNII; | ||
$(dirname "$0")/rename_file "${DUPGZ}" "${PRIMARYGZ}"; | ||
$(dirname "$0")/rename_file CRAPNII "${DUPGZ}" | ||
# DELETE files | ||
git rm "${DUPGZ}" | ||
git rm "${DUPJSON}" | ||
|
||
fi |