-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmrkdup.sh
151 lines (116 loc) · 2.93 KB
/
mrkdup.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
#!/bin/bash
#$ -cwd
#$ -S /bin/bash
#$ -N align
#$ -e align0err
#$ -o align0out
#$ -q !gbs
# #$ -l mem_free=10G
#$ -V
# #$ -h
#$ -t 1-16:1
# $ -t 1-1:1
# $ -t 13-14:1
i=$(expr $SGE_TASK_ID - 1)
# http://bio-bwa.sourceforge.net/bwa.shtml
BWA="~/bin/bwa-0.7.10/bwa"
# http://www.htslib.org/doc/
SAMT="~/bin/samtools-1.1/samtools"
PATH=~/bin/samtools-1.1:$PATH
echo $PATH
echo
REF="/home/bpp/knausb/Grunwald_Lab/home/knausb/pinf_bwa/bwaref/pinf_super_contigs.fa"
# The file samples.txt contains info about sample names and files.
# Each line is one sample and one job.
# The line is a semi colon delimited list.
# The first element is the sample name.
# The second element is the fastq file including any path info.
#
# t30-4;../fastqs/ATCGGC.fastq.gz
#
FILE=( `cat "samples.txt" `)
IFS=';' read -a arr <<< "${FILE[$i]}"
echo "${arr[1]}"
echo -n "Running on: "
hostname
echo "SGE job id: $JOB_ID"
date
# http://bio-bwa.sourceforge.net/bwa.shtml
# Align reads with bwa.
# Report version info.
CMD="$BWA 2>&1"
echo
echo $CMD
eval $CMD
echo
# The GATK needs read group info:
# https://software.broadinstitute.org/gatk/guide/article?id=6472
RG="@RG\tID:${arr[0]}\tLB:${arr[0]}\tPL:illumina\tSM:${arr[0]}\tPU:${arr[0]}"
CMD="$BWA mem -M -R \"$RG\" $REF ${arr[1]} ${arr[2]} > sams/${arr[0]}.sam"
echo
#
echo $CMD
#
eval $CMD
echo
date
# http://www.htslib.org/doc/
# Echo samtools version info.
CMD="$SAMT --version"
echo
eval $CMD
echo
# view
# -b output BAM
# -S ignored (input format is auto-detected)
# -u uncompressed BAM output (implies -b)
# sort
# -n Sort by read name
# -o FILE output file name [stdout]
# -O FORMAT Write output as FORMAT ('sam'/'bam'/'cram') (either -O or
# -T PREFIX Write temporary files to PREFIX.nnnn.bam -T is required)
# fillmd
# -u uncompressed BAM output (for piping)
# Fix mate information and add the MD tag.
CMD="$SAMT view -bSu sams/${arr[0]}.sam | $SAMT sort -n -O bam -o bams/${arr[0]}_nsort -T bams/${arr[0]}_nsort_tmp"
#
echo $CMD
#
eval $CMD
# CMD="$SAMT fixmate -O bam bams/${arr[0]}_nsort /dev/stdout | $SAMT sort -O bam -o - -T bams/${arr[0]}_csort_tmp | $SAMT fillmd -u - $REF > bams/${arr[0]}_fixed.bam"
CMD="$SAMT fixmate -O bam bams/${arr[0]}_nsort /dev/stdout | $SAMT sort -O bam -o - -T bams/${arr[0]}_csort_tmp | $SAMT fillmd -u - $REF | $SAMT view -b > bams/${arr[0]}_fixed.bam"
#
echo $CMD
#
eval $CMD
echo
echo "Samtools done"
echo
date
# Mark duplicates.
JAVA="/home/bpp/knausb/bin/javadir/jre1.8.0_25/bin/java"
PIC="~/bin/picard/picard-tools-2.5.0/picard.jar"
CMD="$JAVA -version"
echo $CMD
eval $CMD
echo
CMD="$JAVA -jar $PIC MarkDuplicates --version"
echo $CMD
eval $CMD
echo
CMD="$JAVA -Djava.io.tmpdir=/data/ \
-jar $PIC MarkDuplicates \
I=bams/${arr[0]}.bam \
O=bams/${arr[0]}_dupmrk.bam \
M=bams/${arr[0]}_marked_dup_metrics.txt"
date
echo
echo $CMD
eval $CMD
date
# Index
CMD="$SAMT index bams/${arr[0]}_dupmrk.bam"
echo $CMD
eval $CMD
date
# EOF.