Mercurial > repos > lldelisle > revertr2orientationinbam
annotate 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 |
rev | line source |
---|---|
0
05aa21d39189
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/revertR2orientationInBam commit fe9813fe41ba241b47f7b2b4e4c9672ef35c0b35-dirty
lldelisle
parents:
diff
changeset
|
1 #!/bin/bash |
05aa21d39189
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/revertR2orientationInBam commit fe9813fe41ba241b47f7b2b4e4c9672ef35c0b35-dirty
lldelisle
parents:
diff
changeset
|
2 |
05aa21d39189
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/revertR2orientationInBam commit fe9813fe41ba241b47f7b2b4e4c9672ef35c0b35-dirty
lldelisle
parents:
diff
changeset
|
3 inputBam=$1 |
05aa21d39189
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/revertR2orientationInBam commit fe9813fe41ba241b47f7b2b4e4c9672ef35c0b35-dirty
lldelisle
parents:
diff
changeset
|
4 outputBam=$2 |
05aa21d39189
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/revertR2orientationInBam commit fe9813fe41ba241b47f7b2b4e4c9672ef35c0b35-dirty
lldelisle
parents:
diff
changeset
|
5 |
05aa21d39189
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/revertR2orientationInBam commit fe9813fe41ba241b47f7b2b4e4c9672ef35c0b35-dirty
lldelisle
parents:
diff
changeset
|
6 samtools view -h "$inputBam" | awk -v OFS="\t" '{ |
05aa21d39189
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/revertR2orientationInBam commit fe9813fe41ba241b47f7b2b4e4c9672ef35c0b35-dirty
lldelisle
parents:
diff
changeset
|
7 # Process only non header lines |
05aa21d39189
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/revertR2orientationInBam commit fe9813fe41ba241b47f7b2b4e4c9672ef35c0b35-dirty
lldelisle
parents:
diff
changeset
|
8 if(!($1~/^@/)){ |
05aa21d39189
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/revertR2orientationInBam commit fe9813fe41ba241b47f7b2b4e4c9672ef35c0b35-dirty
lldelisle
parents:
diff
changeset
|
9 # SAM flag is field 2 |
05aa21d39189
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/revertR2orientationInBam commit fe9813fe41ba241b47f7b2b4e4c9672ef35c0b35-dirty
lldelisle
parents:
diff
changeset
|
10 n=$2 |
05aa21d39189
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/revertR2orientationInBam commit fe9813fe41ba241b47f7b2b4e4c9672ef35c0b35-dirty
lldelisle
parents:
diff
changeset
|
11 # Change only the second in pair flag is 128 |
05aa21d39189
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/revertR2orientationInBam commit fe9813fe41ba241b47f7b2b4e4c9672ef35c0b35-dirty
lldelisle
parents:
diff
changeset
|
12 d=128 |
05aa21d39189
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/revertR2orientationInBam commit fe9813fe41ba241b47f7b2b4e4c9672ef35c0b35-dirty
lldelisle
parents:
diff
changeset
|
13 q=(n-n%d)/d+(n<0) |
05aa21d39189
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/revertR2orientationInBam commit fe9813fe41ba241b47f7b2b4e4c9672ef35c0b35-dirty
lldelisle
parents:
diff
changeset
|
14 if(q%2==1){ |
05aa21d39189
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/revertR2orientationInBam commit fe9813fe41ba241b47f7b2b4e4c9672ef35c0b35-dirty
lldelisle
parents:
diff
changeset
|
15 # Evaluate the strand reverse strand flag is 16 |
05aa21d39189
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/revertR2orientationInBam commit fe9813fe41ba241b47f7b2b4e4c9672ef35c0b35-dirty
lldelisle
parents:
diff
changeset
|
16 d=16 |
05aa21d39189
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/revertR2orientationInBam commit fe9813fe41ba241b47f7b2b4e4c9672ef35c0b35-dirty
lldelisle
parents:
diff
changeset
|
17 q=(n-n%d)/d+(n<0) |
05aa21d39189
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/revertR2orientationInBam commit fe9813fe41ba241b47f7b2b4e4c9672ef35c0b35-dirty
lldelisle
parents:
diff
changeset
|
18 if(q%2==1){ |
05aa21d39189
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/revertR2orientationInBam commit fe9813fe41ba241b47f7b2b4e4c9672ef35c0b35-dirty
lldelisle
parents:
diff
changeset
|
19 # It is reverse it is now forward |
05aa21d39189
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/revertR2orientationInBam commit fe9813fe41ba241b47f7b2b4e4c9672ef35c0b35-dirty
lldelisle
parents:
diff
changeset
|
20 $2-=16 |
05aa21d39189
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/revertR2orientationInBam commit fe9813fe41ba241b47f7b2b4e4c9672ef35c0b35-dirty
lldelisle
parents:
diff
changeset
|
21 }else{ |
05aa21d39189
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/revertR2orientationInBam commit fe9813fe41ba241b47f7b2b4e4c9672ef35c0b35-dirty
lldelisle
parents:
diff
changeset
|
22 # It is forward it is now reverse |
05aa21d39189
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/revertR2orientationInBam commit fe9813fe41ba241b47f7b2b4e4c9672ef35c0b35-dirty
lldelisle
parents:
diff
changeset
|
23 $2+=16 |
05aa21d39189
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/revertR2orientationInBam commit fe9813fe41ba241b47f7b2b4e4c9672ef35c0b35-dirty
lldelisle
parents:
diff
changeset
|
24 } |
05aa21d39189
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/revertR2orientationInBam commit fe9813fe41ba241b47f7b2b4e4c9672ef35c0b35-dirty
lldelisle
parents:
diff
changeset
|
25 } |
05aa21d39189
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/revertR2orientationInBam commit fe9813fe41ba241b47f7b2b4e4c9672ef35c0b35-dirty
lldelisle
parents:
diff
changeset
|
26 } |
05aa21d39189
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/revertR2orientationInBam commit fe9813fe41ba241b47f7b2b4e4c9672ef35c0b35-dirty
lldelisle
parents:
diff
changeset
|
27 print |
05aa21d39189
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/revertR2orientationInBam commit fe9813fe41ba241b47f7b2b4e4c9672ef35c0b35-dirty
lldelisle
parents:
diff
changeset
|
28 }' | samtools view -b - > "$outputBam" |