121 lines
3.3 KiB
Bash
121 lines
3.3 KiB
Bash
#!/usr/bin/env/bash
|
|
# @description Creates, modifies, and parses the study info file
|
|
#
|
|
# TODO
|
|
#
|
|
# * Needs refactoring
|
|
# * Ended up combining a few functions into one
|
|
#
|
|
#
|
|
# @exitcode 0 If one or more studies found
|
|
# @exitcode 1 If no studies found
|
|
# @set STUDIES array contains array of "exp# sd ExpDir"
|
|
parse_study_info() {
|
|
debug "Running: ${FUNCNAME[0]}"
|
|
|
|
# Only run this once per project
|
|
# in case we run multiple modules
|
|
(( SET_STUDIES )) && return 0
|
|
declare -g SET_STUDIES=1
|
|
|
|
# Use initials from project or whoami?
|
|
# Best I can do is first two letters of username
|
|
# See TODO in markdown
|
|
initials="${USER:0:2}"
|
|
INITIALS=${initials^^}
|
|
|
|
empty_study=1
|
|
# Find an Exp directory that does not exist
|
|
while [[ -d $STUDY_RESULTS_DIR/exp$empty_study ]]; do
|
|
(( empty_study++ ))
|
|
done
|
|
|
|
next_study_entry="$empty_study,$PROJECT_NAME,NA,NA,$INITIALS"
|
|
|
|
echo "${underline}Study Info File${nounderline}"
|
|
|
|
if [[ -f $STUDY_INFO_FILE ]]; then
|
|
# Get latest entry
|
|
while IFS=',' read -r col1 _; do # split on comma, get Exp # from 1st column
|
|
studies_nums+=("$col1")
|
|
done < <(tail -n +2 "$STUDY_INFO_FILE")
|
|
largest=${studies_nums[0]}
|
|
for i in "${studies_nums[@]}"; do
|
|
if ((i > largest)); then
|
|
largest=$i
|
|
fi
|
|
done
|
|
empty_study=$((largest+1))
|
|
next_study_entry="$((empty_study)),$PROJECT_NAME,NA,NA,$INITIALS"
|
|
else # create a default study info file
|
|
echo "ExpNumb,ExpLabel,BackgroundSD,ZscoreJoinSD,AnalysisBy" > "$STUDY_INFO_FILE"
|
|
echo "$next_study_entry" >> "$STUDY_INFO_FILE"
|
|
next_study_entry="$((empty_study+1)),$PROJECT_NAME,NA,NA,$INITIALS"
|
|
fi
|
|
|
|
# Print current studies
|
|
cat <<-EOF
|
|
* Give each experiment labels to be used for the plots and specific files.
|
|
* Enter the desired experiment names in the order they should appear in the REMc heatmaps
|
|
|
|
Current study info file contents:
|
|
|
|
${underline}$STUDY_INFO_FILE${nounderline}
|
|
$(cat "$STUDY_INFO_FILE")
|
|
|
|
EOF
|
|
|
|
# Allow user to add/edit the study info file
|
|
if ! ((YES)); then
|
|
for ((i=1; i<2; i++)); do
|
|
cat <<-EOF
|
|
Next entry suggestion: "$next_study_entry"
|
|
|
|
Would you like to:
|
|
* (a)dd the suggested entry
|
|
* (e)dit the study info file manually
|
|
* (c)ontinue (default)
|
|
EOF
|
|
read -r -p "(c): " response
|
|
echo ""
|
|
[[ -z $response ]] && break
|
|
case $response in
|
|
a)
|
|
echo "Adding auto-entry suggestion to $STUDY_INFO_FILE"
|
|
echo "$next_study_entry" >> "$STUDY_INFO_FILE"
|
|
next_study_entry="$((empty_study+1)),$PROJECT_NAME,NA,NA,$INITIALS"
|
|
i=0
|
|
;;
|
|
e)
|
|
debug "$EDITOR $STUDY_INFO_FILE"
|
|
"$EDITOR" "$STUDY_INFO_FILE"
|
|
;;
|
|
c)
|
|
break
|
|
;;
|
|
*)
|
|
err "Invalid response, please try again"
|
|
i=0
|
|
;;
|
|
esac
|
|
break
|
|
done
|
|
fi
|
|
|
|
# Read study info file
|
|
declare -ga STUDIES
|
|
while IFS=',' read -r num _ sd _; do
|
|
STUDIES+=("$num $sd $STUDY_RESULTS_DIR/exp$num")
|
|
done < <(tail -n +2 "$STUDY_INFO_FILE") # skip header
|
|
|
|
# Initialize missing Exp dirs
|
|
for study in "${STUDIES[@]}"; do
|
|
read -r _ _ dir <<< "$study"
|
|
[[ -d $dir ]] || execute mkdir "$dir"
|
|
done
|
|
|
|
((DEBUG)) && declare -p STUDIES
|
|
|
|
# Return true if at least one study was found
|
|
[[ ${#STUDIES[@]} -gt 0 ]]
|
|
} |