EnsEMBL/IdMapping/ResultAnalyser.pm untested

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