-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathassemble_samplesheet.sh
146 lines (121 loc) · 3.59 KB
/
assemble_samplesheet.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/bin/bash
# This script will assemble a samplesheet based on an input directory
# containing the required images files. While the script is designed to
# work with the default file names, it can be easily modified to work with
# your specific directory structure and filenames conventions (BIDS, etc).
echo """
The script is designed to work with the following directory structure:
input/
├── subject1/
│ ├── *t1.nii.gz
│ ├── *t2.nii.gz
│ ├── *dwi.nii.gz
│ ├── *dwi.bval
│ ├── *dwi.bvec
│ ├── *revb0.nii.gz
│ ├── *labels.nii.gz
│ ├── *wmparc.nii.gz
│ ├── *.trk
│ ├── *peaks.nii.gz
│ ├── *fodf.nii.gz
│ ├── *mat.txt
│ ├── *warp.nii.gz
│ ├── metrics/
│ └── *.nii.gz
├── subject2/
│ └── ...
└── subject3/
└── ...
The script will loop through the input directory and assemble a samplesheet with the following columns:
subject,t1,t2,dwi,bval,bvec,rev_b0,labels,wmparc,trk,peaks,fodf,mat,warp,metrics
The script can be executed as follows:
bash assemble_samplesheet.sh input output.csv
"""
# Define the input dir.
input=$1
# Define the output file.
output=$2
# Define the header. (DO NOT CHANGE)
header="subject,t1,t2,dwi,bval,bvec,rev_b0,labels,wmparc,trk,peaks,fodf,mat,warp,metrics"
echo $header > $output
# Loop through the input directory and assemble the samplesheet.
for dir in $input/*; do
if [ -d $dir ]; then
# Fetch sample name.
subject=$(basename $dir)
# Fetch the required files.
if [ -f $dir/*t1.nii.gz ]; then
t1=$(realpath $dir/*t1.nii.gz)
else
t1=""
fi
if [ -f $dir/*t2.nii.gz ]; then
t2=$(realpath $dir/*t2.nii.gz)
else
t2=""
fi
if [ -f $dir/*dwi.nii.gz ]; then
dwi=$(realpath $dir/*dwi.nii.gz)
else
dwi=""
fi
if [ -f $dir/*dwi.bval ]; then
bval=$(realpath $dir/*dwi.bval)
else
bval=""
fi
if [ -f $dir/*dwi.bvec ]; then
bvec=$(realpath $dir/*dwi.bvec)
else
bvec=""
fi
if [ -f $dir/*revb0.nii.gz ]; then
rev_b0=$(realpath $dir/*revb0.nii.gz)
else
rev_b0=""
fi
if [ -f $dir/*labels.nii.gz ]; then
labels=$(realpath $dir/*labels.nii.gz)
else
labels=""
fi
if [ -f $dir/*wmparc.nii.gz ]; then
wmparc=$(realpath $dir/*wmparc.nii.gz)
else
wmparc=""
fi
if [ -f $dir/*.trk ]; then
trk=$(realpath $dir/*.trk)
else
trk=""
fi
if [ -f $dir/*peaks.nii.gz ]; then
peaks=$(realpath $dir/*peaks.nii.gz)
else
peaks=""
fi
if [ -f $dir/*fodf.nii.gz ]; then
fodf=$(realpath $dir/*fodf.nii.gz)
else
fodf=""
fi
if [ -f $dir/*mat.txt ]; then
mat=$(realpath $dir/*mat.txt)
else
mat=""
fi
if [ -f $dir/*warp.nii.gz ]; then
warp=$(realpath $dir/*warp.nii.gz)
else
warp=""
fi
if [ -d $dir/metrics ]; then
metrics=$(realpath $dir/metrics)
else
metrics=""
fi
# Write the assembled samplesheet.
echo "$subject,$t1,$t2,$dwi,$bval,$bvec,$rev_b0,$labels,$wmparc,$trk,$peaks,$fodf,$mat,$warp,$metrics" >> $output
fi
done
echo "Samplesheet assembled successfully!"