EnsEMBL/IdMapping/ResultAnalyser.pm untested

filter: Statementstmt 0.0% 0 / 236 Branchbran 0.0% 0 / 60 Conditioncond 0.0% 0 / 26 Subroutinesub 0.0% 0 / 22 Podpod 0.0% 0 / 16 totaltotal 0.0% 0 / 360 CC 31 SCAR 28.1
CC
31
Cov
0%
create_mapping_summary
42.0
classify_genes_by_mapping
30.0
classify_genes_by_mapping_simple
20.0
CRAP 16.7
1 =head1 LICENSE
2  
3 See the NOTICE file distributed with this work for additional information
4 regarding copyright ownership.
5  
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
9  
10 http://www.apache.org/licenses/LICENSE-2.0
11  
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17  
18 =cut
19  
20  
21 =head1 CONTACT
22  
23 Please email comments or questions to the public Ensembl
24 developers list at <http://lists.ensembl.org/mailman/listinfo/dev>.
25  
26 Questions may also be sent to the Ensembl help desk at
27 <http://www.ensembl.org/Help/Contact>.
28  
29 =cut
30  
31 =head1 NAME
32  
33 Bio::EnsEMBL::IdMapping::ResultAnalyser - analyse stable Id mapping results
34  
35 =head1 SYNOPSIS
36  
37 # get a result analyser
38 my $analyser = Bio::EnsEMBL::IdMapping::ResultAnalyser->new(
39 -LOGGER => $logger,
40 -CONF => $conf,
41 -CACHE => $cache
42 );
43  
44 # analyse results
45 $analyser->analyse( $gene_mappings,
46 $stable_id_mapper->get_all_stable_id_events('similarity') );
47  
48 # write results to file
49 $analyser->write_results_to_file;
50  
51 # create click lists
52 $analyser->create_clicklist;
53  
54 # mapping_summary
55 $analyser->create_mapping_summary;
56  
57 =head1 DESCRIPTION
58  
59 This is a utility module which analyses the stable Id mapping results
60 by providing various sorts of mapping statistics. It also creates
61 clicklists and a mapping summary.
62  
63 =head1 METHODS
64  
65 analyse
66 analyse_db
67 classify_source_genes_by_type
68 classify_genes_by_mapping_simple
69 classify_genes_by_mapping
70 add
71 get
72 get_all_by_subclass
73 get_all_by_class
74 get_count_by_subclass
75 get_count_by_class
76 get_all_classes
77 class_key
78 write_results_to_file
79 create_clicklist
80 create_mapping_summary
81 read_from_file
82  
83 =cut
84  
85  
86 package Bio::EnsEMBL::IdMapping::ResultAnalyser;
87 $Bio::EnsEMBL::IdMapping::ResultAnalyser::VERSION = '114.0.0_50'; # TRIAL
88 $Bio::EnsEMBL::IdMapping::ResultAnalyser::VERSION = '114.0.050';
89 use strict;
90 use warnings;
91 no warnings 'uninitialized';
92  
93 use Bio::EnsEMBL::IdMapping::BaseObject;
94 our @ISA = qw(Bio::EnsEMBL::IdMapping::BaseObject);
95  
96 use Bio::EnsEMBL::Utils::Exception qw(throw warning);
97 use Bio::EnsEMBL::Utils::ScriptUtils qw(path_append);
98  
99  
100 =head2 analyse
101  
102 Arg[1] : Bio::EnsEMBL::IdMapping::MappingList $gene_mappings - the gene
103 mappings to analyse
104 Arg[2] : Arrayref of Strings - similarity events
105 Example : $analyser->analyse($gene_mappings,
106 $stable_id_mapper->get_all_stable_id_events('similarity'));
107 Description : Analyses the results of a stable Id mapping run.
108 Return type : none
109 Exceptions : thrown on wrong or missing arguments
110 Caller : general
111 Status : At Risk
112 : under development
113  
114 =cut
115  
116 sub analyse {
117 my $self = shift;
118 my $gene_mappings = shift;
119 my $similarity_events = shift;
120
121 # argument check
122 unless ($gene_mappings and
123 $gene_mappings->isa('Bio::EnsEMBL::IdMapping::MappingList')) {
124 throw("Need a Bio::EnsEMBL::IdMapping::MappingList of genes.");
125 }
126  
127 unless ($similarity_events and ref($similarity_events) eq 'ARRAY') {
128 throw("Need a list of similarity events.");
129 }
130  
131 # classify source genes by type (logic_name-biotype)
132 $self->classify_source_genes_by_type;
133  
134 # classify source genes by mapping status
135 $self->classify_genes_by_mapping($gene_mappings, $similarity_events);
136 }
137  
138  
139 =head2 classify_source_genes_by_type
140  
141 Example : $analyser->classify_source_genes_by_type;
142 Description : Classifies source genes by type and adds them to the internal
143 datastructure. For the format of the classification string see
144 class_key().
145 Return type : none
146 Exceptions : none
147 Caller : internal
148 Status : At Risk
149 : under development
150  
151 =cut
152  
153 sub classify_source_genes_by_type {
154 my $self = shift;
155  
156 foreach my $s_gene (values %{ $self->cache->get_by_name('genes_by_id', 'source') }) {
157 $self->add('source', $self->class_key($s_gene), 'all', $s_gene->stable_id);
158 }
159 }
160  
161  
162 =head2 classify_genes_by_mapping_simple
163  
164 Arg[1] : Bio::EnsEMBL::IdMapping::MapppingList $gene_mappings - gene
165 mappings to classify
166 Example : $analyser->classify_genes_by_mapping_simple;
167 Description : Classifies target genes by mapping ('mapped' or 'unmapped').
168 Return type : none
169 Exceptions : thrown on wrong or missing argument
170 Caller : This method is not in use at the momen.
171 Status : At Risk
172 : under development
173  
174 =cut
175  
176 sub classify_genes_by_mapping_simple {
177 my $self = shift;
178 my $gene_mappings = shift;
179  
180 # argument check
181 unless ($gene_mappings and
182 $gene_mappings->isa('Bio::EnsEMBL::IdMapping::MappingList')) {
183 throw("Need a Bio::EnsEMBL::IdMapping::MappingList of genes.");
184 }
185  
186 my %result = ();
187
188 # firrst, create a lookup hash of source genes by target internal ID
189 my %source_genes_by_target = ();
190 foreach my $e (@{ $gene_mappings->get_all_Entries }) {
191 my $s_gene = $self->cache->get_by_key('genes_by_id', 'source', $e->source);
192 my $t_gene = $self->cache->get_by_key('genes_by_id', 'target', $e->target);
193 $source_genes_by_target{$t_gene->id} = $s_gene;
194 }
195  
196 # now loop over target genes
197 foreach my $t_gene (values %{ $self->cache->get_by_name('genes_by_id', 'target') }) {
198
199 # check if target gene has all required properties set
200 unless ($t_gene->logic_name and $t_gene->biotype) {
201 $self->logger->warning("Missing data for target gene: ".
202 $t_gene->to_string."\n", 1);
203 }
204  
205 my $class = $self->class_key($t_gene);
206  
207 # classify as '1' if mapped (using source gene's stable ID), otherwise '0'
208 if (my $s_gene = $source_genes_by_target{$t_gene->id}) {
209 $self->add('target', $class, 'mapped', $s_gene->stable_id);
210 } else {
211 $self->add('target', $class, 'unmapped', $t_gene->stable_id);
212 }
213  
214 }
215 }
216  
217  
218 =head2 classify_genes_by_mapping
219  
220 Arg[1] : Bio::EnsEMBL::IdMapping::MapppingList $gene_mappings - gene
221 mappings to classify
222 Arg[2] : Arrayref of Strings - similarity events
223 Example : $analyser->classify_genes_by_mapping;
224 Description : Classifies genes by mapping. Status is
225 'mapped' => stable Id was mapped
226 'lost_similar' => stable Id not mapped, but there is a
227 similarity entry for the source Id
228 'lost_definite' => not mapped and no similarity
229 Return type : none
230 Exceptions : thrown on wrong or missing argument
231 Caller : This method is not in use at the momen.
232 Status : At Risk
233 : under development
234  
235 =cut
236  
237 sub classify_genes_by_mapping {
238 my $self = shift;
239 my $gene_mappings = shift;
240 my $similarity_events = shift;
241
242 # argument check
243 unless ($gene_mappings and
244 $gene_mappings->isa('Bio::EnsEMBL::IdMapping::MappingList')) {
245 throw("Need a Bio::EnsEMBL::IdMapping::MappingList of genes.");
246 }
247  
248 unless ($similarity_events and ref($similarity_events) eq 'ARRAY') {
249 throw("Need a list of similarity events.");
250 }
251  
252 # mapped genes
253 foreach my $e (@{ $gene_mappings->get_all_Entries }) {
254 my $s_gene = $self->cache->get_by_key('genes_by_id', 'source', $e->source);
255 $self->add('source', $self->class_key($s_gene), 'mapped',
256 $s_gene->stable_id);
257 }
258  
259 # lookup hash for similarities
260 my %similar = ();
261 foreach my $event (@{ $similarity_events }) {
262 my ($stable_id) = split("\t", $event);
263 $similar{$stable_id} = 1;
264 }
265
266 # deleted genes
267 foreach my $s_gene (values %{ $self->cache->get_by_name('genes_by_id', 'source') }) {
268
269 my $stable_id = $s_gene->stable_id;
270 my $class = $self->class_key($s_gene);
271  
272 unless ($self->get('source', $class, 'mapped', $stable_id)) {
273  
274 # sub-classify as 'lost_similar' or 'lost_definite'
275 if ($similar{$stable_id}) {
276 $self->add('source', $class, 'lost_similar', $stable_id);
277 } else {
278 $self->add('source', $class, 'lost_definite', $stable_id);
279 }
280  
281 }
282 }
283
284 }
285  
286  
287 =head2 add
288  
289 Arg[1] : String $dbtype - db type ('source' or 'target')
290 Arg[2] : String $class - key identifying a gene type (see class_key())
291 Arg[3] : String $subclass - status identifier (e.g. 'mapped', 'lost')
292 Arg[4] : String $stable_id - gene stable Id
293 Arg[5] : String $val - value (usually 0 or 1)
294 Example : $analyser->add('source', 'KNOWN-ensembl-protein_coding',
295 'mapped', 'ENSG00002342', 1);
296 Description : Add a stable Id / property pair to a name/dbtype lookup hash.
297
298 The datastructure is a bit of a bloat, but is general enough to
299 be used as a lookup hash and to generate statistics (counts by
300 type) and debug lists (dump by type).
301 Return type : String - the added value
302 Exceptions : none
303 Caller : internal
304 Status : At Risk
305 : under development
306  
307 =cut
308  
309 sub add {
310 my ($self, $dbtype, $class, $subclass, $stable_id, $val) = @_;
311  
312 # private method, so no argument check done for performance reasons
313  
314 # default to a value of '1'
315 $val = 1 unless (defined($val));
316  
317 $self->{$dbtype}->{$class}->{$subclass}->{$stable_id} = $val;
318 }
319  
320  
321 =head2 get
322  
323 Arg[1] : String $dbtype - db type ('source' or 'target')
324 Arg[2] : String $class - key identifying a gene type (see class_key())
325 Arg[3] : String $subclass - status identifier (e.g. 'mapped', 'lost')
326 Arg[4] : String $stable_id - gene stable Id
327 Example : my $mapping_status = $analyser->get('source',
328 'KNOWN-ensembl-protein_coding', 'mapped', 'ENSG00002342');
329 Description : Gets a stable Id mapping status from the internal datastructure.
330 Return type : String
331 Exceptions : none
332 Caller : internal
333 Status : At Risk
334 : under development
335  
336 =cut
337  
338 sub get {
339 my ($self, $dbtype, $class, $subclass, $stable_id) = @_;
340  
341 # private method, so no argument check done for performance reasons
342  
343 return $self->{$dbtype}->{$class}->{$subclass}->{$stable_id};
344 }
345  
346  
347 =head2 get_all_by_subclass
348  
349 Arg[1] : String $dbtype - db type ('source' or 'target')
350 Arg[2] : String $class - key identifying a gene type (see class_key())
351 Arg[3] : String $subclass - status identifier (e.g. 'mapped', 'lost')
352 Example : my @mapped_stable_ids = @{
353 $analyser->get_all_by_subclass(
354 'source', 'KNOWN-ensembl-protein_coding',
355 'mapped'
356 ) };
357 Description : Gets a list of stable Id for a given subclass.
358 Return type : Arrayref of String (stable Ids)
359 Exceptions : thrown on missing arguments
360 Caller : internal
361 Status : At Risk
362 : under development
363  
364 =cut
365  
366 sub get_all_by_subclass {
367 my ($self, $dbtype, $class, $subclass) = @_;
368  
369 # argument check
370 throw("Need a dbtype (source|target).") unless ($dbtype);
371 throw("Need a class.") unless ($class);
372 throw("Need a subclass.") unless ($subclass);
373  
374 return [ keys %{ $self->{$dbtype}->{$class}->{$subclass} || {} } ];
375 }
376  
377  
378 =head2 get_all_by_class
379  
380 Arg[1] : String $dbtype - db type ('source' or 'target')
381 Arg[2] : String $class - key identifying a gene type (see class_key())
382 Example : my @stable_ids = @{
383 $analyser->get_all_by_class( 'source',
384 'KNOWN-ensembl-protein_coding' ) };
385 Description : Gets a list of stable Id for a given class.
386 Return type : Arrayref of String (stable Ids)
387 Exceptions : thrown on missing arguments
388 Caller : internal
389 Status : At Risk
390 : under development
391  
392 =cut
393  
394 sub get_all_by_class {
395 my ($self, $dbtype, $class) = @_;
396  
397 # argument check
398 throw("Need a dbtype (source|target).") unless ($dbtype);
399 throw("Need a class.") unless ($class);
400  
401 my %merged = ();
402  
403 foreach my $subclass (keys %{ $self->{$dbtype}->{$class} || {} }) {
404 while (my ($key, $val) = each(%{ $self->{$dbtype}->{$class}->{$subclass} })) {
405 $merged{$key} = $val;
406 }
407 }
408  
409 return [ keys %merged ];
410 }
411  
412  
413 =head2 get_count_by_subclass
414  
415 Arg[1] : String $dbtype - db type ('source' or 'target')
416 Arg[2] : String $class - key identifying a gene type (see class_key())
417 Arg[3] : String $subclass - status identifier (e.g. 'mapped', 'lost')
418 Example : my $num_mapped = $analyser->get_count_by_subclass('source',
419 'KNOWN-ensembl-protein_coding', 'mapped');
420 Description : Gets the number of stable Ids for a given subclass.
421 Return type : Int
422 Exceptions : thrown on missing arguments
423 Caller : internal
424 Status : At Risk
425 : under development
426  
427 =cut
428  
429 sub get_count_by_subclass {
430 my ($self, $dbtype, $class, $subclass) = @_;
431  
432 # argument check
433 throw("Need a dbtype (source|target).") unless ($dbtype);
434 throw("Need a class.") unless ($class);
435 throw("Need a subclass.") unless ($subclass);
436  
437 return scalar(keys %{ $self->{$dbtype}->{$class}->{$subclass} || {} });
438 }
439  
440  
441 =head2 get_count_by_class
442  
443 Arg[1] : String $dbtype - db type ('source' or 'target')
444 Arg[2] : String $class - key identifying a gene type (see class_key())
445 Example : my $num_mapped = $analyser->get_count_by_class('source',
446 'KNOWN-ensembl-protein_coding');
447 Description : Gets the number of stable Ids for a given class.
448 Return type : Int
449 Exceptions : thrown on missing arguments
450 Caller : internal
451 Status : At Risk
452 : under development
453  
454 =cut
455  
456 sub get_count_by_class {
457 my ($self, $dbtype, $class) = @_;
458  
459 # argument check
460 throw("Need a dbtype (source|target).") unless ($dbtype);
461 throw("Need a class.") unless ($class);
462  
463 return scalar(@{ $self->get_all_by_class($dbtype, $class) });
464 }
465  
466  
467 =head2 get_all_classes
468  
469 Arg[1] : String $dbtype - db type ('source' or 'target')
470 Example : foreach my $class (@{ $analyser->get_all_classes('source') }) {
471 print "$class\n";
472 }
473 Description : Gets a list of classes in the ResultAnalyser.
474 Return type : Arrayref of String
475 Exceptions : thrown on missing argument
476 Caller : internal
477 Status : At Risk
478 : under development
479  
480 =cut
481  
482 sub get_all_classes {
483 my ($self, $dbtype) = @_;
484  
485 # argument check
486 throw("Need a dbtype (source|target).") unless ($dbtype);
487  
488 return [ sort keys %{ $self->{$dbtype} || {} } ];
489 }
490  
491  
492 =head2 class_key
493  
494 Arg[1] : Bio::EnsEMBL::IdMapping::TinyGene $gene - a gene object
495 Example : my $class = $analyser->class_key($gene);
496 Description : Generates a key identifying a gene class. This identifier is
497 composed from the gene's logic naame, and biotye.
498 Return type : String
499 Exceptions : none
500 Caller : internal
501 Status : At Risk
502 : under development
503  
504 =cut
505  
506 sub class_key {
507 my ($self, $gene) = @_;
508 return join('-', map { $gene->$_ } qw(logic_name biotype));
509 }
510  
511  
512 =head2 write_results_to_file
513  
514 Example : $analyser->write_results_to_file;
515 Description : Writes the results of the result analysis to a file. This is a
516 human-readable text detailing the mapping statistics.
517 Return type : none
518 Exceptions : none
519 Caller : general
520 Status : At Risk
521 : under development
522  
523 =cut
524  
525 sub write_results_to_file {
526 my $self = shift;
527  
528 my $fh = $self->get_filehandle('gene_detailed_mapping_stats.txt', 'stats');
529  
530 my $fmt1 = "%-60s%-16s%-16s%-16s\n";
531 my $fmt2 = "%-60s%5.0f (%7s) %5.0f (%7s) %5.0f (%7s)\n";
532 my $fmt3 = "%3.2f%%";
533  
534 print $fh "Gene detailed mapping results:\n\n";
535  
536 print $fh sprintf($fmt1, "Gene type", "mapped", "lost (similar)",
537 "lost (definite)");
538  
539 print $fh ('-'x108), "\n";
540  
541 foreach my $class (@{ $self->get_all_classes('source') }) {
542 next if ($class eq 'all');
543  
544 my $total = $self->get_count_by_class('source', $class);
545  
546 # avoid division by zero error
547 unless ($total) {
548 $self->logger->warning("No count found for $class.\n", 1);
549 next;
550 }
551
552 my $mapped = $self->get_count_by_subclass('source', $class, 'mapped');
553 my $similar = $self->get_count_by_subclass('source', $class,
554 'lost_similar');
555 my $lost = $self->get_count_by_subclass('source', $class, 'lost_definite');
556  
557 print $fh sprintf($fmt2,
558 $class,
559 $mapped, sprintf($fmt3, $mapped/$total*100),
560 $similar, sprintf($fmt3, $similar/$total*100),
561 $lost, sprintf($fmt3, $lost/$total*100));
562 }
563  
564 close($fh);
565 }
566  
567  
568 =head2 create_clicklist
569  
570 Example : $analyser->create_clicklist;
571 Description : Writes an html file which contains a list of all lost genes,
572 with hyperlinks to the appropriate archive website. This is to
573 manually check lost genes.
574 Return type : none
575 Exceptions : none
576 Caller : general
577 Status : At Risk
578 : under development
579  
580 =cut
581  
582 sub create_clicklist {
583 my $self = shift;
584  
585 my $fh = $self->get_filehandle('genes_lost.html', 'stats');
586  
587 # start html output
588 print $fh qq(<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n);
589 print $fh qq(<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-gb" lang="en-gb">);
590 print $fh "<head>\n";
591 print $fh "<title>Lost genes ";
592 print $fh $self->conf->param('sourcedbname'), ' -&gt; ',
593 $self->conf->param('targetdbname');
594 print $fh "</title>\n";
595 print $fh "</head>\n<body>\n";
596  
597 my $prefix = $self->conf->param('urlprefix');
598 unless ($prefix) {
599 $self->logger->warning("No urlprefix set, clicklists might not be useable.\n", 1);
600 }
601  
602 my $navigation;
603 my $clicklist;
604  
605 foreach my $class (@{ $self->get_all_classes('source') }) {
606 next if ($class eq 'all');
607  
608 $navigation .= "$class ";
609 $clicklist .= "<h1>$class</h1>\n";
610
611 foreach my $subclass (qw(lost_similar lost_definite)) {
612  
613 # navigation
614 $navigation .= qq(<a href="#${class}-$subclass">$subclass</a> );
615
616 # clicklist
617 $clicklist .= "<h2>$subclass</h2>\n";
618  
619 foreach my $stable_id (@{ $self->get_all_by_subclass('source', $class, $subclass) }) {
620 $clicklist .= qq(<a href="${prefix}$stable_id">$stable_id</a><br />\n);
621 }
622
623 }
624  
625 $navigation .= "<br />\n";
626 }
627  
628 # print navigation and clicklist
629 print $fh "$navigation\n\n";
630 print $fh "$clicklist\n\n";
631  
632 # html footer
633 print $fh "</body></html>\n";
634  
635 close($fh);
636 }
637  
638  
639 =head2 create_mapping_summary
640  
641 Example : $analyser->create_mapping_summary();
642 Description : Writes a text file containing a summary of the mapping stats.
643 This will be emailed to the genebuilder for evaluation (you will
644 have to manually send the email, using the text in
645 "mapping_summary.txt" as the template).
646 Return type : none
647 Exceptions : none
648 Caller : general
649 Status : At Risk
650 : under development
651  
652 =cut
653  
654 sub create_mapping_summary {
655 my $self = shift;
656
657 my $fh = $self->get_filehandle('mapping_summary.txt');
658  
659 #
660 # title
661 #
662 print $fh qq(Stable ID mapping results\n);
663 print $fh qq(=========================\n\n);
664  
665 #
666 # timing
667 #
668 print $fh "Run at: ".localtime()."\n";
669 print $fh "Runtime: ";
670 print $fh $self->logger->runtime, "\n\n";
671  
672 #
673 # parameters used for this run
674 #
675 print $fh $self->conf->list_param_values;
676 print $fh "\n";
677  
678 #
679 # mapping stats
680 #
681 foreach my $type (qw(exon transcript translation gene gene_detailed)) {
682 my $filename = "${type}_mapping_stats.txt";
683
684 if ($self->file_exists($filename, 'stats')) {
685 print $fh $self->read_from_file($filename, 'stats');
686 print $fh "\n\n";
687 } else {
688 print $fh "No mapping stats found for $type.\n\n";
689 }
690 }
691  
692 #
693 # db uploads
694 #
695 my @uploads = (
696 ['stable_ids' => 'Stable IDs'],
697 ['events' => 'Stable ID events and mapping session'],
698 ['archive' => 'Gene and peptide archive'],
699 );
700
701 my $fmt1 = "%-40s%-20s\n";
702  
703 print $fh qq(Data uploaded to db:\n);
704 print $fh qq(====================\n\n);
705  
706 if ($self->conf->param('dry_run')) {
707
708 print $fh "None (dry run).\n";
709
710 } else {
711
712 foreach my $u (@uploads) {
713 my $uploaded = 'no';
714 $uploaded = 'yes' if ($self->conf->is_true("upload_".$u->[0]));
715 print $fh sprintf($fmt1, $u->[1], $uploaded);
716 }
717
718 }
719  
720 print $fh "\n";
721  
722 #
723 # stats and clicklist
724 #
725 my @output = (
726 ['stats' => 'statistics (including clicklists of deleted IDs)'],
727 ['debug' => 'detailed mapping output for debugging'],
728 ['tables' => 'data files for db upload'],
729 );
730
731 my $fmt2 = "%-20s%-50s\n";
732  
733 print $fh qq(\nOutput directories:\n);
734 print $fh qq(===================\n\n);
735  
736 print $fh sprintf($fmt2, qw(DIRECTORY DESCRIPTION));
737 print $fh ('-'x72), "\n";
738  
739 print $fh sprintf($fmt2, 'basedir', $self->conf->param('basedir'));
740  
741 foreach my $o (@output) {
742 print $fh sprintf($fmt2, '$basedir/'.$o->[0], $o->[1]);
743 }
744  
745 print $fh "\n";
746  
747 #
748 # clicklist of first 10 deleted genes
749 #
750 print $fh qq(\nFirst 10 deleted known genes:\n);
751 print $fh qq(=============================\n\n);
752  
753 my $in_fh = $self->get_filehandle('genes_lost.txt', 'debug', '<');
754 my $prefix = $self->conf->param('urlprefix');
755 my $i;
756
757 while (<$in_fh>) {
758 last if (++$i > 10);
759
760 chomp;
761 my ($stable_id, $type) = split(/\s+/);
762
763 next unless ($type eq 'known');
764  
765 print $fh sprintf($fmt2, $stable_id, "${prefix}$stable_id");
766 }
767  
768 close($in_fh);
769 close($fh);
770 }
771  
772  
773 =head2 read_from_file
774  
775 Arg[1] : String $filename - name of file to read
776 Arg[2] : (optional) String $append - directory name to append to basedir
777 Example : my $stats_text = $analyser->read_from_file('gene_mapping_stats',
778 'stats');
779 Description : Reads mapping stats from a file.
780 Return type : String
781 Exceptions : none
782 Caller : internal
783 Status : At Risk
784 : under development
785  
786 =cut
787  
788 sub read_from_file {
789 my $self = shift;
790 my $filename = shift;
791 my $append = shift;
792  
793 my $in_fh = $self->get_filehandle($filename, $append, '<');
794  
795 my $txt;
796  
797 while (<$in_fh>) {
798 $txt .= $_;
799 }
800  
801 return $txt;
802 }
803  
804 1;
805