Mercurial > repos > ldelisle > revertr2orientationinbam
diff revertR2orientationInBam.sh @ 1:2c86ad672f52 draft default tip
planemo upload commit 89aa8abdc88aa922cab8d9c5f17078ba1e388339-dirty
author | ldelisle |
---|---|
date | Wed, 19 Oct 2022 08:34:43 +0000 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/revertR2orientationInBam.sh Wed Oct 19 08:34:43 2022 +0000 @@ -0,0 +1,28 @@ +#!/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" \ No newline at end of file