Mercurial > repos > big-tiandm > mirplant2
comparison siRNA.pl @ 50:7b5a48b972e9 draft
Uploaded
author | big-tiandm |
---|---|
date | Fri, 05 Dec 2014 00:11:02 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
49:f008ab2cadc6 | 50:7b5a48b972e9 |
---|---|
1 #!/usr/bin/perl -w | |
2 my $version=1.00; | |
3 use strict; | |
4 use warnings; | |
5 use Getopt::Long; | |
6 use Getopt::Std; | |
7 use threads; | |
8 use threads::shared; | |
9 use Parallel::ForkManager; | |
10 use lib '/leofs/biotrans/chentt/perl_module/'; | |
11 #perl ../siRNA.pl -i config -g /leofs/biotrans/projects/rice/smallRNA/sRNA_package/bin/test/ref/genome.fa -f /share_bio/hs4/disk3-4/Reference/Plants/Rice_TIGR/Reference/TIGR/version_6.1/all.dir/all.gff3 -path /leofs/biotrans/projects/rice/smallRNA/sRNA_package/bin/ -o /leofs/biotrans/projects/rice/smallRNA/sRNA_package/bin/test -t 3 -rfam /leofs/biotrans/projects/rice/smallRNA/sRNA_package/bin/test/ref/Rfam.fasta -idx /leofs/biotrans/projects/rice/smallRNA/sRNA_package/bin/test/ref/genome -idx2 /leofs/biotrans/projects/rice/smallRNA/sRNA_package/bin/test/ref/rfam -deg deg -n 25 -nat class/nat_1 -repeat class/repeat_1 -cen centromere_TIGR.txt -format fastq | |
12 print " | |
13 ##################################### | |
14 # # | |
15 # sRNA cluster # | |
16 # # | |
17 ##################################### | |
18 "; | |
19 ########################################################################################### | |
20 my $usage="$0 | |
21 Options: | |
22 -i input file# fasta | |
23 -config input file | |
24 -g genome file | |
25 -f gff file | |
26 | |
27 -o workdir file | |
28 -path script path | |
29 -t int, number of threads [1] | |
30 -format fastq, fq, fasta or fa | |
31 -idx string, genome file index, file-prefix #(must be indexed by bowtie-build) The parameter | |
32 string must be the prefix of the bowtie index. For instance, if | |
33 the first indexed file is called 'h_sapiens_37_asm.1.ebwt' then | |
34 the prefix is 'h_sapiens_37_asm'.##can be null | |
35 -mis int number of allowed mismatches when mapping reads to genome, default 0 | |
36 | |
37 -n int max hits number,default 25; used in genome alignment | |
38 -d int distance of tag to merged a cluster; default 100 | |
39 -p cluster method F :conventional default is F | |
40 T :NIBLES | |
41 -l int the length of the upstream and downstream,default 1000;used in position annotate | |
42 | |
43 -nat natural antisense transcripts file | |
44 -repeat repeat information file out of Repeatmasker | |
45 -deg file config of de sample | |
46 -cen centromere file input | |
47 -span plot span, default 50000 | |
48 "; | |
49 | |
50 my %options; | |
51 GetOptions(\%options,"i:s","config=s","g=s","f=s","o=s","path:s","p=s","format=s","nat:s","repeat:s","deg:s","n:i","mis:i","t:i","d:i","l:i","idx:s","cen:s","span:s","h"); | |
52 #print help if that option is used | |
53 if($options{h}){die $usage;} | |
54 | |
55 my $filein=$options{'i'}; | |
56 | |
57 #my $config=$options{'i'}; | |
58 my $genome_fa=$options{'g'}; | |
59 my $gff=$options{'f'}; | |
60 | |
61 | |
62 ########################################################################################## | |
63 my $predir=`pwd`; | |
64 chomp $predir; | |
65 my $workdir=defined($options{'o'}) ? $options{'o'}:$predir; | |
66 | |
67 my $path=$options{'path'}; | |
68 | |
69 my $t=defined($options{'t'})? $options{'t'}:1; #threads number | |
70 | |
71 my $mis=defined $options{'mis'} ? $options{'mis'}:0; | |
72 | |
73 | |
74 my $hit=defined $options{'n'}?$options{'n'}:25; | |
75 | |
76 my $distance_of_merged_tag=defined $options{'d'} ? $options{'d'}:100; | |
77 | |
78 my $up_down_dis=defined $options{'l'} ?$options{'l'}:1000; | |
79 | |
80 my $cluster_mothod=defined $options{'p'}?$options{'p'}:"F"; | |
81 | |
82 my $format=$options{'format'}; | |
83 #if ($format ne "fastq" && $format ne "fq" && $format ne "fasta" && $format ne "fa") { | |
84 # die "Parameter \"-format\" is error! Parameter is fastq, fq, fasta or fa\n"; | |
85 #} | |
86 | |
87 | |
88 | |
89 my $sample_number; | |
90 my ($dir,$dir_tmp); | |
91 ################################ MAIN ################################################## | |
92 print "\ncluster program start:"; | |
93 my $time=Time(); | |
94 make_dir_tmp(); | |
95 | |
96 my $mark; | |
97 my $sample_mark; | |
98 | |
99 my $config=$opts{'config'}; | |
100 my (@filein,@mark); | |
101 &read_config(); | |
102 $sample_number=@mark; | |
103 $mark=join "\t",@mark; | |
104 $sample_mark=join "\#",@mark; | |
105 | |
106 | |
107 | |
108 my $data3=$filein; ### rfam not mapped reads | |
109 genome(); | |
110 | |
111 my $bed=$dir."cluster\/"."sample\.bed"; | |
112 my $read=$dir."cluster\/"."sample_reads\.cluster"; | |
113 my $read_txt=$dir."cluster\/"."cluster\.txt"; | |
114 my $rpkm=$dir."cluster\/"."sample_rpkm\.cluster"; | |
115 my $preprocess; | |
116 my $cluster_file; | |
117 my $annotate_dir; | |
118 my $deg_dir; | |
119 my $plot_dir; | |
120 my %id; | |
121 for (my $i=0;$i<@mark ;$i++) { | |
122 $id{$mark[$i]}=$i+4; | |
123 } | |
124 | |
125 | |
126 my @map_read; | |
127 my $map_tag=0; | |
128 | |
129 bwt2bed(); | |
130 | |
131 cluster(); | |
132 | |
133 quantify(); | |
134 | |
135 phase(); | |
136 | |
137 if (defined($options{'nat'})&&defined($options{'repeat'})) { | |
138 class(); | |
139 } | |
140 else{ | |
141 get_genelist(); | |
142 } | |
143 | |
144 annotate(); | |
145 | |
146 genome_length(); | |
147 | |
148 plot(); | |
149 | |
150 my @pairdir; | |
151 if (defined($options{'deg'})) { | |
152 dec(); | |
153 infor_merge(); | |
154 } | |
155 else{infor_merge_no_dec()} | |
156 html(); | |
157 print "\ncluster program end:"; | |
158 Time(); | |
159 ############################sub program################################################### | |
160 sub make_dir_tmp{ | |
161 | |
162 #make temporary directory | |
163 if(not -d "$workdir\/cluster_runs"){ | |
164 mkdir("$workdir\/cluster_runs"); | |
165 mkdir("$workdir\/cluster_runs\/ref\/"); | |
166 } | |
167 | |
168 $dir="$workdir\/cluster_runs\/"; | |
169 #print STDERR "mkdir $dir\n\n"; | |
170 return; | |
171 } | |
172 | |
173 sub genome{ | |
174 if(defined $options{'idx'}){ | |
175 system("perl $path\/matching.pl -i $data3 -g $genome_fa -v $mis -p $t -r $hit -o $dir -index $options{idx}") ; | |
176 }else{ | |
177 system("perl $path\/matching.pl -i $data3 -g $genome_fa -v $mis -p $t -r $hit -o $dir ") ; | |
178 } | |
179 #=================== mapping sta =================================================== | |
180 my $map_file=$dir."genome_match\/genome_mapped\.fa"; | |
181 open (MAP,"<$map_file")||die"$!"; | |
182 print "\n#each sample mapping reads sta:\n\n"; | |
183 print "#$mark\ttotal\n"; | |
184 while (my $ID=<MAP>) { | |
185 chomp $ID; | |
186 my @tmp=split/\:/,$ID; | |
187 my @exp=split/\_/,$tmp[1]; | |
188 $exp[-1] =~ s/^x//; | |
189 for (my $i=0;$i<@exp ;$i++) { | |
190 $map_read[$i]+=$exp[$i]; | |
191 } | |
192 $map_tag++; | |
193 my $seq=<MAP>; | |
194 } | |
195 my $map_read=join"\t",@map_read; | |
196 print "$map_read\n\n"; | |
197 print "#total mapped tags:$map_read\n\n"; | |
198 close MAP; | |
199 return 0; | |
200 } | |
201 | |
202 sub bwt2bed{ | |
203 $cluster_file=$dir."cluster\/"; | |
204 mkdir ("$cluster_file"); | |
205 print "sam file changed to bed file\n"; | |
206 my ($file) = $dir."genome_match\/genome_mapped\.bwt"; | |
207 | |
208 my $sam2bed=`perl $path\/sam2Bed_bowtie.pl -i $file -mark $sample_mark -o $bed `; | |
209 print "perl $path\/sam2Bed_bowtie.pl -i $file -mark $sample_mark -o $bed\n\n"; | |
210 return 0; | |
211 } | |
212 | |
213 sub cluster{ | |
214 print "tags is ready to merged clusters\n\n"; | |
215 my ($file) =$bed; | |
216 if ($cluster_mothod eq "F") { | |
217 my $cluster=`perl $path\/conventional.pl -i $file -d $distance_of_merged_tag -n $sample_number -mark $sample_mark -o $read -t $read_txt`; | |
218 print "Using converntional method\n perl $path\/conventional.pl -i $file -d $distance_of_merged_tag -n $sample_number -mark $sample_mark -o $read -t $read_txt\n\n"; | |
219 } | |
220 elsif($cluster_mothod eq "T"){ | |
221 my $cluster=`perl $path\/nibls.pl -f $file -m $distance_of_merged_tag -o $read -t $read_txt -k $sample_mark`; | |
222 print "Using nibls method\n perl $path\/nibls.pl -f $file -m $distance_of_merged_tag -o $read -t $dir\/cluster.txt -k $sample_mark\n\n"; | |
223 } | |
224 else{print "\-p is wrong!\n\n";} | |
225 return 0; | |
226 } | |
227 | |
228 | |
229 sub quantify{ | |
230 print "clusters is ready to quantified\n\n"; | |
231 my @depth=@map_read; | |
232 pop @depth; | |
233 my $depth=join ",",@depth; | |
234 my $quantify=`perl $path\/quantify.pl -i $read -d $depth -o $rpkm`; | |
235 print "perl $path\/quantify_siRNA.pl -i $read -d $depth -o $rpkm\n\n\n"; | |
236 return 0; | |
237 } | |
238 | |
239 sub phase{ | |
240 $annotate_dir=$dir."annotate\/"; | |
241 mkdir ("$annotate_dir"); | |
242 print "clusters is to predict phase siRNA\n"; | |
243 my $phase=`perl $path\/phased_siRNA.pl -i $read_txt -o $annotate_dir\/phase.out`; | |
244 print "perl $path\/phased_siRNA.pl -i $read_txt -o $annotate_dir\/phase.out\n\n\n"; | |
245 return 0; | |
246 } | |
247 | |
248 sub class{ | |
249 print "clusters is ready to annotate by sources\n\n"; | |
250 my $nat=$options{'nat'}; | |
251 my $repeat=$options{'repeat'}; | |
252 my $class=`perl $path\/ClassAnnotate.pl -i $rpkm -g $gff -n $nat -r $repeat -p $annotate_dir\/phase.out -o $annotate_dir\/sample_class.anno -t $annotate_dir\/nat.out -l $dir\/ref\/genelist.txt`; | |
253 print "perl $path\/ClassAnnotate.pl -i $rpkm -g $gff -n $nat -r $repeat -p $annotate_dir\/phase.out -o $annotate_dir\/sample_class.anno -t $annotate_dir\/nat.out -l $dir\/ref\/genelist.txt\n\n"; | |
254 } | |
255 | |
256 sub annotate{ | |
257 print "clusters is ready to annotate by gff file\n\n"; | |
258 my $file; | |
259 if (defined($options{'nat'})&&defined($options{'repeat'})) { | |
260 $file="$annotate_dir\/sample_class.anno"; | |
261 } | |
262 else{ | |
263 $file=$rpkm; | |
264 } | |
265 my $annotate=`perl $path\/Annotate.pl -i $file -g $dir\/ref\/genelist.txt -d $up_down_dis -o $annotate_dir\/sample_c_p.anno`; | |
266 print "perl $path\/Annotate.pl -i $file -g $dir\/ref\/genelist.txt -d $up_down_dis -o $annotate_dir\/sample_c_p.anno\n\n"; | |
267 return 0; | |
268 } | |
269 sub get_genelist{ | |
270 | |
271 my $get_genelist=`perl $path\/get_genelist.pl -i $gff -o $dir\/ref\/genelist.txt`; | |
272 print "perl $path\/get_genelist.pl -i $gff -o $dir\/ref\/genelist.txt"; | |
273 } | |
274 | |
275 sub dec{ | |
276 print "deg reading\n\n"; | |
277 my $deg_file=$options{'deg'}; | |
278 open IN,"<$deg_file"; | |
279 my @deg; | |
280 my $s=0; | |
281 while (my $aline=<IN>) { | |
282 chomp $aline; | |
283 next if($aline=~/^\#/); | |
284 $deg[$s]=$aline; | |
285 my @ea=split/\s+/,$aline; | |
286 push @pairdir,"$ea[0]_VS_$ea[1]\/"; | |
287 #print "$deg[$s]\n"; | |
288 $s++; | |
289 } | |
290 close IN; | |
291 $deg_dir=$dir."deg\/"; | |
292 mkdir ("$deg_dir"); | |
293 my $max_process = 10; | |
294 my $pm = new Parallel::ForkManager( $max_process ); | |
295 my $number=@deg-1; | |
296 foreach(0..$number){ | |
297 $pm->start and next; | |
298 &dec_pel($deg[$_]); | |
299 $pm->finish; | |
300 } | |
301 $pm->wait_all_children; | |
302 } | |
303 | |
304 sub dec_pel{ | |
305 print "\n******************\nstart:\n"; | |
306 Time(); | |
307 my $sample=shift(@_); | |
308 my @each=split/\s+/,$sample; | |
309 print "$each[0]\t$each[1]\n"; | |
310 my $deg_sample_dir=$deg_dir."$each[0]_VS_$each[1]\/"; | |
311 mkdir ("$deg_sample_dir"); | |
312 print "read: $read\n"; | |
313 print "deg_sample_dir: $deg_sample_dir\n"; | |
314 print "$id{$each[0]}\t$each[0]\n"; | |
315 print "$id{$each[1]}\t$each[1]\n"; | |
316 my $deg=`perl $path\/DEGseq_2.pl -i $read -outdir $deg_sample_dir -column1 $id{$each[0]} -mark1 $each[0] -column2 $id{$each[1]} -mark2 $each[1]`; #-depth1 -depth2 | |
317 my $time2=time(); | |
318 print "end:\n*************************\n"; | |
319 Time(); | |
320 sleep 1; | |
321 } | |
322 | |
323 sub infor_merge{ | |
324 my ($input,$mark); | |
325 foreach (@pairdir) { | |
326 print "@pairdir\n"; | |
327 $mark.=" -mark $_ "; | |
328 $input.=" -i $dir/deg\/$_\/output_score\.txt "; | |
329 print "$input\n$mark\n"; | |
330 } | |
331 my $infor_merge=`perl $path\/SampleDEGseqMerge.pl $input $mark -f $annotate_dir\/sample_c_p.anno -n $sample_number -o $dir\/total.result `; | |
332 print "perl $path\/SampleDEGseqMerge.pl $input $mark -f $annotate_dir\/sample_c_p.anno -n $sample_number -o $dir\/total.result\n\n"; | |
333 } | |
334 | |
335 sub infor_merge_no_dec{ | |
336 my $infor_merge_no_dec=`cp $annotate_dir\/sample_c_p.anno $dir\/total.result`; | |
337 } | |
338 | |
339 sub genome_length{ | |
340 my $length=`perl $path\/count_ref_length.pl -i $genome_fa -o $dir\/ref\/genome\.length`; | |
341 print "perl $path\/count_ref_length.pl -i $genome_fa -o $dir\/ref\/genome\.length\n\n" | |
342 | |
343 } | |
344 | |
345 sub plot{ | |
346 $plot_dir="$dir\/plot\/"; | |
347 mkdir ("$plot_dir"); | |
348 my $span=defined($options{span})?$options{span}:50000; | |
349 my $cen=""; | |
350 if (defined $options{cen}) { | |
351 $cen="-cen $options{cen}"; | |
352 } | |
353 my $plot=`perl $path/sRNA_plot.pl -c $rpkm -g $dir/ref/genelist.txt -span 50000 -mark $sample_mark -l $dir/ref/genome\.length $cen -o $plot_dir/cluster.html -out $plot_dir/cluster.txt `; | |
354 "print perl $path/sRNA_plot.pl -c $rpkm -g $dir/ref/genelist.txt -span 50000 -mark $sample_mark -l $dir/ref/genome.length $cen -o $plot_dir/cluster.html -out $plot_dir/cluster.txt \n"; | |
355 | |
356 } | |
357 | |
358 sub html{ | |
359 my $pathfile="$dir/path.txt"; | |
360 open PA,">$pathfile"; | |
361 print PA "$config\n"; | |
362 print PA "$preprocess\n"; | |
363 print PA "$dir"."rfam_match\n"; | |
364 print PA "$dir"."genome_match\n"; | |
365 print PA "$cluster_file\n"; | |
366 print PA "$annotate_dir\n"; | |
367 print PA "$plot_dir\n"; | |
368 if (defined($deg_dir)) { | |
369 print PA "$deg_dir\n"; | |
370 } | |
371 close PA; | |
372 my $html=`perl $path\/html.pl -i $pathfile -format $format -o $dir/result.html`; | |
373 } | |
374 | |
375 sub Time{ | |
376 my $time=time(); | |
377 my ($sec,$min,$hour,$day,$month,$year) = (localtime($time))[0,1,2,3,4,5,6]; | |
378 $month++; | |
379 $year+=1900; | |
380 if (length($sec) == 1) {$sec = "0"."$sec";} | |
381 if (length($min) == 1) {$min = "0"."$min";} | |
382 if (length($hour) == 1) {$hour = "0"."$hour";} | |
383 if (length($day) == 1) {$day = "0"."$day";} | |
384 if (length($month) == 1) {$month = "0"."$month";} | |
385 print "$year-$month-$day $hour:$min:$sec\n"; | |
386 return("$year-$month-$day-$hour-$min-$sec"); | |
387 } | |
388 ################################################################################# | |
389 sub read_config{ | |
390 open CON,"<$config"; | |
391 while (my $aline=<CON>) { | |
392 chomp $aline; | |
393 my @tmp=split/\t/,$aline; | |
394 push @filein,$tmp[0]; | |
395 push @mark,$tmp[1]; | |
396 #&check_rawdata($tmp[0]); | |
397 } | |
398 close CON; | |
399 if (@filein != @mark) { | |
400 #&printErr(); | |
401 die "Maybe config file have some wrong!!!\n"; | |
402 } | |
403 } |