-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathfrc_data_gen.sh
More file actions
executable file
·298 lines (227 loc) · 7.92 KB
/
frc_data_gen.sh
File metadata and controls
executable file
·298 lines (227 loc) · 7.92 KB
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
#!/bin/bash
# Perform for ref-guided, denovo and merged contigs.
# 1. Prep reads into one file.
# 2. Create bowtie2 index out of contigs.
# 3. Align reads to contigs.
# 4. Run frc code.
usage="
Generate Feature Response Curve data for reference-guided, denovo and merged contigs.
bash $(basename "$0") -f <forward_reads> -r <reverse_reads> -u <unpaired_reads> \
-ref <ref-guided_contigs> -d <denovo_contigs> -m <merged_contigs> -o <out_dir>
where:
[-f | --forward] path_to_forward_read.
[-r | --reverse] path_to_reverse_read.
[-u | --unpaired] path_to_unpaired_read.
[-s | --split_reads] path to mapped and unmapped reads (Directory structure assumes output format from align_reads step of reference culling process).
[-ref | --refguided_contigs] path to ref-guided contigs directory (Directory structure assumes output format from pilon step of ref-guided assembly process).
[-d | --denovo_contigs] path to file containing denovo contigs.
[-m | --merged_contigs] path to file containing merged contigs.
[-frc | --frc] path to FRC executable.
[-libavg | --libsize_avg] Average library size of reads.
[-libstd | --libsize_sdv] Standard Deviation for library size of reads.
[-oa | --orientation_a] Orientation of forward reads.
[-ob | --orientation_b] Orientation of reverse reads.
[-mpsize | --mp_size_z_cutoff] Mate pair size cutoff.
[-mpedge | --mp_edge_z_cutoff] Mate edge size cutoff.
[-doclogp | --doc_logp_cutoff] Depth of coverage cutoff (log(p)).
[-o | --out] path to output directory.
[-l | --log] path to log file.
[-h | --help] print usage."
forward=""
reverse=""
unpaired=""
split_reads=""
r_contigs=""
d_contigs=""
m_contigs=""
FRC=""
# Start default params for FRC code #
# data properties
libsize_avg="165"
libsize_sdv="92.8"
orientation_a="+"
orientation_b="+"
# statistical parameters
mp_size_z_cutoff="2.58"
mp_edge_z_cutoff="2.58"
doc_logp_cutoff="7"
# End default params for FRC code #
out=""
log=""
help=0
while [[ "$#" -gt 0 ]]; do
case $1 in
-f|--forward)
forward="$2";
shift;;
-r|--reverse)
reverse="$2";
shift;;
-u|--unpaired)
unpaired="$2";
shift;;
-s|--split_reads)
split_reads="$2";
shift;;
-ref|--refguided_contigs)
r_contigs="$2";
shift;;
-d|--denovo_contigs)
d_contigs="$2";
shift;;
-m|--merged_contigs)
m_contigs="$2";
shift;;
-frc|--frc)
FRC="$2";
shift;;
-libavg|--libsize_avg)
libsize_avg="$2";
shift;;
-libstd|--libsize_sdv)
libsize_sdv="$2";
shift;;
-oa|--orientation_a)
orientation_a="$2";
shift;;
-ob|--orientation_b)
orientation_b="$2";
shift;;
-mpsize|--mp_size_z_cutoff)
mp_size_z_cutoff="$2";
shift;;
-mpedge|--mp_edge_z_cutoff)
mp_edge_z_cutoff="$2";
shift;;
-doclogp|--doc_logp_cutoff)
doc_logp_cutoff="$2";
shift;;
-o|--out)
out="$2";
shift;;
-l|--log)
log="$2";
shift;;
-h|--help)
help=1;
shift;;
esac
shift
done
if [ $help = 1 ]; then
echo "$usage"
exit 0
fi
#check reads
if [[ ("$forward" != '' && "$reverse" == '') || ("$forward" == '' && "$reverse" != '') ]]; then
echo "Error: Only have forward or reverse but need both."
exit 1
elif [[ "$forward" == '' && "$reverse" == '' && "$unpaired" == '' ]]; then
echo "Error: No reads provided."
exit 1
fi
# only merged contigs required.
if [[ "$m_contigs" == '' ]]; then
echo "Error: Need merged contigs file."
exit 1
elif [[ ! -f "$m_contigs" ]]; then
echo "Error: Merged contigs file path does not exist."
exit 1
fi
if [[ "$out" == '' ]]; then
echo "Error: Need output folder."
exit 1
elif [[ ! -d "$out" ]]; then
echo "Error: Output folder path does not exist."
exit 1
fi
#check existence
if [[ "$forward" != '' && ! -f "$forward" ]]; then
echo "Error: Forward reads path does not exist."
exit 1
fi
if [[ "$reverse" != '' && ! -f "$reverse" ]]; then
echo "Error: Reverse reads path does not exist."
exit 1
fi
if [[ "$unpaired" != '' && ! -f "$unpaired" ]]; then
echo "Error: Unpaired reads path does not exist."
exit 1
fi
if [[ "$split_reads" != '' && ! -d "$split_reads" ]]; then
echo "Error: Split reads reads path does not exist."
exit 1
fi
if [[ "$FRC" != '' && ! -f "$FRC" ]]; then
echo "Error: FRC executable path does not exist."
exit 1
fi
get_data() {
reads=$1
contigs=$2
out_path=$3
name=$4
sam=${out_path}"/"${name}".sam"
bam=${out_path}"/"${name}".bam"
bed_pre=${out_path}"/"${name}".pre.bed"
bed_post=${out_path}"/"${name}".post.bed"
fai=${contigs}".fai"
out_file=${out_path}"/"${name}".tsv"
# create index
bowtie2_index=${out_path}"/idx/idx"
bowtie2_output=${out_path}"/bowtie2_output.txt"
mkdir $out_path
mkdir ${out_path}"/idx"
bowtie2-build $contigs $bowtie2_index > $bowtie2_output
# create necessary files
cat $reads | bowtie2 -U - -x $bowtie2_index -S $sam -p 8 >> $bowtie2_output
samtools view -bS $sam > $bam
samtools faidx $contigs
bamToBed -i $bam > $bed_pre
env LC_COLLATE=C sort -k 1,1 -k 4,4 -o $bed_post $bed_pre
cmd="$FRC $bed_post $fai $out_file $libsize_avg $libsize_sdv $orientation_a $orientation_b $mp_size_z_cutoff $mp_edge_z_cutoff $doc_logp_cutoff"
echo "Execute: $cmd" >> $log
$cmd
}
if [[ -f $forward && -f $reverse && -f $unpaired ]]; then
get_data "$forward $reverse $unpaired" "$m_contigs" "${out}/merged" "merged"
elif [[ -f $forward && -f $reverse ]]; then
get_data "$forward $reverse" "$m_contigs" "${out}/merged" "merged"
elif [[ -f $unpaired ]]; then
get_data "$unpaired" "$m_contigs" "${out}/merged" "merged"
fi
if [[ -f $forward && -f $reverse && -f $unpaired ]]; then
unmapped_reads1=$(find $split_reads -name '*_unmapped.1*')
unmapped_reads2=$(find $split_reads -name '*_unmapped.2*')
unmapped_readsu=$(find $split_reads -name '*_unmapped.u*')
get_data "$unmapped_reads1 $unmapped_reads2 $unmapped_readsu" "$d_contigs" "${out}/denovo" "denovo"
elif [[ -f $forward && -f $reverse ]]; then
unmapped_reads1=$(find $split_reads -name '*_unmapped.1*')
unmapped_reads2=$(find $split_reads -name '*_unmapped.2*')
get_data "$unmapped_reads1 $unmapped_reads2" "$d_contigs" "${out}/denovo" "denovo"
elif [[ -f $unpaired ]]; then
unmapped_readsu=$(find $split_reads -name '*_unmapped.u*')
get_data "$unmapped_readsu" "$d_contigs" "${out}/denovo" "denovo"
fi
ref_out=$out"/ref_guided"
mkdir $ref_out
for ref in $(ls $split_reads); do
out=${ref_out}"/"${ref}
fasta="${r_contigs}/${ref}/contigs.pilon.fasta"
if [[ ! -f $fasta ]]; then
continue
fi
if [[ -f $forward && -f $reverse && -f $unpaired ]]; then
mapped_reads1=$(find ${split_reads}/${ref} -name '*_mapped.1*')
mapped_reads2=$(find ${split_reads}/${ref} -name '*_mapped.2*')
mapped_readsu=$(find ${split_reads}/${ref} -name '*_mapped.u*')
get_data "$mapped_reads1 $mapped_reads2 $mapped_readsu" "$fasta" "$out" "$ref"
elif [[ -f $forward && -f $reverse ]]; then
mapped_reads1=$(find ${split_reads}/${ref} -name '*_mapped.1*')
mapped_reads2=$(find ${split_reads}/${ref} -name '*_mapped.2*')
get_data "$mapped_reads1 $mapped_reads2" "$fasta" "$out" "$ref"
elif [[ -f $unpaired ]]; then
mapped_readsu=$(find ${split_reads}/${ref} -name '*_mapped.u*')
get_data "$mapped_readsu" "$fasta" "$out" "$ref"
fi
done