GenOO/Data/File/SAM/CigarAndMDZ.pm

filter: Statementstmt 100% 67 / 67 Branchbran 100% 20 / 20 Conditioncond 75.0% 18 / 24 MC/DCmcdc 50.0% 6 / 12 Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 2 totaltotal 89.2% 116 / 130 CC 25 SCAR 23.4
CC
25
Cov
95%
mismatch_positions_on_query_calculated_from_mdz
12.0
mismatch_nt_on_query
12.0
_how_many_are_smaller
3.0
CRAP 10.3
« GenOO/Helper/MyMath.pm ↑ Summary GenOO/Module/Search/Binary.pm »
1 # POD documentation - main docs before the code
2  
3 =head1 NAME
4  
5 GenOO::Data::File::SAM::CigarAndMDZ - Role that combines SAM CIGAR string with MD:Z tag
6  
7 =head1 SYNOPSIS
8  
9 This role when consumed requires specific attributes and provides
10 methods to extract information from the CIGAR string in combination
11 with the MD:Z tag.
12  
13 =head1 DESCRIPTION
14  
15 The cigar string does not usually contain information regarding the deletions.
16 For this the MD:Z tag is usually provided. Combining the CIGAR information with
17 the MD:Z tag we can extract information such as for example the deletion positions
18 on the query sequence.
19  
20 =head1 EXAMPLES
21  
22 # Get the location information on the reference sequence
23 $obj_with_role->mismatch_positions_on_query_calculated_from_mdz; # (10, 19)
24  
25 =cut
26  
27 # Let the code begin...
28  
29 package GenOO::Data::File::SAM::CigarAndMDZ;
30 1 $GenOO::Data::File::SAM::CigarAndMDZ::VERSION = '1.4.9';
31  
32 #######################################################################
33 ####################### Load External modules #####################
34 #######################################################################
35 1 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
37  
38  
39 #######################################################################
40 ######################## Required attributes ######################
41 #######################################################################
42 1 requires qw(query_length);
43  
44  
45 #######################################################################
46 ########################## Consumed Roles #########################
47 #######################################################################
48 1 with 'GenOO::Data::File::SAM::Cigar', 'GenOO::Data::File::SAM::MDZ';
49  
50  
51 #######################################################################
52 ######################## Interface Methods ########################
53 #######################################################################
54 sub mismatch_positions_on_query_calculated_from_mdz {
55 6 ▶ my ($self) = @_;
Subroutine mismatch_positions_on_query_calculated_from_mdz: called CC=12 SCAR=24.9
Pod undocumented
56 #Tag: AGTGATGGGA------GGATGTCTCGTCTGTGAGTTACAGCA -> CIGAR: 2M1I7M6D26M
57 # - -
58 #Genome: AG-GCTGGTAGCTCAGGGATGTCTCGTCTGTGAGTTACAGCA -> MD:Z: 3C3T1^GCTCAG26
59
60 6 my $cigar = $self->cigar;
61
62 # Find positions of insertions and deletions (dashes) on the query sequence
63 6 my @deletion_positions;
64 my @insertion_positions;
65 6 my $position = 0;
66 6 ▶ while ($cigar =~ /(\d+)([MIDNSHP=X])/g) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cigar =~ /(\d+)([MIDNSHP=X])/g) 28 6 34
67 28 my $count = $1;
68 28 my $identifier = $2;
69
70 28 ▶ if ($identifier eq 'D' or $identifier eq 'N' or $identifier eq 'P' or $identifier eq 'H') {
Branch: 2 branches
BranchTrueFalseTotal
if ($identifier eq 'D' or $identifier eq 'N' or $identifier eq 'P' or $identifier eq 'H') { } 6 22 28
elsif ($identifier eq 'I' or $identifier eq 'S') { } 5 17 22
Condition77%7/9
$identifier eq "D" or $identifier eq "N" or $identifier eq "P" or $identifier eq "H"
l!l&&r!l&&!r
6022
$identifier eq "D" or $identifier eq "N" or $identifier eq "P"
l!l&&r!l&&!r
6022
$identifier eq "D" or $identifier eq "N"
l!l&&r!l&&!r
5122
MC/DC50%2/4
$identifier eq "D" or $identifier eq "N" or $identifier eq "P" or $identifier eq "H"
$identifier eq "D" $identifier eq "N" $identifier eq "P" $identifier eq "H"
Truth table60%3/5
A or B or C or D
A= $identifier eq "D"B= $identifier eq "N"C= $identifier eq "P"D= $identifier eq "H"
ABCDresult
1XXX1
01XX1
001X1
00011
00000
71 6 push (@deletion_positions, $position + $_) for (0..$count-1)
72 }
73 ▶ elsif ($identifier eq 'I' or $identifier eq 'S') {
Condition66%2/3
$identifier eq "I" or $identifier eq "S"
l!l&&r!l&&!r
5017
MC/DC50%1/2
$identifier eq "I" or $identifier eq "S"
$identifier eq "I" $identifier eq "S"
Truth table66%2/3
A or B
A= $identifier eq "I"B= $identifier eq "S"
ABresult
1X1
011
000
74 5 push (@insertion_positions, $position + $_) for (0..$count-1)
75 }
76 28 $position += $count;
77 }
78
79 6 my @mismatch_positions_on_reference = $self->mismatch_positions_on_reference;
80 6 my @relative_mismatch_positions_on_reference = map {$_ - $self->start} @mismatch_positions_on_reference;
81
82 6 my @mismatch_positions;
83 6 foreach my $relative_mismatch_position_on_reference (@relative_mismatch_positions_on_reference) {
84 15 my $deletion_adjustment = _how_many_are_smaller($relative_mismatch_position_on_reference, \@deletion_positions);
85 15 my $insertion_adjustment = _how_many_are_smaller($relative_mismatch_position_on_reference, \@insertion_positions);
86
87 15 my $mismatch_position_on_query = $relative_mismatch_position_on_reference - $deletion_adjustment + $insertion_adjustment;
88
89 15 ▶ if ($self->strand == -1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->strand == -1) 2 13 15
90 2 $mismatch_position_on_query = ($self->query_length - 1) - $mismatch_position_on_query;
91 }
92
93 15 push @mismatch_positions, $mismatch_position_on_query;
94 }
95
96 6 return @mismatch_positions;
97 }
98  
99 sub mismatch_nt_on_query {
100 7 ▶ my ($self) = @_;
Subroutine mismatch_nt_on_query: called CC=12 SCAR=24.9
Pod undocumented
101 #Tag: AGTGATGGGA------GGATGTCTCGTCTGTGAGTTACAGCA -> CIGAR: 2M1I7M6D26M
102 # - -
103 #Genome: AG-GCTGGTAGCTCAGGGATGTCTCGTCTGTGAGTTACAGCA -> MD:Z: 3C3T1^GCTCAG26
104
105 #returns an array containing a hash with keys {query_nt} {reference_nt} {query_pos}
106
107 7 my $cigar = $self->cigar;
108
109 # Find positions of insertions and deletions (dashes) on the query sequence
110 7 my @deletion_positions;
111 my @insertion_positions;
112 7 my $position = 0;
113 7 ▶ while ($cigar =~ /(\d+)([MIDNSHP=X])/g) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cigar =~ /(\d+)([MIDNSHP=X])/g) 46 7 53
114 46 my $count = $1;
115 46 my $identifier = $2;
116
117 46 ▶ if ($identifier eq 'D' or $identifier eq 'N' or $identifier eq 'P' or $identifier eq 'H') {
Branch: 2 branches
BranchTrueFalseTotal
if ($identifier eq 'D' or $identifier eq 'N' or $identifier eq 'P' or $identifier eq 'H') { } 9 37 46
elsif ($identifier eq 'I' or $identifier eq 'S') { } 8 29 37
Condition77%7/9
$identifier eq "D" or $identifier eq "N" or $identifier eq "P" or $identifier eq "H"
l!l&&r!l&&!r
9037
$identifier eq "D" or $identifier eq "N" or $identifier eq "P"
l!l&&r!l&&!r
9037
$identifier eq "D" or $identifier eq "N"
l!l&&r!l&&!r
7237
MC/DC50%2/4
$identifier eq "D" or $identifier eq "N" or $identifier eq "P" or $identifier eq "H"
$identifier eq "D" $identifier eq "N" $identifier eq "P" $identifier eq "H"
Truth table60%3/5
A or B or C or D
A= $identifier eq "D"B= $identifier eq "N"C= $identifier eq "P"D= $identifier eq "H"
ABCDresult
1XXX1
01XX1
001X1
00011
00000
118 9 push (@deletion_positions, $position + $_) for (0..$count-1)
119 }
120 ▶ elsif ($identifier eq 'I' or $identifier eq 'S') {
Condition66%2/3
$identifier eq "I" or $identifier eq "S"
l!l&&r!l&&!r
8029
MC/DC50%1/2
$identifier eq "I" or $identifier eq "S"
$identifier eq "I" $identifier eq "S"
Truth table66%2/3
A or B
A= $identifier eq "I"B= $identifier eq "S"
ABresult
1X1
011
000
121 8 push (@insertion_positions, $position + $_) for (0..$count-1)
122 }
123 46 $position += $count;
124 }
125
126 7 my @mismatch_positions_on_reference = $self->mismatch_positions_on_reference;
127 7 my @relative_mismatch_positions_on_reference = map {$_ - $self->start} @mismatch_positions_on_reference;
128 7 my @nts_on_reference = $self->reference_nt_for_mismatch_positions;
129
130 7 my @outarray;
131 7 my $query_seq = $self->query_seq;
132 7 ▶ for (my $i = 0; $i < @relative_mismatch_positions_on_reference; $i++){
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @relative_mismatch_positions_on_reference) 18 7 25
133 18 my $relative_mismatch_position_on_reference = $relative_mismatch_positions_on_reference[$i];
134 18 my $deletion_adjustment = _how_many_are_smaller($relative_mismatch_position_on_reference, \@deletion_positions);
135 18 my $insertion_adjustment = _how_many_are_smaller($relative_mismatch_position_on_reference, \@insertion_positions);
136
137 18 my $mismatch_position_on_query = $relative_mismatch_position_on_reference - $deletion_adjustment + $insertion_adjustment;
138
139 18 ▶ if ($self->strand == -1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->strand == -1) 2 16 18
140 2 $mismatch_position_on_query = ($self->query_length - 1) - $mismatch_position_on_query;
141 }
142
143 18 my $nt_on_query = substr($query_seq, $mismatch_position_on_query, 1);
144
145 18 my $nt_on_reference = $nts_on_reference[$i];
146
147 18 push @outarray, {'query_nt' => $nt_on_query, 'reference_nt' => $nt_on_reference, 'query_pos' => $mismatch_position_on_query};
148  
149 }
150
151 # print $outarray[0]->{'query_pos'}."\n";
152 7 return @outarray;
153 }
154  
155  
156 #######################################################################
157 ####################### Private Subroutines ########################
158 #######################################################################
159 sub _how_many_are_smaller {
160 66 ▶ my ($value, $array) = @_;
Subroutine _how_many_are_smaller: called CC=3 SCAR=11.0
161
162 66 my $count = 0;
163 66 foreach my $array_value (@$array) {
164 131 ▶ if ($array_value < $value) {
Branch: 1 branch
BranchTrueFalseTotal
if ($array_value < $value) 65 66 131
165 65 $count++;
166 }
167 }
168 66 return $count;
169 }
170  
171 1 1;
« GenOO/Helper/MyMath.pm ↑ Summary GenOO/Module/Search/Binary.pm »