-
Notifications
You must be signed in to change notification settings - Fork 2
/
CIGAR.pm
94 lines (60 loc) · 1.98 KB
/
CIGAR.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package CIGAR;
use strict;
use warnings;
use Nuc_translator;
####
sub construct_cigar {
my ($genome_coords_aref, $query_coords_aref, $read_length, # required
$genome_seq_sref, $strand # optional
) = @_;
my $cigar = "";
for (my $i = 0; $i <= $#$genome_coords_aref; $i++) {
my ($curr_genome_lend, $curr_genome_rend) = @{$genome_coords_aref->[$i]};
my ($curr_query_lend, $curr_query_rend) = @{$query_coords_aref->[$i]};
if ($i == 0) {
if ($curr_query_lend > 1) {
$cigar .= ($curr_query_lend - 1) . "S";
}
}
else {
my ($prev_genome_lend, $prev_genome_rend) = @{$genome_coords_aref->[$i-1]};
my ($prev_query_lend, $prev_query_rend) = @{$query_coords_aref->[$i-1]};
if ( (my $delta_genome = $curr_genome_lend - $prev_genome_rend) > 1) {
my $deletion_intron_char = ($genome_seq_sref && $strand) ? &_check_intron_consensus($prev_genome_rend, $curr_genome_lend, $genome_seq_sref, $strand) : 'D'; # intron or deletion?
$cigar .= ($delta_genome-1) . $deletion_intron_char;
}
if ( (my $delta_query = $curr_query_lend - $prev_query_rend) > 1) {
$cigar .= ($delta_query-1) . "I";
}
}
my $len = $curr_genome_rend - $curr_genome_lend + 1;
$cigar .= "$len" . "M";
if ($i == $#$genome_coords_aref) {
if ($curr_query_rend < $read_length) {
$cigar .= ($read_length - $curr_query_rend) . "S";
}
}
}
return($cigar);
}
####
sub _check_intron_consensus {
my ($left_segment_bound, $right_segment_bound, $genome_sref, $strand) = @_;
my $left_dinuc = uc substr($$genome_sref, $left_segment_bound, 2);
my $right_dinuc = uc substr($$genome_sref, $right_segment_bound-3, 2);
if ($strand eq '-') {
$left_dinuc = &reverse_complement($right_dinuc);
$right_dinuc = &reverse_complement($left_dinuc);
}
if (
( ($left_dinuc eq "GT" || $left_dinuc eq "GC") && $right_dinuc eq "AG")
||
($left_dinuc eq "CT" && $right_dinuc eq "AC")
) {
return("N"); # got splice pair
}
else {
return("D"); # deletion
}
}
1; #EOM