Mercurial > repos > lldelisle > revertr2orientationinbam
view revertR2orientationInBam.sh @ 1:21ddefab2e4f draft default tip
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/revertR2orientationInBam commit 49a42d0e75d6ae7faa3ce399524157c35546fbaa
author | lldelisle |
---|---|
date | Thu, 20 Oct 2022 10:51:18 +0000 |
parents | 05aa21d39189 |
children |
line wrap: on
line source
#!/bin/bash inputBam=$1 outputBam=$2 samtools view -h "$inputBam" | awk -v OFS="\t" '{ # Process only non header lines if(!($1~/^@/)){ # SAM flag is field 2 n=$2 # Change only the second in pair flag is 128 d=128 q=(n-n%d)/d+(n<0) if(q%2==1){ # Evaluate the strand reverse strand flag is 16 d=16 q=(n-n%d)/d+(n<0) if(q%2==1){ # It is reverse it is now forward $2-=16 }else{ # It is forward it is now reverse $2+=16 } } } print }' | samtools view -b - > "$outputBam"