annotate splicesitescore/score3.pl @ 7:3fd430270c0c

Uploaded
author xuebing
date Sun, 01 Apr 2012 01:59:22 -0400
parents 85af77643e89
children ec97befe722b
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
85af77643e89 Uploaded
xuebing
parents:
diff changeset
7
85af77643e89 Uploaded
xuebing
parents:
diff changeset
8 my @metables = &makemaxentscores;
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{
85af77643e89 Uploaded
xuebing
parents:
diff changeset
54 my $dir = "splicemodels/";
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 }
85af77643e89 Uploaded
xuebing
parents:
diff changeset
74 sub makewmmscores{
85af77643e89 Uploaded
xuebing
parents:
diff changeset
75 my $dir = "splicemodels/";
85af77643e89 Uploaded
xuebing
parents:
diff changeset
76 my @list = ('me1s0acc1','me1s0acc2','me1s0acc3','me1s0acc4',
85af77643e89 Uploaded
xuebing
parents:
diff changeset
77 'me1s0acc5','me1s0acc6','me1s0acc7','me1s0acc8','me1s0acc9');
85af77643e89 Uploaded
xuebing
parents:
diff changeset
78 my @metables;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
79 my $num = 0 ;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
80 foreach my $file (@list) {
85af77643e89 Uploaded
xuebing
parents:
diff changeset
81 my $n = 0;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
82 open (SCOREF,"<".$dir.$file) || die "Can't open $file!\n";
85af77643e89 Uploaded
xuebing
parents:
diff changeset
83 while(<SCOREF>) {
85af77643e89 Uploaded
xuebing
parents:
diff changeset
84 chomp;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
85 $_=~ s/\s//;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
86 $metables[$num]{$n} = $_;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
87 $n++;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
88 }
85af77643e89 Uploaded
xuebing
parents:
diff changeset
89 close(SCOREF);
85af77643e89 Uploaded
xuebing
parents:
diff changeset
90 #print STDERR $file."\t".$num."\t".$n."\n";
85af77643e89 Uploaded
xuebing
parents:
diff changeset
91 $num++;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
92 }
85af77643e89 Uploaded
xuebing
parents:
diff changeset
93 return @metables;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
94 }
85af77643e89 Uploaded
xuebing
parents:
diff changeset
95 sub makemmscores{
85af77643e89 Uploaded
xuebing
parents:
diff changeset
96 my $dir = "splicemodels/";
85af77643e89 Uploaded
xuebing
parents:
diff changeset
97 my @list = ('me2s0acc1','me2s0acc2','me2s0acc3','me2s0acc4',
85af77643e89 Uploaded
xuebing
parents:
diff changeset
98 'me2s0acc5','me2s0acc6','me2s0acc7','me2s0acc8','me2s0acc9');
85af77643e89 Uploaded
xuebing
parents:
diff changeset
99 my @metables;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
100 my $num = 0 ;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
101 foreach my $file (@list) {
85af77643e89 Uploaded
xuebing
parents:
diff changeset
102 my $n = 0;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
103 open (SCOREF,"<".$dir.$file) || die "Can't open $file!\n";
85af77643e89 Uploaded
xuebing
parents:
diff changeset
104 while(<SCOREF>) {
85af77643e89 Uploaded
xuebing
parents:
diff changeset
105 chomp;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
106 $_=~ s/\s//;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
107 $metables[$num]{$n} = $_;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
108 $n++;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
109 }
85af77643e89 Uploaded
xuebing
parents:
diff changeset
110 close(SCOREF);
85af77643e89 Uploaded
xuebing
parents:
diff changeset
111 #print STDERR $file."\t".$num."\t".$n."\n";
85af77643e89 Uploaded
xuebing
parents:
diff changeset
112 $num++;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
113 }
85af77643e89 Uploaded
xuebing
parents:
diff changeset
114 return @metables;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
115 }
85af77643e89 Uploaded
xuebing
parents:
diff changeset
116 sub maxentscore{
85af77643e89 Uploaded
xuebing
parents:
diff changeset
117 my $seq = shift;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
118 my $table_ref = shift;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
119 my @metables = @$table_ref;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
120 my @sc;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
121 $sc[0] = $metables[0]{&hashseq(substr($seq,0,7))};
85af77643e89 Uploaded
xuebing
parents:
diff changeset
122 $sc[1] = $metables[1]{&hashseq(substr($seq,7,7))};
85af77643e89 Uploaded
xuebing
parents:
diff changeset
123 $sc[2] = $metables[2]{&hashseq(substr($seq,14,7))};
85af77643e89 Uploaded
xuebing
parents:
diff changeset
124 $sc[3] = $metables[3]{&hashseq(substr($seq,4,7))};
85af77643e89 Uploaded
xuebing
parents:
diff changeset
125 $sc[4] = $metables[4]{&hashseq(substr($seq,11,7))};
85af77643e89 Uploaded
xuebing
parents:
diff changeset
126 $sc[5] = $metables[5]{&hashseq(substr($seq,4,3))};
85af77643e89 Uploaded
xuebing
parents:
diff changeset
127 $sc[6] = $metables[6]{&hashseq(substr($seq,7,4))};
85af77643e89 Uploaded
xuebing
parents:
diff changeset
128 $sc[7] = $metables[7]{&hashseq(substr($seq,11,3))};
85af77643e89 Uploaded
xuebing
parents:
diff changeset
129 $sc[8] = $metables[8]{&hashseq(substr($seq,14,4))};
85af77643e89 Uploaded
xuebing
parents:
diff changeset
130 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
131 return $finalscore;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
132 }
85af77643e89 Uploaded
xuebing
parents:
diff changeset
133
85af77643e89 Uploaded
xuebing
parents:
diff changeset
134
85af77643e89 Uploaded
xuebing
parents:
diff changeset
135
85af77643e89 Uploaded
xuebing
parents:
diff changeset
136 sub getrest{
85af77643e89 Uploaded
xuebing
parents:
diff changeset
137 my $seq = shift;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
138 my $seq_noconsensus = substr($seq,0,18).substr($seq,20,3);
85af77643e89 Uploaded
xuebing
parents:
diff changeset
139 return $seq_noconsensus;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
140 }
85af77643e89 Uploaded
xuebing
parents:
diff changeset
141
85af77643e89 Uploaded
xuebing
parents:
diff changeset
142 sub scoreconsensus{
85af77643e89 Uploaded
xuebing
parents:
diff changeset
143 my $seq = shift;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
144 my @seqa = split(//,uc($seq));
85af77643e89 Uploaded
xuebing
parents:
diff changeset
145 my %bgd;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
146 $bgd{'A'} = 0.27;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
147 $bgd{'C'} = 0.23;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
148 $bgd{'G'} = 0.23;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
149 $bgd{'T'} = 0.27;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
150 my %cons1;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
151 $cons1{'A'} = 0.9903;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
152 $cons1{'C'} = 0.0032;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
153 $cons1{'G'} = 0.0034;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
154 $cons1{'T'} = 0.0030;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
155 my %cons2;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
156 $cons2{'A'} = 0.0027;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
157 $cons2{'C'} = 0.0037;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
158 $cons2{'G'} = 0.9905;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
159 $cons2{'T'} = 0.0030;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
160 my $addscore = $cons1{$seqa[18]} * $cons2{$seqa[19]}/ ($bgd{$seqa[18]} * $bgd{$seqa[19]});
85af77643e89 Uploaded
xuebing
parents:
diff changeset
161 return $addscore;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
162 }
85af77643e89 Uploaded
xuebing
parents:
diff changeset
163 sub log2{
85af77643e89 Uploaded
xuebing
parents:
diff changeset
164 my ($val) = @_;
85af77643e89 Uploaded
xuebing
parents:
diff changeset
165 return log($val)/log(2);
85af77643e89 Uploaded
xuebing
parents:
diff changeset
166 }