modified: myjupyterlab.sh
[GalaxyCodeBases.git] / etc / salus / extract_bam_tag.sh
bloba9ae33be17852608e61f72a662e8d582320de4e9
1 #!/usr/bin/env bash
3 # https://gist.github.com/Shians/a95c49bda68481fb0adc83600d9eb6b8
4 # called by
5 # sh extract_bam_tag.sh input.bam BC
6 # to print read_id and BC tag value
8 # two arguments, a bam file and the tag to extract
9 BAM=$1
10 TAG=$2
12 # write a tsv with columns read_id and tag value
13 echo -e "read_id\t$TAG"
14 samtools view "$BAM" | grep "$TAG:." | perl -pe 's/(^.+?)\t.*'$TAG':.:(.+?)\t.*/$1\t$2/g'
15 # regular expression substutes pattern (read_id)*(tag_value)* for (read_id)\t(tag_value)