FAST/Bio/Tools/GuessSeqFormat.pm untested

filter: Statementstmt 0.0% 0 / 162 Branchbran 0.0% 0 / 34 Conditioncond 0.0% 0 / 216 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 42 Podpod 0.0% 0 / 39 totaltotal 0.0% 0 / 493 SCAR 58.3
CC
18
Cov
0%
guess
240.0
file
6.0
fh
6.0
CRAP 342.0
1 #------------------------------------------------------------------
2 #
3 # BioPerl module FAST::Bio::Tools::GuessSeqFormat
4 #
5 # Please direct questions and support issues to <bioperl-l@bioperl.org>
6 #
7 # Cared for by Andreas Kahari, andreas.kahari@ebi.ac.uk
8 #
9 # You may distribute this module under the same terms as perl itself
10 #------------------------------------------------------------------
11  
12 =head1 NAME
13  
14 FAST::Bio::Tools::GuessSeqFormat - Module for determining the sequence
15 format of the contents of a file, a string, or through a
16 filehandle.
17  
18 =head1 SYNOPSIS
19  
20 # To guess the format of a flat file, given a filename:
21 my $guesser = FAST::Bio::Tools::GuessSeqFormat->new( -file => $filename );
22 my $format = $guesser->guess;
23  
24 # To guess the format from an already open filehandle:
25 my $guesser = FAST::Bio::Tools::GuessSeqFormat->new( -fh => $filehandle );
26 my $format = $guesser->guess;
27 # If the filehandle is seekable (STDIN isn't), it will be
28 # returned to its original position.
29  
30 # To guess the format of one or several lines of text (with
31 # embedded newlines):
32 my $guesser = FAST::Bio::Tools::GuessSeqFormat->new( -text => $linesoftext );
33 my $format = $guesser->guess;
34  
35 # To create a FAST::Bio::Tools::GuessSeqFormat object and set the
36 # filename, filehandle, or line to parse afterwards:
37 my $guesser = FAST::Bio::Tools::GuessSeqFormat->new();
38 $guesser->file($filename);
39 $guesser->fh($filehandle);
40 $guesser->text($linesoftext);
41  
42 # To guess in one go, given e.g. a filename:
43 my $format = FAST::Bio::Tools::GuessSeqFormat->new( -file => $filename )->guess;
44  
45 =head1 DESCRIPTION
46  
47 FAST::Bio::Tools::GuessSeqFormat tries to guess the format ("swiss",
48 "pir", "fasta" etc.) of the sequence or MSA in a file, in a
49 scalar, or through a filehandle.
50  
51 The guess() method of a FAST::Bio::Tools::GuessSeqFormat object will
52 examine the data, line by line, until it finds a line to which
53 only one format can be assigned. If no conclusive guess can be
54 made, undef is returned.
55  
56 If the FAST::Bio::Tools::GuessSeqFormat object is given a filehandle
57 which is seekable, it will be restored to its original position
58 on return from the guess() method.
59  
60 =head2 Formats
61  
62 Tests are currently implemented for the following formats:
63  
64 =over
65  
66 =item *
67  
68 ACeDB ("ace")
69  
70 =item *
71  
72 Blast ("blast")
73  
74 =item *
75  
76 ClustalW ("clustalw")
77  
78 =item *
79  
80 Codata ("codata")
81  
82 =item *
83  
84 EMBL ("embl")
85  
86 =item *
87  
88 FastA sequence ("fasta")
89  
90 =item *
91  
92 FastQ sequence ("fastq")
93  
94 =item *
95  
96 FastXY/FastA alignment ("fastxy")
97  
98 =item *
99  
100 Game XML ("game")
101  
102 =item *
103  
104 GCG ("gcg")
105  
106 =item *
107  
108 GCG Blast ("gcgblast")
109  
110 =item *
111  
112 GCG FastA ("gcgfasta")
113  
114 =item *
115  
116 GDE ("gde")
117  
118 =item *
119  
120 Genbank ("genbank")
121  
122 =item *
123  
124 Genscan ("genscan")
125  
126 =item *
127  
128 GFF ("gff")
129  
130 =item *
131  
132 HMMER ("hmmer")
133  
134 =item *
135  
136 PAUP/NEXUS ("nexus")
137  
138 =item *
139  
140 Phrap assembly file ("phrap")
141  
142 =item *
143  
144 NBRF/PIR ("pir")
145  
146 =item *
147  
148 Mase ("mase")
149  
150 =item *
151  
152 Mega ("mega")
153  
154 =item *
155  
156 GCG/MSF ("msf")
157  
158 =item *
159  
160 Pfam ("pfam")
161  
162 =item *
163  
164 Phylip ("phylip")
165  
166 =item *
167  
168 Prodom ("prodom")
169  
170 =item *
171  
172 Raw ("raw")
173  
174 =item *
175  
176 RSF ("rsf")
177  
178 =item *
179  
180 Selex ("selex")
181  
182 =item *
183  
184 Stockholm ("stockholm")
185  
186 =item *
187  
188 Swissprot ("swiss")
189  
190 =item *
191  
192 Tab ("tab")
193  
194 =item *
195  
196 Variant Call Format ("vcf")
197  
198 =back
199  
200 =head1 FEEDBACK
201  
202 =head2 Mailing Lists
203  
204 User feedback is an integral part of the evolution of this and
205 other Bioperl modules. Send your comments and suggestions
206 preferably to one of the Bioperl mailing lists. Your
207 participation is much appreciated.
208  
209 bioperl-l@bioperl.org - General discussion
210 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
211  
212 =head2 Support
213  
214 Please direct usage questions or support issues to the mailing list:
215  
216 I<bioperl-l@bioperl.org>
217  
218 rather than to the module maintainer directly. Many experienced and
219 reponsive experts will be able look at the problem and quickly
220 address it. Please include a thorough description of the problem
221 with code and data examples if at all possible.
222  
223 =head2 Reporting Bugs
224  
225 Report bugs to the Bioperl bug tracking system to help us
226 keep track the bugs and their resolution. Bug reports can be
227 submitted via the web:
228  
229 https://redmine.open-bio.org/projects/bioperl/
230  
231 =head1 AUTHOR
232  
233 Andreas Kahari, andreas.kahari@ebi.ac.uk
234  
235 =head1 CONTRIBUTORS
236  
237 Heikki Lehvaslaiho, heikki-at-bioperl-dot-org
238 Mark A. Jensen, maj-at-fortinbras-dot-us
239  
240 =cut
241  
242  
243 package FAST::Bio::Tools::GuessSeqFormat;
244  
245 use strict;
246 use warnings;
247  
248  
249 use base qw(FAST::Bio::Root::Root);
250  
251 =head1 METHODS
252  
253 Methods available to FAST::Bio::Tools::GuessSeqFormat objects
254 are described below. Methods with names beginning with an
255 underscore are considered to be internal.
256  
257 =cut
258  
259 =head2 new
260  
261 Title : new
262 Usage : $guesser = FAST::Bio::Tools::GuessSeqFormat->new( ... );
263 Function : Creates a new object.
264 Example : See SYNOPSIS.
265 Returns : A new object.
266 Arguments : -file The filename of the file whose format is to
267 be guessed, or
268 -fh An already opened filehandle from which a text
269 stream may be read, or
270 -text A scalar containing one or several lines of
271 text with embedded newlines.
272  
273 If more than one of the above arguments are given, they
274 are tested in the order -text, -file, -fh, and the first
275 available argument will be used.
276  
277 =cut
278  
279 sub new
280 {
281 my $class = shift;
282 my @args = @_;
283  
284 my $self = $class->SUPER::new(@args);
285  
286 my $attr;
287 my $value;
288  
289 while (@args) {
290 $attr = shift @args;
291 $attr = lc $attr;
292 $value = shift @args;
293 $self->{$attr} = $value;
294 }
295  
296 return $self;
297 }
298  
299 =head2 file
300  
301 Title : file
302 Usage : $guesser->file($filename);
303 $filename = $guesser->file;
304 Function : Gets or sets the current filename associated with
305 an object.
306 Returns : The new filename.
307 Arguments : The filename of the file whose format is to be
308 guessed.
309  
310 A call to this method will clear the current filehandle and
311 the current lines of text associated with the object.
312  
313 =cut
314  
315 sub file
316 {
317 # Sets and/or returns the filename to use.
318 my $self = shift;
319 my $file = shift;
320  
321 if (defined $file) {
322 # Set the active filename, and clear the filehandle and
323 # text line, if present.
324 $self->{-file} = $file;
325 $self->{-fh} = $self->{-text} = undef;
326 }
327  
328 return $self->{-file};
329 }
330  
331 =head2 fh
332  
333 Title : fh
334 Usage : $guesser->fh($filehandle);
335 $filehandle = $guesser->fh;
336 Function : Gets or sets the current filehandle associated with
337 an object.
338 Returns : The new filehandle.
339 Arguments : An already opened filehandle from which a text
340 stream may be read.
341  
342 A call to this method will clear the current filename and
343 the current lines of text associated with the object.
344  
345 =cut
346  
347 sub fh
348 {
349 # Sets and/or returns the filehandle to use.
350 my $self = shift;
351 my $fh = shift;
352  
353 if (defined $fh) {
354 # Set the active filehandle, and clear the filename and
355 # text line, if present.
356 $self->{-fh} = $fh;
357 $self->{-file} = $self->{-text} = undef;
358 }
359  
360 return $self->{-fh};
361 }
362  
363  
364 =head2 text
365  
366 Title : text
367 Usage : $guesser->text($linesoftext);
368 $linesofext = $guesser->text;
369 Function : Gets or sets the current text associated with an
370 object.
371 Returns : The new lines of texts.
372 Arguments : A scalar containing one or several lines of text,
373 including embedded newlines.
374  
375 A call to this method will clear the current filename and
376 the current filehandle associated with the object.
377  
378 =cut
379  
380 sub text
381 {
382 # Sets and/or returns the text lines to use.
383 my $self = shift;
384 my $text = shift;
385  
386 if (defined $text) {
387 # Set the active text lines, and clear the filehandle
388 # and filename, if present.
389 $self->{-text} = $text;
390 $self->{-fh} = $self->{-file} = undef;
391 }
392  
393 return $self->{-text};
394 }
395  
396 =head2 guess
397  
398 Title : guess
399 Usage : $format = $guesser->guess;
400 @format = $guesser->guess; # if given a line of text
401 Function : Guesses the format of the data accociated with the
402 object.
403 Returns : A format string such as "swiss" or "pir". If a
404 format can not be found, undef is returned.
405 Arguments : None.
406  
407 If the object is associated with a filehandle and if that
408 filehandle is searchable, the position of the filehandle
409 will be returned to its original position before the method
410 returns.
411  
412 =cut
413  
414 our %formats = (
415 ace => { test => \&_possibly_ace },
416 blast => { test => \&_possibly_blast },
417 bowtie => { test => \&_possibly_bowtie },
418 clustalw => { test => \&_possibly_clustalw },
419 codata => { test => \&_possibly_codata },
420 embl => { test => \&_possibly_embl },
421 fasta => { test => \&_possibly_fasta },
422 fastq => { test => \&_possibly_fastq },
423 fastxy => { test => \&_possibly_fastxy },
424 game => { test => \&_possibly_game },
425 gcg => { test => \&_possibly_gcg },
426 gcgblast => { test => \&_possibly_gcgblast },
427 gcgfasta => { test => \&_possibly_gcgfasta },
428 gde => { test => \&_possibly_gde },
429 genbank => { test => \&_possibly_genbank },
430 genscan => { test => \&_possibly_genscan },
431 gff => { test => \&_possibly_gff },
432 hmmer => { test => \&_possibly_hmmer },
433 nexus => { test => \&_possibly_nexus },
434 mase => { test => \&_possibly_mase },
435 mega => { test => \&_possibly_mega },
436 msf => { test => \&_possibly_msf },
437 phrap => { test => \&_possibly_phrap },
438 pir => { test => \&_possibly_pir },
439 pfam => { test => \&_possibly_pfam },
440 phylip => { test => \&_possibly_phylip },
441 prodom => { test => \&_possibly_prodom },
442 raw => { test => \&_possibly_raw },
443 rsf => { test => \&_possibly_rsf },
444 selex => { test => \&_possibly_selex },
445 stockholm => { test => \&_possibly_stockholm },
446 swiss => { test => \&_possibly_swiss },
447 tab => { test => \&_possibly_tab },
448 vcf => { test => \&_possibly_vcf }
449 );
450  
451 sub guess
452 {
453 my $self = shift;
454  
455 foreach my $fmt_key (keys %formats) {
456 $formats{$fmt_key}{fmt_string} = $fmt_key;
457 }
458  
459 my $fh;
460 my $start_pos;
461 my @lines;
462 if (defined $self->{-text}) {
463 # Break the text into separate lines.
464 @lines = split /\n/, $self->{-text};
465 } elsif (defined $self->{-file}) {
466 # If given a filename, open the file.
467 open($fh, $self->{-file}) or
468 $self->throw("Can not open '$self->{-file}' for reading: $!");
469 } elsif (defined $self->{-fh}) {
470 # If given a filehandle, figure out if it's a plain GLOB
471 # or a IO::Handle which is seekable. In the case of a
472 # GLOB, we'll assume it's seekable. Get the current
473 # position in the stream.
474 $fh = $self->{-fh};
475 if (ref $fh eq 'GLOB') {
476 $start_pos = tell($fh);
477 } elsif (UNIVERSAL::isa($fh, 'IO::Seekable')) {
478 $start_pos = $fh->getpos();
479 }
480 }
481  
482 my $done = 0;
483 my $lineno = 0;
484 my $fmt_string;
485 while (!$done) {
486 my $line; # The next line of the file.
487 my $match = 0; # Number of possible formats of this line.
488  
489 if (defined $self->{-text}) {
490 last if (scalar @lines == 0);
491 $line = shift @lines;
492 } else {
493 last if (!defined($line = <$fh>));
494 }
495 next if ($line =~ /^\s*$/); # Skip white and empty lines.
496  
497 chomp($line);
498 $line =~ s/\r$//; # Fix for DOS files on Unix.
499 ++$lineno;
500  
501 while (my ($fmt_key, $fmt) = each (%formats)) {
502 if ($fmt->{test}($line, $lineno)) {
503 ++$match;
504 $fmt_string = $fmt->{fmt_string};
505 }
506 }
507  
508 # We're done if there was only one match.
509 $done = ($match == 1);
510 }
511  
512 if (defined $self->{-file}) {
513 # Close the file we opened.
514 close($fh);
515 } elsif (ref $fh eq 'GLOB') {
516 # Try seeking to the start position.
517 seek($fh, $start_pos, 0) || $self->throw("Failed resetting the ".
518 "filehandle; IO error occurred");;
519 } elsif (defined $fh && $fh->can('setpos')) {
520 # Seek to the start position.
521 $fh->setpos($start_pos);
522 }
523 return ($done ? $fmt_string : undef);
524 }
525  
526 =head1 HELPER SUBROUTINES
527  
528 All helper subroutines will, given a line of text and the line
529 number of the same line, return 1 if the line possibly is from a
530 file of the type that they perform a test of.
531  
532 A zero return value does not mean that the line is not part
533 of a certain type of file, just that the test did not find any
534 characteristics of that type of file in the line.
535  
536 =head2 _possibly_ace
537  
538 From bioperl test data, and from
539 "http://www.isrec.isb-sib.ch/DEA/module8/B_Stevenson/Practicals/transcriptome_recon/transcriptome_recon.html".
540  
541 =cut
542  
543 sub _possibly_ace
544 {
545 my ($line, $lineno) = (shift, shift);
546 return ($line =~ /^(?:Sequence|Peptide|DNA|Protein) [":]/);
547 }
548  
549 =head2 _possibly_blast
550  
551 From various blast results.
552  
553 =cut
554  
555 sub _possibly_blast
556 {
557 my ($line, $lineno) = (shift, shift);
558 return ($lineno == 1 &&
559 $line =~ /^[[:upper:]]*BLAST[[:upper:]]*.*\[.*\]$/);
560 }
561  
562 =head2 _possibly_bowtie
563  
564 Contributed by kortsch.
565  
566 =cut
567  
568 sub _possibly_bowtie
569 {
570 my ($line, $lineno) = (shift, shift);
571 return ($line =~ /^[[:graph:]]+\t[-+]\t[[:graph:]]+\t\d+\t([[:alpha:]]+)\t([[:graph:]]+)\t\d+\t[[:graph:]]?/)
572 && length($1)==length($2);
573 }
574  
575 =head2 _possibly_clustalw
576  
577 From "http://www.ebi.ac.uk/help/formats.html".
578  
579 =cut
580  
581 sub _possibly_clustalw
582 {
583 my ($line, $lineno) = (shift, shift);
584 return ($lineno == 1 && $line =~ /CLUSTAL/);
585 }
586  
587 =head2 _possibly_codata
588  
589 From "http://www.ebi.ac.uk/help/formats.html".
590  
591 =cut
592  
593 sub _possibly_codata
594 {
595 my ($line, $lineno) = (shift, shift);
596 return (($lineno == 1 && $line =~ /^ENTRY/) ||
597 ($lineno == 2 && $line =~ /^SEQUENCE/) ||
598 $line =~ m{^(?:ENTRY|SEQUENCE|///)});
599 }
600  
601 =head2 _possibly_embl
602  
603 From
604 "http://www.ebi.ac.uk/embl/Documentation/User_manual/usrman.html#3.3".
605  
606 =cut
607  
608 sub _possibly_embl
609 {
610 my ($line, $lineno) = (shift, shift);
611 return ($lineno == 1 && $line =~ /^ID / && $line =~ /BP\.$/);
612 }
613  
614 =head2 _possibly_fasta
615  
616 From "http://www.ebi.ac.uk/help/formats.html".
617  
618 =cut
619  
620 sub _possibly_fasta
621 {
622 my ($line, $lineno) = (shift, shift);
623 return (($lineno != 1 && $line =~ /^[A-IK-NP-Z]+$/i) ||
624 $line =~ /^>\s*\w/);
625 }
626  
627 =head2 _possibly_fastq
628  
629 From bioperl test data.
630  
631 =cut
632  
633 sub _possibly_fastq
634 {
635 my ($line, $lineno) = (shift, shift);
636 return ( ($lineno == 1 && $line =~ /^@/) ||
637 ($lineno == 3 && $line =~ /^\+/) );
638 }
639  
640 =head2 _possibly_fastxy
641  
642 From bioperl test data.
643  
644 =cut
645  
646 sub _possibly_fastxy
647 {
648 my ($line, $lineno) = (shift, shift);
649 return (($lineno == 1 && $line =~ /^ FAST(?:XY|A)/) ||
650 ($lineno == 2 && $line =~ /^ version \d/));
651 }
652  
653 =head2 _possibly_game
654  
655 From bioperl testdata.
656  
657 =cut
658  
659 sub _possibly_game
660 {
661 my ($line, $lineno) = (shift, shift);
662 return ($line =~ /^<!DOCTYPE game/);
663 }
664  
665 =head2 _possibly_gcg
666  
667 From bioperl, FAST::Bio::SeqIO::gcg.
668  
669 =cut
670  
671 sub _possibly_gcg
672 {
673 my ($line, $lineno) = (shift, shift);
674 return ($line =~ /Length: .*Type: .*Check: .*\.\.$/);
675 }
676  
677 =head2 _possibly_gcgblast
678  
679 From bioperl testdata.
680  
681 =cut
682  
683 sub _possibly_gcgblast
684 {
685 my ($line, $lineno) = (shift, shift);
686 return (($lineno == 1 && $line =~ /^!!SEQUENCE_LIST/) ||
687 ($lineno == 2 &&
688 $line =~ /^[[:upper:]]*BLAST[[:upper:]]*.*\[.*\]$/));
689 }
690  
691 =head2 _possibly_gcgfasta
692  
693 From bioperl testdata.
694  
695 =cut
696  
697 sub _possibly_gcgfasta
698 {
699 my ($line, $lineno) = (shift, shift);
700 return (($lineno == 1 && $line =~ /^!!SEQUENCE_LIST/) ||
701 ($lineno == 2 && $line =~ /FASTA/));
702 }
703  
704 =head2 _possibly_gde
705  
706 From "http://www.ebi.ac.uk/help/formats.html".
707  
708 =cut
709  
710 sub _possibly_gde
711 {
712 my ($line, $lineno) = (shift, shift);
713 return ($line =~ /^[{}]$/ ||
714 $line =~ /^(?:name|longname|sequence-ID|
715 creation-date|direction|strandedness|
716 type|offset|group-ID|creator|descrip|
717 comment|sequence)/x);
718 }
719  
720 =head2 _possibly_genbank
721  
722 From "http://www.ebi.ac.uk/help/formats.html".
723 Format of [apparantly optional] file header from
724 "http://www.umdnj.edu/rcompweb/PA/Notes/GenbankFF.htm". (TODO: dead link)
725  
726 =cut
727  
728 sub _possibly_genbank
729 {
730 my ($line, $lineno) = (shift, shift);
731 return (($lineno == 1 && $line =~ /GENETIC SEQUENCE DATA BANK/) ||
732 ($lineno == 1 && $line =~ /^LOCUS /) ||
733 ($lineno == 2 && $line =~ /^DEFINITION /) ||
734 ($lineno == 3 && $line =~ /^ACCESSION /));
735 }
736  
737 =head2 _possibly_genscan
738  
739 From bioperl test data.
740  
741 =cut
742  
743 sub _possibly_genscan
744 {
745 my ($line, $lineno) = (shift, shift);
746 return (($lineno == 1 && $line =~ /^GENSCAN.*Date.*Time/) ||
747 ($line =~ /^(?:Sequence\s+\w+|Parameter matrix|Predicted genes)/));
748 }
749  
750 =head2 _possibly_gff
751  
752 From bioperl test data.
753  
754 =cut
755  
756 sub _possibly_gff
757 {
758 my ($line, $lineno) = (shift, shift);
759 return (($lineno == 1 && $line =~ /^##gff-version/) ||
760 ($lineno == 2 && $line =~ /^##date/));
761 }
762  
763 =head2 _possibly_hmmer
764  
765 From bioperl test data.
766  
767 =cut
768  
769 sub _possibly_hmmer
770 {
771 my ($line, $lineno) = (shift, shift);
772 return (($lineno == 2 && $line =~ /^HMMER/) ||
773 ($lineno == 3 &&
774 $line =~ /Washington University School of Medicine/));
775 }
776  
777 =head2 _possibly_nexus
778  
779 From "http://paup.csit.fsu.edu/nfiles.html".
780  
781 =cut
782  
783 sub _possibly_nexus
784 {
785 my ($line, $lineno) = (shift, shift);
786 return ($lineno == 1 && $line =~ /^#NEXUS/);
787 }
788  
789 =head2 _possibly_mase
790  
791 From bioperl test data.
792 More detail from "http://www.umdnj.edu/rcompweb/PA/Notes/GenbankFF.htm" (TODO: dead link)
793  
794 =cut
795  
796 sub _possibly_mase
797 {
798 my ($line, $lineno) = (shift, shift);
799 return (($lineno == 1 && $line =~ /^;;/) ||
800 ($lineno > 1 && $line =~ /^;[^;]?/));
801 }
802  
803 =head2 _possibly_mega
804  
805 From the ensembl broswer (AlignView data export).
806  
807 =cut
808  
809 sub _possibly_mega
810 {
811 my ($line, $lineno) = (shift, shift);
812 return ($lineno == 1 && $line =~ /^#mega$/);
813 }
814  
815  
816 =head2 _possibly_msf
817  
818 From "http://www.ebi.ac.uk/help/formats.html".
819  
820 =cut
821  
822 sub _possibly_msf
823 {
824 my ($line, $lineno) = (shift, shift);
825 return ($line =~ m{^//} ||
826 $line =~ /MSF:.*Type:.*Check:|Name:.*Len:/);
827 }
828  
829 =head2 _possibly_phrap
830  
831 From "http://biodata.ccgb.umn.edu/docs/contigimage.html". (TODO: dead link)
832 From "http://genetics.gene.cwru.edu/gene508/Lec6.htm". (TODO: dead link)
833 From bioperl test data ("*.ace.1" files).
834  
835 =cut
836  
837 sub _possibly_phrap
838 {
839 my ($line, $lineno) = (shift, shift);
840 return ($line =~ /^(?:AS\ |CO\ Contig|BQ|AF\ |BS\ |RD\ |
841 QA\ |DS\ |RT\{)/x);
842 }
843  
844 =head2 _possibly_pir
845  
846 From "http://www.ebi.ac.uk/help/formats.html".
847 The ".,()" spotted in bioperl test data.
848  
849 =cut
850  
851 sub _possibly_pir # "NBRF/PIR" (?)
852 {
853 my ($line, $lineno) = (shift, shift);
854 return (($lineno != 1 && $line =~ /^[\sA-IK-NP-Z.,()]+\*?$/i) ||
855 $line =~ /^>(?:P1|F1|DL|DC|RL|RC|N3|N1);/);
856 }
857  
858 =head2 _possibly_pfam
859  
860 From bioperl test data.
861  
862 =cut
863  
864 sub _possibly_pfam
865 {
866 my ($line, $lineno) = (shift, shift);
867 return ($line =~ m{^\w+/\d+-\d+\s+[A-IK-NP-Z.]+}i);
868 }
869  
870 =head2 _possibly_phylip
871  
872 From "http://www.ebi.ac.uk/help/formats.html". Initial space
873 allowed on first line (spotted in ensembl AlignView exported
874 data).
875  
876 =cut
877  
878 sub _possibly_phylip
879 {
880 my ($line, $lineno) = (shift, shift);
881 return (($lineno == 1 && $line =~ /^\s*\d+\s\d+/) ||
882 ($lineno == 2 && $line =~ /^\w\s+[A-IK-NP-Z\s]+/) ||
883 ($lineno == 3 && $line =~ /(?:^\w\s+[A-IK-NP-Z\s]+|\s+[A-IK-NP-Z\s]+)/)
884 );
885 }
886  
887 =head2 _possibly_prodom
888  
889 From "http://prodom.prabi.fr/prodom/current/documentation/data.php".
890  
891 =cut
892  
893 sub _possibly_prodom
894 {
895 my ($line, $lineno) = (shift, shift);
896 return ($lineno == 1 && $line =~ /^ID / && $line =~ /\d+ seq\.$/);
897 }
898  
899 =head2 _possibly_raw
900  
901 From "http://www.ebi.ac.uk/help/formats.html".
902  
903 =cut
904  
905 sub _possibly_raw
906 {
907 my ($line, $lineno) = (shift, shift);
908 return ($line =~ /^[A-Za-z\s]+$/);
909 }
910  
911 =head2 _possibly_rsf
912  
913 From "http://www.ebi.ac.uk/help/formats.html".
914  
915 =cut
916  
917 sub _possibly_rsf
918 {
919 my ($line, $lineno) = (shift, shift);
920 return (($lineno == 1 && $line =~ /^!!RICH_SEQUENCE/) ||
921 $line =~ /^[{}]$/ ||
922 $line =~ /^(?:name|type|longname|
923 checksum|creation-date|strand|sequence)/x);
924 }
925  
926 =head2 _possibly_selex
927  
928 From "http://www.ebc.ee/WWW/hmmer2-html/node27.html".
929  
930 Assuming presence of Selex file header. Data exported by
931 Bioperl on Pfam and Selex formats are identical, but Pfam file
932 only holds one alignment.
933  
934 =cut
935  
936 sub _possibly_selex
937 {
938 my ($line, $lineno) = (shift, shift);
939 return (($lineno == 1 && $line =~ /^#=ID /) ||
940 ($lineno == 2 && $line =~ /^#=AC /) ||
941 ($line =~ /^#=SQ /));
942 }
943  
944 =head2 _possibly_stockholm
945  
946 From bioperl test data.
947  
948 =cut
949  
950 sub _possibly_stockholm
951 {
952 my ($line, $lineno) = (shift, shift);
953 return (($lineno == 1 && $line =~ /^# STOCKHOLM/) ||
954 $line =~ /^#=(?:GF|GS) /);
955 }
956  
957  
958  
959 =head2 _possibly_swiss
960  
961 From "http://ca.expasy.org/sprot/userman.html#entrystruc".
962  
963 =cut
964  
965 sub _possibly_swiss
966 {
967 my ($line, $lineno) = (shift, shift);
968 return ($lineno == 1 && $line =~ /^ID / && $line =~ /AA\.$/);
969 }
970  
971 =head2 _possibly_tab
972  
973 Contributed by Heikki.
974  
975 =cut
976  
977 sub _possibly_tab
978 {
979 my ($line, $lineno) = (shift, shift);
980 return ($lineno == 1 && $line =~ /^[^\t]+\t[^\t]+/) ;
981 }
982  
983 =head2 _possibly_vcf
984  
985 From "http://www.1000genomes.org/wiki/analysis/vcf4.0".
986  
987 Assumptions made about sanity - format and date lines are line 1 and 2
988 respectively. This is not specified in the format document.
989  
990 =cut
991  
992 sub _possibly_vcf
993 {
994 my ($line, $lineno) = (shift, shift);
995 return (($lineno == 1 && $line =~ /##fileformat=VCFv/) ||
996 ($lineno == 2 && $line =~ /##fileDate=/));
997 }
998  
999  
1000  
1001 1;