Hi there! We have two separate studies in different patient populations running concurrently - participants in both studies went through identical MRI protocols. When processing the data, I short-sightedly processed the studies as separate fmriprep projects, not realizing that we would want to compare the two patient groups later down the line. I’m now trying to import them both into a single CONN project for running a PPI analysis, but unfortunately they have overlapping subject numbers. Does anyone know of any easy way to import both projects into the same CONN project and just have the second group of subjects be added as the subsequent numbers? I have tried just selecting both projects in the import window, but they overwrite one another.
Why not just write a script to increment the numbers of one dataset?
I asked chatGPT to do it, here’s what it came up with:
#!/bin/bash
# Function to recursively rename files within a directory
rename_files() {
local directory="$1"
local num_dataset1_subjects="$2"
local subject="$3"
local new_subject_number="$4"
# Rename files within the subject directory
for file in "$directory"/"$subject"/*; do
if [ -f "$file" ]; then
file_extension="${file##*.}"
new_file_name="$directory/$subject/$subject"_$(printf "%04d" $((10#$new_subject_number - 10#$num_dataset1_subjects)))".$file_extension"
mv "$file" "$new_file_name"
fi
done
}
# Path to the first dataset
dataset1_path="/path/to/first_dataset"
# Path to the second dataset
dataset2_path="/path/to/second_dataset"
# Determine the number of subjects in the first dataset
num_dataset1_subjects=$(find "$dataset1_path" -maxdepth 1 -type d -name "sub-*" | wc -l)
# Increment subject numbers in the second dataset
for subject in "$dataset2_path"/sub-*; do
if [ -d "$subject" ]; then
subject_number=$(basename "$subject" | cut -d'-' -f2)
new_subject_number=$((subject_number + num_dataset1_subjects))
new_subject_name="sub-$(printf "%02d" $new_subject_number)"
mv "$subject" "$dataset2_path/$new_subject_name"
rename_files "$dataset2_path" "$num_dataset1_subjects" "$new_subject_name" "$new_subject_number"
fi
done
You can try that, or something like that, on your dataset. I would start by testing it on a copy of the data so you don’t irreversibly alter something in an unintended way.