annotate quantify.pl @ 23:45de5e1ff487 draft

Deleted selected files
author big-tiandm
date Fri, 25 Jul 2014 05:57:27 -0400
parents a79212816cbc
children 0c4e11018934
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
1 #!/usr/bin/perl -w
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
2 #Filename:
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
3 #Author: Tian Dongmei
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
4 #Email: tiandm@big.ac.cn
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
5 #Date: 2013/7/19
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
6 #Modified:
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
7 #Description:
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
8 my $version=1.00;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
9
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
10 use File::Path;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
11 use strict;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
12 use File::Basename;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
13 #use Getopt::Std;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
14 use Getopt::Long;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
15 use RNA;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
16
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
17 my %opts;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
18 GetOptions(\%opts,"r=s","p=s","m=s","mis:i","t:i","e:i","f:i","tag:s","o=s","time:s","h");
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
19 if (!(defined $opts{r} and defined $opts{p} and defined $opts{m} and defined $opts{o} ) || defined $opts{h}) { #necessary arguments
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
20 &usage;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
21 }
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
22
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
23 my $read=$opts{'r'};
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
24 my $pre=$opts{'p'};
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
25 my $mature=$opts{'m'};
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
26
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
27 my $dir=$opts{'o'};
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
28 unless ($dir=~/\/$/) {$dir .="/";}
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
29 if (not -d $dir) {
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
30 mkdir $dir;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
31 }
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
32
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
33 my $threads=defined $opts{'t'} ? $opts{'t'} : 1;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
34 my $mismatch=defined $opts{'mis'} ? $opts{'mis'} : 0;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
35
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
36 my $upstream = 2;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
37 my $downstream = 5;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
38
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
39 $upstream = $opts{'e'} if(defined $opts{'e'});
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
40 $downstream = $opts{'f'} if(defined $opts{'f'});
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
41
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
42 my $marks=defined $opts{'tag'} ? $opts{'tag'} : "";
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
43
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
44 my $time=Time();
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
45 if (defined $opts{'time'}) { $time=$opts{'time'};}
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
46
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
47 my $tmpdir="${dir}/miRNA_Express_${time}";
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
48 if(not -d $tmpdir){
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
49 mkdir($tmpdir);
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
50 }
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
51 chdir $tmpdir;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
52
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
53 `cp $pre ./`;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
54 my $pre_file_name=basename($pre);
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
55
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
56 &mapping(); # matures align to precursors && reads align to precursors;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
57
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
58 my %pre_mature; # $pre_mature{pre_id}{matre_ID}{"mature"}[0]->start; $pre_mature{pre_id}{matre_ID}{"mature"}[1]->end;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
59 &maturePosOnPre(); # acknowledge mature positions on precursor
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
60
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
61 my %pre_read;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
62 &readPosOnPre(); # acknowledge reads positions on precursors
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
63
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
64 if(!(defined $opts{'tag'})){
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
65 foreach my $key (keys %pre_read) {
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
66 $pre_read{$key}[0][0]=~/:([\d|_]+)_x(\d+)$/;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
67 my @ss=split/_/,$1;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
68 for (my $i=1;$i<=@ss;$i++) {
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
69 $marks .="Smp$i;";
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
70 }
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
71 last;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
72 }
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
73 }
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
74
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
75 my %pre;## read in precursor sequences #$pre{pre_id}="CGTA...."
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
76 &attachPre();
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
77
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
78 my $preno=scalar (keys %pre);
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
79 print "Total Precursor Number is $preno !!!!\n";
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
80
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
81 my %struc; #mature star loop; $struc{$key}{"struc"}=$str; $struc{$key}{"mfe"}=$mfe;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
82 &structure();
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
83
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
84
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
85 ##### analysis and print out && moRs
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
86 my $aln=$dir."known_microRNA_express.aln";
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
87 my $list=$dir."known_microRNA_express.txt";
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
88 my $moRs=$dir."known_microRNA_express.moRs";
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
89
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
90 system("ln $mature $dir/known_microRNA_mature.fa ");
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
91 system("ln $pre $dir/known_microRNA_precursor.fa ");
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
92
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
93 open ALN,">$aln";
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
94 open LIST,">$list";
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
95 open MORS,">$moRs";
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
96
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
97 $"="\t"; ##### @array print in \t
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
98
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
99 my @marks=split/\;/,$marks;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
100 #print LIST "#matueID\tpreID\tpos1\tpos2\tmatureExp\tstarExp\ttotalExp\n";
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
101 print LIST "#matueID\tpreID\tpos1\tpos2";
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
102 for (my $i=0;$i<@marks;$i++) {
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
103 print LIST "\t",$marks[$i],"_matureExp";
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
104 }
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
105 for (my $i=0;$i<@marks;$i++) {
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
106 print LIST "\t",$marks[$i],"_starExp";
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
107 }
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
108 for (my $i=0;$i<@marks;$i++) {
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
109 print LIST "\t",$marks[$i],"_totalExp";
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
110 }
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
111 print LIST "\n";
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
112 print ALN "#>precursor ID \n#precursor sequence\n#precursor structure (mfe)\n#RNA_seq\t@marks\ttotal\n";
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
113 print MORS "#>precursor ID\tstrand\texpress_reads\texpress_reads\/total_reads\tblock_number\tprecursor_sequence\n#\tblock_start\tblock_end\t@marks\ttotal\ttag_number\tsequence\n";
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
114 my %moRs;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
115
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
116 foreach my $key (keys %pre) {
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
117 print ALN ">$key\n$pre{$key}\n$struc{$key}{struc} ($struc{$key}{mfe})\n";
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
118 next if(! (exists $pre_read{$key}));
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
119 my @array=@{$pre_read{$key}};
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
120 @array=sort{$a->[3]<=> $b->[3]} @array;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
121
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
122 my $length=length($pre{$key});
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
123
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
124 my $maxline=-1;my $max=0; ### storage the maxinum express read line
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
125 my $totalReadsNo=0;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
126 my @not_over=(); ### new read format better for moRs analysis
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
127
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
128 ####print out Aln file start
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
129 for (my $i=0;$i<@array;$i++) {
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
130 my $maps=$array[$i][3]+1;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
131 my $mape=$array[$i][3]+length($array[$i][4]);
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
132 my $str="";
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
133 $str .= "." x ($maps-1);
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
134 $str .=$array[$i][4];
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
135 $str .="." x ($length-$mape);
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
136 $str .=" ";
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
137
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
138 $array[$i][0]=~/:([\d|_]+)_x(\d+)$/;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
139 my @sample=split /\_/,$1;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
140 my $total=$2;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
141 print ALN $str,"@sample","\t",$total,"\n";
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
142
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
143 if($total>$max){$max=$total; $maxline=$i;}
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
144 $totalReadsNo+=$total;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
145
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
146 push @not_over,[$key,$maps,$mape,$array[$i][0],$total,"+"];
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
147 }
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
148 ####print out Aln file end
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
149
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
150 #### express list start
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
151 my ($ms,$me,$ss,$se);
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
152 if (!(exists($pre_mature{$key}))) {
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
153 $ms=$array[$maxline][3]+1;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
154 $me=$array[$maxline][3]+length($array[$maxline][4]);
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
155 ($ss,$se)=&other_pair($ms,$me,$struc{$key}{'struc'});
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
156
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
157 my ($mexp,$sexp,$texp)=&express($ms-$upstream,$me+$downstream,$ss-$upstream,$se+$downstream,\@array);
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
158 print LIST "$key\t$key\tmature:$ms..$me\tstar:$ss..$se\t@$mexp\t@$sexp\t@$texp\n";
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
159 }
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
160 else{
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
161 foreach my $maID (keys %{$pre_mature{$key}}) {
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
162 $ms=$pre_mature{$key}{$maID}{"mature"}[0];
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
163 $me=$pre_mature{$key}{$maID}{"mature"}[1];
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
164 $ss=$pre_mature{$key}{$maID}{"star"}[0];
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
165 $se=$pre_mature{$key}{$maID}{"star"}[1];
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
166 my ($mexp,$sexp,$texp)=&express($ms-$upstream,$me+$downstream,$ss-$upstream,$se+$downstream,\@array);
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
167 print LIST "$maID\t$key\tmature:$ms..$me\tstar:$ss..$se\t@$mexp\t@$sexp\t@$texp\n";
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
168 }
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
169 }
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
170 #### express list end
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
171
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
172 #### analysis moRs start
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
173 my @result; my @m_texp;my $m_texp=0; ### moRs informations
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
174
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
175 while (@not_over>0) {
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
176 my @over=@not_over;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
177 @not_over=();
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
178
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
179 #·á¶È×î¸ßtag
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
180 my $m_max=0;my $m_maxline=-1;my $m_start=0;my $m_end=0;my $m_exp=0;my @m_exp;my $m_no=1;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
181 for (my $i=0;$i<@over;$i++) {
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
182 my @m_array=@{$over[$i]};
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
183 if ($m_max<$m_array[4]) {
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
184 $m_max=$m_array[4];
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
185 $m_maxline=$i;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
186 }
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
187 }
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
188 $m_start=$over[$m_maxline][1];
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
189 $m_end=$over[$m_maxline][2];
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
190 $m_exp=$m_max;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
191 $over[$m_maxline][3]=~/:([\d|_]+)_x(\d+)$/;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
192 my @m_nums=split/_/,$1;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
193 for (my $j=0;$j<@m_nums;$j++) {
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
194 $m_exp[$j]=$m_nums[$j];
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
195 }
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
196
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
197 #ͳ¼ÆÒÔ·á¶È×î¸ßtagΪ×ø±êµÄreads, Á½¶ËλÖòîÒì²»³¬¹ý3nt
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
198 for (my $i=0;$i<@over;$i++) {
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
199 next if($i==$m_maxline);
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
200 my @m_array=@{$over[$i]};
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
201 if (abs($m_array[1]-$m_start)<=3 && abs($m_array[2]-$m_end)<=3) {
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
202 $m_exp+=$m_array[4];
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
203 $m_no++;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
204 $m_array[3]=~/:([\d|_]+)_x(\d+)$/;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
205 my @m_nums=split/_/,$1;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
206 for (my $j=0;$j<@m_nums;$j++) {
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
207 $m_exp[$j] +=$m_nums[$j];
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
208 }
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
209 }
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
210 elsif($m_array[1]>=$m_end || $m_array[2]<=$m_start){push @not_over,[@{$over[$i]}];} #È¥³ý¿çÔ½blockµÄreads
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
211 }
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
212 if($m_exp>5){### 5¸öreads
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
213 $m_texp+=$m_exp;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
214 for (my $j=0;$j<@m_exp;$j++) {
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
215 $m_texp[$j]+=$m_exp[$j];
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
216 }
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
217 my $string=&subseq($pre{$key},$m_start,$m_end,"+");
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
218 push @result,"\t$m_start\t$m_end\t@m_exp\t$m_exp\t$m_no\t$string" ;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
219 }
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
220 }
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
221
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
222 my $str=scalar @result;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
223 my $percent=sprintf("%.2f",$m_texp/$totalReadsNo);
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
224 $str=">$key\t+\t$m_texp\t$percent\t".$str."\t$pre{$key}";
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
225 @{$moRs{$str}}=@result;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
226
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
227 #### analysis moRs end
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
228 }
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
229
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
230 ##### moRs print out start
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
231 foreach my $key (keys %moRs) {
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
232 my @tmp=split/\t/,$key;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
233 next if ($tmp[4]<=2);
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
234 next if($tmp[3]<0.95);
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
235 my @over;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
236 for (my $i=0;$i<@{$moRs{$key}};$i++) {
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
237 my @arrayi=split/\t/,$moRs{$key}[$i];
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
238 for (my $j=0;$j<@{$moRs{$key}};$j++) {
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
239 next if($i==$j);
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
240 my @arrayj=split/\t/,$moRs{$key}[$j];
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
241 if ((($arrayj[1]-$arrayi[2]>=0 && $arrayj[1]-$arrayi[2] <=3) || ($arrayj[1]-$arrayi[2]>=18 && $arrayj[1]-$arrayi[2] <=25) )||(($arrayi[1]-$arrayj[2]>=0 && $arrayi[1]-$arrayj[2] <=3)||($arrayi[1]-$arrayj[2]>=18 && $arrayi[1]-$arrayj[2] <=25))) {
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
242 push @over,$moRs{$key}[$i];
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
243 }
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
244 }
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
245 }
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
246 if (@over>0) {
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
247 print MORS "$key\n";
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
248 foreach (@{$moRs{$key}}) {
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
249 print MORS "$_\n";
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
250 }
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
251 }
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
252 }
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
253 ###### moRs print out end
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
254 close ALN;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
255 close LIST;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
256 close MORS;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
257
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
258 $"=" ";##### reset
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
259
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
260
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
261 ################### Sub programs #################
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
262 sub express{
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
263 my ($ms,$me,$ss,$se,$read)=@_;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
264 my (@mexp,@sexp,@texp);
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
265 $$read[0][0]=~/:([_|\d]+)_x(\d+)$/;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
266 my @numsample=split/_/,$1;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
267 for (my $i=0;$i<@numsample;$i++) {
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
268 $mexp[$i]=0;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
269 $sexp[$i]=0;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
270 $texp[$i]=0;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
271 }
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
272
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
273 for (my $i=0;$i<@{$read};$i++) {
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
274 my $start=$$read[$i][3]+1;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
275 my $end=$$read[$i][3]+length($$read[$i][4]);
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
276 $$read[$i][0]=~/:([_|\d]+)_x(\d+)$/;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
277 my $expresses=$1;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
278 my @nums=split/_/,$expresses;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
279
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
280 for (my $j=0;$j<@nums;$j++) {
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
281 $texp[$j]+=$nums[$j];
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
282 }
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
283 if ($start>=$ms && $end<=$me) {
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
284 for (my $j=0;$j<@nums;$j++) {
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
285 $mexp[$j]+=$nums[$j];
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
286 }
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
287 }
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
288 if ($start>=$ss && $end<=$se) {
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
289 for (my $j=0;$j<@nums;$j++) {
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
290 $sexp[$j]+=$nums[$j];
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
291 }
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
292 }
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
293 }
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
294 return(\@mexp,\@sexp,\@texp);
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
295 }
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
296
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
297 sub structure{
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
298 foreach my $key (keys %pre_mature) {
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
299 if (!(defined $pre{$key})){die "!!!!! No precursor sequence $key, please check it!\n";}
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
300 my ($str,$mfe)=RNA::fold($pre{$key});
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
301 $struc{$key}{"struc"}=$str;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
302 $struc{$key}{"mfe"}=sprintf ("%.2f",$mfe);
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
303
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
304 foreach my $id (keys %{$pre_mature{$key}}) {
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
305 ($pre_mature{$key}{$id}{"star"}[0],$pre_mature{$key}{$id}{"star"}[1])=&other_pair($pre_mature{$key}{$id}{"mature"}[0],$pre_mature{$key}{$id}{"mature"}[1],$str);
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
306 }
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
307 =cut
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
308 ##### Nucleotide complementary
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
309 my @tmp=split//,$str;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
310 my %a2b;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
311 my @bps;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
312 for (my $i=0;$i<@tmp;$i++) {
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
313 if ($tmp[$i] eq "("){push @bps,$i+1 ; next;}
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
314 if ($tmp[$i] eq ")") {
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
315 my $up=pop @bps;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
316 $a2b{$i+1}=$up;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
317 $a2b{$up}=$i+1;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
318 }
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
319 }
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
320
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
321 ##### search star position
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
322 foreach my $id (keys %{$pre_mature{$key}}) {
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
323 my $n=0;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
324 for (my $i=$pre_mature{$key}{$id}{"mature"}[0];$i<=$pre_mature{$key}{$id}{"mature"}[1] ; $i++) {
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
325 if (defined $a2b{$i}) {
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
326 my $a=$i; my $b=$a2b{$i};
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
327 if($a>$b){
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
328 $pre_mature{$key}{$id}{"star"}[0]=$b-$n+2;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
329 $pre_mature{$key}{$id}{"star"}[1]=$b-$n+2+($pre_mature{$key}{$id}{"mature"}[1]-$pre_mature{$key}{$id}{"mature"}[0]);
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
330 }
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
331 if($a<$b{
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
332 $pre_mature{$key}{$id}{"star"}[1]=$b+$n+2;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
333 $pre_mature{$key}{$id}{"star"}[0]=$b+$n+2-($pre_mature{$key}{$id}{"mature"}[1]-$pre_mature{$key}{$id}{"mature"}[0]);
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
334 }
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
335 last;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
336 }
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
337 $n++;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
338 }
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
339 }
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
340 =cut
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
341 }
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
342 }
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
343 sub other_pair{
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
344 my ($start,$end,$structure)=@_;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
345 ##### Nucleotide complementary
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
346 my @tmp=split//,$structure;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
347 my %a2b; my @bps;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
348 for (my $i=0;$i<@tmp;$i++) {
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
349 if ($tmp[$i] eq "("){push @bps,$i+1 ; next;}
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
350 if ($tmp[$i] eq ")") {
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
351 my $up=pop @bps;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
352 $a2b{$i+1}=$up;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
353 $a2b{$up}=$i+1;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
354 }
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
355 }
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
356 ##### search star position
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
357 my $n=0;my $startpos; my $endpos;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
358 for (my $i=$start;$i<=$end ; $i++) {
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
359 if (defined $a2b{$i}) {
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
360 my $a=$i; my $b=$a2b{$i};
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
361 # if($a>$b){
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
362 # $startpos=$b-$n+2;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
363 # $endpos=$b-$n+2+($end-$start);
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
364 # }
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
365 # if($a<$b){
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
366 $endpos=$b+$n+2;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
367 if($endpos>length($structure)){$endpos=length($structure);}
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
368 $startpos=$b+$n+2-($end-$start);
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
369 if($startpos<1){$startpos=1;}
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
370 # }
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
371 last;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
372 }
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
373 $n++;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
374 }
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
375 return ($startpos,$endpos);
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
376 }
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
377 sub attachPre{
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
378 open IN, "<$pre_file_name";
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
379 my $name;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
380 while (my $aline=<IN>) {
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
381 chomp $aline;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
382 if ($aline=~/^>(\S+)/) {
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
383 $name=$1;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
384 next;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
385 }
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
386 $pre{$name} .=$aline;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
387 }
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
388 close IN;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
389 }
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
390 sub readPosOnPre{
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
391 open IN,"<read_mapped.bwt";
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
392 while (my $aline=<IN>) {
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
393 chomp $aline;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
394 my @tmp=split/\t/,$aline;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
395 my $id=lc($tmp[2]);
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
396 push @{$pre_read{$tmp[2]}},[@tmp];
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
397 }
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
398 close IN;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
399 }
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
400 sub maturePosOnPre{
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
401 open IN,"<mature_mapped.bwt";
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
402 while (my $aline=<IN>) {
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
403 chomp $aline;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
404 my @tmp=split/\t/,$aline;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
405 my $mm=$tmp[0];
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
406 # $mm=~s/\-3P|\-5P//i;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
407 $mm=lc($mm);
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
408 my $pm=$tmp[2];
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
409 $pm=lc($pm);
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
410
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
411 # next if ($mm ne $pm);### stringent mapping let7a only allowed to map pre-let7a
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
412 next if($mm!~/$pm/);
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
413 # print "$tmp[2]\t$tmp[0]\n";
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
414 # $pre_mature{$tmp[2]}{$tmp[0]}{"mature"}[0]=$tmp[3]-$upstream;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
415 # $pre_mature{$tmp[2]}{$tmp[0]}{"mature"}[0]=0 if($pre_mature{$tmp[2]}{$tmp[0]}{"mature"}[0]<0);
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
416 # $pre_mature{$tmp[2]}{$tmp[0]}{"mature"}[1]=$tmp[3]+length($tmp[4])-1+$downstream;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
417 $pre_mature{$tmp[2]}{$tmp[0]}{"mature"}[0]=$tmp[3]+1;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
418 $pre_mature{$tmp[2]}{$tmp[0]}{"mature"}[1]=$tmp[3]+length($tmp[4]);
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
419 }
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
420 close IN;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
421 }
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
422 sub mapping{
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
423 my $err;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
424 ## build bowtie index
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
425 print STDERR "building bowtie index\n";
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
426 $err = `bowtie-build $pre_file_name miRNA_precursor`;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
427
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
428 ## map mature sequences against precursors
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
429 print STDERR "mapping mature sequences against index\n";
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
430 $err = `bowtie -p $threads -f -v 0 -a --best --strata --norc miRNA_precursor $mature mature_mapped.bwt`;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
431
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
432 ## map reads against precursors
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
433 print STDERR "mapping read sequences against index\n";
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
434 $err=`bowtie -p $threads -f -v $mismatch -a --best --strata --norc miRNA_precursor $read --al mirbase_mapped.fa --un mirbase_not_mapped.fa read_mapped.bwt `;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
435
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
436 }
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
437
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
438 sub subseq{
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
439 my $seq=shift;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
440 my $beg=shift;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
441 my $end=shift;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
442 my $strand=shift;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
443
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
444 my $subseq=substr($seq,$beg-1,$end-$beg+1);
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
445 if ($strand eq "-") {
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
446 $subseq=revcom($subseq);
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
447 }
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
448 return uc $subseq;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
449 }
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
450
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
451 sub revcom{
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
452 my $seq=shift;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
453 $seq=~tr/ATCGatcg/TAGCtagc/;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
454 $seq=reverse $seq;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
455 return uc $seq;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
456 }
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
457
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
458 sub Time{
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
459 my $time=time();
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
460 my ($sec,$min,$hour,$day,$month,$year) = (localtime($time))[0,1,2,3,4,5,6];
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
461 $month++;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
462 $year+=1900;
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
463 if (length($sec) == 1) {$sec = "0"."$sec";}
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
464 if (length($min) == 1) {$min = "0"."$min";}
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
465 if (length($hour) == 1) {$hour = "0"."$hour";}
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
466 if (length($day) == 1) {$day = "0"."$day";}
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
467 if (length($month) == 1) {$month = "0"."$month";}
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
468 #print "$year-$month-$day $hour:$min:$sec\n";
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
469 return("$year-$month-$day-$hour-$min-$sec");
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
470 }
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
471
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
472 sub usage{
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
473 print <<"USAGE";
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
474 Version $version
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
475 Usage:
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
476 $0 -r -p -m -mis -t -e -f -tag -o -time
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
477 mandatory parameters:
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
478 -p precursor.fa miRNA precursor sequences from miRBase # must be absolute path
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
479 -m mature.fa miRNA sequences from miRBase # must be absolute path
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
480 -r reads.fa your read sequences #must be absolute path
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
481
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
482 -o output directory
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
483
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
484 options:
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
485 -mis [int] number of allowed mismatches when mapping reads to precursors, default 0
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
486 -t [int] threads number,default 1
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
487 -e [int] number of nucleotides upstream of the mature sequence to consider, default 2
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
488 -f [int] number of nucleotides downstream of the mature sequence to consider, default 5
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
489 -tag [string] sample marks# eg. sampleA;sampleB;sampleC
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
490 -time sting #make directory time,default is the local time
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
491 -h help
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
492 USAGE
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
493 exit(1);
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
494 }
a79212816cbc Uploaded
big-tiandm
parents:
diff changeset
495