-
Notifications
You must be signed in to change notification settings - Fork 2
/
ChimericCigarParser.pm
executable file
·70 lines (46 loc) · 1.66 KB
/
ChimericCigarParser.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package ChimericCigarParser;
use strict;
use warnings;
use Carp;
require Exporter;
our @ISA = qw(Exporter);
our @EXPORT = qw(get_genome_coords_via_cigar);
####
sub get_genome_coords_via_cigar {
my ($rst, $cigar) = @_;
## borrowing this code from my SAM_entry.pm
my $genome_lend = $rst;
my $alignment = $cigar;
my $query_lend = 0;
my @genome_coords;
my @query_coords;
$genome_lend--; # move pointer just before first position.
while ($alignment =~ /(\d+)([A-Zp])/g) {
my $len = $1;
my $code = $2;
unless ($code =~ /^[MSDNIHp]$/) {
confess "Error, cannot parse cigar code [$code] ";
}
# print "parsed $len,$code\n";
if ($code eq 'M') { # aligned bases match or mismatch
my $genome_rend = $genome_lend + $len;
my $query_rend = $query_lend + $len;
push (@genome_coords, [$genome_lend+1, $genome_rend]);
push (@query_coords, [$query_lend+1, $query_rend]);
# reset coord pointers
$genome_lend = $genome_rend;
$query_lend = $query_rend;
}
elsif ($code eq 'D' || $code eq 'N' || $code eq 'p') { # insertion in the genome or gap in query (intron, perhaps)
$genome_lend += $len;
}
elsif ($code eq 'I' # gap in genome or insertion in query
||
$code eq 'S' || $code eq 'H') # masked region of query
{
$query_lend += $len;
}
}
return(\@genome_coords, \@query_coords);
}
1; #EOM