blib/lib/Software/GenoScan/HSS_Annotator.pm untested

filter: Statementstmt 0.0% 0 / 133 Branchbran 0.0% 0 / 46 Conditioncond 0.0% 0 / 52 MC/DCmcdc 0.0% 0 / 32 Subroutinesub 0.0% 0 / 4 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 268 CC 24 SCAR 62.8
CC
24
Cov
0%
annotateHSS
600.0
BEGIN
2.0
BEGIN
2.0
CRAP 533.6
1 package Software::GenoScan::HSS_Annotator;
2  
3 use warnings;
4 use strict;
5  
6 require Exporter;
7  
8 our $VERSION = "v1.0.4";
9 our @ISA = qw(Exporter);
10 our %EXPORT_TAGS = ("all" => [ qw(
11 annotateHSS
12 ) ] );
13 our @EXPORT_OK = (@{ $EXPORT_TAGS{"all"} });
14  
15 # HSS notation
16 #
17 #Structure elements
18 #
19 #Tail (T)
20 #Hairpin loop (H)
21 #Watson-Crick basepair (P)
22 #U-G wobble (W)
23 #Symmetric internal loop (S)
24 #Asymmetric internal loop (A)
25 #Bulge (B)
26 #
27 #Regions
28 #
29 #stem (S)
30 #hairpin loop (L)
31  
32 my $TAIL = "T";
33 my $BASEPAIR = "P";
34 my $WOBBLE = "W";
35 my $SYMMETRIC_LOOP = "S";
36 my $ASYMMETRIC_LOOP = "A";
37 my $BULGE = "B";
38 my $HAIRPIN_LOOP = "H";
39 my $STEM = "S";
40 my $TERMINAL_LOOP = "L";
41  
42 #Description: Wrapper function for hairpin annotation
43 #Parameters: Visualized hairpins file, (2) output file name
44 #Return value: None
45 sub annotateHSS($ $){
46 my ($inputFile, $outputFile) = @_;
47  
48 open(MIRNA, "$inputFile") or die "GenoScan error: Unable to read '$inputFile'\n";
49 my @mirnas = split(/>/, join("", <MIRNA>));
50 shift(@mirnas);
51 close(MIRNA);
52 open(ANNOT, ">$outputFile") or die "GenoScan error: Unable to write '$outputFile'\n";
53  
54 foreach my $mir (@mirnas){
55 $mir =~ m/^([^\s]+)/;
56 my $name = $1;
57 $mir = ">$mir";
58
59 #Extract visual secondary structure
60 my @visual = split(/\n/, $mir);
61 my $header = shift(@visual);
62 my $seq = shift(@visual);
63 my $str = shift(@visual);
64 $str =~ m/(\s*-?[0-9]+(\.[0-9]+)?)/;
65 my $MFE = $1;
66 $str =~ s/\s*\(\s*-?[0-9]+(\.[0-9]+)?\s*\)//;
67 shift(@visual);
68 my @visualMatrix;
69 foreach my $row (@visual){
70 my @cols = split(//, $row);
71 push(@visualMatrix, \@cols);
72 }
73
74 #Determine hairpin loop position
75 my $numLoops = () = $str =~ m/(\(\.+\))/g;
76 my $hairpinLoopLength = length($1) - 2;
77 my $hairpinLoopStart = index($str, $1) + 2;
78 my $hairpinLoopEnd = $hairpinLoopStart + $hairpinLoopLength - 1;
79
80 #Derive region annotation
81 my $nucIndex = 0;
82 my @regions;
83 for(my $pos = 3; $pos < scalar(@{$visualMatrix[0]}) - 2; $pos++){
84 if($visualMatrix[0][$pos] =~ m/[AUCG]/i || $visualMatrix[1][$pos] =~ m/[AUCG]/i){
85 $nucIndex++;
86 }
87 if($nucIndex < $hairpinLoopStart){
88 push(@regions, $STEM);
89 }
90 }
91 if($hairpinLoopLength == 3){
92 push(@regions, $TERMINAL_LOOP);
93 push(@regions, $TERMINAL_LOOP);
94 }
95 elsif($hairpinLoopLength % 2 == 0){
96 foreach my $pos (1 .. ($hairpinLoopLength - 2) / 2 + 1){
97 push(@regions, $TERMINAL_LOOP);
98 }
99 }
100 elsif($hairpinLoopLength % 2 != 0){
101 foreach my $pos (1 .. ($hairpinLoopLength - 3) / 2 + 1){
102 push(@regions, $TERMINAL_LOOP);
103 }
104 }
105
106 #Derive structure annotation
107 my @structure;
108 my $tailPassed = 0;
109 $nucIndex = 0;
110 for(my $pos = 3; $pos < scalar(@{$visualMatrix[0]}) - 2; $pos++){
111 if($visualMatrix[0][$pos] =~ m/[AUCG]/i || $visualMatrix[1][$pos] =~ m/[AUCG]/i){
112 $nucIndex++;
113 }
114 if(!$tailPassed){ #Tail
115 if($visualMatrix[2][$pos] eq "|"){
116 $tailPassed = 1;
117 }
118 else{
119 push(@structure, $TAIL);
120 }
121 }
122 if($tailPassed && $nucIndex < $hairpinLoopStart){ #Stem passed the tail
123 if($visualMatrix[2][$pos] eq "|"){ #Basepair or wobble
124 if(($visualMatrix[1][$pos] =~ m/G/i && $visualMatrix[3][$pos] =~ m/U/i) || ($visualMatrix[1][$pos] =~ m/U/i && $visualMatrix[3][$pos] =~ m/G/i)){
125 push(@structure, $WOBBLE);
126 }
127 else{
128 push(@structure, $BASEPAIR);
129 }
130 }
131 else{ #Symmetric/asymmetric loop or bulge
132 my $mismatchSpan = 0;
133 my $mismatchType;
134
135 #Find length of mismatch
136 for(my $lookAhead = 0; $nucIndex + $lookAhead < $hairpinLoopStart; $lookAhead++){
137 if($visualMatrix[2][$pos+$lookAhead] eq "|"){
138 last;
139 }
140 else{
141 $mismatchSpan++;
142 }
143 }
144
145 #Find type of mismatch
146 my $fivePrime = "";
147 my $threePrime = "";
148 foreach my $mismatch (0 .. $mismatchSpan - 1){
149 $fivePrime .= $visualMatrix[0][$pos+$mismatch];
150 $threePrime .= $visualMatrix[4][$pos+$mismatch];
151 }
152 my $fiveNuc = () = $fivePrime =~ m/[AUGC]/ig;
153 my $fiveNucComp = 0;
154 if($fivePrime =~ m/^[AUGC]/i){
155 $fiveNucComp = 1;
156 }
157 if($fivePrime =~ m/^[AUGC]+$/i && $threePrime =~ m/^[AUGC]+$/i){
158 $mismatchType = "sym";
159 }
160 elsif(($fivePrime =~ m/^[AUGC]+$/i && $threePrime =~ m/[AUGC]/i && $threePrime =~ m/-/) || ($fivePrime =~ m/[AUGC]/i && $fivePrime =~ m/-/ && $threePrime =~ m/^[AUGC]+$/i)){
161 $mismatchType = "asym";
162 }
163 elsif(($fivePrime =~ m/^[AUGC]+$/i && $threePrime =~ m/^-+$/) || ($fivePrime =~ m/^-+$/ && $threePrime =~ m/^[AUGC]+$/i)){
164 $mismatchType = "bulge";
165 }
166
167 #Add mismatch to @structure
168 foreach my $mismatch (1 .. $mismatchSpan){
169 if($mismatchType eq "sym"){ #Symmetric loop
170 push(@structure, $SYMMETRIC_LOOP);
171 }
172 elsif($mismatchType eq "asym"){ #Asymmetric loop
173 push(@structure, $ASYMMETRIC_LOOP);
174 }
175 elsif($mismatchType eq "bulge"){ #Bulge
176 push(@structure, $BULGE);
177 }
178 }
179 $pos += $mismatchSpan - 1;
180 $nucIndex += $fiveNuc - $fiveNucComp;
181 }
182 }
183 elsif($tailPassed && $nucIndex >= $hairpinLoopStart){ #Hairpin loop
184 push(@structure, $HAIRPIN_LOOP);
185 }
186 }
187
188 #Add region and structure annotation to miRNA
189 $mir .= " " . join("", @regions) . "\n " . join("", @structure) . "\n\n";
190 my $stem = "";
191 my $loop = "";
192 my $currentRegion = "STEM";
193 foreach my $index (0 .. scalar(@structure) - 1){
194 if($regions[$index] eq $TERMINAL_LOOP){
195 $currentRegion = "LOOP"
196 }
197 if($currentRegion eq "STEM"){
198 $stem .= $structure[$index];
199 }
200 elsif($currentRegion eq "LOOP"){
201 $loop .= $structure[$index];
202 }
203 }
204 print(ANNOT $mir);
205 }
206 close(ANNOT);
207 }
208  
209 return 1;
210