# HG changeset patch
# User ldelisle
# Date 1666168483 0
# Node ID 2c86ad672f524f844359d1735c36c9d2faa92092
# Parent 07695b197e6c54a2ec5e82cb491d81e5e94d5e6d
planemo upload commit 89aa8abdc88aa922cab8d9c5f17078ba1e388339-dirty
diff -r 07695b197e6c -r 2c86ad672f52 revertR2orientationInBam.sh
--- /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
diff -r 07695b197e6c -r 2c86ad672f52 revertR2orientationInBam.xml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/revertR2orientationInBam.xml Wed Oct 19 08:34:43 2022 +0000
@@ -0,0 +1,40 @@
+
+ Revert the mapped orientation of R2 mates in a bam.
+
+ samtools
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff -r 07695b197e6c -r 2c86ad672f52 revertR2orientationInBam/.shed.yml
--- a/revertR2orientationInBam/.shed.yml Wed Oct 19 08:30:26 2022 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,6 +0,0 @@
-categories:
- - SAM
-description: Revert the mapped orientation of R2 mates in a bam.
-name: revertr2orientationinbam
-owner: lldelisle
-long_description: This tool is very useful when you have paired-end stranded RNA-seq. Using this tool prior to a bedtools genome coverage allow to have strand specific coverage using both mates. It uses samtools to convert input to sam format and then awk to modify the flag "reverse strand" for the second mate of pairs.
diff -r 07695b197e6c -r 2c86ad672f52 revertR2orientationInBam/revertR2orientationInBam.sh
--- a/revertR2orientationInBam/revertR2orientationInBam.sh Wed Oct 19 08:30:26 2022 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,28 +0,0 @@
-#!/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
diff -r 07695b197e6c -r 2c86ad672f52 revertR2orientationInBam/revertR2orientationInBam.xml
--- a/revertR2orientationInBam/revertR2orientationInBam.xml Wed Oct 19 08:30:26 2022 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,40 +0,0 @@
-
- Revert the mapped orientation of R2 mates in a bam.
-
- samtools
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff -r 07695b197e6c -r 2c86ad672f52 revertR2orientationInBam/test-data/input.sam
--- a/revertR2orientationInBam/test-data/input.sam Wed Oct 19 08:30:26 2022 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,7 +0,0 @@
-@HD VN:1.4 SO:coordinate
-@SQ SN:chr1 LN:195471971
-1 163 chr1 3151308 255 43M = 3151560 295 GTCCCAAAAAGCAGAGAGAAATATCTCTCTGGGCCTTATAGCA AAAAAEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE NH:i:1 HI:i:1 AS:i:82 nM:i:1
-1 83 chr1 3151560 255 43M = 3151308 -295 CTGCTGGAAAAACTGTTCGTTTTAGGAAATAAGGGCGAGTGCG EEEEEEAEEEEEEEEEAEEEEEEEEEEEEEEEEEEEEEAAAAA NH:i:1 HI:i:1 AS:i:82 nM:i:1
-2 137 chr1 3155261 255 9S20M * 0 0 TGTGGGTTTTACACACGGGAGGAATCGGG AAAAA/EEE/EE6EAEE6EAE6/EEEAEE NH:i:1 HI:i:1 AS:i:19 nM:i:0
-3 99 chr1 3195817 255 43M = 3195911 137 ATCTTACTCTGTTTCACAGATAGGTGCTGAGGTTAAATTTTGC AAAAAEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE NH:i:1 HI:i:1 AS:i:84 nM:i:0
-3 147 chr1 3195911 255 43M = 3195817 -137 GGTGTAGGTTCTTAGACGCAAGAAATCTCAGGTAGAGTTTGGC EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEAAAAA NH:i:1 HI:i:1 AS:i:84 nM:i:0
diff -r 07695b197e6c -r 2c86ad672f52 revertR2orientationInBam/test-data/output.bam
Binary file revertR2orientationInBam/test-data/output.bam has changed
diff -r 07695b197e6c -r 2c86ad672f52 test-data/input.sam
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/input.sam Wed Oct 19 08:34:43 2022 +0000
@@ -0,0 +1,7 @@
+@HD VN:1.4 SO:coordinate
+@SQ SN:chr1 LN:195471971
+1 163 chr1 3151308 255 43M = 3151560 295 GTCCCAAAAAGCAGAGAGAAATATCTCTCTGGGCCTTATAGCA AAAAAEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE NH:i:1 HI:i:1 AS:i:82 nM:i:1
+1 83 chr1 3151560 255 43M = 3151308 -295 CTGCTGGAAAAACTGTTCGTTTTAGGAAATAAGGGCGAGTGCG EEEEEEAEEEEEEEEEAEEEEEEEEEEEEEEEEEEEEEAAAAA NH:i:1 HI:i:1 AS:i:82 nM:i:1
+2 137 chr1 3155261 255 9S20M * 0 0 TGTGGGTTTTACACACGGGAGGAATCGGG AAAAA/EEE/EE6EAEE6EAE6/EEEAEE NH:i:1 HI:i:1 AS:i:19 nM:i:0
+3 99 chr1 3195817 255 43M = 3195911 137 ATCTTACTCTGTTTCACAGATAGGTGCTGAGGTTAAATTTTGC AAAAAEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE NH:i:1 HI:i:1 AS:i:84 nM:i:0
+3 147 chr1 3195911 255 43M = 3195817 -137 GGTGTAGGTTCTTAGACGCAAGAAATCTCAGGTAGAGTTTGGC EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEAAAAA NH:i:1 HI:i:1 AS:i:84 nM:i:0
diff -r 07695b197e6c -r 2c86ad672f52 test-data/output.bam
Binary file test-data/output.bam has changed