annotate precursors.pl @ 0:87fe81de0931 draft default tip

Uploaded
author bigrna
date Sun, 04 Jan 2015 02:47:25 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
1 #!/usr/bin/perl -w
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
2 #Filename:
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
3 #Author: Tian Dongmei
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
4 #Email: tiandm@big.ac.cn
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
5 #Date: 2013/7/19
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
6 #Modified:
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
7 #Description:
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
8 my $version=1.00;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
9
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
10 use strict;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
11 use Getopt::Long;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
12 #use RNA;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
13
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
14 my %opts;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
15 GetOptions(\%opts,"map=s","g=s","d:i","f:i","o=s","e:f","s=s","h");
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
16 if (!(defined $opts{map} and defined $opts{g} and defined $opts{o} and defined $opts{s} ) || defined $opts{h}) { #necessary arguments
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
17 &usage;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
18 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
19
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
20 my $checkno=1;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
21 my $filein=$opts{'map'};
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
22 my $faout=$opts{'o'};
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
23 my $strout=$opts{'s'};
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
24 my $genome= $opts{'g'};
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
25
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
26 my $maxd=defined $opts{'d'} ? $opts{'d'} : 200;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
27 my $flank=defined $opts{'f'}? $opts{'f'} : 10;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
28
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
29 my $MAX_ENERGY=-18;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
30 if (defined $opts{'e'}) {$MAX_ENERGY=$opts{'e'};}
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
31 my $MAX_UNPAIR=5;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
32 my $MIN_PAIR=15;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
33 my $MAX_SIZEDIFF=4;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
34 my $MAX_BULGE=2;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
35 my $ASYMMETRY=5;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
36 my $MIN_UNPAIR=0;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
37 my $MIN_SPACE=5;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
38 my $MAX_SPACE=$maxd;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
39 my $FLANK=$flank;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
40
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
41 ######### load in genome sequences start ########
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
42 my %genome;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
43 my %lng;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
44 my $name;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
45 open IN,"<$genome";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
46 while (my $aline=<IN>) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
47 chomp $aline;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
48 next if($aline=~/^\#/);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
49 if ($aline=~/^>(\S+)/) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
50 $name=$1;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
51 next;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
52 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
53 $genome{$name} .=$aline;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
54 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
55 close IN;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
56 foreach my $key (keys %genome) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
57 $lng{$key}=length($genome{$key});
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
58 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
59 ####### load in genome sequences end ##########
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
60
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
61 my %breaks; ### reads number bigger than 3
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
62 open IN,"<$filein"; #input file
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
63 while (my $aline=<IN>) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
64 chomp $aline;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
65 my @tmp=split/\t/,$aline;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
66 $tmp[0]=~/_x(\d+)$/;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
67 my $no=$1;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
68 next if($no<3);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
69 #my $trand=&find_strand($tmp[9]);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
70 #my @pos=split/\.\./,$tmp[5];
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
71 my $end=$tmp[3]+length($tmp[4])-1;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
72 if($tmp[1] eq "-"){$tmp[4]=revcom($tmp[4]);}
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
73 push @{$breaks{$tmp[2]}{$tmp[1]}},[$tmp[3],$end,$no,$tmp[4]]; ### 0 base
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
74 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
75 close IN;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
76
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
77 my %cites; ### peaks
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
78 foreach my $chr (keys %breaks) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
79 foreach my $strand (keys %{$breaks{$chr}}) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
80 my @array=@{$breaks{$chr}{$strand}};
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
81 @array=sort{$a->[0]<=>$b->[0]} @array;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
82 for (my $i=0;$i<@array;$i++) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
83 my $start=$array[$i][0];my $end=$array[$i][1];
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
84 my @subarray=();
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
85 push @subarray,$array[$i];
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
86
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
87 for (my $j=$i+1;$j<@array;$j++) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
88 if ($start<$array[$j][1] && $end>$array[$j][0]) { ###overlap
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
89 push @subarray,$array[$j];
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
90 ($start,$end)=&newpos($start,$end,$array[$j][0],$array[$j][1]);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
91 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
92 else{
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
93 $i=$j-1;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
94 &find_cites(\@subarray,$chr,$strand);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
95 last;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
96 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
97 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
98 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
99 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
100 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
101
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
102 my %cluster;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
103 foreach my $chr (keys %cites) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
104 foreach my $strand (keys %{$cites{$chr}}) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
105 my @array=@{$sites{$chr}{$strand}};
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
106 @array=sort{$a->[0]<=>$b->[0]} @array;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
107 for (my $i=0;$i<@array;$i++) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
108 my $start=$array[$i][0];my $end=$array[$i][1];
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
109 my @subarray=();
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
110 push @subarray,$array[$i];
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
111
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
112 for (my $j=$i+1;$j<@array;$j++) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
113 if ($end>$array[$j][0]-$maxd) { ###distance less than 200bp
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
114 push @subarray,$array[$j];
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
115 ($start,$end)=&newpos($start,$end,$array[$j][0],$array[$j][1]);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
116 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
117 else{
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
118 @{$cluster{$chr}{$strand}{$i}}=@subarray;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
119 $i=$j-1;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
120 last;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
121 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
122 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
123 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
124
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
125 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
126 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
127
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
128
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
129 open FA,">$faout"; #output file
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
130 open STR,">$strout";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
131 foreach my $chr (keys %cluster) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
132 foreach my $strand (keys %{$cluster{$chr}}) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
133 foreach my $no (keys %{$cluster{$chr}{$strand}}) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
134 my @array2=@{$cluster{$chr}{$strand}{$no}};
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
135 @array2=sort{$a->[0]<=>$b->[0]} @array2;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
136 &excise(\@array2,$chr,$strand);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
137 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
138 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
139 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
140 close FA;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
141 close STR;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
142 sub oneCiteDn{
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
143 my ($array,$a,$chr,$strand)=@_;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
144
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
145 my $ss=$$array[$a][0]-$flank;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
146 $ss=0 if($ss<0);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
147 my $ee=$$array[$a][1]+$maxd+$flank;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
148 $ee=$lng{$chr} if($ee>$lng{$chr});
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
149
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
150 my $seq=substr($genome{$chr},$ss,$ee-$ss+1);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
151 if($strand eq "-"){$seq=revcom($seq);}
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
152
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
153 my $val=&ffw1($seq,$$array[$a][3],$chr,$strand,$ss,$ee);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
154 return $val;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
155 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
156 sub oneCiteUp{
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
157 my ($array,$a,$chr,$strand)=@_;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
158
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
159 my $ss=$$array[$a][0]-$maxd-$flank;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
160 $ss=0 if($ss<0);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
161 my $ee=$$array[$a][1]+$flank;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
162 $ee=$lng{$chr} if($ee>$lng{$chr});
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
163
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
164 my $seq=substr($genome{$chr},$ss,$ee-$ss+1);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
165 if($strand eq "-"){$seq=revcom($seq);}
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
166
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
167 my $val=&ffw1($seq,$$array[$a][3],$chr,$strand,$ss,$ee);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
168 return $val;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
169
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
170 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
171
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
172 sub twoCites{
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
173 my ($array,$a,$b,$chr,$strand)=@_;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
174
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
175 my $ss=$$array[$a][0]-$flank;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
176 $ss=0 if($ss<0);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
177 my $ee=$$array[$b][1]+$flank;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
178 $ee=$lng{$chr} if($ee>$lng{$chr});
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
179
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
180 my $seq=substr($genome{$chr},$ss,$ee-$ss+1);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
181 if($strand eq "-"){$seq=revcom($seq);}
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
182
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
183 # my( $str,$mfe)=RNA::fold($seq);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
184 # return 0 if($mfe>$MAX_ENERGY); ### minimum mfe
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
185 my $val=&ffw2($seq,$$array[$a][3],$$array[$b][3],$chr,$strand,$ss,$ee);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
186
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
187 return $val;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
188
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
189 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
190 sub excise{
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
191 my ($cluster,$chr,$strand)=@_;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
192
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
193 if(@{$cluster}==1){
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
194 $ok=&oneCiteDn($cluster,0,$chr,$strand);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
195 $ok=&oneCiteUp($cluster,0,$chr,$strand);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
196 }else{
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
197 my $peak_pos=0;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
198
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
199 for (my $i=0;$i<@{$cluster};$i++) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
200 if($$cluster[$i][2]>$$cluster[$peak_pos][2]){$peak_pos=$i;}
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
201 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
202
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
203 my $ok=0;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
204 for (my $i=0;$i<@{$cluster};$i++) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
205 next if($i==$peak_pos);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
206 if($i<$peak_pos){$ok=&twoCites($cluster,$i,$peak_pos,$chr,$strand);}
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
207 else{$ok=&twoCites($cluster,$peak_pos,$i,$chr,$strand);}
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
208 last if($ok);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
209 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
210 if (!$ok) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
211 $ok=&oneCiteDn($cluster,$peak_pos,$chr,$strand);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
212 $ok=&oneCiteUp($cluster,$peak_pos,$chr,$strand);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
213 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
214
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
215 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
216 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
217
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
218 sub ffw2{
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
219 my ($seq,$tag1,$tag2,$chr,$strand,$ss,$ee)=@_;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
220
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
221 my $N_count=$seq=~tr/N//; ## precursor sequence has not more than 5 Ns
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
222 if ($N_count > 5) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
223 return 0;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
224 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
225
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
226 my $seq_length=length $seq;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
227 # position tag1 and tag2
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
228 my $tag1_beg=index($seq,$tag1,0)+1;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
229 if ($tag1_beg < 1) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
230 warn "[ffw2] coordinate error.\n";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
231 # $fold->{reason}="coordinate error";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
232 return 0;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
233 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
234 my $tag2_beg=index($seq,$tag2,0)+1;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
235 if ($tag2_beg < 1) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
236 warn "[ffw2] coordinate error.\n";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
237 # $fold->{reason}="coordinate error";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
238 return 0;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
239 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
240 if ($tag2_beg < $tag1_beg) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
241 # swap tag1 and tag2
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
242 ($tag1,$tag2)=($tag2,$tag1);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
243 ($tag1_beg,$tag2_beg)=($tag2_beg,$tag1_beg);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
244 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
245 my $tag1_end=$tag1_beg+length($tag1)-1;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
246 my $tag2_end=$tag2_beg+length($tag2)-1;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
247 # re-clipping
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
248 my $beg=$tag1_beg-$FLANK; $beg=1 if $beg < 1;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
249 my $end=$tag2_end+$FLANK; $end=$seq_length if $end > $seq_length;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
250 $seq=substr($seq,$beg-1,$end-$beg+1);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
251 $seq_length=length $seq;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
252 # re-reposition
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
253 $tag1_beg=index($seq,$tag1,0)+1;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
254 if ($tag1_beg < 1) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
255 warn "[ffw2] coordinate error.\n";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
256 # $fold->{reason}="coordinate error";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
257 return 0;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
258 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
259
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
260 $tag2_beg=index($seq,$tag2,0)+1;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
261 if ($tag2_beg < 1) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
262 warn "[ffw2] coordinate error.\n";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
263 # $fold->{reason}="coordinate error";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
264 return 0;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
265 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
266 $tag1_end=$tag1_beg+length($tag1)-1;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
267 $tag2_end=$tag2_beg+length($tag2)-1;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
268
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
269 # fold
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
270 #my ($struct,$mfe)=RNA::fold($seq);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
271 my $rnafold=`perl -e 'print "$seq"' | RNAfold --noPS`;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
272 my @rawfolds=split/\s+/,$rnafold;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
273 my $struct=$rawfolds[1];
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
274 my $mfe=$rawfolds[-1];
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
275 $mfe=~s/\(//;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
276 $mfe=~s/\)//;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
277 #$mfe=sprintf "%.2f", $mfe;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
278 if ($mfe > $MAX_ENERGY) {return 0;}
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
279
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
280 # tag1
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
281 my $tag1_length=$tag1_end-$tag1_beg+1;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
282 my $tag1_struct=substr($struct,$tag1_beg-1,$tag1_length);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
283 my $tag1_arm=which_arm($tag1_struct);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
284 my $tag1_unpair=$tag1_struct=~tr/.//;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
285 my $tag1_pair=$tag1_length-$tag1_unpair;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
286 my $tag1_max_bulge=biggest_bulge($tag1_struct);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
287 if ($tag1_arm ne "5p") { return 0;} # tag not in stem
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
288 # if ($tag1_unpair > $MAX_UNPAIR) {$fold->{reason}="unpair=$tag1_unpair ($MAX_UNPAIR)"; return $pass}
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
289 if ($tag1_pair < $MIN_PAIR) {return 0;}
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
290 if ($tag1_max_bulge > $MAX_BULGE) {return 0;}
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
291
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
292 # tag2
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
293 my $tag2_length=$tag2_end-$tag2_beg+1;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
294 my $tag2_struct=substr($struct,$tag2_beg-1,$tag2_length);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
295 my $tag2_arm=which_arm($tag2_struct);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
296 my $tag2_unpair=$tag2_struct=~tr/.//;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
297 my $tag2_pair=$tag2_length-$tag2_unpair;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
298 my $tag2_max_bulge=biggest_bulge($tag2_struct);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
299 if ($tag2_arm ne "3p") {return 0;} # star not in stem
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
300 # if ($tag2_unpair > $MAX_UNPAIR) {$fold->{reason}="unpair=$tag2_unpair ($MAX_UNPAIR)"; return $pass}
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
301 if ($tag2_pair < $MIN_PAIR) {return 0;}
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
302 if ($tag2_max_bulge > $MAX_BULGE) {return 0;}
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
303
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
304 # space size between miR and miR*
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
305 my $space=$tag2_beg-$tag1_end-1;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
306 if ($space < $MIN_SPACE) {return 0;}
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
307 if ($space > $MAX_SPACE) {return 0;}
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
308
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
309 # size diff of miR and miR*
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
310 my $size_diff=abs($tag1_length-$tag2_length);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
311 if ($size_diff > $MAX_SIZEDIFF) {return 0;}
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
312
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
313 # build base pairing table
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
314 my %pairtable;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
315 &parse_struct($struct,\%pairtable); # coords count from 1
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
316
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
317 my $asy1=get_asy(\%pairtable,$tag1_beg,$tag1_end);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
318 my $asy2=get_asy(\%pairtable,$tag2_beg,$tag2_end);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
319 my $asy=($asy1 < $asy2) ? $asy1 : $asy2;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
320 if ($asy > $ASYMMETRY) {return 0}
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
321
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
322 # duplex fold, determine whether two matures like a miR/miR* ike duplex
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
323 my ($like_mir_duplex1,$duplex_pair,$overhang1,$overhang2)=likeMirDuplex1($tag1,$tag2);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
324 # parse hairpin, determine whether two matures form miR/miR* duplex in hairpin context
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
325 my ($like_mir_duplex2,$duplex_pair2,$overhang_b,$overhang_t)=likeMirDuplex2(\%pairtable,$tag1_beg,$tag1_end,$tag2_beg,$tag2_end);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
326 if ($like_mir_duplex1==0 && $like_mir_duplex2==0) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
327 return 0;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
328 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
329
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
330 print FA ">$chr:$strand:$ss..$ee\n$seq\n";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
331 print STR ">$chr:$strand:$ss..$ee\n$seq\n$struct\t($mfe)\n";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
332
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
333 return 1;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
334 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
335
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
336 sub ffw1{
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
337 my ($seq,$tag,$chr,$strand,$ss,$ee)=@_;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
338 my $pass=0;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
339
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
340 my $N_count=$seq=~tr/N//;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
341 if ($N_count > 5) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
342 return 0;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
343 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
344
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
345 my $seq_length=length $seq;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
346 my $tag_length=length $tag;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
347
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
348 # position
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
349 my $tag_beg=index($seq,$tag,0)+1;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
350 if ($tag_beg < 1) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
351 warn "[ffw1] coordinate error.\n";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
352 return $pass;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
353 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
354 my $tag_end=$tag_beg+length($tag)-1;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
355
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
356
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
357 # define candidate precursor by hybrid short arm to long arm, not solid enough
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
358 my($beg,$end)=define_precursor($seq,$tag);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
359 if (not defined $beg) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
360 return $pass;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
361 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
362 if (not defined $end) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
363 return $pass;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
364 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
365 $seq=substr($seq,$beg-1,$end-$beg+1);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
366 $seq_length=length $seq;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
367
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
368
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
369 # fold
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
370 #my ($struct,$mfe)=RNA::fold($seq);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
371 my $rnafold=`perl -e 'print "$seq"' | RNAfold --noPS`;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
372 my @rawfolds=split/\s+/,$rnafold;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
373 my $struct=$rawfolds[1];
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
374 my $mfe=$rawfolds[-1];
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
375 $mfe=~s/\(//;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
376 $mfe=~s/\)//;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
377
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
378 if ($mfe > $MAX_ENERGY) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
379 $pass=0;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
380 return $pass;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
381 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
382
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
383 # reposition
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
384 $tag_beg=index($seq,$tag,0)+1;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
385 if ($tag_beg < 1) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
386 warn "[ffw1] coordinate error.\n";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
387 return 0;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
388 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
389 $tag_end=$tag_beg+length($tag)-1;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
390
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
391 my $tag_struct=substr($struct,$tag_beg-1,$tag_length);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
392 my $tag_arm=which_arm($tag_struct);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
393 my $tag_unpair=$tag_struct=~tr/.//;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
394 my $tag_pair=$tag_length-$tag_unpair;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
395 my $tag_max_bulge=biggest_bulge($tag_struct);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
396 if ($tag_arm eq "-") { return $pass;}
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
397 # if ($tag_unpair > $MAX_UNPAIR) {$fold->{reason}="unpair=$tag_unpair ($MAX_UNPAIR)"; return $pass}
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
398 if ($tag_pair < $MIN_PAIR) { return $pass;}
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
399 if ($tag_max_bulge > $MAX_BULGE) {return $pass;}
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
400
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
401 # build base pairing table
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
402 my %pairtable;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
403 &parse_struct($struct,\%pairtable); # coords count from 1
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
404
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
405 # get star
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
406 my ($star_beg,$star_end)=get_star(\%pairtable,$tag_beg,$tag_end);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
407 my $star=substr($seq,$star_beg-1,$star_end-$star_beg+1);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
408 my $star_length=$star_end-$star_beg+1;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
409 my $star_struct=substr($struct,$star_beg-1,$star_end-$star_beg+1);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
410 my $star_arm=which_arm($star_struct);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
411 my $star_unpair=$star_struct=~tr/.//;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
412 my $star_pair=$star_length-$star_unpair;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
413 my $star_max_bulge=biggest_bulge($star_struct);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
414 if ($star_arm eq "-") { return $pass;}
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
415 # if ($star_unpair > $MAX_UNPAIR) {$fold->{reason}="unpair=$star_unpair ($MAX_UNPAIR)"; return $pass}
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
416 if ($star_pair < $MIN_PAIR) {return $pass;}
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
417 if ($star_max_bulge > $MAX_BULGE) {return $pass;}
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
418
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
419 if ($tag_arm eq $star_arm) {return $pass;}
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
420
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
421 # space size between miR and miR*
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
422 my $space;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
423 if ($tag_beg < $star_beg) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
424 $space=$star_beg-$tag_end-1;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
425 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
426 else {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
427 $space=$tag_beg-$star_end-1;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
428 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
429 if ($space < $MIN_SPACE) { return $pass;}
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
430 if ($space > $MAX_SPACE) { return $pass;}
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
431
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
432 # size diff
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
433 my $size_diff=abs($tag_length-$star_length);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
434 if ($size_diff > $MAX_SIZEDIFF) { return $pass;}
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
435
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
436 # asymmetry
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
437 my $asy=get_asy(\%pairtable,$tag_beg,$tag_end);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
438 if ($asy > $ASYMMETRY) {return $pass;}
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
439
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
440 $pass=1;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
441 print FA ">$chr:$strand:$ss..$ee\n$seq\n";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
442 print STR ">$chr:$strand:$ss..$ee\n$seq\n$struct\t($mfe)\n";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
443 return $pass;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
444
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
445 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
446 sub get_star {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
447 my($table,$beg,$end)=@_;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
448
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
449 my ($s1,$e1,$s2,$e2); # s1 pair to s2, e1 pair to e2
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
450 foreach my $i ($beg..$end) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
451 if (defined $table->{$i}) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
452 my $j=$table->{$i};
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
453 $s1=$i;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
454 $s2=$j;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
455 last;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
456 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
457 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
458 foreach my $i (reverse ($beg..$end)) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
459 if (defined $table->{$i}) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
460 my $j=$table->{$i};
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
461 $e1=$i;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
462 $e2=$j;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
463 last;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
464 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
465 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
466 # print "$s1,$e1 $s2,$e2\n";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
467
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
468 # correct terminus
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
469 my $off1=$s1-$beg;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
470 my $off2=$end-$e1;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
471 $s2+=$off1;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
472 $s2+=2; # 081009
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
473 $e2-=$off2; $e2=1 if $e2 < 1;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
474 $e2+=2; $e2=1 if $e2 < 1; # 081009
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
475 ($s2,$e2)=($e2,$s2) if ($s2 > $e2);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
476 return ($s2,$e2);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
477 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
478
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
479 sub define_precursor {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
480 my $seq=shift;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
481 my $tag=shift;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
482
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
483 my $seq_length=length $seq;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
484 my $tag_length=length $tag;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
485 my $tag_beg=index($seq,$tag,0)+1;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
486 my $tag_end=$tag_beg+$tag_length-1;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
487
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
488 # split the candidate region into short arm and long arm
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
489 my $tag_arm;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
490 my ($larm,$larm_beg,$larm_end);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
491 my ($sarm,$sarm_beg,$sarm_end);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
492 if ($tag_beg-1 < $seq_length-$tag_end) { # on 5' arm
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
493 $sarm=substr($seq,0,$tag_end);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
494 $larm=substr($seq,$tag_end);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
495 $sarm_beg=1;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
496 $sarm_end=$tag_end;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
497 $larm_beg=$tag_end+1;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
498 $larm_end=$seq_length;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
499 $tag_arm="5p";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
500 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
501 else {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
502 $larm=substr($seq,0,$tag_beg-1); # on 3' arm
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
503 $sarm=substr($seq,$tag_beg-1);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
504 $larm_beg=1;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
505 $larm_end=$tag_beg-1;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
506 $sarm_beg=$tag_beg;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
507 $sarm_end=$seq_length;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
508 $tag_arm="3p";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
509 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
510
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
511 # print "$sarm_beg,$sarm_end $sarm\n";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
512 # print "$larm_beg,$larm_end $larm\n";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
513
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
514 # clipping short arm
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
515 if ($tag_arm eq "5p") {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
516 $sarm_beg=$tag_beg-$flank; $sarm_beg=1 if $sarm_beg < 1;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
517 $sarm=substr($seq,$sarm_beg-1,$sarm_end-$sarm_beg+1);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
518 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
519 else {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
520 $sarm_end=$tag_end+$flank; $sarm_end=$seq_length if $sarm_end > $seq_length;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
521 $sarm=substr($seq,$sarm_beg-1,$sarm_end-$sarm_beg+1);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
522 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
523 # print "$sarm_beg,$sarm_end $sarm\n";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
524 # print "$larm_beg,$larm_end $larm\n";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
525
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
526 # define the precursor by hybriding short arm to long arm
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
527 =cut #modify in 2014-10-28
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
528 my $duplex=RNA::duplexfold($sarm,$larm);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
529 my $struct=$duplex->{structure};
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
530 my $energy=sprintf "%.2f", $duplex->{energy};
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
531 my ($str1,$str2)=split(/&/,$struct);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
532 my $pair=$str1=~tr/(//;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
533 # print "pair=$pair\n";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
534 my $beg1=$duplex->{i}+1-length($str1);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
535 my $end1=$duplex->{i};
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
536 my $beg2=$duplex->{j};
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
537 my $end2=$duplex->{j}+length($str2)-1;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
538 =cut
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
539 ###### new codes begin
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
540 my $duplex=`perl -e 'print "$sarm\n$larm"' | RNAduplex`;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
541 #(.(.(((.....(((.&))))))...).). 1,16 : 1,13 (-7.20)
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
542 my @tmpduplex=split/\s+/,$duplex;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
543 my $struct=$tmpduplex[0];
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
544 $tmpduplex[-1]=~s/[(|)]//g;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
545 my $energy=$tmpduplex[-1];
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
546 my ($str1,$str2)=split(/&/,$struct);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
547 my $pair=$str1=~tr/(//;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
548 my ($beg1,$end1)=split/,/,$tmpduplex[1];
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
549 my ($beg2,$end2)=split/,/,$tmpduplex[3];
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
550 ######## new codes end
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
551
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
552 # print "$beg1:$end1 $beg2:$end2\n";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
553 # transform coordinates
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
554 $beg1=$beg1+$sarm_beg-1;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
555 $end1=$end1+$sarm_beg-1;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
556 $beg2=$beg2+$larm_beg-1;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
557 $end2=$end2+$larm_beg-1;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
558 # print "$beg1:$end1 $beg2:$end2\n";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
559
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
560 my $off5p=$beg1-$sarm_beg;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
561 my $off3p=$sarm_end-$end1;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
562 $beg2-=$off3p; $beg2=1 if $beg2 < 1;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
563 $end2+=$off5p; $end2=$seq_length if $end2 > $seq_length;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
564
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
565 # print "$beg1:$end1 $beg2:$end2\n";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
566
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
567 my $beg=$sarm_beg < $beg2 ? $sarm_beg : $beg2;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
568 my $end=$sarm_end > $end2 ? $sarm_end : $end2;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
569
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
570 return if $pair < $MIN_PAIR;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
571 # print "$beg,$end\n";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
572 return ($beg,$end);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
573 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
574
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
575
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
576 # duplex fold, judge whether two short seqs like a miRNA/miRNA* duplex
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
577 sub likeMirDuplex1 {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
578 my $seq1=shift;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
579 my $seq2=shift;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
580 my $like_mir_duplex=1;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
581
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
582 my $length1=length $seq1;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
583 my $length2=length $seq2;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
584 =cut
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
585 my $duplex=RNA::duplexfold($seq1, $seq2);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
586 my $duplex_struct=$duplex->{structure};
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
587 my $duplex_energy=sprintf "%.2f", $duplex->{energy};
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
588 my ($str1,$str2)=split(/&/,$duplex_struct);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
589 my $beg1=$duplex->{i}+1-length($str1);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
590 my $end1=$duplex->{i};
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
591 my $beg2=$duplex->{j};
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
592 my $end2=$duplex->{j}+length($str2)-1;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
593 =cut
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
594 my $duplex=`perl -e 'print "$seq1\n$seq2"' | RNAduplex`;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
595 #(.(.(((.....(((.&))))))...).). 1,16 : 1,13 (-7.20)
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
596 my @tmpduplex=split/\s+/,$duplex;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
597 my $duplex_struct=$tmpduplex[0];
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
598 $tmpduplex[-1]=~s/[(|)]//g;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
599 my $duplex_energy=$tmpduplex[-1];
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
600 my ($str1,$str2)=split(/&/,$duplex_struct);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
601 #my $pair=$str1=~tr/(//;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
602 my ($beg1,$end1)=split/,/,$tmpduplex[1];
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
603 my ($beg2,$end2)=split/,/,$tmpduplex[3];
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
604
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
605 # revise beg1, end1, beg2, end2
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
606 $str1=~/^(\.*)/;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
607 $beg1+=length($1);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
608 $str1=~/(\.*)$/;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
609 $end1-=length($1);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
610 $str2=~/^(\.*)/;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
611 $beg2+=length($1);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
612 $str2=~/(\.*)$/;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
613 $end2-=length($1);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
614
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
615 my $pair_num=$str1=~tr/(//;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
616 my $overhang1=($length2-$end2)-($beg1-1); # 3' overhang at hairpin bottom
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
617 my $overhang2=($length1-$end1)-($beg2-1); # 3' overhang at hairpin neck
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
618 # print $pair_num,"\n";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
619 # print $overhang1,"\n";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
620 # print $overhang2,"\n";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
621 if ($pair_num < 13) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
622 $like_mir_duplex=0;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
623 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
624 if ($overhang1 < 0 || $overhang2 < 0 ) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
625 $like_mir_duplex=0;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
626 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
627 if ($overhang1 > 4 || $overhang2 > 4) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
628 $like_mir_duplex=0;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
629 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
630 return ($like_mir_duplex,$pair_num,$overhang1,$overhang2);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
631 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
632
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
633 # judge whether two matures form miR/miR* duplex, in hairpin context
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
634 sub likeMirDuplex2 {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
635 my ($table,$beg1,$end1,$beg2,$end2)=@_;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
636 my $like_mir_duplex=1;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
637
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
638 # s1 e1
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
639 # 5 ----------------------------3
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
640 # | | |||| ||| |
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
641 #3 -------------------------------5
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
642 # e2 s2
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
643
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
644 my $pair_num=0;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
645 my $overhang1=0;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
646 my $overhang2=0;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
647 my ($s1,$e1,$s2,$e2);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
648 foreach my $i ($beg1..$end1) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
649 if (defined $table->{$i}) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
650 my $j=$table->{$i};
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
651 if ($j <= $end2 && $j >= $beg2) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
652 $s1=$i;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
653 $e2=$j;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
654 last;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
655 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
656 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
657 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
658 foreach my $i (reverse ($beg1..$end1)) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
659 if (defined $table->{$i}) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
660 my $j=$table->{$i};
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
661 if ($j <= $end2 && $j >= $beg2) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
662 $e1=$i;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
663 $s2=$j;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
664 last;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
665 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
666 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
667 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
668
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
669 # print "$beg1,$end1 $s1,$e1\n";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
670 # print "$beg2,$end2 $s2,$e2\n";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
671
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
672 foreach my $i ($beg1..$end1) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
673 if (defined $table->{$i}) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
674 my $j=$table->{$i};
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
675 if ($j <= $end2 && $j >= $beg2) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
676 ++$pair_num;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
677 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
678 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
679 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
680 if (defined $s1 && defined $e2) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
681 $overhang1=($end2-$e2)-($s1-$beg1);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
682 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
683 if (defined $e1 && defined $s2) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
684 $overhang2=($end1-$e1)-($s2-$beg2);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
685 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
686
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
687 if ($pair_num < 13) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
688 $like_mir_duplex=0;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
689 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
690 if ($overhang1 < 0 && $overhang2 < 0) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
691 $like_mir_duplex=0;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
692 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
693 return ($like_mir_duplex,$pair_num,$overhang1,$overhang2);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
694 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
695 sub parse_struct {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
696 my $struct=shift;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
697 my $table=shift;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
698
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
699 my @t=split('',$struct);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
700 my @lbs; # left brackets
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
701 foreach my $k (0..$#t) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
702 if ($t[$k] eq "(") {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
703 push @lbs, $k+1;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
704 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
705 elsif ($t[$k] eq ")") {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
706 my $lb=pop @lbs;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
707 my $rb=$k+1;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
708 $table->{$lb}=$rb;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
709 $table->{$rb}=$lb;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
710 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
711 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
712 if (@lbs) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
713 warn "unbalanced RNA struct.\n";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
714 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
715 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
716 sub which_arm {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
717 my $substruct=shift;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
718 my $arm;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
719 if ($substruct=~/\(/ && $substruct=~/\)/) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
720 $arm="-";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
721 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
722 elsif ($substruct=~/\(/) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
723 $arm="5p";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
724 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
725 else {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
726 $arm="3p";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
727 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
728 return $arm;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
729 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
730 sub biggest_bulge {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
731 my $struct=shift;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
732 my $bulge_size=0;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
733 my $max_bulge=0;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
734 while ($struct=~/(\.+)/g) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
735 $bulge_size=length $1;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
736 if ($bulge_size > $max_bulge) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
737 $max_bulge=$bulge_size;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
738 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
739 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
740 return $max_bulge;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
741 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
742 sub get_asy {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
743 my($table,$a1,$a2)=@_;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
744 my ($pre_i,$pre_j);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
745 my $asymmetry=0;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
746 foreach my $i ($a1..$a2) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
747 if (defined $table->{$i}) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
748 my $j=$table->{$i};
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
749 if (defined $pre_i && defined $pre_j) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
750 my $diff=($i-$pre_i)+($j-$pre_j);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
751 $asymmetry += abs($diff);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
752 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
753 $pre_i=$i;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
754 $pre_j=$j;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
755 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
756 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
757 return $asymmetry;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
758 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
759
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
760 sub peaks{
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
761 my @cluster=@{$_[0]};
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
762
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
763 return if(@cluster<1);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
764
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
765 my $max=0; my $index=-1;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
766 for (my $i=0;$i<@cluster;$i++) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
767 if($cluster[$i][2]>$max){
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
768 $max=$cluster[$i][2];
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
769 $index=$i;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
770 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
771 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
772 # &excise(\@cluster,$index,$_[1],$_[2]);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
773 return($index);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
774 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
775
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
776 sub find_cites{
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
777 my @tmp=@{$_[0]};
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
778 my $i=&peaks(\@tmp);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
779
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
780 my $start=$tmp[$i][0];
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
781 my $total=0; my $node5=0;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
782 for (my $j=0;$j<@tmp ;$j++) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
783 $total+=$tmp[$j][2];
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
784 $node5 +=$tmp[$j][2] if($tmp[$j][0]-$start<=2 && $tmp[$j][0]-$start>=-2);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
785 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
786 push @{$cites{$_[1]}{$_[2]}},$tmp[$i] if($node5/$total>0.80 && $tmp[$i][2]/$node5>0.5);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
787 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
788
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
789 sub newpos{
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
790 my ($a,$b,$c,$d)=@_;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
791 my $s= $a>$c ? $c : $a;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
792 my $e=$b>$d ? $b : $d;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
793 return($s,$e);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
794 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
795
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
796 sub rev{
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
797
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
798 my($sequence)=@_;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
799
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
800 my $rev=reverse $sequence;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
801
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
802 return $rev;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
803 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
804
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
805 sub com{
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
806
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
807 my($sequence)=@_;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
808
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
809 $sequence=~tr/acgtuACGTU/TGCAATGCAA/;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
810
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
811 return $sequence;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
812 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
813
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
814 sub revcom{
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
815
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
816 my($sequence)=@_;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
817
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
818 my $revcom=rev(com($sequence));
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
819
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
820 return $revcom;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
821 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
822
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
823 sub find_strand{
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
824
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
825 #A subroutine to find the strand, parsing different blast formats
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
826 my($other)=@_;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
827
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
828 my $strand="+";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
829
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
830 if($other=~/-/){
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
831 $strand="-";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
832 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
833
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
834 if($other=~/minus/i){
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
835 $strand="-";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
836 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
837
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
838 return($strand);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
839 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
840 sub usage{
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
841 print <<"USAGE";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
842 Version $version
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
843 Usage:
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
844 $0 -map -g -d -f -o -s -e
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
845 options:
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
846 -map input file# align result # bst. format
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
847 -g input file # genome sequence fasta format
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
848 -d <int> Maximal space between miRNA and miRNA* (200)
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
849 -f <int> Flank sequence length of miRNA precursor (10)
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
850 -o output file# percursor fasta file
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
851 -s output file# precursor structure file
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
852 -e <folat> Maximal free energy allowed for a miRNA precursor (-18 kcal/mol)
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
853
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
854 -h help
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
855 USAGE
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
856 exit(1);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
857 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
858