3 # https://gist.github.com/Shians/a95c49bda68481fb0adc83600d9eb6b8
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
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)