annotate rapsodyn/PrepareFastqLight.pl~ @ 15:56d328bce3a7 draft default tip

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