-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathrun_coverages.sh
69 lines (45 loc) · 1.85 KB
/
run_coverages.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
#!/bin/bash
# create coverages of all chrY bases in the alignments
# http://bedtools.readthedocs.io/en/latest/content/tools/genomecov.html
# ~~~~~ SETUP ~~~~~ #
hg19_chrY="/local/data/iGenomes/Homo_sapiens/UCSC/hg19/Sequence/Chromosomes/chrY.fa"
qsub_logdir="${PWD}/logs"
mkdir -p "$qsub_logdir"
output_dir="${PWD}/output"
mkdir -p "$output_dir"
# ~~~~~ FUNCTIONS ~~~~~ #
run_cov () {
# run bedtools genomecov on a sample
local sampleID="$1"
local job_name="job_${sampleID}"
local bamfile="$2"
# the same as above but without 0 regions
local output_good_bedgraph="${output_dir}/${sampleID}.chrY.bedgraph"
# coverage for all contiguously covered regions
local output_bedgraph="${output_dir}/${sampleID}.chrY.all.bedgraph"
# all covereage values for every base
local output_cov="${output_dir}/${sampleID}.chrY.cov.txt"
qsub -wd $PWD -o :${qsub_logdir}/ -e :${qsub_logdir}/ -j y -N "${job_name}.chrY.bedgraph" <<E0F
module load bedtools/2.26.0
set -x
bedtools genomecov -ibam "$bamfile" -g "$hg19_chrY" -bg | grep -w 'chrY' > "$output_good_bedgraph"
E0F
qsub -wd $PWD -o :${qsub_logdir}/ -e :${qsub_logdir}/ -j y -N "${job_name}.chrY.all.bedgraph" <<E0F
module load bedtools/2.26.0
set -x
bedtools genomecov -ibam "$bamfile" -g "$hg19_chrY" -bga | grep -w 'chrY' > "$output_bedgraph"
E0F
qsub -wd $PWD -o :${qsub_logdir}/ -e :${qsub_logdir}/ -j y -N "${job_name}.chrY.cov.txt" <<E0F
module load bedtools/2.26.0
set -x
bedtools genomecov -ibam "$bamfile" -g "$hg19_chrY" -d | grep -w 'chrY' > "$output_cov"
E0F
}
# ~~~~~ RUN ~~~~~ #
# find all the alignment files in the output directory
find "$(readlink -f BAM-BWA)" -name "*.bam" | while read file; do
sampleID="$(basename "$file")"
sampleID="${sampleID%%.bam}"
printf "%s %s\n\n" "$sampleID" "$file"
run_cov "$sampleID" "$file"
done