From 3536e2113ceef0c4cd5e7b11e89f76dc7043190c Mon Sep 17 00:00:00 2001 From: Tobias Marschall Date: Wed, 7 Sep 2011 14:31:28 +0200 Subject: [PATCH] Bugfix: reverse (complement) sequence and phred string if alternative alignment has different orientation than primary alignment --- xa2multi.pl | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/xa2multi.pl b/xa2multi.pl index 6dae38b..2409c29 100755 --- a/xa2multi.pl +++ b/xa2multi.pl @@ -10,7 +10,16 @@ while (<>) { my @t = split("\t"); while ($l =~ /([^,;]+),([-+]\d+),([^,]+),(\d+);/g) { my $mchr = ($t[6] eq $1)? '=' : $t[6]; # FIXME: TLEN/ISIZE is not calculated! - print(join("\t", $t[0], 0x100|($t[1]&0x6e9)|($2<0?0x10:0), $1, abs($2), 0, $3, @t[6..7], 0, @t[9..10], "NM:i:$4"), "\n"); + my $seq = $t[9]; + my $phred = $t[10]; + # if alternative alignment has other orientation than primary, + # then print the reverse (complement) of sequence and phred string + if ((($t[1]&0x10)>0) xor ($2<0)) { + $seq = reverse $seq; + $seq =~ tr/ACGTacgt/TGCAtgca/; + $phred = reverse $phred; + } + print(join("\t", $t[0], 0x100|($t[1]&0x6e9)|($2<0?0x10:0), $1, abs($2), 0, $3, @t[6..7], 0, $seq, $phred, "NM:i:$4"), "\n"); } } else { print; } }