-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbam2intron
49 lines (33 loc) · 1 KB
/
bam2intron
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
#!/bin/bash
# specify input data in order and output settings
bam=$1
intronbed=$2
output=$3
purename=$4
MAPQ=$5
threads=$6
mem=$7
# prepare out directory
if [ ! -d $output ];then
mkdir -p $output
fi
#filename=$(echo ${bam} | awk 'BEGIN {FS="/"} {print $NF}')
#purename=$(echo ${filename} | awk 'BEGIN {FS=".bam"} {print $1}')
prefix="$output"/"$purename"
umapbam="${prefix}""_umap.bam"
bambed="${prefix}""_bambed.bed"
overlap="${prefix}""_overlap_initial.bed"
# index bam file
bai="$bam".bai
if [ ! -e "$bai" ]; then
echo "BAM index does not exist. Create using Samtools."
samtools index $bam
fi
# pre-filter bam using intron bed files
samtools view -b -q $MAPQ -@ $threads -L $intronbed $bam > $umapbam
# covert to bed format
#echo '---> Converting bam to bed file'
bam2bed —input bam -r tmp -m $mem < "${umapbam}" |bedscore > $bambed
# get intron-spanning reads
bedmap --bp-ovr 1 --skip-unmapped --echo --sum --echo-overlap-size --echo-map-id-uniq $intronbed $bambed > $overlap
rm "${umapbam}"