From 7368a1da206660a5c65da344c83f45b383e0ace3 Mon Sep 17 00:00:00 2001 From: Yuuki Galaxy Date: Fri, 11 Oct 2024 09:45:49 +0800 Subject: [PATCH] new file: extract_bam_tag.sh --- etc/salus/extract_bam_tag.sh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100755 etc/salus/extract_bam_tag.sh diff --git a/etc/salus/extract_bam_tag.sh b/etc/salus/extract_bam_tag.sh new file mode 100755 index 000000000..a9ae33be1 --- /dev/null +++ b/etc/salus/extract_bam_tag.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash + +# https://gist.github.com/Shians/a95c49bda68481fb0adc83600d9eb6b8 +# called by +# sh extract_bam_tag.sh input.bam BC +# to print read_id and BC tag value + +# two arguments, a bam file and the tag to extract +BAM=$1 +TAG=$2 + +# write a tsv with columns read_id and tag value +echo -e "read_id\t$TAG" +samtools view "$BAM" | grep "$TAG:." | perl -pe 's/(^.+?)\t.*'$TAG':.:(.+?)\t.*/$1\t$2/g' +# regular expression substutes pattern (read_id)*(tag_value)* for (read_id)\t(tag_value) -- 2.11.4.GIT