-
Notifications
You must be signed in to change notification settings - Fork 0
/
bam2fastq_Reza.sh
55 lines (40 loc) · 1.3 KB
/
bam2fastq_Reza.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
#!/bin/bash -eu
#$ -cwd -V
#$ -pe smp 1
#$ -l h_rt=24:00:00
#$ -l h_vmem=6G
#$ -R y
#$ -q all.q,bigmem.q
# 2017
# Converts aligned BAM to gziped FASTQ using BAM file passed in at command-line.
# Uses SAMtools to randomly order reads in aligned BAM file, to avoid mapping
# bias as discussed here:
# http://gatkforums.broadinstitute.org/discussion/2908/howto-revert-a-bam-file-to-fastq-format
set -o pipefail
hostname
date
#source ../GATKsettings.sh
## Base dir - should auto set to where this script resides
BASE_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
TMPDIR=$BASE_DIR
SAMTOOLS="/opt/software/bsu/bin/samtools"
BAM=$1
B_NAME=$(basename $BAM)
echo "** Variables **"
echo " - BASE_DIR = $BASE_DIR"
echo " - PWD = $PWD"
echo " - BAM = $BAM"
echo " - B_NAME = $B_NAME"
#read -p "before copy process"
#echo "Copying input $BAM to $TMPDIR/"
#/usr/bin/time --verbose cp -v $BAM $TMPDIR
echo "Running SAMtools on $TMPDIR/$B_NAME saving output as a gziped FASTQ file"
/usr/bin/time --verbose $SAMTOOLS bamshuf -uOn 128 $TMPDIR/$B_NAME $TMPDIR/tmp | $SAMTOOLS bam2fq - | gzip > $TMPDIR/$B_NAME.fastq.gz
echo "Copying $TMPDIR/*.fastq.gz to $PWD"
/usr/bin/time --verbose cp -v $TMPDIR/*.fastq.gz $PWD
echo "Deleting $TMPDIR/*.bam"
rm $TMPDIR/*.bam
echo "Deleting $TMPDIR/*.gz"
rm $TMPDIR/*.gz
date
echo "END"