-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhg38-ATAC.sh
206 lines (160 loc) · 3.56 KB
/
hg38-ATAC.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
# Now with automatic file parsing!
cd fastq
var=( $(ls) )
if [ "${var[0]##*.}" = "gz" ]; then
find ./*.fastq.gz -type f -maxdepth 1 | cut -c3- | rev | cut -c4- | rev | paste -sd ';\n' > filePairs.txt
fi
if [ "${var[0]##*.}" = "fastq" ]; then
find ./*.fastq -type f -maxdepth 1 | cut -c3- | paste -sd ';\n' > filePairs.txt
fi
cd ..
source /etc/profile.d/apps.sh
echo "Program Started: $(date)" > timelog.txt
parallel gunzip ::: ./fastq/*.gz
echo "Files Unzipped: $(date)" >> timelog.txt
cd fastq/
for FILEPAIR in $(cat filePairs.txt)
do
F1=$(echo $FILEPAIR | awk 'BEGIN{FS=";"}{print $1}')
F2=$(echo $FILEPAIR | awk 'BEGIN{FS=";"}{print $2}')
echo "Paired End mode ${FILEPAIR}"
cutadapt -a CTGTCTCTTATACACATCT \
-A AGATGTGTATAAGAGACAG \
--minimum-length=25 -j 0 \
-o "trimmed_${F1}" -p "trimmed_${F2}" \
${F1} ${F2} >"${F1}_cutadapt_report.txt"
done
wait
cd ../
echo "Adapters Trimmed: $(date)" >> timelog.txt
mkdir trimmedFastq
for FILE in ./fastq/trimmed*
do
{
mv $FILE ./trimmedFastq
} &
done
wait
mkdir BAM
mv ./fastq/filePairs.txt ./trimmedFastq/filePairs.txt
cd trimmedFastq/
for FILEPAIR in $(cat filePairs.txt)
do
F1=$(echo $FILEPAIR | awk 'BEGIN{FS=";"}{print $1}')
F2=$(echo $FILEPAIR | awk 'BEGIN{FS=";"}{print $2}')
echo "beginning alignment to GRCh38 of file ${FILEPAIR}"
bowtie2 --local --very-sensitive-local \
--no-unal --no-mixed --no-discordant \
--threads 62 \
-x /data/Austin/workdir/genome/hg38/hg38_bt2/GRCh38 \
-I 10 -X 1000 \
-1 "trimmed_${F1}" \
-2 "trimmed_${F2}" \
-S ${F1/_R1.fastq/_toGRCh38.SAM}
echo "complete"
done
wait
cd ../
echo "Reads Aligned: $(date)" >> timelog.txt
for FILE in ./trimmedFastq/*.SAM; do
samtools view -F 1804 -b -@ 62 $FILE |
samtools sort -@ 62 > "${FILE/.SAM/.bam}" &&
samtools index -@ 62 "${FILE/.SAM/.bam}"
done
wait
for FILE in ./trimmedFastq/*.bam
do
{
mv $FILE ./BAM
} &
done
wait
for FILE in ./trimmedFastq/*.bai
do
{
mv $FILE ./BAM
} &
done
wait
for file in ./BAM/*.bam
do
java -Xmx10g -jar $PICARD MarkDuplicates \
I="${file}" \
O="${file/.bam/_nodups.bam}" \
M="${file/.bam/_dupsMarkedStats.txt}" \
MAX_RECORDS_IN_RAM=2000000 \
REMOVE_DUPLICATES=true
done
wait
echo "Duplicates marked: $(date)" >> timelog.txt
for FILE in ./BAM/*_nodups.bam
do
samtools sort -@ 62 $FILE -O BAM -o "${FILE/_nodups.bam/_sorted_nodups.bam}" &&
samtools index "${FILE/_nodups.bam/_sorted_nodups.bam}"
done
wait
echo "Duplicates removed: $(date)" >> timelog.txt
for FILE in ./BAM/*_sorted_nodups.bam
do
bamCoverage --bam "$FILE" \
--outFileName "${FILE/.bam/.bw}" \
--outFileFormat bigwig \
--binSize 5 \
--numberOfProcessors 62 \
--normalizeUsing RPGC \
--effectiveGenomeSize 2913022398 \
--extendReads \
--blackListFileName /data/Austin/workdir/genome/hg38/blacklist/UCSC_hg38_blacklist.bed
done
wait
echo "BigWigs made: $(date)" >> timelog.txt
mkdir BW
for FILE in ./BAM/*.bw
do
{
mv $FILE ./BW
} &
done
wait
for FILE in ./BAM/*_nodups.bam
do
macs2 callpeak -t "$FILE" \
-n "$FILE" \
-f BAMPE \
-g 2913022398 \
-q 0.05 \
--call-summits \
--nomodel --shift 37 --extsize 73 # ATAC-Seq Shift
done
echo "Peaks called: $(date)" >> timelog.txt
mkdir Peaks
for FILE in ./BAM/*.narrowPeak
do
{
mv $FILE ./Peaks
} &
done
wait
for FILE in ./BAM/*.r
do
{
mv $FILE ./Peaks
} &
done
wait
for FILE in ./BAM/*.bed
do
{
mv $FILE ./Peaks
} &
done
wait
for FILE in ./BAM/*.xls
do
{
mv $FILE ./Peaks
} &
done
wait
multiqc .
echo "Complete! $(date)" >> timelog.txt