File Coverage

Bio/Prospect/File.pm
Criterion Covered Total %
statement 36 43 83.7
branch 3 8 37.5
condition 2 6 33.3
subroutine 11 12 91.6
pod 5 5 100.0
total 57 74 77.0


line stmt bran cond sub pod time code
1             # Bio::Prospect::File
2             # $Id: File.pm,v 1.15 2003/11/18 19:45:45 rkh Exp $
3             # @@banner@@
4              
5             =head1 NAME
6              
7             Bio::Prospect::File -- interface to Prospect Files
8              
9             S<$Id: File.pm,v 1.15 2003/11/18 19:45:45 rkh Exp $>
10              
11             =head1 SYNOPSIS
12              
13             use Bio::Prospect::File;
14              
15             my $pf = new Bio::Prospect::File( $fn );
16              
17             while( my $t = $pf->next_thread() ) {
18             printf("%s->%s raw=%d mut=%d pair=%d\n",
19             $t->qname(), $t->tname(), $t->raw_score(),
20             $t->mutation_score(), $t->pair_score() );
21             print $t->alignment();
22             }
23              
24             =head1 DESCRIPTION
25              
26             Bio::Prospect::File is a subclass of IO::File and is intended
27             for use for parsing Prospect XML files. It is used by
28             Bio::Prospect::LocalClient to return Thread objects from
29             Prospect output.
30              
31             =cut
32              
33              
34             package Bio::Prospect::File;
35              
36             # ISA:
37 2     2   813 use base IO::File;
  2         3  
  2         1118  
38              
39 2     2   22107 use strict;
  2         4  
  2         50  
40 2     2   9 use warnings;
  2         4  
  2         48  
41 2     2   9 use Carp;
  2         3  
  2         118  
42 2     2   1942 use Bio::Prospect::Thread;
  2         10  
  2         76  
43 2     2   17 use vars qw( $VERSION );
  2         3  
  2         874  
44             $VERSION = sprintf( "%d.%02d", q$Revision: 1.15 $ =~ /(\d+)\.(\d+)/ );
45              
46              
47              
48             =pod
49              
50             =head1 METHODS
51              
52             =cut
53              
54             #-------------------------------------------------------------------------------
55             # new()
56             #-------------------------------------------------------------------------------
57              
58             =head2 new()
59              
60             Name: new()
61             Purpose: constructor
62             Arguments:
63             Returns: Bio::Prospect::File
64              
65             =cut
66              
67             sub new {
68 1     1 1 1092 my $class = shift;
69 1         11 my $self = $class->SUPER::new( @_ );
70             }
71              
72              
73             #-------------------------------------------------------------------------------
74             # fdopen()
75             #-------------------------------------------------------------------------------
76              
77             =head2 fdopen()
78              
79             Name: fdopen()
80             Purpose: overrides fdopen in IO::File
81             Arguments: same as IO::File::fdopen
82             Returns: nothing
83              
84             =cut
85              
86             sub fdopen {
87 0     0 1 0 my $self = shift;
88 0         0 my $rv = $self->SUPER::fdopen( @_ );
89 0 0       0 if (not $self->_advance()) {
90 0         0 throw Bio::Prospect::RuntimeError("file doesn't look like a Prospect XML file\n");
91             }
92 0         0 return 1;
93             }
94              
95              
96             #-------------------------------------------------------------------------------
97             # open()
98             #-------------------------------------------------------------------------------
99              
100             =head2 open()
101              
102             Name: open()
103             Purpose: overrides open in IO::File
104             Arguments: same as IO::File::open
105             Returns: nothing
106              
107             =cut
108              
109             sub open {
110 1     1 1 492 my $self = shift;
111 1         9 my $rv = $self->SUPER::open( @_ );
112 1 50       92 if (not $self->_advance()) {
113 0         0 throw Bio::Prospect::RuntimeError("file doesn't look like a Prospect XML file\n");
114             }
115 1         6 return 1;
116             }
117              
118              
119              
120              
121             #-------------------------------------------------------------------------------
122             # next_thread()
123             #-------------------------------------------------------------------------------
124              
125             =head2 next_thread()
126              
127             Name: next_thread()
128             Purpose: return next Thread object
129             Arguments: none
130             Returns: Bio::Prospect::Thread
131              
132             =cut
133              
134             sub next_thread {
135 1     1 1 2 my $self = shift;
136              
137 1         4 my $xml = $self->next_thread_as_xml();
138 1 50       5 return unless defined $xml;
139              
140 1         10 return( new Bio::Prospect::Thread( $xml ) );
141             }
142              
143              
144             #-------------------------------------------------------------------------------
145             # next_thread_as_xml()
146             #-------------------------------------------------------------------------------
147              
148             =head2 next_thread_as_xml()
149              
150             Name: next_thread_as_xml()
151             Purpose: return next threading xml tag
152             Arguments: none
153             Returns: xml string
154              
155             =cut
156              
157             sub next_thread_as_xml {
158 1     1 1 2 my $self = shift;
159 1         4 local $/ = '</threading>';
160 1         29 my $retval = $self->SUPER::getline();
161 1 50 33     59 if ( !defined $retval or
162             $retval !~ m/<threading/ ) {
163 0         0 return();
164             } else {
165 1         6 return( $retval );
166             }
167             }
168              
169              
170             #---------------------------------------------
171             # INTERNAL METHODS
172             #---------------------------------------------
173              
174             #-------------------------------------------------------------------------------
175             # _advance()
176             #-------------------------------------------------------------------------------
177              
178             =head2 fdopen()
179              
180             Name: _advance()
181             Purpose: INTERNAL METHOD: check if proper Prospect xml
182             Arguments: none
183             Returns: 1 - okay, 0 - bad xml
184              
185             =cut
186              
187             sub _advance {
188 1     1   3 my $self = shift;
189 1         41 my $firstline = $self->getline();
190 1   33     53 return( (defined $firstline) and ($firstline =~ m/^<prospectOutput>/) );
191             }
192              
193              
194             1;