annotate rapsodyn/PrepareFastqLight.pl @ 9:0e7c6fe60646 draft

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