annotate siRNA.pl @ 18:22d79320085c draft

Uploaded
author big-tiandm
date Thu, 30 Oct 2014 21:31:55 -0400
parents a0222bdfe2ac
children e0884a4b996b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
1 #!/usr/bin/perl -w
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
2 my $version=1.00;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
3 use strict;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
4 use warnings;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
5 use Getopt::Long;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
6 use Getopt::Std;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
7 use threads;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
8 use threads::shared;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
9 use Parallel::ForkManager;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
10 use lib '/leofs/biotrans/chentt/perl_module/';
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
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
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
12 print "
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
13 #####################################
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
14 # #
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
15 # sRNA cluster #
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
16 # #
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
17 #####################################
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
18 ";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
19 ###########################################################################################
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
20 my $usage="$0
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
21 Options:
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
22 -i input file# raw data file
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
23 -tag string #raw data sample name
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
24 -g genome file
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
25 -f gff file
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
26
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
27 -o workdir file
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
28 -path script path
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
29 -t int, number of threads [1]
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
30 -format fastq, fq, fasta or fa
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
31 -idx string, genome file index, file-prefix #(must be indexed by bowtie-build) The parameter
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
32 string must be the prefix of the bowtie index. For instance, if
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
33 the first indexed file is called 'h_sapiens_37_asm.1.ebwt' then
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
34 the prefix is 'h_sapiens_37_asm'.##can be null
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
35 -mis int number of allowed mismatches when mapping reads to genome, default 0
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
36 -rfam string, input file# rfam database file.
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
37 -idx2 string, rfam file index, file-prefix #(must be indexed by bowtie-build) The parameter
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
38 string must be the prefix of the bowtie index. For instance, if
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
39 the first indexed file is called 'h_sapiens_37_asm.1.ebwt' then
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
40 the prefix is 'h_sapiens_37_asm'.##can be null
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
41
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
42 -v int report end-to-end hits w/ <=v mismatches; ignore qualities,default 0; used in rfam alignment
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
43
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
44 -a string, ADAPTER string. default is ATCTCGTATG.
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
45 -n int max hits number,default 25; used in genome alignment
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
46 -d int distance of tag to merged a cluster; default 100
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
47 -p cluster method F :conventional default is F
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
48 T :NIBLES
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
49 -l int the length of the upstream and downstream,default 1000;used in position annotate
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
50
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
51 -nat natural antisense transcripts file
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
52 -repeat repeat information file out of Repeatmasker
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
53 -deg file config of de sample
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
54 -cen centromere file input
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
55 -span plot span, default 50000
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
56 ";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
57
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
58 my %options;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
59 GetOptions(\%options,"i:s@","tag:s@","g=s","f=s","o=s","a:s","path:s","p=s","format=s","nat:s","repeat:s","deg:s","n:i","mis:i","rfam:s","t:i","v:i","d:i","l:i","idx:s","idx2:s","cen:s","span:s","h");
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
60 #print help if that option is used
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
61 if($options{h}){die $usage;}
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
62
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
63 my @filein=@{$options{'i'}};
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
64 my @mark=@{$options{'tag'}};
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
65
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
66 #my $config=$options{'i'};
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
67 my $genome_fa=$options{'g'};
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
68 my $gff=$options{'f'};
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
69
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
70
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
71 ##########################################################################################
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
72 my $predir=`pwd`;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
73 chomp $predir;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
74 my $workdir=defined($options{'o'}) ? $options{'o'}:$predir;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
75
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
76 my $path=$options{'path'};
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
77
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
78 my $t=defined($options{'t'})? $options{'t'}:1; #threads number
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
79
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
80 my $mis=defined $options{'mis'} ? $options{'mis'}:0;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
81
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
82 my $mis_rfam=defined $options{'v'} ? $options{'v'}:0;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
83
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
84 my $hit=defined $options{'n'}?$options{'n'}:25;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
85
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
86 my $distance_of_merged_tag=defined $options{'d'} ? $options{'d'}:100;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
87
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
88 my $up_down_dis=defined $options{'l'} ?$options{'l'}:1000;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
89
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
90 my $cluster_mothod=defined $options{'p'}?$options{'p'}:"F";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
91
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
92 my $format=$options{'format'};
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
93 #if ($format ne "fastq" && $format ne "fq" && $format ne "fasta" && $format ne "fa") {
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
94 # die "Parameter \"-format\" is error! Parameter is fastq, fq, fasta or fa\n";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
95 #}
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
96
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
97 my $adpter="ATCTCGTATG"; #adapter
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
98 if (defined $options{'a'}) {$adpter=$options{'a'};}
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
99
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
100
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
101 my $phred_qv=64;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
102 my $sample_number;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
103 my ($dir,$dir_tmp);
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
104 ################################ MAIN ##################################################
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
105 print "\ncluster program start:";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
106 my $time=Time();
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
107 make_dir_tmp();
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
108
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
109 my @clip;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
110 my $mark;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
111 my $sample_mark;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
112
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
113 my $config=$dir."/input_config";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
114 open CONFIG,">$config";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
115 for (my $i=0;$i<@filein;$i++) {
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
116 print CONFIG $filein[$i],"\t",$mark[$i],"\n";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
117 }
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
118 close CONFIG;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
119 if (@filein != @mark) {
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
120 die "Maybe config file have some wrong!!!\n";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
121 }
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
122 $sample_number=@mark;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
123 $mark=join "\t",@mark;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
124 $sample_mark=join "\#",@mark;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
125
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
126
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
127 #read_config();
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
128
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
129 trim_adapter_and_filter();
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
130
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
131 my $filter_out=$dir."preProcess\/"."collapse_reads_out.fa";## raw clean data
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
132 my $data2=$filter_out; ### mirbase not mapped reads
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
133 my $data3=$dir."\/rfam_match\/rfam_not_mapped\.fa"; ### rfam not mapped reads
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
134 my $bed=$dir."cluster\/"."sample\.bed";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
135 my $read=$dir."cluster\/"."sample_reads\.cluster";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
136 my $read_txt=$dir."cluster\/"."cluster\.txt";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
137 my $rpkm=$dir."cluster\/"."sample_rpkm\.cluster";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
138 my $preprocess;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
139 my $cluster_file;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
140 my $annotate_dir;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
141 my $deg_dir;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
142 my %id;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
143 for (my $i=0;$i<@mark ;$i++) {
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
144 $id{$mark[$i]}=$i+4;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
145 }
18
22d79320085c Uploaded
big-tiandm
parents: 11
diff changeset
146
22d79320085c Uploaded
big-tiandm
parents: 11
diff changeset
147
11
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
148 group_and_filter(); #collapse reads to tags
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
149
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
150 rfam();
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
151
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
152 my @map_read;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
153 my $map_tag=0;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
154 genome();
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
155
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
156 bwt2bed();
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
157
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
158 cluster();
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
159
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
160 quantify();
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
161
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
162 phase();
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
163
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
164 if (defined($options{'nat'})&&defined($options{'repeat'})) {
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
165 class();
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
166 }
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
167 else{
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
168 get_genelist();
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
169 }
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
170
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
171 annotate();
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
172
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
173 genome_length();
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
174
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
175 plot();
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
176
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
177 my @pairdir;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
178 if (defined($options{'deg'})) {
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
179 dec();
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
180 infor_merge();
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
181 }
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
182 else{infor_merge_no_dec()}
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
183 html();
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
184 print "\ncluster program end:";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
185 Time();
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
186 ############################sub program###################################################
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
187 sub make_dir_tmp{
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
188
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
189 #make temporary directory
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
190 if(not -d "$workdir\/cluster_runs"){
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
191 mkdir("$workdir\/cluster_runs");
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
192 mkdir("$workdir\/cluster_runs\/ref\/");
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
193 }
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
194
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
195 $dir="$workdir\/cluster_runs\/";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
196 #print STDERR "mkdir $dir\n\n";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
197 return;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
198 }
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
199
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
200 #sub read_config{
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
201 # open IN,"<$config";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
202 # while (my $aline=<IN>) {
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
203 # chomp $aline;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
204 # my @tmp=split/\t/,$aline;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
205 # push @filein,$tmp[0];
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
206 # push @mark,$tmp[1];
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
207 # }
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
208 # close IN;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
209 # if (@filein != @mark) {
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
210 # die "Maybe config file have some wrong!!!\n";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
211 # }
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
212 # $sample_number=@mark;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
213 # $mark=join "\t",@mark;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
214 # $sample_mark=join "\#",@mark;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
215 #}
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
216
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
217
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
218 sub trim_adapter_and_filter{
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
219 my $time=time();
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
220 $preprocess=$dir."preProcess/";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
221 mkdir $preprocess;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
222 my $can_use_threads = eval 'use threads; 1';
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
223 if ($can_use_threads) {
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
224 # Do processing using threads
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
225 my @filein1=@filein; my @mark1=@mark;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
226 while (@filein1>0) {
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
227 my @thrs; my @res;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
228 for (my $i=0;$i<$t ;$i++) {
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
229 last if(@filein1==0);
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
230 my $in=shift @filein1;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
231 my $out=shift @mark1;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
232 push @clip,$dir."preProcess\/$out\_clip\.fq";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
233 $thrs[$i]=threads->create(\&clips,$in,$out);
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
234 }
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
235 for (my $i=0;$i<@thrs;$i++) {
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
236 $res[$i]=$thrs[$i]->join();
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
237 }
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
238 }
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
239 }
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
240 else {
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
241 # Do not processing using threads
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
242 for (my $i=0;$i<@filein ;$i++) {
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
243 my $in=$filein[$i];
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
244 my $out=$mark[$i];
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
245 push @clip,$dir."preProcess\/$out\_clip\.fq";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
246 &clips($in,$out);
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
247 }
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
248 }
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
249 }
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
250
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
251 sub clips{
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
252 my ($filein,$fileout)=@_;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
253 my $adapter=$dir."preProcess\/$fileout\_clip\.fq";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
254 if($format eq "fq" || $format eq "fastq"){
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
255 my $clip=`fastx_clipper -a $adpter -M 6 -Q $phred_qv -i $filein -o $adapter`;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
256 }
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
257 if($format eq "fa" || $format eq "fasta"){
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
258 my $clip=`fastx_clipper -a $adpter -M 6 -i $filein -o $adapter`;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
259 }
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
260 #my $clean=$dir."preProcess\/$fileout\_clean.fq";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
261 #my $filter=`filterReadsByLength.pl -i $adapter -o $clean -min 18 -max 40 `;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
262 return $fileout;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
263 }
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
264
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
265 sub group_and_filter{
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
266 #my ($ins,$data)=@_;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
267 my @ins=@clip;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
268 my $str="";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
269 my $group_out_file=$dir."preProcess\/"."collapse_reads.fa";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
270 #print "$$ins[0]\t$$ins[0]\n";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
271 for (my $i=0;$i<@clip;$i++) {
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
272 $str .="-i $clip[$i] ";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
273 #print "$$ins[$i]\n";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
274 }
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
275 my $group=`perl $path\/collapseReads2Tags.pl $str -mark seq -o $group_out_file -format $format`;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
276 print "perl $path\/collapseReads2Tags.pl $str -mark seq -o $group_out_file -format $format\n\n";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
277
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
278 my $l_out=$dir."preProcess\/"."collapse_reads_18-40.fa";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
279 my $length_f=`perl $path\/filterReadsByLength_1.pl -i $group_out_file -o $l_out -min 18 -max 40 -mark $sample_mark`;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
280 print "perl $path\/filterReadsByLength_1.pl -i $group_out_file -o $l_out -min 18 -max 40 -mark $sample_mark\n\n";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
281 my $cout_f=`perl $path\/filterReadsByCount.pl -i $l_out -o $filter_out -mark $sample_mark`;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
282 print "perl $path\/filterReadsByCount.pl -i $l_out -o $filter_out -mark $sample_mark\n\n";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
283 return 0;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
284 }
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
285
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
286 sub rfam{
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
287 if (defined $options{'idx2'}) {
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
288 system("perl $path\/rfam.pl -i $data2 -ref $options{rfam} -v $mis_rfam -p $t -o $dir -index $options{idx2}");
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
289 }else{
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
290 system("perl $path\/rfam.pl -i $data2 -ref $options{rfam} -v $mis_rfam -p $t -o $dir");
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
291 }
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
292 my $tag=join "\\;" ,@mark;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
293 my $rfam_count=`perl $path\/count_rfam_express.pl -i $dir\/rfam_match\/rfam_mapped.bwt -tag $tag -o $dir\/rfam_match\/rfam_non-miRNA_annotation.txt`;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
294 return 0;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
295 }
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
296 sub genome{
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
297 if(defined $options{'idx'}){
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
298 system("perl $path\/matching.pl -i $data3 -g $genome_fa -v $mis -p $t -r $hit -o $dir -index $options{idx}") ;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
299 }else{
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
300 system("perl $path\/matching.pl -i $data3 -g $genome_fa -v $mis -p $t -r $hit -o $dir ") ;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
301 }
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
302 #=================== mapping sta ===================================================
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
303 my $map_file=$dir."genome_match\/genome_mapped\.fa";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
304 open (MAP,"<$map_file")||die"$!";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
305 print "\n#each sample mapping reads sta:\n\n";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
306 print "#$mark\ttotal\n";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
307 while (my $ID=<MAP>) {
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
308 chomp $ID;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
309 my @tmp=split/\:/,$ID;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
310 my @exp=split/\_/,$tmp[1];
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
311 $exp[-1] =~ s/^x//;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
312 for (my $i=0;$i<@exp ;$i++) {
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
313 $map_read[$i]+=$exp[$i];
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
314 }
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
315 $map_tag++;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
316 my $seq=<MAP>;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
317 }
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
318 my $map_read=join"\t",@map_read;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
319 print "$map_read\n\n";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
320 print "#total mapped tags:$map_read\n\n";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
321 close MAP;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
322 return 0;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
323 }
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
324
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
325 sub bwt2bed{
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
326 $cluster_file=$dir."cluster\/";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
327 mkdir ("$cluster_file");
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
328 print "sam file changed to bed file\n";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
329 my ($file) = $dir."genome_match\/genome_mapped\.bwt";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
330
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
331 my $sam2bed=`perl $path\/sam2Bed_bowtie.pl -i $file -mark $sample_mark -o $bed `;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
332 print "perl $path\/sam2Bed_bowtie.pl -i $file -mark $sample_mark -o $bed\n\n";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
333 return 0;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
334 }
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
335
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
336 sub cluster{
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
337 print "tags is ready to merged clusters\n\n";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
338 my ($file) =$bed;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
339 if ($cluster_mothod eq "F") {
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
340 my $cluster=`perl $path\/conventional.pl -i $file -d $distance_of_merged_tag -n $sample_number -mark $sample_mark -o $read -t $read_txt`;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
341 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";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
342 }
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
343 elsif($cluster_mothod eq "T"){
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
344 my $cluster=`perl $path\/nibls.pl -f $file -m $distance_of_merged_tag -o $read -t $read_txt -mark $sample_mark`;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
345 print "Using nibls method\n perl $path\/nibls.pl -f $file -m $distance_of_merged_tag -o $read -t $dir\/cluster.txt -mark $sample_mark\n\n";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
346 }
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
347 else{print "\-p is wrong!\n\n";}
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
348 return 0;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
349 }
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
350
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
351
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
352 sub quantify{
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
353 print "clusters is ready to quantified\n\n";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
354 my @depth=@map_read;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
355 pop @depth;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
356 my $depth=join ",",@depth;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
357 my $quantify=`perl $path\/quantify.pl -i $read -d $depth -o $rpkm`;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
358 print "perl $path\/quantify.pl -i $read -d $depth -o $rpkm\n\n\n";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
359 return 0;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
360 }
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
361
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
362 sub phase{
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
363 $annotate_dir=$dir."annotate\/";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
364 mkdir ("$annotate_dir");
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
365 print "clusters is to predict phase siRNA\n";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
366 my $phase=`perl $path\/phased_siRNA.pl -i $read_txt -o $annotate_dir\/phase.out`;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
367 print "perl $path\/phased_siRNA.pl -i $read_txt -o $annotate_dir\/phase.out\n\n\n";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
368 return 0;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
369 }
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
370
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
371 sub class{
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
372 print "clusters is ready to annotate by sources\n\n";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
373 my $nat=$options{'nat'};
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
374 my $repeat=$options{'repeat'};
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
375 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`;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
376 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";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
377 }
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
378
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
379 sub annotate{
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
380 print "clusters is ready to annotate by gff file\n\n";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
381 my $file;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
382 if (defined($options{'nat'})&&defined($options{'repeat'})) {
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
383 $file="$annotate_dir\/sample_class.anno";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
384 }
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
385 else{
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
386 $file=$rpkm;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
387 }
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
388 my $annotate=`perl $path\/Annotate.pl -i $file -g $dir\/ref\/genelist.txt -d $up_down_dis -o $annotate_dir\/sample_c_p.anno`;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
389 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";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
390 return 0;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
391 }
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
392 sub get_genelist{
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
393
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
394 my $get_genelist=`perl $path\/get_genelist.pl -i $gff -o $dir\/ref\/genelist.txt`;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
395 print "perl $path\/get_genelist.pl -i $gff -o $dir\/ref\/genelist.txt";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
396 }
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
397
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
398 sub dec{
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
399 print "deg reading\n\n";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
400 my $deg_file=$options{'deg'};
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
401 open IN,"<$deg_file";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
402 my @deg;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
403 my $s=0;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
404 while (my $aline=<IN>) {
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
405 chomp $aline;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
406 next if($aline=~/^\#/);
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
407 $deg[$s]=$aline;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
408 my @ea=split/\s+/,$aline;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
409 push @pairdir,"$ea[0]_VS_$ea[1]\/";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
410 #print "$deg[$s]\n";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
411 $s++;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
412 }
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
413 close IN;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
414 $deg_dir=$dir."deg\/";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
415 mkdir ("$deg_dir");
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
416 my $max_process = 10;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
417 my $pm = new Parallel::ForkManager( $max_process );
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
418 my $number=@deg-1;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
419 foreach(0..$number){
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
420 $pm->start and next;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
421 &dec_pel($deg[$_]);
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
422 $pm->finish;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
423 }
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
424 $pm->wait_all_children;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
425 }
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
426
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
427 sub dec_pel{
18
22d79320085c Uploaded
big-tiandm
parents: 11
diff changeset
428 print "\n******************\nstart:\n";
11
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
429 Time();
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
430 my $sample=shift(@_);
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
431 my @each=split/\s+/,$sample;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
432 print "$each[0]\t$each[1]\n";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
433 my $deg_sample_dir=$deg_dir."$each[0]_VS_$each[1]\/";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
434 mkdir ("$deg_sample_dir");
18
22d79320085c Uploaded
big-tiandm
parents: 11
diff changeset
435 print "read: $read\n";
22d79320085c Uploaded
big-tiandm
parents: 11
diff changeset
436 print "deg_sample_dir: $deg_sample_dir\n";
22d79320085c Uploaded
big-tiandm
parents: 11
diff changeset
437 print "$id{$each[0]}\t$each[0]\n";
22d79320085c Uploaded
big-tiandm
parents: 11
diff changeset
438 print "$id{$each[1]}\t$each[1]\n";
11
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
439 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
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
440 my $time2=time();
18
22d79320085c Uploaded
big-tiandm
parents: 11
diff changeset
441 print "end:\n*************************\n";
11
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
442 Time();
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
443 sleep 1;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
444 }
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
445
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
446 sub infor_merge{
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
447 my ($input,$mark);
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
448 foreach (@pairdir) {
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
449 print "@pairdir\n";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
450 $mark.=" -mark $_ ";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
451 $input.=" -i $dir/deg\/$_\/output_score\.txt ";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
452 print "$input\n$mark\n";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
453 }
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
454 my $infor_merge=`perl $path\/SampleDEGseqMerge.pl $input $mark -f $annotate_dir\/sample_c_p.anno -n $sample_number -o $dir\/total.result `;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
455 print "perl $path\/SampleDEGseqMerge.pl $input $mark -f $annotate_dir\/sample_c_p.anno -n $sample_number -o $dir\/total.result\n\n";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
456 }
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
457
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
458 sub infor_merge_no_dec{
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
459 my $infor_merge_no_dec=`cp $annotate_dir\/sample_c_p.anno $dir\/total.result`;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
460 }
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
461
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
462 sub genome_length{
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
463 my $length=`perl $path\/count_ref_length.pl -i $genome_fa -o $dir\/ref\/genome\.length`;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
464 print "perl $path\/count_ref_length.pl -i $genome_fa -o $dir\/ref\/genome\.length\n\n"
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
465
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
466 }
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
467
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
468 sub plot{
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
469 my $plot_file="$dir\/plot\/";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
470 mkdir ("$plot_file");
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
471 my $genome_plot="$dir\/plot\/genome\/";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
472 mkdir ("$genome_plot");
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
473 #genome cluster
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
474 my $span=defined($options{span})?$options{span}:50000;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
475 foreach (1..$sample_number) {
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
476 my $mark=$mark[$_-1];
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
477 my $cen="";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
478 if (defined $options{cen}) {
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
479 $cen="-cen $options{cen}";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
480 }
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
481 my $plot=`perl $path\/sRNA_rpkm_distribution_along_genome.pl -c $rpkm -n $_ -mark $mark -span $span -l $dir\/ref\/genome\.length $cen -o $genome_plot\/$mark\.html -out $genome_plot\/$mark\.txt`;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
482 print "perl $path\/sRNA_rpkm_distribution_along_genome.pl -c $rpkm -n $_ -mark $mark -span $span -l $dir\/ref\/genome\.length $cen -o $genome_plot\/$mark\.html -out $genome_plot\/$mark\.txt\n\n";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
483 }
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
484
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
485 my $chr_plot_dir="$dir\/plot\/chr\/";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
486 mkdir("$chr_plot_dir");
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
487 my %chr;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
488 open LEN,"<$dir\/ref\/genome\.length";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
489 while (my $aline=<LEN>) {
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
490 next if($aline=~/^\#/);
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
491 chomp $aline;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
492 my @temp=split/\t/,$aline;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
493 $chr{$temp[0]}=$temp[1];
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
494 }
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
495 close LEN;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
496 foreach my $chr (sort keys %chr) {
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
497 my $cen="";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
498 if (defined $options{cen}) {
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
499 $cen="-cen $options{cen}";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
500 }
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
501 my $chr_plot=`perl $path\/chr_plot.pl -l $chr{$chr} -chro $chr -g $dir\/ref\/genelist.txt -span $span -c $rpkm -mark $sample_mark -o $chr_plot_dir\/$chr\.html`;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
502 print "perl $path\/chr_plot.pl -l $chr{$chr} -chro $chr -g $dir\/ref\/genelist.txt -span $span -c $rpkm -mark $sample_mark -o $chr_plot_dir\/$chr\.html\n";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
503 }
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
504 }
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
505
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
506 sub html{
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
507 my $pathfile="$dir/path.txt";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
508 open PA,">$pathfile";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
509 print PA "$config\n";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
510 print PA "$preprocess\n";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
511 print PA "$dir"."rfam_match\n";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
512 print PA "$dir"."genome_match\n";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
513 print PA "$cluster_file\n";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
514 print PA "$annotate_dir\n";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
515 if (defined($deg_dir)) {
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
516 print PA "$deg_dir\n";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
517 }
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
518 close PA;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
519 my $html=`perl $path\/html.pl -i $pathfile -format $format -o $dir/result.html`;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
520 }
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
521
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
522 sub Time{
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
523 my $time=time();
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
524 my ($sec,$min,$hour,$day,$month,$year) = (localtime($time))[0,1,2,3,4,5,6];
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
525 $month++;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
526 $year+=1900;
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
527 if (length($sec) == 1) {$sec = "0"."$sec";}
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
528 if (length($min) == 1) {$min = "0"."$min";}
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
529 if (length($hour) == 1) {$hour = "0"."$hour";}
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
530 if (length($day) == 1) {$day = "0"."$day";}
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
531 if (length($month) == 1) {$month = "0"."$month";}
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
532 print "$year-$month-$day $hour:$min:$sec\n";
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
533 return("$year-$month-$day-$hour-$min-$sec");
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
534 }
a0222bdfe2ac Uploaded
big-tiandm
parents:
diff changeset
535 #################################################################################