15
die("Usage: bowtie2sam.pl <aln.bowtie>\n") if (@ARGV == 0 && -t STDIN);
17
my (@s, $last, @staging, $k, $best_s, $subbest_s, $best_k);
20
my ($name, $nm) = &bowtie2sam_aux($_, \@s); # read_name, number of mismatches
22
# I do not know whether the multiple hits are ordered on the
23
# number of mismatches. I assume they are not and so I have to
24
# keep all these multiple hits in memory.
30
} elsif ($subbest_s > $nm) {
36
if ($best_s == $subbest_s) {
37
$staging[$best_k][4] = 0;
38
} elsif ($subbest_s - $best_s == 1) {
39
$staging[$best_k][4] = 15 if ($staging[$best_k][4] > 15);
41
print join("\t", @{$staging[$best_k]}), "\n";
43
$k = 1; $best_s = $nm; $subbest_s = 1000; $best_k = 0;
48
print join("\t", @{$staging[$best_k]}), "\n" if ($best_k >= 0);
54
my @t = split("\t", $line);
58
$s->[0] = $ret = $t[0];
59
$s->[0] =~ s/\/[12]$//g;
60
# initial flag (will be updated later)
63
$s->[9] = $t[4]; $s->[10] = $t[5];
65
$s->[5] = length($s->[9]) . "M";
67
$s->[2] = $t[2]; $s->[3] = $t[3] + 1;
68
$s->[1] |= 0x10 if ($t[1] eq '-');
70
$s->[4] = $t[6] == 0? 25 : 0;
72
$s->[6] = '*'; $s->[7] = $s->[8] = 0;
75
push(@$s, "NM:i:" . (@t-7));
76
push(@$s, "X$nm:i:" . ($t[6]+1));
81
while (/(\d+):[ACGTN]>([ACGTN])/gi) {
82
my ($y, $z) = ($1, $2);
83
$md .= (int($y)-$a) . $z;
86
$md .= length($s->[9]) - $a;
88
$md = length($s->[9]);
90
push(@$s, "MD:Z:$md");