-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_template.sh
73 lines (63 loc) · 1.82 KB
/
create_template.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/bin/bash
# Script to create a directory structure for ACDC Data Transfer and initialize a manifest file.
# Function to display help message
show_help() {
echo "Usage: $0 [-h] [-s STUDY_ID] [-o OUTPUT_DIR]"
echo
echo "This script creates a directory structure for ACDC Data Transfer and initializes a manifest file."
echo
echo "Options:"
echo " -s STUDY_ID The study identifier used to name the root directory."
echo " -o OUTPUT_DIR Specify the output directory where the structure will be created. Default is the current directory."
}
# Default output directory is the current directory
OUTPUT_DIR="."
STUDY_ID=""
# Parse options
while getopts ":hs:o:" opt; do
case ${opt} in
h )
show_help
exit 0
;;
s )
STUDY_ID=$OPTARG
;;
o )
OUTPUT_DIR=$OPTARG
;;
\? )
echo "Invalid option: -$OPTARG" 1>&2
show_help
exit 1
;;
esac
done
shift $((OPTIND -1))
# Check if STUDY_ID is provided
if [ -z "$STUDY_ID" ]; then
echo "Error: STUDY_ID is required."
show_help
exit 1
fi
DATE=$(date +%Y-%m-%d)
ROOT_NAME="${OUTPUT_DIR}/${DATE}_${STUDY_ID}_ACDC_Data_Transfer"
# Create root directory
if ! mkdir -p "$ROOT_NAME"; then
echo "Error: Failed to create directory $ROOT_NAME" 1>&2
exit 1
fi
# Echo the root directory name
echo "Root directory created: $ROOT_NAME"
# Create subdirectories
for dir in clinical genomic imaging metabolomic proteomic study study/data_dictionaries; do
if ! mkdir -p "$ROOT_NAME/$dir"; then
echo "Error: Failed to create directory $ROOT_NAME/$dir" 1>&2
exit 1
fi
done
# Create manifest file with header
if ! echo -e "study_id\tsubject_id\tfile_path\tfile_name\tdata_category\tfile_size\tmd5_hash" > "$ROOT_NAME/manifest.tsv"; then
echo "Error: Failed to create manifest file $ROOT_NAME/manifest.tsv" 1>&2
exit 1
fi