ensembl-hive  2.7.0
conservation_statistics.pl
Go to the documentation of this file.
1 #!/usr/bin/env perl
2 # See the NOTICE file distributed with this work for additional information
3 # regarding copyright ownership.
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 
17 
18 ## Script used in conjunction with exon_conservation_check.pl. Requires
19 ## Tie::IxHash for key ordering.
20 
21 ## RUN:
22 ## conservation_statistics.pl my_conservation.log
23 
24 use strict;
25 use warnings;
26 use Tie::IxHash;
27 
28 tie my %exon_states, 'Tie::IxHash', (
29  '!!' => 'Protein Coding MisMatch',
30  '%%' => 'Non-Coding MisMatch',
31  '??' => 'Missed mapping',
32  '&&' => 'Eval error'
33 );
34 tie my %transcript_states, 'Tie::IxHash', (
35  '@@' => 'Protein Coding Protein MisMatch',
36  ';;' => 'Protein Coding cDNA MisMatch',
37  '**' => 'Non-Coding MisMatch',
38  'XX' => 'Missed mapping',
39  '^^' => 'Eval error'
40 );
41 
42 my $file = $ARGV[0];
43 die "Cannot find $file" if ! -f $file;
44 my %states = map { $_, 0 } (keys %exon_states, keys %transcript_states);
45 my %totals;
46 open my $fh, '<', $file or die "Cannot open file '$file': $!";
47 while(my $line = <$fh>) {
48  chomp $line;
49  if($line =~ /(^[!%?&@;*X^]{2})/xms) {
50  $states{$1}++;
51  next;
52  }
53  if($line =~ /^Total ((?:exons|transcripts)) : (\d+)$/) {
54  $totals{$1} = $2;
55  }
56 }
57 close $fh;
58 
59 my $format = "%s : %d (%.2f%%)\n";
60 
61 print "Exon summary\n";
62 foreach my $key (keys %exon_states) {
63  my $count = $states{$key};
64  my $percentage = ($count / $totals{exons})*100;
65  printf $format, $exon_states{$key}, $count, $percentage;
66 }
67 
68 print "\nTranscript summary\n";
69 foreach my $key (keys %transcript_states) {
70  my $count = $states{$key};
71  my $percentage = ($count / $totals{transcripts})*100;
72  printf $format, $transcript_states{$key}, $count, $percentage;
73 }
map
public map()