annotate splicesitescore/score3.pl @ 8:ec97befe722b

Uploaded
author xuebing
date Sun, 01 Apr 2012 08:14:45 -0400
parents 85af77643e89
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6
85af77643e89 Uploaded
xuebing
parents:
diff changeset
1 use strict;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
2
85af77643e89 Uploaded
xuebing
parents:
diff changeset
3
85af77643e89 Uploaded
xuebing
parents:
diff changeset
4 my $inputfile = $ARGV[0];
85af77643e89 Uploaded
xuebing
parents:
diff changeset
5 my $usemaxent = 1;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
6
8
ec97befe722b Uploaded
xuebing
parents: 6
diff changeset
7 my $modelpath = "/home/wuxbl/rowley/tools/maxentscan/splicemodels/";
ec97befe722b Uploaded
xuebing
parents: 6
diff changeset
8 my @metables = &makemaxentscores($modelpath);
6
85af77643e89 Uploaded
xuebing
parents:
diff changeset
9
85af77643e89 Uploaded
xuebing
parents:
diff changeset
10 open (FILE,"<$inputfile") || die "can't open!\n";
85af77643e89 Uploaded
xuebing
parents:
diff changeset
11
85af77643e89 Uploaded
xuebing
parents:
diff changeset
12 while(<FILE>) {
85af77643e89 Uploaded
xuebing
parents:
diff changeset
13 chomp;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
14 if (/^\s*$/) { #discard blank lines;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
15 next;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
16 }
85af77643e89 Uploaded
xuebing
parents:
diff changeset
17 elsif (/^>/) { #discard comment lines;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
18 print $_."\t";
85af77643e89 Uploaded
xuebing
parents:
diff changeset
19 next;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
20 }
85af77643e89 Uploaded
xuebing
parents:
diff changeset
21 elsif (/[NQWERYUIOPLKJHFDSZXVBM]/) {
85af77643e89 Uploaded
xuebing
parents:
diff changeset
22 next;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
23 }
85af77643e89 Uploaded
xuebing
parents:
diff changeset
24 else {
85af77643e89 Uploaded
xuebing
parents:
diff changeset
25 $_ =~ s/\cM//g; #gets rid of carriage return
85af77643e89 Uploaded
xuebing
parents:
diff changeset
26 my $str = $_;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
27 print $str."\t";
85af77643e89 Uploaded
xuebing
parents:
diff changeset
28 $str = uc($str);
85af77643e89 Uploaded
xuebing
parents:
diff changeset
29 if ($usemaxent) {
85af77643e89 Uploaded
xuebing
parents:
diff changeset
30 print sprintf("%.2f",&log2(&scoreconsensus($str)*&maxentscore(&getrest($str),\@metables)))."\n";
85af77643e89 Uploaded
xuebing
parents:
diff changeset
31 }
85af77643e89 Uploaded
xuebing
parents:
diff changeset
32 }
85af77643e89 Uploaded
xuebing
parents:
diff changeset
33 }
85af77643e89 Uploaded
xuebing
parents:
diff changeset
34
85af77643e89 Uploaded
xuebing
parents:
diff changeset
35 sub hashseq{
85af77643e89 Uploaded
xuebing
parents:
diff changeset
36 #returns hash of sequence in base 4
85af77643e89 Uploaded
xuebing
parents:
diff changeset
37 # &hashseq('CAGAAGT') returns 4619
85af77643e89 Uploaded
xuebing
parents:
diff changeset
38 my $seq = shift;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
39 $seq = uc($seq);
85af77643e89 Uploaded
xuebing
parents:
diff changeset
40 $seq =~ tr/ACGT/0123/;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
41 my @seqa = split(//,$seq);
85af77643e89 Uploaded
xuebing
parents:
diff changeset
42 my $sum = 0;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
43 my $len = length($seq);
85af77643e89 Uploaded
xuebing
parents:
diff changeset
44 my @four = (1,4,16,64,256,1024,4096,16384);
85af77643e89 Uploaded
xuebing
parents:
diff changeset
45 my $i=0;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
46 while ($i<$len) {
85af77643e89 Uploaded
xuebing
parents:
diff changeset
47 $sum+= $seqa[$i] * $four[$len - $i -1] ;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
48 $i++;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
49 }
85af77643e89 Uploaded
xuebing
parents:
diff changeset
50 return $sum;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
51 }
85af77643e89 Uploaded
xuebing
parents:
diff changeset
52
85af77643e89 Uploaded
xuebing
parents:
diff changeset
53 sub makemaxentscores{
8
ec97befe722b Uploaded
xuebing
parents: 6
diff changeset
54 my $dir = shift;
6
85af77643e89 Uploaded
xuebing
parents:
diff changeset
55 my @list = ('me2x3acc1','me2x3acc2','me2x3acc3','me2x3acc4',
85af77643e89 Uploaded
xuebing
parents:
diff changeset
56 'me2x3acc5','me2x3acc6','me2x3acc7','me2x3acc8','me2x3acc9');
85af77643e89 Uploaded
xuebing
parents:
diff changeset
57 my @metables;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
58 my $num = 0 ;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
59 foreach my $file (@list) {
85af77643e89 Uploaded
xuebing
parents:
diff changeset
60 my $n = 0;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
61 open (SCOREF,"<".$dir.$file) || die "Can't open $file!\n";
85af77643e89 Uploaded
xuebing
parents:
diff changeset
62 while(<SCOREF>) {
85af77643e89 Uploaded
xuebing
parents:
diff changeset
63 chomp;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
64 $_=~ s/\s//;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
65 $metables[$num]{$n} = $_;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
66 $n++;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
67 }
85af77643e89 Uploaded
xuebing
parents:
diff changeset
68 close(SCOREF);
85af77643e89 Uploaded
xuebing
parents:
diff changeset
69 #print STDERR $file."\t".$num."\t".$n."\n";
85af77643e89 Uploaded
xuebing
parents:
diff changeset
70 $num++;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
71 }
85af77643e89 Uploaded
xuebing
parents:
diff changeset
72 return @metables;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
73 }
8
ec97befe722b Uploaded
xuebing
parents: 6
diff changeset
74
6
85af77643e89 Uploaded
xuebing
parents:
diff changeset
75 sub maxentscore{
85af77643e89 Uploaded
xuebing
parents:
diff changeset
76 my $seq = shift;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
77 my $table_ref = shift;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
78 my @metables = @$table_ref;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
79 my @sc;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
80 $sc[0] = $metables[0]{&hashseq(substr($seq,0,7))};
85af77643e89 Uploaded
xuebing
parents:
diff changeset
81 $sc[1] = $metables[1]{&hashseq(substr($seq,7,7))};
85af77643e89 Uploaded
xuebing
parents:
diff changeset
82 $sc[2] = $metables[2]{&hashseq(substr($seq,14,7))};
85af77643e89 Uploaded
xuebing
parents:
diff changeset
83 $sc[3] = $metables[3]{&hashseq(substr($seq,4,7))};
85af77643e89 Uploaded
xuebing
parents:
diff changeset
84 $sc[4] = $metables[4]{&hashseq(substr($seq,11,7))};
85af77643e89 Uploaded
xuebing
parents:
diff changeset
85 $sc[5] = $metables[5]{&hashseq(substr($seq,4,3))};
85af77643e89 Uploaded
xuebing
parents:
diff changeset
86 $sc[6] = $metables[6]{&hashseq(substr($seq,7,4))};
85af77643e89 Uploaded
xuebing
parents:
diff changeset
87 $sc[7] = $metables[7]{&hashseq(substr($seq,11,3))};
85af77643e89 Uploaded
xuebing
parents:
diff changeset
88 $sc[8] = $metables[8]{&hashseq(substr($seq,14,4))};
85af77643e89 Uploaded
xuebing
parents:
diff changeset
89 my $finalscore = $sc[0] * $sc[1] * $sc[2] * $sc[3] * $sc[4] / ($sc[5] * $sc[6] * $sc[7] * $sc[8]);
85af77643e89 Uploaded
xuebing
parents:
diff changeset
90 return $finalscore;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
91 }
85af77643e89 Uploaded
xuebing
parents:
diff changeset
92
85af77643e89 Uploaded
xuebing
parents:
diff changeset
93
85af77643e89 Uploaded
xuebing
parents:
diff changeset
94
85af77643e89 Uploaded
xuebing
parents:
diff changeset
95 sub getrest{
85af77643e89 Uploaded
xuebing
parents:
diff changeset
96 my $seq = shift;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
97 my $seq_noconsensus = substr($seq,0,18).substr($seq,20,3);
85af77643e89 Uploaded
xuebing
parents:
diff changeset
98 return $seq_noconsensus;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
99 }
85af77643e89 Uploaded
xuebing
parents:
diff changeset
100
85af77643e89 Uploaded
xuebing
parents:
diff changeset
101 sub scoreconsensus{
85af77643e89 Uploaded
xuebing
parents:
diff changeset
102 my $seq = shift;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
103 my @seqa = split(//,uc($seq));
85af77643e89 Uploaded
xuebing
parents:
diff changeset
104 my %bgd;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
105 $bgd{'A'} = 0.27;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
106 $bgd{'C'} = 0.23;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
107 $bgd{'G'} = 0.23;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
108 $bgd{'T'} = 0.27;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
109 my %cons1;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
110 $cons1{'A'} = 0.9903;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
111 $cons1{'C'} = 0.0032;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
112 $cons1{'G'} = 0.0034;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
113 $cons1{'T'} = 0.0030;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
114 my %cons2;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
115 $cons2{'A'} = 0.0027;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
116 $cons2{'C'} = 0.0037;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
117 $cons2{'G'} = 0.9905;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
118 $cons2{'T'} = 0.0030;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
119 my $addscore = $cons1{$seqa[18]} * $cons2{$seqa[19]}/ ($bgd{$seqa[18]} * $bgd{$seqa[19]});
85af77643e89 Uploaded
xuebing
parents:
diff changeset
120 return $addscore;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
121 }
85af77643e89 Uploaded
xuebing
parents:
diff changeset
122 sub log2{
85af77643e89 Uploaded
xuebing
parents:
diff changeset
123 my ($val) = @_;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
124 return log($val)/log(2);
85af77643e89 Uploaded
xuebing
parents:
diff changeset
125 }