comparison revertR2orientationInBam.sh @ 0:05aa21d39189 draft

planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/revertR2orientationInBam commit fe9813fe41ba241b47f7b2b4e4c9672ef35c0b35-dirty
author lldelisle
date Wed, 19 Oct 2022 08:50:18 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:05aa21d39189
1 #!/bin/bash
2
3 inputBam=$1
4 outputBam=$2
5
6 samtools view -h "$inputBam" | awk -v OFS="\t" '{
7 # Process only non header lines
8 if(!($1~/^@/)){
9 # SAM flag is field 2
10 n=$2
11 # Change only the second in pair flag is 128
12 d=128
13 q=(n-n%d)/d+(n<0)
14 if(q%2==1){
15 # Evaluate the strand reverse strand flag is 16
16 d=16
17 q=(n-n%d)/d+(n<0)
18 if(q%2==1){
19 # It is reverse it is now forward
20 $2-=16
21 }else{
22 # It is forward it is now reverse
23 $2+=16
24 }
25 }
26 }
27 print
28 }' | samtools view -b - > "$outputBam"