-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdubdub.sh
executable file
·211 lines (154 loc) · 6.34 KB
/
dubdub.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#!/usr/bin/env bash
# Find dubdub directory
DUBDIR=`dirname $0`
# Load configuration
source ${DUBDIR}/config.sh
# Read input flags
while getopts d:f:l:L:U:P:D:t: flag
do
case "${flag}" in
d) WORKDIR=${OPTARG};; # Working directory in which results appear
f) FASTQDIR=${OPTARG};; # Directory with input fastq files
l) LAYOUT=${OPTARG};; # Barseq experiment layout file
L) LIBRARY=${OPTARG};; # DubSeq library to use
U) LSEQ=${OPTARG};; # If necessary, supply alternative LSEQ
P) LPOS=${OPTARG};; # If necessary, supply alternative LPOS
D) RSEQ=${OPTARG};; # If necessary, supply alternative RSEQ
t) ZEROCUT=${OPTARG};; # If necessary, supply time0 read count cutoff
esac
done
# Remove trailing slash from inputs
WORKDIR=`echo $WORKDIR | sed -e 's|/$||'`
FASTQDIR=`echo $FASTQDIR | sed -e 's|/$||'`
# Create working directory if it does not exist
[ ! -d "$WORKDIR" ] && mkdir -p $WORKDIR
# Exit if any of the required inputs do not exist
if [ ! -d "$WORKDIR" ]; then
echo -e "\n\e[31mError: Output directory does not exist.\e[0m\n"; exit 1
fi
if [ ! -d "$FASTQDIR" ]; then
echo -e "\n\e[31mError: FASTQ directory does not exist.\e[0m\n"; exit 1
fi
if [ ! -f "$LAYOUT" ]; then
echo -e "\n\e[31mError: Barseq layout file does not exist.\e[0m\n"; exit 1
fi
BPAG="`dirname $(realpath $0)`/libraries/${LIBRARY}/${LIBRARY}.bpag.tab"
if [ ! -f "$BPAG" ]; then
echo -e "\n\e[31mError: DubSeq library (BPAG) does not exist.\e[0m\n"; exit 1
fi
# Exit if working directory is not empty
if [ "$(ls -A $WORKDIR)" ]; then
echo -e "\n\e[31mError: Output directory is not empty.\e[0m\n"; exit 1
fi
# Set step counter to zero
S=0
# Count total number of steps
T=`grep -cP "^\(\(S\+\+\)\)$" $0`
# Concatenate FASTQ.gz files
((S++))
echo -e "\n\e[94mStep $S of $T: Concatenating fastq.gz files...\e[0m\n"
${DUBDIR}/source/concatenate_fastq.sh $FASTQDIR ${WORKDIR}/fastq
FILECOUNT=`find ${WORKDIR}/fastq -name *fastq.gz | wc -l`
if [ "$FILECOUNT" -lt "1" ]; then
echo -e "\n\e[31mError: Step $S failed.\e[0m\n"; exit 1
fi
FILECOUNT="0"
echo -e "\n\e[92mStep $S of $T: Done.\e[0m\n"
# Count barcodes
((S++))
echo -e "\n\e[94mStep $S of $T: Counting barcodes...\e[0m\n"
${DUBDIR}/source/run_barseq.sh ${WORKDIR}/fastq ${WORKDIR}/barseq \
$LSEQ $LPOS $RSEQ
FILECOUNT=`find ${WORKDIR}/barseq -name *bstat.tsv | wc -l`
if [ "$FILECOUNT" -lt "1" ]; then
echo -e "\n\e[31mError: Step $S failed.\e[0m\n"; exit 1
fi
FILECOUNT="0"
echo -e "\n\e[92mStep $S of $T: Done.\e[0m\n"
# Create links to bstat files in new directory
((S++))
echo -e "\n\e[94mStep $S of $T: Linking barseq statistics files...\e[0m\n"
${DUBDIR}/source/link_bstat_files_with_itnums.sh $WORKDIR
FILECOUNT=`find ${WORKDIR}/bstat -name *bstat.tsv | wc -l`
if [ "$FILECOUNT" -lt "1" ]; then
echo -e "\n\e[31mError: Step $S failed.\e[0m\n"; exit 1
fi
FILECOUNT="0"
echo -e "\n\e[92mStep $S of $T: Done.\e[0m\n"
# Add IT numbering (itnum) to layout
((S++))
echo -e "\n\e[94mStep $S of $T: Adding IT numbers to layout...\e[0m\n"
${DUBDIR}/source/add_itnum_to_layout.R $WORKDIR $LAYOUT
FILECOUNT=`find ${WORKDIR} -name layout.tab | wc -l`
if [ "$FILECOUNT" -lt "1" ]; then
echo -e "\n\e[31mError: Step $S failed.\e[0m\n"; exit 1
fi
FILECOUNT="0"
echo -e "\n\e[92mStep $S of $T: Done.\e[0m\n"
# Filter layout file to valid samples (has >= 10 t0 reads recommended barcodes)
((S++))
echo -e "\n\e[94mStep $S of $T: Filtering layout to valid samples...\e[0m\n"
${DUBDIR}/source/determine_valid_samples.R $WORKDIR $BPAG $LAYOUT
${DUBDIR}/source/filter_layout_table_to_valid_samples.R \
${WORKDIR}/valid_samples.txt ${WORKDIR}/sample_itnum.tab ${WORKDIR}/layout.tab
FILECOUNT=`find ${WORKDIR} -name layout.valid.tab | wc -l`
if [ "$FILECOUNT" -lt "1" ]; then
echo -e "\n\e[31mError: Step $S failed.\e[0m\n"; exit 1
fi
FILECOUNT="0"
echo -e "\n\e[92mStep $S of $T: Done.\e[0m\n"
# Perform fscore calculation if deduplicated barcodes are present in library
DEDUP="`dirname $(realpath $0)`/libraries/${LIBRARY}/${LIBRARY}.dedup.bpag.tab"
if [ -f "$DEDUP" ]; then
echo -e "\n\e[95mDedup detour: Filtering layout to valid samples...\e[0m\n"
${DUBDIR}/source/determine_valid_samples.R $WORKDIR $DEDUP $LAYOUT
${DUBDIR}/source/filter_layout_table_to_valid_samples.R \
${WORKDIR}/valid_samples.dedup.txt ${WORKDIR}/sample_itnum.tab \
${WORKDIR}/layout.tab
echo -e "\n\e[95mDedup detour: Calculating fragment fitness values...\e[0m\n"
${DUBDIR}/source/run_fscore.sh ${WORKDIR}/bstat ${WORKDIR}/fscore \
$LIBRARY ${WORKDIR}/layout.valid.dedup.tab $ZEROCUT
echo -e "\n\e[95mDedup detour: Creating combined fragment score table...\e[0m\n"
${DUBDIR}/source/create_fscore_table.R $WORKDIR
echo -e "\n\e[95mDedup detour: Adding genes and multi-barcodes...\e[0m\n"
${DUBDIR}/source/finalize_fscore_table.R ${WORKDIR}/fragment_scores.tab \
${DUBDIR}/libraries/${LIBRARY}/${LIBRARY}.multi.bpag.tab \
${DUBDIR}/libraries/${LIBRARY}/${LIBRARY}.gff
echo -e "\n\e[93mDedup detour: Done.\e[0m\n"
fi
# Calculate gene fitness values
((S++))
echo -e "\n\e[94mStep $S of $T: Calculating gene fitness values...\e[0m\n"
${DUBDIR}/source/run_gscore.sh ${WORKDIR}/bstat ${WORKDIR}/gscore \
$LIBRARY ${WORKDIR}/layout.valid.tab $ZEROCUT
FILECOUNT=`find ${WORKDIR}/gscore -name *gscore.tsv | wc -l`
if [ "$FILECOUNT" -lt "1" ]; then
echo -e "\n\e[31mError: Step $S failed.\e[0m\n"; exit 1
fi
FILECOUNT="0"
echo -e "\n\e[92mStep $S of $T: Done.\e[0m\n"
# Create a combined gene score table
((S++))
echo -e "\n\e[94mStep $S of $T: Creating combined gene score table...\e[0m\n"
${DUBDIR}/source/create_gscore_table.R $WORKDIR
FILECOUNT=`find ${WORKDIR} -name gene_scores.tab | wc -l`
if [ "$FILECOUNT" -lt "1" ]; then
echo -e "\n\e[31mError: Step $S failed.\e[0m\n"; exit 1
fi
FILECOUNT="0"
echo -e "\n\e[92mStep $S of $T: Done.\e[0m\n"
# Perform principal component analysis on gene scores
((S++))
echo -e "\n\e[94mStep $S of $T: Performing PCA on gene scores...\e[0m\n"
${DUBDIR}/source/gscore_pca.R $WORKDIR
FILECOUNT=`find ${WORKDIR} -name gene_score_PCA.pdf | wc -l`
if [ "$FILECOUNT" -lt "1" ]; then
echo -e "\n\e[31mError: Step $S failed.\e[0m\n"; exit 1
fi
FILECOUNT="0"
echo -e "\n\e[92mStep $S of $T: Done.\e[0m\n"
# Clean up the working directory
((S++))
echo -e "\n\e[94mStep $S of $T: Cleaning up output directory...\e[0m\n"
${DUBDIR}/source/cleanup.sh $WORKDIR
echo -e "\n\e[92mStep $S of $T: Done.\e[0m\n"