0
|
1 use strict;
|
|
2 use List::Util qw[min max];
|
|
3
|
|
4 my $all = "ALL";
|
|
5 my $close = "CLOSEST";
|
|
6 my $first_idx = 0;
|
|
7 my $left = -1;
|
|
8 my $right = 1;
|
|
9 my $both = 0;
|
|
10 my $keys = "KEYS";
|
|
11 my $NOT_FOUND = -3;
|
|
12 my $NOT_FOUND_STR = "NOT FOUND";
|
|
13 my $ENCOMPASSING = -2;
|
|
14 #my $ENCOMPASSING_STR = "";
|
|
15 my $ENCOMPASSING_STR = "ENCOMPASSING FEATURE";
|
|
16 my $INTERNAL = -1;
|
|
17 #my $INTERNAL_STR = "";
|
|
18 my $INTERNAL_STR = "INTERNAL FEATURE";
|
|
19
|
|
20 return 1;
|
|
21
|
|
22 sub feature_index {
|
|
23 my ($feature_file, $window, $fchrom_col, $fstart_col, $fend_col, $debug) = @_;
|
|
24 open(FEATURES, "<${$feature_file}") || die "Unable to open features file, ${$feature_file}: $!\n";
|
|
25 my %feature_hash = ();
|
|
26 my $num_indexed = 0;
|
|
27 while (<FEATURES>) {
|
|
28 if (${$debug}) {
|
|
29 if (($num_indexed % 1000) == 0) {
|
|
30 my ($sec, $min, $hour, $day, $mon, $year, $wday, $yday, $isdst) = localtime(time);
|
|
31 print sprintf("%02d-%02d %02d:%02d:%02d Features Indexed: %9s\n", ($mon+1), $day, $hour, $min, $sec, $num_indexed);
|
|
32 }
|
|
33 }
|
|
34 chomp;
|
|
35 $num_indexed++;
|
|
36 my @split_line = split("\t");
|
|
37 if (!@split_line) { next; }
|
|
38 my $interim_hash1 = int($split_line[${$fstart_col}]/${$window});
|
|
39 my $interim_hash2 = int($split_line[${$fend_col}]/${$window});
|
|
40 for (my $interim_hash = min($interim_hash1, $interim_hash2); $interim_hash <= max($interim_hash1, $interim_hash2); $interim_hash++) {
|
|
41 push @{$feature_hash{$split_line[${$fchrom_col}]}->{$interim_hash}->{$split_line[${$fstart_col}]}}, \@split_line;
|
|
42 }
|
|
43 }
|
|
44 close(FEATURES);
|
|
45 if (${$debug}) { print "$num_indexed indexed\n"; }
|
|
46
|
|
47 my $min_keys_in_window;
|
|
48 my $max_keys_in_window;
|
|
49 my $num_idxs = 0;
|
|
50 my $total_keys = 0;
|
|
51 foreach my $chrom (keys %feature_hash) {
|
|
52 foreach my $interim_hash (keys %{$feature_hash{$chrom}}) {
|
|
53 $num_idxs++;
|
|
54 my @sorted_keys = sort {$a <=> $b} keys %{$feature_hash{$chrom}->{$interim_hash}};
|
|
55 my $interim_key = join("_", ($interim_hash, $keys));
|
|
56 my $num_keys = $#sorted_keys+1;
|
|
57 #print OUT "interim_hash:$interim_hash interim_key:$interim_key num_keys:$num_keys @sorted_keys\n";
|
|
58 $feature_hash{$chrom}->{$interim_key} = \@sorted_keys;
|
|
59 $total_keys += $#sorted_keys + 1;
|
|
60 if (!defined($min_keys_in_window) || ($#sorted_keys+1) < $min_keys_in_window) { $min_keys_in_window = ($#sorted_keys+1); }
|
|
61 if (!defined($max_keys_in_window) || ($#sorted_keys+1) > $max_keys_in_window) { $max_keys_in_window = ($#sorted_keys+1); }
|
|
62 }
|
|
63 }
|
|
64 if (${$debug}) {
|
|
65 my $avg_keys = $total_keys/$num_idxs;
|
|
66 print "Smallest # of keys in window: $min_keys_in_window, Largest: $max_keys_in_window $total_keys in $num_idxs windows for an average of $avg_keys\n";
|
|
67 }
|
|
68
|
|
69 return \%feature_hash;
|
|
70 }
|
|
71
|
|
72 sub process_intervals {
|
|
73 my ($intervals_file, $out_file, $feature_hash_ref, $req_res_type_ref, $direction_ref, $window_ref, $html_ref, $cturl_ref, $db_ref, $icols_ref, $fcols_ref, $debug_ref, $dd_ref, $capture, $promoter) = @_;
|
|
74 if (${$debug_ref}) { print sprintf("process_intervals(intervals:%s, out:%s, direction:%s, window:%s, icols_ref:%s)\n", ${$intervals_file}, ${$out_file}, ${$direction_ref}, ${$window_ref}, ${$icols_ref}); }
|
|
75 open(INTERVALS, "<${$intervals_file}") || die "Unable to open intervals file, ${$intervals_file}: $!\n";
|
|
76 open(my $out_h, ">${$out_file}") || die "Unable to open output file, ${$out_file}: $!\n";
|
|
77
|
|
78 #if (${$debug_ref}) { print sprintf("%s features in index.\n", keys %{$feature_hash_ref}); }
|
|
79
|
|
80 my @icols = split(":", ${$icols_ref});
|
|
81 #pod2usage({ message => "Must specify 5 columns with -icol, chrom:start:end:label:strand.\n", exitval => 2}) if ($#icols != 4);
|
|
82 my $ichrom = $icols[0]-1;
|
|
83 my $istart = $icols[1]-1;
|
|
84 my $iend = $icols[2]-1;
|
|
85 my $ilabel = $icols[3]-1;
|
|
86 my $istrand = $icols[4]-1;
|
|
87
|
|
88 my @fcols = split(":", ${$fcols_ref});
|
|
89 #pod2usage({ message => "Must specify 5 columns with -fcol, chrom:start:end:label:strand.\n", exitval => 2}) if ($#fcols != 4);
|
|
90 my $fchrom = $fcols[0]-1;
|
|
91 my $fstart = $fcols[1]-1;
|
|
92 my $fend = $fcols[2]-1;
|
|
93 my $flabel = $fcols[3]-1;
|
|
94 my $fstrand = $fcols[4]-1;
|
|
95
|
|
96 my $cturl;
|
|
97 my $print = \&print_res;
|
|
98 if (${$html_ref}) {
|
|
99 $print = \&print_res_html;
|
|
100 print $out_h "<HTML>\n<HEAD>\n\t<TITLE>Feature Finder Annotation</TITLE>\n</HEAD>\n<BODY>\n<TABLE>\n";
|
|
101 if (defined(${$cturl_ref})) {
|
|
102 ${$cturl} =~ s/X26/\%26/g;
|
|
103 }
|
|
104 }
|
|
105
|
|
106 my $count = 0;
|
|
107 foreach (<INTERVALS>) {
|
|
108 if (${$debug_ref}) {
|
|
109 if (($count % 1000) == 0) {
|
|
110 my ($sec, $min, $hour, $day, $mon, $year, $wday, $yday, $isdst) = localtime(time);
|
|
111 print sprintf("%02d-%02d %02d:%02d:%02d Intervals Processed: %9s\n", ($mon+1), $day, $hour, $min, $sec, $count);
|
|
112 }
|
|
113 $count++;
|
|
114 }
|
|
115 chomp;
|
|
116 my @split_line = split("\t");
|
|
117 if (!@split_line) { next; }
|
|
118 if (!defined(${$feature_hash_ref}{$split_line[$ichrom]})) {
|
|
119 #if (${$debug_ref}) { print "."; }
|
|
120 next;
|
|
121 }
|
|
122 my $win_start = min($split_line[$istart], $split_line[$iend]) - ${$window_ref};
|
|
123 if ($win_start < 0) { $win_start = 0; }
|
|
124 my $start_idx = int($win_start/${$window_ref}) -1;
|
|
125 if ($start_idx < 0) { $start_idx = 0; }
|
|
126 my $win_end = max($split_line[$istart], $split_line[$iend]) + ${$window_ref};
|
|
127 my $end_idx = int($win_end/${$window_ref}) +1;
|
|
128
|
|
129 if (uc ${$req_res_type_ref} eq $all) {
|
|
130 &$print(\$out_h, \@split_line, \$istart, \$iend, &compare(\$out_h, $feature_hash_ref, \$all, \@split_line, \$split_line[$ichrom], \$win_start, \$win_end, \$start_idx, \$end_idx, \$both, \$ichrom, \$istart, \$iend, \$ilabel, \$istrand, \$fchrom, \$fstart, \$fend, \$flabel, $debug_ref), \$flabel, \$fstart, \$fend, \$fstrand, $window_ref, $promoter, $capture, $dd_ref, $db_ref, $cturl_ref, \$ichrom, \$istart, \$iend);
|
|
131 }
|
|
132 else {
|
|
133 my %left_res = ();
|
|
134 my %right_res = ();
|
|
135 #if (${$debug_ref}) { print sprintf("STRAND:%s\tDIRECTION:%s\n", $split_line[$istrand], ${$direction_ref}); }
|
|
136 if ($split_line[$istrand] ne "+" && $split_line[$istrand] ne "-") { warn sprintf("Found \"%s\" as the strand of %s:%s-%s %s, please verify icols match your input data\n", $split_line[$istrand], $split_line[$ichrom], $split_line[$istart], $split_line[$iend], $split_line[$ilabel]); }
|
|
137 if (($split_line[$istrand] eq "+" && uc ${$direction_ref} ne "DOWNSTREAM") || ($split_line[$istrand] eq "-" && uc ${$direction_ref} ne "UPSTREAM")) {
|
|
138 %left_res = %{&compare(\$out_h, $feature_hash_ref, \$close, \@split_line, \$split_line[$ichrom], \$win_start, \$win_end, \$start_idx, \$end_idx, \$left, \$ichrom, \$istart, \$iend, \$ilabel, \$istrand, \$fchrom, \$fstart, \$fend, \$flabel, $debug_ref)};
|
|
139 }
|
|
140 if (($split_line[$istrand] eq "-" && uc ${$direction_ref} ne "DOWNSTREAM") || ($split_line[$istrand] eq "+" && uc ${$direction_ref} ne "UPSTREAM")) {
|
|
141 %right_res = %{&compare(\$out_h, $feature_hash_ref, \$close, \@split_line, \$split_line[$ichrom], \$win_start, \$win_end, \$start_idx, \$end_idx, \$right, \$ichrom, \$istart, \$iend, \$ilabel, \$istrand, \$fchrom, \$fstart, \$fend, \$flabel, $debug_ref)};
|
|
142 }
|
|
143 if (keys %left_res == 0) {
|
|
144 &$print(\$out_h, \@split_line, \$istart, \$iend, \%right_res, \$flabel, \$fstart, \$fend, \$fstrand, $window_ref, $promoter, $capture, $dd_ref, $db_ref, $cturl_ref, \$ichrom);
|
|
145 }
|
|
146 elsif (keys %right_res == 0) {
|
|
147 &$print(\$out_h, \@split_line, \$istart, \$iend, \%left_res, \$flabel, \$fstart, \$fend, \$fstrand, $window_ref, $promoter, $capture, $dd_ref, $db_ref, $cturl_ref, \$ichrom);
|
|
148 }
|
|
149 else {
|
|
150 my @left_keys = keys %left_res;
|
|
151 my @right_keys = keys %right_res;
|
|
152 if (uc ${$direction_ref} eq "BOTH") {
|
|
153 @left_res{keys %right_res} = values %right_res;
|
|
154 &$print(\$out_h, \@split_line, \$istart, \$iend, \%left_res, \$flabel, \$fstart, \$fend, \$fstrand, $window_ref, $promoter, $capture, $dd_ref, $db_ref, $cturl_ref, \$ichrom);
|
|
155 }
|
|
156 else {
|
|
157 if ($left_keys[0] <= $right_keys[0]) {
|
|
158 &$print(\$out_h, \@split_line, \$istart, \$iend, \%left_res, \$flabel, \$fstart, \$fend, \$fstrand, $window_ref, $promoter, $capture, $dd_ref, $db_ref, $cturl_ref, \$ichrom);
|
|
159 }
|
|
160 elsif ($right_keys[0] < $left_keys[0]) {
|
|
161 &$print(\$out_h, \@split_line, \$istart, \$iend, \%right_res, \$flabel, \$fstart, \$fend, \$fstrand, $window_ref, $promoter, $capture, $dd_ref, $db_ref, $cturl_ref, \$ichrom);
|
|
162 }
|
|
163 }
|
|
164 }
|
|
165 }
|
|
166 }
|
|
167 close(INTERVALS);
|
|
168 if (${$html_ref}) {
|
|
169 print $out_h "</TABLE>\n</BODY>\n</HTML>\n";
|
|
170 }
|
|
171 close($out_h);
|
|
172
|
|
173 }
|
|
174
|
|
175 sub compare {
|
|
176 my ($out_h_ref, $feature_hash_ref, $res_type, $interval_array_ref, $chrom, $window_start, $window_end, $start_idx, $end_idx, $direction, $ichrom, $istart, $iend, $ilabel, $istrand, $fchrom, $fstart, $fend, $flabel, $debug) = @_;
|
|
177 #if (${$debug}) { print sprintf("compare(result type:%s, chrom:%s, win start:%s, win end:%s, direction:%s, ichrom_col:%s, fchrom_col:%s, ilabel_col:%s, flabel_col:%s, debug:%s)\n", ${$res_type}, ${$chrom}, ${$window_start}, ${$window_end}, ${$direction}, ${$ichrom}, ${$fchrom}, ${$ilabel}, ${$flabel}, ${$debug}); }
|
|
178 my %result = ();
|
|
179 my %reshash = ();
|
|
180 my $feature_start;
|
|
181 my $feature_end;
|
|
182 my $interval_start;
|
|
183 my $interval_end;
|
|
184 my $interval_idx;
|
|
185 my $best_distance = $NOT_FOUND;
|
|
186 for ($interval_idx = ${$start_idx}; $interval_idx <= ${$end_idx}; $interval_idx++) {
|
|
187 my $interval_key = join("_", ($interval_idx, $keys));
|
|
188 if (!defined(${$feature_hash_ref}{${$chrom}}->{$interval_key})) {
|
|
189 next;
|
|
190 }
|
|
191
|
|
192 my @feature_keys = @{${$feature_hash_ref}{${$chrom}}->{$interval_key}};
|
|
193 my $interval_midp = (($interval_array_ref->[${$istart}] + $interval_array_ref->[${$iend}])/2);
|
|
194 foreach my $feature_idx (@feature_keys) {
|
|
195 foreach my $feature (@{${$feature_hash_ref}{${$chrom}}->{$interval_idx}->{$feature_idx}}) {
|
|
196 $feature_start = min($feature->[${$fstart}], $feature->[${$fend}]);
|
|
197 $feature_end = max($feature->[${$fstart}], $feature->[${$fend}]);
|
|
198 $interval_start = min($interval_array_ref->[${$istart}], $interval_array_ref->[${$iend}]);
|
|
199 $interval_end = max($interval_array_ref->[${$istart}], $interval_array_ref->[${$iend}]);
|
|
200 my $reskey = join(":", ($interval_array_ref->[${$ichrom}], ${$window_start}, ${$window_end}, $interval_array_ref->[${$ilabel}], $feature->[${$fchrom}], $feature_start, $feature_end, $feature->[${$flabel}]));
|
|
201 my $distance;
|
|
202 if ($feature_start <= $interval_start && $feature_end >= $interval_end) { $distance = $ENCOMPASSING; }
|
|
203 elsif ($interval_start < $feature_start && $interval_end > $feature_end) { $distance = $INTERNAL; }
|
|
204 else {
|
|
205 $distance = min(abs($interval_array_ref->[${$istart}] - $feature_start), abs($interval_array_ref->[${$istart}] - $feature_end), abs($interval_array_ref->[${$iend}] - $feature_start), abs($interval_array_ref->[${$iend}] - $feature_end));
|
|
206 #if (${$debug}) { print "FEATURE:$feature->[${$flabel}]\tDISTANCE:$distance\n"; }
|
|
207 }
|
|
208 my $dir_str = "";
|
|
209 my $feature_midp = ($feature_start + $feature_end)/2;
|
|
210 if ($interval_midp >= $feature_midp) {
|
|
211 if ($interval_array_ref->[${$istrand}] eq "+") { $dir_str = "UPSTREAM"; }
|
|
212 else { $dir_str = "DOWNSTREAM" }
|
|
213 }
|
|
214 else {
|
|
215 if ($interval_array_ref->[${$istrand}] eq "-") { $dir_str = "UPSTREAM"; }
|
|
216 else { $dir_str = "DOWNSTREAM" }
|
|
217 }
|
|
218
|
|
219 if (${$res_type} eq $close) {
|
|
220 if (${$direction} == $left) {
|
|
221 if ($interval_midp < $feature_midp) { next; }
|
|
222 }
|
|
223 elsif (${$direction} == $right) {
|
|
224 if ($interval_midp >= $feature_midp) { next; }
|
|
225 }
|
|
226
|
|
227 #print ${$out_h_ref} "distance:$distance best_distance:$best_distance\n";
|
|
228 if ($best_distance > $NOT_FOUND) {
|
|
229 if ($distance < $best_distance) {
|
|
230 delete $result{$best_distance};
|
|
231 if (!defined($reshash{$reskey})) {
|
|
232 $reshash{$reskey} = $feature;
|
|
233 push @{$result{$distance}{$feature->[${$flabel}]}}, $feature, $dir_str;
|
|
234 #$result{$distance}{$feature->[${$flabel}]} = $dir_str;
|
|
235 $best_distance = $distance;
|
|
236 }
|
|
237 }
|
|
238 }
|
|
239 else {
|
|
240 if (!defined($reshash{$reskey})) {
|
|
241 $reshash{$reskey} = $feature;
|
|
242 push @{$result{$distance}{$feature->[${$flabel}]}}, $feature, $dir_str;
|
|
243 #$result{$distance}{$feature->[${$flabel}]} = $dir_str;
|
|
244 $best_distance= $distance;
|
|
245 }
|
|
246 }
|
|
247 }
|
|
248 else {
|
|
249 # if the interval start - the window is less than the end of the feature and the interval end + the window is greater than the start of the feature it's included
|
|
250 if (${$window_start} <= $feature_end && ${$window_end} >= $feature_start) {
|
|
251 if (!defined($reshash{$reskey})) {
|
|
252 $reshash{$reskey} = $feature;
|
|
253 push @{$result{$distance}{$feature->[${$flabel}]}}, $feature, $dir_str;
|
|
254 #$result{$distance}{$feature->[${$flabel}]} = $dir_str;
|
|
255 }
|
|
256 }
|
|
257 }
|
|
258 }
|
|
259 }
|
|
260 }
|
|
261 return \%result;
|
|
262 }
|
|
263
|
|
264 sub print_res {
|
|
265 my ($out_h_ref, $interval_array_ref, $istart, $iend, $result_hash_ref, $flabel, $fstart, $fend, $fstrand, $window, $promoter_len, $capture, $dd_ref) = @_;
|
|
266 print ${$out_h_ref} join("\t", @{$interval_array_ref});
|
|
267 my @sorted_keys = sort {$a <=> $b} keys %{$result_hash_ref};
|
|
268 if (defined($sorted_keys[0])) {
|
|
269 print ${$out_h_ref} sprintf("\t");
|
|
270 my $left_end = $interval_array_ref->[${$istart}];
|
|
271 my $right_end = $interval_array_ref->[${$iend}];
|
|
272 my $fstart_pos;
|
|
273 my $fend_pos;
|
|
274 foreach my $next_key (@sorted_keys) {
|
|
275 foreach my $res (keys %{$result_hash_ref->{$next_key}}) {
|
|
276 #my @feature_keys = keys %{$res};
|
|
277 if (defined($capture) && ${$capture}) {
|
|
278 if (@{$result_hash_ref->{$next_key}->{$res}}[0]->[${$fstrand}] eq '+') {
|
|
279 $fstart_pos = @{$result_hash_ref->{$next_key}->{$res}}[0]->[${$fstart}] - ${$promoter_len};
|
|
280 } else {
|
|
281 $fstart_pos = @{$result_hash_ref->{$next_key}->{$res}}[0]->[${$fstart}];
|
|
282 }
|
|
283 if (@{$result_hash_ref->{$next_key}->{$res}}[0]->[${$fstrand}] eq '-') {
|
|
284 $fend_pos = @{$result_hash_ref->{$next_key}->{$res}}[0]->[${$fend}] + ${$promoter_len};
|
|
285 } else {
|
|
286 $fend_pos = @{$result_hash_ref->{$next_key}->{$res}}[0]->[${$fend}];
|
|
287 }
|
|
288 if ($fstart_pos < $left_end) { $left_end = $fstart_pos; }
|
|
289 if ($fend_pos > $right_end) { $right_end = $fend_pos; }
|
|
290 }
|
|
291 if (!${$dd_ref}) {
|
|
292 print ${$out_h_ref} sprintf("%s, ", $res);
|
|
293 } else {
|
|
294 if ($next_key == $ENCOMPASSING) {
|
|
295 print ${$out_h_ref} sprintf("%s (%s), ", $res, $ENCOMPASSING_STR);
|
|
296 }
|
|
297 elsif ($next_key == $INTERNAL) {
|
|
298 print ${$out_h_ref} sprintf("%s (%s), ", $res, $INTERNAL_STR);
|
|
299 }
|
|
300 else {
|
|
301 print ${$out_h_ref} sprintf("%s (%s bp %s), ", $res, $next_key, @{$result_hash_ref->{$next_key}->{$res}}[1]);
|
|
302 }
|
|
303 }
|
|
304 }
|
|
305 }
|
|
306 if (defined($capture) && ${$capture}) {
|
|
307 print ${$out_h_ref} sprintf("\t%s\t%s\t%s", $left_end, $right_end, $right_end - $left_end);
|
|
308 }
|
|
309 }
|
|
310 else {
|
|
311 print ${$out_h_ref} sprintf("\tNo results within ${$window} bp window");
|
|
312 }
|
|
313 print ${$out_h_ref} sprintf("\n");
|
|
314 }
|
|
315
|
|
316 sub print_res_html {
|
|
317 my ($out_h_ref, $interval_array_ref, $istart, $iend, $result_hash_ref, $flabel, $fstart, $fend, $fstrand, $window, $promoter_len, $capture, $dd_ref, $db, $cturl, $ichrom) = @_;
|
|
318 print ${$out_h_ref} sprintf("<TR>\n\t<TD>");
|
|
319 my $win_start = min($interval_array_ref->[${$istart}], $interval_array_ref->[${$iend}]) - $window;
|
|
320 my $win_end = max($interval_array_ref->[${$istart}], $interval_array_ref->[${$iend}]) + $window;
|
|
321 print ${$out_h_ref} sprintf("<A HREF=\"http://genome.ucsc.edu/cgi-bin/hgTracks?db=%s&position=%s:%s-%s&display_app=ucsc&authz_method=display_at", $db, $interval_array_ref->[${$ichrom}], $win_start, $win_end);
|
|
322 my $left_end = $interval_array_ref->[${$istart}];
|
|
323 my $right_end = $interval_array_ref->[${$iend}];
|
|
324 my $fstart_pos;
|
|
325 my $fend_pos;
|
|
326 if (defined($cturl)) {
|
|
327 #print ${$out_h_ref} sprintf ("&hgt.customText=%s/display_as?id=%s&display_app=ucsc&authz_method=display_at", $server_url, $out_dbkey);
|
|
328 print ${$out_h_ref} sprintf("&hgt.customText=%s", $cturl);
|
|
329 }
|
|
330 print ${$out_h_ref} sprintf("\">UCSC Visualization</A></TD><TD>");
|
|
331 #custom track stuff something like : &hgt.customText=%s/display_as?id=%s&display_app=ucsc&authz_method=display_at, $server_url, $out_dbkey
|
|
332 print ${$out_h_ref} join("</TD><TD>", @{$interval_array_ref});
|
|
333 my @sorted_keys = sort {$a <=> $b} keys %{$result_hash_ref};
|
|
334 if (defined($sorted_keys[0])) {
|
|
335 foreach my $next_key (@sorted_keys) {
|
|
336 foreach my $res (keys %{$result_hash_ref->{$next_key}}) {
|
|
337 if (${$capture}) {
|
|
338 if (@{$result_hash_ref->{$next_key}->{$res}}[0]->[${$fstrand}] eq '+') {
|
|
339 $fstart_pos = @{$result_hash_ref->{$next_key}->{$res}}[0]->[${$fstart}] - ${$promoter_len};
|
|
340 } else {
|
|
341 $fstart_pos = @{$result_hash_ref->{$next_key}->{$res}}[0]->[${$fstart}];
|
|
342 }
|
|
343 if (@{$result_hash_ref->{$next_key}->{$res}}[0]->[${$fstrand}] eq '-') {
|
|
344 $fend_pos = @{$result_hash_ref->{$next_key}->{$res}}[0]->[${$fend}] + ${$promoter_len};
|
|
345 } else {
|
|
346 $fend_pos = @{$result_hash_ref->{$next_key}->{$res}}[0]->[${$fend}];
|
|
347 }
|
|
348 if ($fstart_pos < $left_end) { $left_end = $fstart_pos; }
|
|
349 if ($fend_pos > $right_end) { $right_end = $fend_pos; }
|
|
350 }
|
|
351
|
|
352 if (!${$dd_ref}) {
|
|
353 print ${$out_h_ref} sprintf("<TD>%s</TD>", $res);
|
|
354 } else {
|
|
355 if ($next_key == $ENCOMPASSING) {
|
|
356 print ${$out_h_ref} sprintf("<TD>%s (%s)</TD>", $res, $ENCOMPASSING_STR);
|
|
357 }
|
|
358 elsif ($next_key == $INTERNAL) {
|
|
359 print ${$out_h_ref} sprintf("<TD>%s (%s)</TD>", $res, $INTERNAL_STR);
|
|
360 }
|
|
361 else {
|
|
362 print ${$out_h_ref} sprintf("<TD>%s (%s bp %s)</TD>", $res, $next_key, @{$result_hash_ref->{$next_key}->{$res}}[0]);
|
|
363 }
|
|
364 }
|
|
365 }
|
|
366 }
|
|
367
|
|
368 if (${$capture}) {
|
|
369 print ${$out_h_ref} sprintf("<TD>%s</TD><TD>%s</TD><TD>%s</TD>", $left_end, $right_end, $right_end - $left_end);
|
|
370 }
|
|
371 }
|
|
372 else {
|
|
373 print ${$out_h_ref} sprintf("<TD>No results within $window bp window</TD>");
|
|
374 }
|
|
375 print ${$out_h_ref} sprintf("</TD>\n</TR>\n");
|
|
376 }
|