@@ -139,46 +139,6 @@ use base qw(Bio::DB::IndexedBase);
139
139
our $obj_class = ' Bio::PrimarySeq::Fasta' ;
140
140
our $file_glob = ' *.{fa,FA,fasta,FASTA,fast,FAST,dna,DNA,fna,FNA,faa,FAA,fsa,FSA}' ;
141
141
142
- # Compiling the below regular expressions speeds up the Pure Perl
143
- # seq/subseq() by about 7% from 7.76s to 7.22s over 32358 calls on
144
- # Variant Effect Prediction data.
145
- my $nl = qr /\n / ;
146
- my $cr = qr /\r / ;
147
-
148
- # Remove carriage returns (\r) and newlines (\n) from a string. When
149
- # called from subseq, this can take a signficiant portion of time, in
150
- # Variant Effect Prediction. Therefore we compile the match
151
- # portion.
152
- sub strip_crnl {
153
- my $str = shift ;
154
- $str =~ s / $nl// g ;
155
- $str =~ s / $cr// g ;
156
- return $str ;
157
- }
158
-
159
- # C can do perfrom strip_crnl much faster. But this requires the
160
- # Inline::C module which we don't require people to have. So we make
161
- # this optional by wrapping the C code in an eval. If the eval works,
162
- # the Perl strip_crnl() function is overwritten.
163
- eval q{
164
- use Inline C => <<'END_OF_C_CODE';
165
- /* Strip all new line (\n) and carriage return (\r) characters
166
- from string str
167
- */
168
- char* strip_crnl(char* str) {
169
- char *s;
170
- char *s2 = str;
171
- for (s = str; *s; *s++) {
172
- if (*s != '\n ' && *s != '\r ') {
173
- *s2++ = *s;
174
- }
175
- }
176
- *s2 = '\0 ';
177
- return str;
178
- }
179
- END_OF_C_CODE
180
- } ;
181
-
182
142
183
143
=head2 new
184
144
@@ -329,7 +289,7 @@ sub subseq {
329
289
seek ($fh , $filestart ,0);
330
290
read ($fh , $data , $filestop -$filestart +1);
331
291
332
- $data = strip_crnl ($data );
292
+ $data = Bio::DB::IndexedBase::_strip_crnl ($data );
333
293
334
294
if ($strand == -1) {
335
295
# Reverse-complement the sequence
@@ -371,7 +331,7 @@ sub header {
371
331
read ($fh , $data , $headerlen );
372
332
# On Windows chomp remove '\n' but leaves '\r'
373
333
# when reading '\r\n' in binary mode
374
- $data = strip_crnl ($data );
334
+ $data = Bio::DB::IndexedBase::_strip_crnl ($data );
375
335
substr ($data , 0, 1) = ' ' ;
376
336
return $data ;
377
337
}
0 commit comments