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

Uploaded
author bigrna
date Sun, 04 Jan 2015 02:47:25 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
1 #!/usr/bin/perl -w
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
2 #Filename:
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
3 #Author: Tian Dongmei
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
4 #Email: tiandm@big.ac.cn
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
5 #Date: 2014-12-2
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
6 #Modified:
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
7 #Description: RNA-seq data pre-process
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
8 my $version=1.00;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
9
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
10 use strict;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
11 use Getopt::Long;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
12 use threads;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
13 #use threads::shared;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
14 use File::Path;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
15 use File::Basename;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
16 #use RNA;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
17 #use Term::ANSIColor;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
18
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
19 my %opts;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
20 GetOptions(\%opts,"i:s@","tag:s@","format=s","phred:i","gfa=s","rfam:s","idx:s","idx2:s","mis:i","v:i","a:s","M:i","t:i","min:i","max:i","o:s","path:s","h");
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
21 if (!(defined $opts{i} and defined $opts{format} and defined $opts{gfa} ) || defined $opts{h}) { #necessary arguments
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
22 &usage;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
23 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
24
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
25 my $time=&Time();
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
26 print "miPlant program start:\n The time is $time!\n";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
27 print "Command line:\n $0 @ARGV\n";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
28
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
29 my $format=$opts{'format'};
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
30 if ($format ne "fastq" && $format ne "fq" && $format ne "fasta" && $format ne "fa") {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
31 #&printErr();
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
32 die "Parameter \"-format\" is error! Parameter is fastq, fq, fasta or fa\n";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
33 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
34
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
35 my $phred_qv=64;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
36 if (defined $opts{'phred'}) {$phred_qv=$opts{'phred'};}
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
37
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
38 my @inputfiles=@{$opts{'i'}};
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
39 my @inputtags=@{$opts{'tag'}};
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
40
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
41 my $mypath=`pwd`;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
42 chomp $mypath;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
43
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
44 my $dir=defined $opts{'o'} ? $opts{'o'} : "$mypath/preProcess/";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
45
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
46
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
47 unless ($dir=~/\/$/) {$dir.="/";}
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
48 if (not -d $dir) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
49 mkdir $dir;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
50 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
51 my $config=$dir."/input_config";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
52 open CONFIG,">$config";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
53 for (my $i=0;$i<@inputfiles;$i++) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
54 print CONFIG $inputfiles[$i],"\t",$inputtags[$i],"\n";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
55 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
56 close CONFIG;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
57
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
58 my $scipt_path=defined $opts{'path'} ? $opts{'path'} : "/Users/big/galaxy-dist/tools/myTools/";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
59
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
60 my $a="ATCTCGTATG"; #adapter
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
61 if (defined $opts{'a'}) {$a=$opts{'a'};}
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
62
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
63 my $m=6; #adapter minimum mapped nt
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
64 if (defined $opts{'M'}) {$m=$opts{'M'};}
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
65
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
66 my $t=1; #threads number
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
67 if (defined $opts{'t'}) {$t=$opts{'t'};}
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
68
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
69 my $min_nt=19; # minimum reads length
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
70 if (defined $opts{'min'}) {$min_nt=$opts{'min'};}
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
71
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
72 my $max_nt=28; #maximum reads length
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
73 if (defined $opts{'max'}) {$max_nt=$opts{'max'};}
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
74
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
75 my $mis=0; #mismatch number for microRNA
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
76 if (defined $opts{'mis'}) {$mis=$opts{'mis'};}
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
77
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
78 my $mis_rfam=0;# mismatch number for rfam
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
79 if (defined $opts{'v'}) {$mis_rfam=$opts{'v'};}
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
80
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
81 my (@filein,@mark,@clean);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
82 #&read_config();
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
83 @filein=@inputfiles;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
84 @mark=@inputtags;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
85
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
86 &checkfa($opts{gfa});
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
87
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
88
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
89 ##### clip adpter --> clean data start
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
90 my $preprocess=$dir."preProcess_clean/";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
91 mkdir $preprocess;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
92 my $can_use_threads = eval 'use threads; 1';
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
93 if ($can_use_threads) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
94 # Do processing using threads
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
95 print "Do processing using threads\n";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
96 my @filein1=@filein; my @mark1=@mark;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
97 while (@filein1>0) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
98 my @thrs; my @res;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
99 for (my $i=0;$i<$t ;$i++) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
100 last if(@filein1==0);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
101 my $in=shift @filein1;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
102 my $out=shift @mark1;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
103 push @clean,$preprocess.$out."_clips_adapter.fq";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
104 $thrs[$i]=threads->create(\&clips,$in,$out);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
105 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
106 for (my $i=0;$i<@thrs;$i++) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
107 $res[$i]=$thrs[$i]->join();
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
108 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
109 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
110 } else {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
111 # Do not processing using threads
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
112 print "Do not processing using threads\n";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
113 for (my $i=0;$i<@filein ;$i++) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
114 my $in=$filein[$i];
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
115 my $out=$mark[$i];
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
116 push @clean,$preprocess.$out."_clips_adapter.fq";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
117 &clips($in,$out);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
118 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
119 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
120
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
121 ##### clip adpter --> clean data end
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
122
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
123 my $collapsed=$preprocess."collapse_reads.fa";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
124 my $data=$preprocess."collapse_reads_${min_nt}_${max_nt}.fa"; ## raw clean data
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
125 &collapse(\@clean,$collapsed); #collapse reads to tags
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
126
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
127 &filterbylength(); # filter <$min_nt && >$max_nt
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
128
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
129 print "The final clean data file is $data, only contains reads which length is among $min_nt\~$max_nt\n\n";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
130
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
131 my $clean_data=$preprocess."clean_data.fa";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
132 system("ln -s $data $clean_data");
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
133
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
134 $time=Time();
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
135 print "$time: Genome alignment!\n\n";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
136 my $genome_map=$dir."genome_match";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
137 &genome($data);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
138 #my $genome_map=&search($dir,"genome_match_");
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
139 my $mapfile=$genome_map."/genome_mapped.bwt";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
140 my $mapfa=$genome_map."/genome_mapped.fa";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
141 my $unmap=$genome_map."/genome_not_mapped.fa";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
142
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
143 chdir $dir;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
144 my $pathfile="$dir/path.txt";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
145 open PA,">$pathfile";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
146 print PA "$config\n";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
147 print PA "$preprocess\n";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
148 print PA "$genome_map\n";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
149
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
150 if (defined $opts{'rfam'}) { #rfam mapping and analysis
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
151 $time=Time();
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
152 print "$time: RNA annotate!\n\n";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
153 $time=~s/:/-/g;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
154 $time=~s/ /-/g;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
155 my $rfam_exp_dir=$dir."rfam_match";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
156 &rfam();
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
157 #my $rfam_exp_dir=&search($dir,"rfam_match_");
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
158 print PA "$rfam_exp_dir\n";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
159
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
160 my $tag=join "\\;" ,@mark;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
161 system("perl $scipt_path/count_rfam_express.pl -i $rfam_exp_dir/rfam_mapped.bwt -tag $tag -o rfam_non-miRNA_annotation.txt");
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
162 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
163
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
164
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
165 close PA;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
166 system("perl $scipt_path/html_preprocess.pl -i $pathfile -format $format -min $min_nt -max $max_nt -o $dir/preprocessResult.html");
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
167
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
168 $time=Time();
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
169 print "$time: Program end!!\n";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
170
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
171 ############################## sub programs ###################################
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
172 sub genome{
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
173 my ($file)=@_;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
174 if(defined $opts{'idx'}){
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
175 system("perl $scipt_path/matching.pl -i $file -g $opts{gfa} -r 1000 -v $mis -p $t -o $dir -index $opts{idx}") ;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
176 # print "\nmatching.pl -i $file -g $opts{gfa} -v $mis -p $t -r $hit -o $dir -index $opts{idx} -time $time\n";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
177 }else{
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
178 system("perl $scipt_path/matching.pl -i $file -g $opts{gfa} -r 1000 -v $mis -p $t -o $dir") ;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
179 # print "\nmatching.pl -i $file -g $opts{gfa} -v $mis -p $t -r $hit -o $dir -time $time\n";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
180 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
181 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
182 sub rfam{
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
183 if (defined $opts{'idx2'}) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
184 system("perl $scipt_path/rfam.pl -i $mapfa -ref $opts{rfam} -v $mis_rfam -p $t -o $dir -index $opts{idx2} ");
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
185 # print "\nrfam.pl -i $data2 -ref $opts{rfam} -v $mis_rfam -p $t -o $dir -index $opts{idx2} -time $time\n";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
186 }else{
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
187 system("perl $scipt_path/rfam.pl -i $mapfa -ref $opts{rfam} -v $mis_rfam -p $t -o $dir ");
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
188 # print "\nrfam.pl -i $data2 -ref $opts{rfam} -v $mis_rfam -p $t -o $dir -time $time\n";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
189 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
190 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
191 sub filterbylength{
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
192 my $tmpmark=join ",", @mark;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
193 system("perl $scipt_path/filterReadsByLength.pl -i $collapsed -o $data -min $min_nt -max $max_nt -mark $tmpmark");
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
194 system("perl $scipt_path/Length_Distibution.pl -i $preprocess/reads_length_distribution.txt -o $preprocess/length.html");
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
195 # print "\nfilterReadsByLength.pl -i $collapsed -o $data -min $min_nt -max $max_nt -mark $tmpmark\n";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
196
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
197 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
198 sub collapse{
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
199 my ($ins,$data)=@_;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
200 my $str="";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
201 for (my $i=0;$i<@{$ins};$i++) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
202 $str .="-i $$ins[$i] ";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
203 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
204 system ("perl $scipt_path/collapseReads2Tags.pl $str -mark seq -o $data -format $format");
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
205 # print "\ncollapseReads2Tags.pl $str -mark seq -o $data -format $format\n";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
206 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
207
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
208 sub clips{
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
209 my ($in,$out)=@_;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
210 my $adapter=$preprocess.$out."_clips_adapter.fq";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
211 if($format eq "fq" || $format eq "fastq"){
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
212 system("fastx_clipper -a $a -M $m -Q $phred_qv -i $in -o $adapter") ;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
213 # print "\nfastx_clipper -a $a -M $m -Q $phred_qv -i $in -o $adapter\n";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
214 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
215 if($format eq "fa" || $format eq "fasta"){
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
216 system("fastx_clipper -a $a -M $m -i $in -o $adapter") ;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
217 # print "\nfastx_clipper -a $a -M $m -i $in -o $adapter\n";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
218 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
219 #my $clean=$preprocess.$out."_clean.fq";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
220 #system("filterReadsByLength.pl -i $adapter -o $clean -min $min_nt -max $max_nt ");
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
221
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
222 return;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
223 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
224
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
225 sub read_config{
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
226 open CON,"<$config";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
227 while (my $aline=<CON>) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
228 chomp $aline;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
229 my @tmp=split/\t/,$aline;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
230 push @filein,$tmp[0];
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
231 push @mark,$tmp[1];
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
232 &check_rawdata($tmp[0]);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
233 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
234 close CON;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
235 if (@filein != @mark) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
236 #&printErr();
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
237 die "Maybe config file have some wrong!!!\n";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
238 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
239 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
240 sub check_rawdata{
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
241 my ($fileforcheck)=@_;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
242 if (!(-s $fileforcheck)) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
243 #&printErr();
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
244 die "Can not find $fileforcheck, or file is empty!!!\n";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
245 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
246 if ($format eq "fasta" || $format eq "fa") {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
247 &checkfa($fileforcheck);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
248 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
249 if ($format eq "fastq" || $format eq "fq") {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
250 &checkfq($fileforcheck);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
251 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
252 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
253 sub checkfa{
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
254 my ($file_reads)=@_;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
255 open N,"<$file_reads";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
256 my $line=<N>;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
257 chomp $line;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
258 if($line !~ /^>\S+/){
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
259 #printErr();
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
260 die "The first line of file $file_reads does not start with '>identifier'
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
261 Reads file $file_reads is not a valid fasta file\n\n";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
262 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
263 if(<N> !~ /^[ACGTNacgtn]*$/){
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
264 #printErr();
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
265 die "File $file_reads contains not allowed characters in sequences
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
266 Allowed characters are ACGTN
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
267 Reads file $file_reads is not a fasta file\n\n";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
268 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
269 close N;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
270 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
271 sub checkfq{
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
272 my ($file_reads)=@_;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
273
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
274 open N,"<$file_reads";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
275 for (my $i=0;$i<10;$i++) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
276 my $a=<N>;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
277 my $b=<N>;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
278 my $c=<N>;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
279 my $d=<N>;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
280 chomp $a;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
281 chomp $b;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
282 chomp $c;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
283 chomp $d;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
284 if($a!~/^\@/){
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
285 #&printErr();
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
286 die "$file_reads is not a fastq file\n\n";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
287 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
288 if($b!~ /^[ACGTNacgtn]*$/){
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
289 #&printErr();
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
290 die "File $file_reads contains not allowed characters in sequences
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
291 Allowed characters are ACGTN
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
292 Reads file $file_reads is not a fasta file\n\n";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
293 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
294 if ($c!~/^\@/ && $c!~/^\+/) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
295 #&printErr();
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
296 die "$file_reads is not a fastq file\n\n";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
297 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
298 if ((length $b) != (length $d)) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
299 #&printErr();
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
300 die "$file_reads is not a fastq file\n\n";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
301 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
302 my @qv=split //,$d;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
303 for (my $j=0;$j<@qv ;$j++) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
304 my $q=ord($qv[$j])-64;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
305 if($q<0){$phred_qv=33;}
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
306 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
307 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
308 close N;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
309 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
310
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
311 sub search{
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
312 my ($dir,$str)=@_;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
313 opendir I,$dir;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
314 my @ret;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
315 while (my $file=readdir I) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
316 if ($file=~/$str/) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
317 push @ret, $file;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
318 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
319 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
320 closedir I;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
321 if (@ret != 1) {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
322 #&printErr();
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
323
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
324 die "Can not find directory or file which name has string: $str !!!\n";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
325 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
326 return $ret[0];
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
327 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
328
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
329 sub Time{
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
330 my $time=time();
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
331 my ($sec,$min,$hour,$day,$month,$year) = (localtime($time))[0,1,2,3,4,5,6];
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
332 $month++;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
333 $year+=1900;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
334 if (length($sec) == 1) {$sec = "0"."$sec";}
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
335 if (length($min) == 1) {$min = "0"."$min";}
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
336 if (length($hour) == 1) {$hour = "0"."$hour";}
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
337 if (length($day) == 1) {$day = "0"."$day";}
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
338 if (length($month) == 1) {$month = "0"."$month";}
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
339 #print "$year-$month-$day $hour:$min:$sec\n";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
340 return("$year-$month-$day $hour:$min:$sec");
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
341 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
342
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
343
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
344 sub usage{
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
345 print <<"USAGE";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
346 Version $version
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
347 Usage:
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
348 $0 -i -format -gfa -index -rfam -a -M -min -max -mis -v -t -o -path
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
349 options:
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
350 -i input files, # raw data file, can be multipe eg. -i xxx.fq -i xxx .fq ...
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
351 -tag string # raw data file names, -tag xxx -tag xxx
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
352
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
353 -format string,#specific input rawdata file format : fastq|fq|fasta|fa
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
354 -phred int # phred quality number, default is 64
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
355
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
356 -path scirpt path
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
357
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
358 -gfa string, input file # genome fasta. sequence file
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
359 -idx string, genome file index, file-prefix #(must be indexed by bowtie-build) The parameter
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
360 string must be the prefix of the bowtie index. For instance, if
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
361 the first indexed file is called 'h_sapiens_37_asm.1.ebwt' then
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
362 the prefix is 'h_sapiens_37_asm'.##can be null
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
363
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
364 -rfam string, input file# rfam database file, microRNAs must not be contained in this file## if not define, rfam small RNA will not be count.
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
365 -idx2 string, rfam file index, file-prefix #(must be indexed by bowtie-build) The parameter
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
366 string must be the prefix of the bowtie index. For instance, if
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
367 the first indexed file is called 'h_sapiens_37_asm.1.ebwt' then
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
368 the prefix is 'h_sapiens_37_asm'.##can be null
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
369
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
370 -a string, ADAPTER string. default is ATCTCGTATG.
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
371 -M int, require minimum adapter alignment length of N. If less than N nucleotides aligned with the adapter - don't clip it.
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
372 -min int, reads min length,default is 19.
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
373 -max int, reads max length,default is 28.
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
374
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
375 -mis [int] number of allowed mismatches when mapping reads to genome, default 0
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
376 -v <int> report end-to-end hits w/ <=v mismatches; ignore qualities,default 0; used in rfam alignment
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
377
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
378 -t int, number of threads [1]
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
379
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
380 -o output directory# absolute path
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
381 -h help
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
382 USAGE
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
383 exit(1);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
384 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
385