annotate rapsodyn/PrepareFastqLight.pl @ 14:93e6f2af1ce2 draft

Uploaded
author mcharles
date Mon, 26 Jan 2015 18:10:52 -0500
parents 0a6c1cfe4dc8
children 56d328bce3a7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
1 #!/usr/bin/perl
10
0a6c1cfe4dc8 Uploaded
mcharles
parents: 8
diff changeset
2 #v1.1.0 manage empty files
0a6c1cfe4dc8 Uploaded
mcharles
parents: 8
diff changeset
3 #v1.0.4 bug correction, last read not considered
8
d857538d9fea Uploaded
mcharles
parents: 7
diff changeset
4 #v1.0.3 support rapsodyn header (.... 1:... / .... 2:...)
d857538d9fea Uploaded
mcharles
parents: 7
diff changeset
5 #V1.0.2 added auto type detection
7
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
6 #V1.0.1 added log, option parameters
0
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
7 use strict;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
8 use warnings;
7
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
9 use Getopt::Long;
0
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
10
7
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
11 my $read1_file;
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
12 my $read2_file;
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
13 my $log_file;
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
14 my $output1_file;
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
15 my $output2_file;
0
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
16
7
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
17 my $TYPE="sanger";
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
18 my $MIN_LENGTH=30;
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
19 my $MIN_QUALITY=30;
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
20
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
21 my $VERBOSE = "OFF";
0
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
22
7
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
23 GetOptions (
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
24 "read1_file=s" => \$read1_file,
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
25 "read2_file=s" => \$read2_file,
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
26 "log_file=s" => \$log_file,
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
27 "output1_file=s" => \$output1_file,
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
28 "output2_file=s" => \$output2_file,
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
29 "type=s" => \$TYPE,
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
30 "min_length=i" => \$MIN_LENGTH,
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
31 "min_quality=i" => \$MIN_QUALITY,
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
32 "verbose=s" => \$VERBOSE
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
33 ) or die("Error in command line arguments\n");
0
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
34
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
35
7
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
36 my $nb_read1=0;
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
37 my $nb_base_read1=0;
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
38 my $nb_read2=0;
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
39 my $nb_base_read2=0;
0
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
40
7
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
41 my $nb_read1_t=0;
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
42 my $nb_base_read1_t=0;
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
43 my $nb_read2_t=0;
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
44 my $nb_base_read2_t=0;
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
45
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
46 my $nb_base_current_t=0;
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
47
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
48 open(READ1, $read1_file) or die ("Can't open $read1_file\n");
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
49 open(READ2, $read2_file) or die ("Can't open $read2_file\n");
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
50 open(OUT1, ">$output1_file") or die ("Can't open $output1_file\n");
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
51 open(OUT2, ">$output2_file") or die ("Can't open $output2_file\n");
8
d857538d9fea Uploaded
mcharles
parents: 7
diff changeset
52 open (LF,">$log_file") or die("Can't open $log_file\n");
d857538d9fea Uploaded
mcharles
parents: 7
diff changeset
53
10
0a6c1cfe4dc8 Uploaded
mcharles
parents: 8
diff changeset
54 if (( -z READ1)&&( -z READ2)){
0a6c1cfe4dc8 Uploaded
mcharles
parents: 8
diff changeset
55 exit(0);
0a6c1cfe4dc8 Uploaded
mcharles
parents: 8
diff changeset
56 }
0a6c1cfe4dc8 Uploaded
mcharles
parents: 8
diff changeset
57 elsif (( -z READ1)||( -z READ2)){
0a6c1cfe4dc8 Uploaded
mcharles
parents: 8
diff changeset
58 print STDERR "One empty File\n";
0a6c1cfe4dc8 Uploaded
mcharles
parents: 8
diff changeset
59 exit(0);
0a6c1cfe4dc8 Uploaded
mcharles
parents: 8
diff changeset
60 }
0a6c1cfe4dc8 Uploaded
mcharles
parents: 8
diff changeset
61
0
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
62
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
63 my $error1=0;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
64 my $error2=0;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
65 my $error3=0;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
66 my $error4=0;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
67 my $error5=0;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
68 my $error6=0;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
69 my $error7=0;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
70 my $error8=0;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
71 my $error9=0;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
72 my $error10=0;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
73
8
d857538d9fea Uploaded
mcharles
parents: 7
diff changeset
74 my $auto_type="";
d857538d9fea Uploaded
mcharles
parents: 7
diff changeset
75 my %qual;
d857538d9fea Uploaded
mcharles
parents: 7
diff changeset
76 if ($TYPE eq "auto"){
d857538d9fea Uploaded
mcharles
parents: 7
diff changeset
77 my $compt=0;
d857538d9fea Uploaded
mcharles
parents: 7
diff changeset
78 open(DETECT, $read1_file) or die ("Can't open $read1_file\n");
d857538d9fea Uploaded
mcharles
parents: 7
diff changeset
79 while (my $ligne1_r1 =<DETECT>){
d857538d9fea Uploaded
mcharles
parents: 7
diff changeset
80 my $ligne2_r1 =<DETECT>;
d857538d9fea Uploaded
mcharles
parents: 7
diff changeset
81 my $ligne3_r1 =<DETECT>;
d857538d9fea Uploaded
mcharles
parents: 7
diff changeset
82 my $ligne4_r1 =<DETECT>;
d857538d9fea Uploaded
mcharles
parents: 7
diff changeset
83 $compt++;
d857538d9fea Uploaded
mcharles
parents: 7
diff changeset
84 if ($ligne4_r1 =~ /^(.*)\s*$/i){
d857538d9fea Uploaded
mcharles
parents: 7
diff changeset
85 my $qual = $1;
d857538d9fea Uploaded
mcharles
parents: 7
diff changeset
86 my @q = split(//,$qual);
d857538d9fea Uploaded
mcharles
parents: 7
diff changeset
87 for (my $i=0;$i<=$#q;$i++){
d857538d9fea Uploaded
mcharles
parents: 7
diff changeset
88 my $num = ord($q[$i]);
d857538d9fea Uploaded
mcharles
parents: 7
diff changeset
89 if ($qual{$num}){
d857538d9fea Uploaded
mcharles
parents: 7
diff changeset
90 $qual{$num}++;
d857538d9fea Uploaded
mcharles
parents: 7
diff changeset
91 }
d857538d9fea Uploaded
mcharles
parents: 7
diff changeset
92 else {
d857538d9fea Uploaded
mcharles
parents: 7
diff changeset
93 $qual{$num} = 1;
d857538d9fea Uploaded
mcharles
parents: 7
diff changeset
94 }
d857538d9fea Uploaded
mcharles
parents: 7
diff changeset
95 #range sanger / illumina 1.8+ : 33->94
d857538d9fea Uploaded
mcharles
parents: 7
diff changeset
96 #range illumina 1.3->1.7 : 64->105
d857538d9fea Uploaded
mcharles
parents: 7
diff changeset
97 if ($num > 94){$auto_type = "illumina";last;}
d857538d9fea Uploaded
mcharles
parents: 7
diff changeset
98 if ($num < 64){$auto_type = "sanger";last;}
d857538d9fea Uploaded
mcharles
parents: 7
diff changeset
99 }
d857538d9fea Uploaded
mcharles
parents: 7
diff changeset
100 }
d857538d9fea Uploaded
mcharles
parents: 7
diff changeset
101 else {
d857538d9fea Uploaded
mcharles
parents: 7
diff changeset
102 print STDERR "Error in format detection : quality not recognized\n$ligne4_r1";
d857538d9fea Uploaded
mcharles
parents: 7
diff changeset
103 exit(0);
d857538d9fea Uploaded
mcharles
parents: 7
diff changeset
104 }
d857538d9fea Uploaded
mcharles
parents: 7
diff changeset
105
d857538d9fea Uploaded
mcharles
parents: 7
diff changeset
106 if ($auto_type ne ""){
d857538d9fea Uploaded
mcharles
parents: 7
diff changeset
107 last;
d857538d9fea Uploaded
mcharles
parents: 7
diff changeset
108 }
d857538d9fea Uploaded
mcharles
parents: 7
diff changeset
109
d857538d9fea Uploaded
mcharles
parents: 7
diff changeset
110 }
d857538d9fea Uploaded
mcharles
parents: 7
diff changeset
111 close (DETECT);
d857538d9fea Uploaded
mcharles
parents: 7
diff changeset
112 if ($auto_type eq ""){
d857538d9fea Uploaded
mcharles
parents: 7
diff changeset
113 print STDERR "Error in format detection : type not recognized parsing read1\n";
d857538d9fea Uploaded
mcharles
parents: 7
diff changeset
114 foreach my $key (sort {$a <=> $b} keys %qual){
d857538d9fea Uploaded
mcharles
parents: 7
diff changeset
115 print "$key\t:\t",$qual{$key},"\n";
d857538d9fea Uploaded
mcharles
parents: 7
diff changeset
116 }
d857538d9fea Uploaded
mcharles
parents: 7
diff changeset
117 exit(0);
d857538d9fea Uploaded
mcharles
parents: 7
diff changeset
118 }
d857538d9fea Uploaded
mcharles
parents: 7
diff changeset
119 else {
d857538d9fea Uploaded
mcharles
parents: 7
diff changeset
120 $TYPE = $auto_type;
d857538d9fea Uploaded
mcharles
parents: 7
diff changeset
121 }
d857538d9fea Uploaded
mcharles
parents: 7
diff changeset
122 }
d857538d9fea Uploaded
mcharles
parents: 7
diff changeset
123
d857538d9fea Uploaded
mcharles
parents: 7
diff changeset
124
d857538d9fea Uploaded
mcharles
parents: 7
diff changeset
125
10
0a6c1cfe4dc8 Uploaded
mcharles
parents: 8
diff changeset
126 my $compt=0;
0
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
127 while (my $ligne1_r1 =<READ1>){
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
128 my $ligne2_r1 =<READ1>;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
129 my $ligne3_r1 =<READ1>;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
130 my $ligne4_r1 =<READ1>;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
131 my $ligne1_r2 =<READ2>;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
132 my $ligne2_r2 =<READ2>;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
133 my $ligne3_r2 =<READ2>;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
134 my $ligne4_r2 =<READ2>;
10
0a6c1cfe4dc8 Uploaded
mcharles
parents: 8
diff changeset
135 # chomp($ligne1_r1);
0a6c1cfe4dc8 Uploaded
mcharles
parents: 8
diff changeset
136 # chomp($ligne2_r1);
0a6c1cfe4dc8 Uploaded
mcharles
parents: 8
diff changeset
137 # chomp($ligne3_r1);
0a6c1cfe4dc8 Uploaded
mcharles
parents: 8
diff changeset
138 # chomp($ligne4_r1);
0a6c1cfe4dc8 Uploaded
mcharles
parents: 8
diff changeset
139 # chomp($ligne2_r1);
0a6c1cfe4dc8 Uploaded
mcharles
parents: 8
diff changeset
140
0a6c1cfe4dc8 Uploaded
mcharles
parents: 8
diff changeset
141 $compt++;
7
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
142 $nb_read1++;
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
143 $nb_read2++;
0
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
144
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
145 #@ 1 sec
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
146 if ((!$ligne1_r1)||(!$ligne2_r1)||(!$ligne3_r1)||(!$ligne4_r1)||(!$ligne1_r2)||(!$ligne2_r2)||(!$ligne3_r2)||(!$ligne4_r2)){
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
147 if ($VERBOSE eq "ON"){
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
148 print "Error in file format";
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
149 if ($ligne1_r1){print $ligne1_r1;}
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
150 if ($ligne2_r1){print $ligne2_r1;}
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
151 if ($ligne3_r1){print $ligne3_r1;}
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
152 if ($ligne4_r1){print $ligne4_r1;}
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
153 if ($ligne1_r2){print $ligne1_r2;}
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
154 if ($ligne2_r2){print $ligne2_r2;}
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
155 if ($ligne3_r2){print $ligne3_r2;}
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
156 if ($ligne4_r2){print $ligne4_r2;}
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
157 print "\n";
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
158 }
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
159 $error1++;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
160 }
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
161 elsif(($ligne1_r1 !~/^\@/)||($ligne1_r2 !~/^\@/)||($ligne3_r1 !~/^\+/)||($ligne3_r2 !~/^\+/)){
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
162 if ($VERBOSE eq "ON"){
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
163 print "Error in header : format\n";
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
164 print $ligne1_r1;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
165 print $ligne2_r1;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
166 print $ligne3_r1;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
167 print $ligne4_r1;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
168 print $ligne1_r2;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
169 print $ligne2_r2;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
170 print $ligne3_r2;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
171 print $ligne4_r2;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
172 print "\n";
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
173 }
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
174 $error2++;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
175 }
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
176 #@ 1 - 2 sec
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
177 else {
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
178
10
0a6c1cfe4dc8 Uploaded
mcharles
parents: 8
diff changeset
179 my $length_seq1 = length(chomp($ligne2_r1));
0a6c1cfe4dc8 Uploaded
mcharles
parents: 8
diff changeset
180 my $length_qual1 =length(chomp($ligne4_r1));
0
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
181 my $seq1;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
182 my $qual1;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
183
10
0a6c1cfe4dc8 Uploaded
mcharles
parents: 8
diff changeset
184 my $length_seq2 = length(chomp($ligne2_r2));
0a6c1cfe4dc8 Uploaded
mcharles
parents: 8
diff changeset
185 my $length_qual2 =length(chomp($ligne4_r2));
0
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
186 my $seq2;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
187 my $qual2;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
188 my $header1="";
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
189 my $header2="";
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
190 my $repheader1="";
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
191 my $repheader2="";
7
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
192
0
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
193
8
d857538d9fea Uploaded
mcharles
parents: 7
diff changeset
194 if ($ligne1_r1 =~/^\@(.*?)[\s\/]/){
0
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
195 $header1 = $1;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
196 }
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
197
8
d857538d9fea Uploaded
mcharles
parents: 7
diff changeset
198 if ($ligne3_r1 =~/^\+(.*?)[\s\/]/){
0
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
199 $repheader1 = $1;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
200 }
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
201
8
d857538d9fea Uploaded
mcharles
parents: 7
diff changeset
202 if ($ligne1_r2 =~/^\@(.*?)[\s\/]/){
0
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
203 $header2 = $1;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
204 }
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
205
8
d857538d9fea Uploaded
mcharles
parents: 7
diff changeset
206 if ($ligne3_r2 =~/^\+(.*?)[\s\/]/){
0
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
207 $repheader2 = $1;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
208 }
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
209 #@ 2 sec
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
210
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
211 ### Verification de la coherence sequence /qualité @ 1 sec
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
212 if (($TYPE eq "illumina")&&((!$header1)||(!$header2)||(!$repheader1)||(!$repheader2))){
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
213 if ($VERBOSE eq "ON"){
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
214 print "Error in header : empty\n";
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
215 print $ligne1_r1;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
216 print $ligne2_r1;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
217 print $ligne3_r1;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
218 print $ligne4_r1;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
219 print $ligne1_r2;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
220 print $ligne2_r2;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
221 print $ligne3_r2;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
222 print $ligne4_r2;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
223 print "\n";
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
224 }
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
225 $error3++;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
226 }
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
227 elsif (($TYPE eq "sanger")&&((!$header1)||(!$header2))){
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
228 if ($VERBOSE eq "ON"){
10
0a6c1cfe4dc8 Uploaded
mcharles
parents: 8
diff changeset
229 print "Error in header ref : empty\n";
0
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
230 print $ligne1_r1;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
231 print $ligne2_r1;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
232 print $ligne3_r1;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
233 print $ligne4_r1;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
234 print $ligne1_r2;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
235 print $ligne2_r2;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
236 print $ligne3_r2;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
237 print $ligne4_r2;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
238 print "\n";
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
239 }
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
240 $error3++;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
241 }
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
242 elsif (($TYPE eq "illumina")&&(($header1 ne $repheader1)||($header2 ne $repheader2)||($header1 ne $header2))){
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
243 if ($VERBOSE eq "ON"){
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
244 print "Error in header : different\n";
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
245 print $ligne1_r1;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
246 print $ligne2_r1;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
247 print $ligne3_r1;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
248 print $ligne4_r1;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
249 print $ligne1_r2;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
250 print $ligne2_r2;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
251 print $ligne3_r2;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
252 print $ligne4_r2;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
253 print "\n";
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
254 }
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
255 $error4++;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
256 }
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
257 elsif (($TYPE eq "sanger")&&($header1 ne $header2)){
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
258 if ($VERBOSE eq "ON"){
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
259 print "Error in header : different\n";
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
260 print $ligne1_r1;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
261 print $ligne2_r1;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
262 print $ligne3_r1;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
263 print $ligne4_r1;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
264 print $ligne1_r2;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
265 print $ligne2_r2;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
266 print $ligne3_r2;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
267 print $ligne4_r2;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
268 print "\n";
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
269 }
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
270 $error4++;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
271 }
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
272 elsif (($length_seq1 != $length_qual1)||($length_seq2 != $length_qual2)){
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
273 if ($VERBOSE eq "ON"){
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
274 print "Error in seq/qual length\n";
10
0a6c1cfe4dc8 Uploaded
mcharles
parents: 8
diff changeset
275 print "$length_seq1 / $length_qual1 \t $length_seq2 / $length_qual2\n";
0
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
276 print $ligne1_r1;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
277 print $ligne2_r1;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
278 print $ligne3_r1;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
279 print $ligne4_r1;
10
0a6c1cfe4dc8 Uploaded
mcharles
parents: 8
diff changeset
280 print "\n";
0
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
281 print $ligne1_r2;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
282 print $ligne2_r2;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
283 print $ligne3_r2;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
284 print $ligne4_r2;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
285 print "\n";
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
286 }
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
287 $error5++;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
288 }
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
289 #@ 1 - 2 sec
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
290 else {
10
0a6c1cfe4dc8 Uploaded
mcharles
parents: 8
diff changeset
291 #print "TEST : $compt\n";
0
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
292 ### Parsing sequence & qualité
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
293 if ($ligne2_r1 =~ /^([ATGCNX]+)\s*$/i){
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
294 $seq1 = $1;
7
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
295 $nb_base_read1 += length($seq1);
0
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
296 }
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
297 if ($ligne2_r2 =~ /^([ATGCNX]+)\s*$/i){
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
298 $seq2 = $1;
7
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
299 $nb_base_read2 += length($seq2);
0
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
300 }
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
301 if ($ligne4_r1 =~ /^(.*)\s*$/i){
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
302 $qual1 = $1;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
303 }
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
304 if ($ligne4_r2 =~ /^(.*)\s*$/i){
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
305 $qual2 = $1;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
306 }
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
307 #@ 2 sec
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
308 ### Verification du parsing et de la coherence sequence /qualité (n°2)
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
309 if ((!$seq1)||(!$seq2)||(!$qual1)||(!$qual2)){
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
310 if ($VERBOSE eq "ON"){
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
311 print "Error parsing seq / quality \n";
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
312 print $ligne1_r1;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
313 print $ligne2_r1;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
314 print $ligne3_r1;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
315 print $ligne4_r1;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
316 print $ligne1_r2;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
317 print $ligne2_r2;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
318 print $ligne3_r2;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
319 print $ligne4_r2;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
320 print "\n";
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
321 }
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
322 $error6++;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
323 }
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
324 elsif ((length($seq1) != length($qual1))||(length($seq2) != length($qual2))){
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
325 if ($VERBOSE eq "ON"){
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
326 print "Error in seq/qual length after parsing\n";
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
327 print $ligne1_r1;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
328 print $ligne2_r1;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
329 print $ligne3_r1;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
330 print $ligne4_r1;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
331 print $ligne1_r2;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
332 print $ligne2_r2;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
333 print $ligne3_r2;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
334 print $ligne4_r2;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
335 print "\n";
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
336 }
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
337 $error7++;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
338 }
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
339 #@ <1 sec
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
340 else {
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
341 my $fastq_lines_r1="";
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
342 my $fastq_lines_r2="";
7
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
343 my $nb_base_current_read1_t = 0;
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
344 my $nb_base_current_read2_t = 0;
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
345
0
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
346 $fastq_lines_r1 = &grooming_and_trimming($ligne1_r1,$seq1,$qual1);
7
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
347 $nb_base_current_read1_t = $nb_base_current_t;
0
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
348 if ($fastq_lines_r1){
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
349 $fastq_lines_r2 = &grooming_and_trimming($ligne1_r2,$seq2,$qual2);
7
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
350 $nb_base_current_read2_t = $nb_base_current_t;
0
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
351 }
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
352 if ($fastq_lines_r2){
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
353 print OUT1 $fastq_lines_r1;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
354 print OUT2 $fastq_lines_r2;
7
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
355
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
356 $nb_read1_t++;
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
357 $nb_read2_t++;
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
358 $nb_base_read1_t += $nb_base_current_read1_t;
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
359 $nb_base_read2_t += $nb_base_current_read2_t;
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
360
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
361
0
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
362 }
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
363 }
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
364 }
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
365
7
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
366
0
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
367 #@ 7 sec
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
368 }
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
369 }
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
370
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
371 close (READ1);
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
372 close (READ2);
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
373 close (OUT1);
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
374 close (OUT2);
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
375
7
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
376 print LF "\n####\t Fastq preparation \n";
8
d857538d9fea Uploaded
mcharles
parents: 7
diff changeset
377 print LF "Fastq format : $TYPE\n";
7
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
378 print LF "## Before preparation\n";
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
379 print LF "#Read1 :\t$nb_read1\t#Base :\t$nb_base_read1\n";
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
380 print LF "#Read2 :\t$nb_read2\t#Base :\t$nb_base_read2\n";
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
381 print LF "## After preparation\n";
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
382 print LF "#Read1 :\t$nb_read1_t\t#Base :\t$nb_base_read1_t\n";
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
383 print LF "#Read2 :\t$nb_read2_t\t#Base :\t$nb_base_read2_t\n";
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
384 close (LF);
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
385
0
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
386
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
387 sub grooming_and_trimming{
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
388 my $header = shift;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
389 my $seq = shift;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
390 my $quality = shift;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
391 my $quality_converted="";
5
b0cbb9d21aa9 Uploaded
mcharles
parents: 4
diff changeset
392 my $quality_ori=$quality;
0
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
393
5
b0cbb9d21aa9 Uploaded
mcharles
parents: 4
diff changeset
394 my $lengthseq = length($seq);
b0cbb9d21aa9 Uploaded
mcharles
parents: 4
diff changeset
395 my $startTrim = 0;
b0cbb9d21aa9 Uploaded
mcharles
parents: 4
diff changeset
396 my $stopTrim = length($quality)-1;
b0cbb9d21aa9 Uploaded
mcharles
parents: 4
diff changeset
397 my $startnoN = $startTrim;
b0cbb9d21aa9 Uploaded
mcharles
parents: 4
diff changeset
398 my $stopnoN = $stopTrim;
0
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
399
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
400
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
401 my $chercheN = $seq;
5
b0cbb9d21aa9 Uploaded
mcharles
parents: 4
diff changeset
402 my @bad_position_N;
b0cbb9d21aa9 Uploaded
mcharles
parents: 4
diff changeset
403 my @bad_position_Q;
0
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
404 my $current_index = index($chercheN,"N");
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
405 my $abs_index = $current_index;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
406 while ($current_index >=0){
5
b0cbb9d21aa9 Uploaded
mcharles
parents: 4
diff changeset
407 push (@bad_position_N,$abs_index);
0
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
408
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
409 if ($current_index<length($seq)){
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
410 $chercheN = substr($chercheN,$current_index+1);
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
411 $current_index = index($chercheN,"N");
5
b0cbb9d21aa9 Uploaded
mcharles
parents: 4
diff changeset
412 $abs_index = $current_index + $bad_position_N[$#bad_position_N]+1;
0
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
413 }
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
414 else {
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
415 last;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
416 }
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
417 }
5
b0cbb9d21aa9 Uploaded
mcharles
parents: 4
diff changeset
418
b0cbb9d21aa9 Uploaded
mcharles
parents: 4
diff changeset
419 my @q = split(//,$quality);
b0cbb9d21aa9 Uploaded
mcharles
parents: 4
diff changeset
420 for (my $i=0;$i<=$#q;$i++){
b0cbb9d21aa9 Uploaded
mcharles
parents: 4
diff changeset
421 my $chr = $q[$i];
b0cbb9d21aa9 Uploaded
mcharles
parents: 4
diff changeset
422 my $num = ord($q[$i]);
b0cbb9d21aa9 Uploaded
mcharles
parents: 4
diff changeset
423 if ($TYPE eq "illumina"){
b0cbb9d21aa9 Uploaded
mcharles
parents: 4
diff changeset
424 $num = $num - 31; # 31 comme la difference entre la plage sanger (33-> 93 / 0->60) et illumina (64->104 / 0->40)
b0cbb9d21aa9 Uploaded
mcharles
parents: 4
diff changeset
425 $quality_converted .= chr($num);
b0cbb9d21aa9 Uploaded
mcharles
parents: 4
diff changeset
426 }
b0cbb9d21aa9 Uploaded
mcharles
parents: 4
diff changeset
427
b0cbb9d21aa9 Uploaded
mcharles
parents: 4
diff changeset
428 if ($num < $MIN_QUALITY + 33){ #33 comme le départ de la plage sanger
b0cbb9d21aa9 Uploaded
mcharles
parents: 4
diff changeset
429 push(@bad_position_Q,$i);
b0cbb9d21aa9 Uploaded
mcharles
parents: 4
diff changeset
430 }
b0cbb9d21aa9 Uploaded
mcharles
parents: 4
diff changeset
431 }
b0cbb9d21aa9 Uploaded
mcharles
parents: 4
diff changeset
432 if ($quality_converted){$quality = $quality_converted;}
0
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
433
5
b0cbb9d21aa9 Uploaded
mcharles
parents: 4
diff changeset
434 my @bad_position = (@bad_position_N, @bad_position_Q);
0
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
435
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
436 if ($#bad_position>=0){
5
b0cbb9d21aa9 Uploaded
mcharles
parents: 4
diff changeset
437 @bad_position = sort {$a <=> $b} @bad_position;
b0cbb9d21aa9 Uploaded
mcharles
parents: 4
diff changeset
438 my %coord=%{&extract_longer_string_coordinates_from_bad_position(0,$stopTrim,\@bad_position)};
b0cbb9d21aa9 Uploaded
mcharles
parents: 4
diff changeset
439 $startTrim = $coord{"start"};
b0cbb9d21aa9 Uploaded
mcharles
parents: 4
diff changeset
440 $stopTrim = $coord{"stop"};
b0cbb9d21aa9 Uploaded
mcharles
parents: 4
diff changeset
441 #print "$startTrim .. $stopTrim\n";
0
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
442
5
b0cbb9d21aa9 Uploaded
mcharles
parents: 4
diff changeset
443 }
b0cbb9d21aa9 Uploaded
mcharles
parents: 4
diff changeset
444 my $lengthTrim = $stopTrim - $startTrim +1;
7
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
445
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
446 #if ($stats_length{$lengthTrim}){
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
447 # $stats_length{$lengthTrim} = 1;
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
448 #}
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
449 #else {
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
450 # $stats_length{$lengthTrim}++;
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
451 #}
5
b0cbb9d21aa9 Uploaded
mcharles
parents: 4
diff changeset
452 my $fastq_lines="";
b0cbb9d21aa9 Uploaded
mcharles
parents: 4
diff changeset
453
b0cbb9d21aa9 Uploaded
mcharles
parents: 4
diff changeset
454 # if ($header =~ /GA8\-EAS671_0005\:3\:1\:1043\:4432/){
b0cbb9d21aa9 Uploaded
mcharles
parents: 4
diff changeset
455 # print "HEAD:\t$header";
b0cbb9d21aa9 Uploaded
mcharles
parents: 4
diff changeset
456 # print "SEQ:\n$seq\n";
b0cbb9d21aa9 Uploaded
mcharles
parents: 4
diff changeset
457 # print "$quality_ori\n";
b0cbb9d21aa9 Uploaded
mcharles
parents: 4
diff changeset
458 # print "$quality\n";
b0cbb9d21aa9 Uploaded
mcharles
parents: 4
diff changeset
459 # for (my $i=0;$i<=$#bad_position;$i++){
b0cbb9d21aa9 Uploaded
mcharles
parents: 4
diff changeset
460 # print $bad_position[$i]."(".$q[$bad_position[$i]]." : ".ord($q[$bad_position[$i]]).")"."\t";
b0cbb9d21aa9 Uploaded
mcharles
parents: 4
diff changeset
461 # }
b0cbb9d21aa9 Uploaded
mcharles
parents: 4
diff changeset
462 # print "\n";
b0cbb9d21aa9 Uploaded
mcharles
parents: 4
diff changeset
463 # print "$startTrim .. $stopTrim / $lengthTrim \n";
b0cbb9d21aa9 Uploaded
mcharles
parents: 4
diff changeset
464 # print $fastq_lines;
b0cbb9d21aa9 Uploaded
mcharles
parents: 4
diff changeset
465 # print "\n";
b0cbb9d21aa9 Uploaded
mcharles
parents: 4
diff changeset
466 # }
b0cbb9d21aa9 Uploaded
mcharles
parents: 4
diff changeset
467
7
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
468 #for (my $i=$startTrim;$i<=$stopTrim;$i++){
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
469 # if ($stats_quality{ord($q{$i])}){
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
470 # $stats_quality{ord($q{$i])}=1;
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
471 # }
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
472 # else {
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
473 # $stats_quality{ord($q{$i])}++;
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
474 # }
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
475 #}
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
476
5
b0cbb9d21aa9 Uploaded
mcharles
parents: 4
diff changeset
477 if ($lengthTrim >= $MIN_LENGTH){
b0cbb9d21aa9 Uploaded
mcharles
parents: 4
diff changeset
478 $fastq_lines .= $header;
7
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
479 my $new_seq = substr($seq,$startTrim,$lengthTrim);
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
480 $nb_base_current_t = length($new_seq);
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
481 $fastq_lines .= $new_seq."\n";
5
b0cbb9d21aa9 Uploaded
mcharles
parents: 4
diff changeset
482 $fastq_lines .= "+\n";
7
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
483 my $new_q = substr($quality,$startTrim,$lengthTrim);
3f7b0788a1c4 Uploaded
mcharles
parents: 5
diff changeset
484 $fastq_lines .= $new_q."\n";
5
b0cbb9d21aa9 Uploaded
mcharles
parents: 4
diff changeset
485 return $fastq_lines;
0
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
486
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
487 }
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
488 else {
5
b0cbb9d21aa9 Uploaded
mcharles
parents: 4
diff changeset
489 #print "Insufficient length after trimming\n";
0
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
490 return "";
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
491 }
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
492 }
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
493
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
494 sub extract_longer_string_coordinates_from_bad_position{
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
495 my $start=shift;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
496 my $stop =shift;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
497 my $refbad = shift;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
498 my @bad_position = @$refbad;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
499 my %coord;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
500
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
501 my $current_start = $start;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
502 my $current_stop = $bad_position[0]-1;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
503 if ($current_stop < $start){$current_stop = $start;}
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
504
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
505
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
506 #debut -> premier N
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
507 my $current_length = $current_stop - $current_start +1;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
508 my $test_length;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
509
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
510 #entre les N
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
511 for (my $i=1;$i<=$#bad_position;$i++){
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
512 $test_length = $bad_position[$i]+1-$bad_position[$i-1]-1;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
513 if ( $test_length > $current_length){
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
514 $current_start = $bad_position[$i-1]+1;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
515 $current_stop = $bad_position[$i]-1;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
516 $current_length = $current_stop - $current_start +1;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
517 }
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
518 }
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
519
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
520 #dernier N -> fin
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
521 $test_length = $stop-$bad_position[$#bad_position]+1;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
522 if ( $test_length > $current_length){
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
523 $current_start = $bad_position[$#bad_position]+1;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
524 if ($current_start > $stop){$current_start=$stop;}
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
525 $current_stop = $stop;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
526 }
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
527 $coord{"start"}=$current_start;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
528 $coord{"stop"}= $current_stop;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
529 $coord{"lenght"}=$current_stop-$current_start+1;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
530
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
531 return \%coord;
442a7c88b886 Uploaded
mcharles
parents:
diff changeset
532 }