Skip to content
Permalink
1c6208126c
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
43 lines (39 sloc) 1.32 KB
#!/bin/bash
REGION="$1"
WORKDIR="$2"
for f in "$WORKDIR"/*.bam;
do
if [ -f "$f.bai" ]
then
#echo "File: $f"
with_sa="$(samtools view "$f" "$REGION" -@8 | awk '$21 ~ /chr[0-9MSID,+]*;/ {print $1, $6, $21}')"
while read -r read_data
do
SAs="$(echo "$read_data" | grep -o 'chr[0-9MSID,+]*;')"
[[ -z "$SAs" ]] && continue
#echo "Read: $(echo "$read_data" | cut -d' ' -f1)"
while read -r sa
do
start_pos="$(echo "$sa" | cut -d, -f2)"
chrom="$(echo "$sa" | cut -d, -f1)"
cigar="$(echo "$sa" | cut -d, -f4)"
quality="$(echo "$sa" | cut -d, -f5)"
echo "$cigar" | grep -Eo '[0-9]+[MSID]' | while read -r cig
do
len="${cig::-1}"
case "${cig:(-1)}" in
M)
echo "Matches at $chrom:$start_pos-$((start_pos+len)) (length:$len, quality:$quality)"
break
;;
S)
((start_pos+=len))
;;
I)
;;
esac
done
done <<< "$SAs"
done <<< "$with_sa"
fi
done