-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcallSvFromFastq.sh
executable file
·148 lines (107 loc) · 3.73 KB
/
callSvFromFastq.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
#!/bin/bash
OPTSTRING="hr:s:i:o:t:l:c:"
usage()
{
echo -e "You did it wrong"
}
declare SWITCH
threads=8
# Examine individual options
while getopts "$OPTSTRING" SWITCH; do
case $SWITCH in
r) ref="$OPTARG"
ref=$(readlink -e "$ref")
echo "Reference = $ref"
;;
s) settings="$OPTARG"
echo "Settings = $settings"
;;
i) fasta_dir="$OPTARG"
fasta_dir=$(readlink -e "$fasta_dir")
echo "Fasta Directory = $fasta_dir"
;;
o) out_dir="$OPTARG"
out_dir=$(readlink -e "$out_dir")
echo "Outdir = $out_dir"
;;
t) tools_dir="$OPTARG"
tools_dir=$(readlink -e "$tools_dir")
echo "Tools directory = $tools_dir"
;;
l) tools_list="$OPTARG"
declare -a tools=($tools_list)
echo "Going to run the following tools = $tools"
;;
c) threads="$OPTARG"
echo "Threads = $threads"
;;
*) echo "script error: unhandled argument"
usage
exit 1
;;
esac
done
source $tools_dir/log_eval.sh
SAMBAMBA="docker run -u 1001:1001 --name sambamba --rm -v $PWD:$PWD -w $PWD clinicalgenomics/sambamba:0.8.0"
declare -a tools=("breseq")
declare -a fractionOfReads=(100)
seed=87
stamp="$(date +'%Y_%d_%m-%H_%M_%S')"
org="CBS7435"
grep -v '^#' $settings | while IFS=$'\t' read -r -a settings_array
do
base_in=$(basename "$fasta_dir")
settings_string="${settings_array[0]}_f${settings_array[1]}_l${settings_array[2]}_m${settings_array[3]}_s${settings_array[4]}"
bamdir=$out_dir/${base_in/fasta/bam}/$settings_string
fastqdir=$out_dir/${base_in/fasta/fastq}/$settings_string
svsdir=$out_dir/${base_in/fasta/svs}/$settings_string
echo "THIS IS the DIRECTORY: $fastqdir"
timing=${svsdir}/${stamp}_timing.tsv
log=${svsdir}/${stamp}_sv_calling.log
echo "THIS IS the DIRECTORY: $bamdir"
if [ ! -d $svsdir ]; then
mkdir $svsdir
fi
touch $timing
touch $log
for dir in "$fasta_dir"/*; do
if [[ -d $dir ]]; then
base=$(basename "$dir")
if [ ! -d $svsdir/$base ]; then
mkdir $svsdir/$base
fi
READ1_FILE="${fastqdir}/${base}_1.fq.gz"
READ2_FILE="${fastqdir}/${base}_2.fq.gz"
echo "╔══════════════════════════════════════════════════════════════╗"
echo "║ starting SV analysis ║"
echo "╚══════════════════════════════════════════════════════════════╝"
if [ -s "$READ1_FILE" -a -s "$READ2_FILE" ]; then
for fraction in "${fractionOfReads[@]}"; do
# READ1_FILE_FRACTION=$READ1_FILE
# READ2_FILE_FRACTION=$READ2_FILE
# if [ $fraction -ne 100 ]; then
# READ1_FILE_FRACTION="${READ1_FILE/.fastq/-${fraction}.fastq}"
# READ2_FILE_FRACTION="${READ2_FILE/.fastq/-${fraction}.fastq}"
# log_eval $PWD "$SAMBAMBA sambamba view -h -t $threads -s 0.$fraction -f bam \
# --subsampling-seed=$seed -o $BAM_FRACTION $BAM_SORTED"
# fi
# For teh sake of consistency
BAM_FRACTION="NONE"
for tool in "${tools[@]}"; do
tool_outdir="$svsdir/$base/${tool}_${fraction}"
if [ ! -d "$tool_outdir" ]; then
mkdir "$tool_outdir"
export -f log_eval
log_eval $PWD "$tools_dir/$tool/${tool}.sh $BAM_FRACTION $ref $READ1_FILE $READ2_FILE $tool_outdir $threads $tools_dir $timing" "$log"
fi
done
# if [ $fraction -ne 100 ]; then
# rm $BAM_FRACTION
# fi
done
else
echo "Could not find files $READ1_FILE, $READ2_FILE"
fi
fi
done
done