Last active
October 11, 2024 01:38
-
-
Save Shians/a95c49bda68481fb0adc83600d9eb6b8 to your computer and use it in GitHub Desktop.
Extract BAM tag as tsv
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# 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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment