3 # BioPerl module for Bio::Tools::Grail
5 # Cared for by Jason Stajich <jason-at-bioperl.org>
7 # Copyright Jason Stajich
9 # You may distribute this module under the same terms as perl itself
11 # POD documentation - main docs before the code
15 Bio::Tools::Grail - Results of one Grail run
19 $grail = Bio::Tools::Grail->new(-file => 'result.grail');
21 $grail = Bio::Tools::Grail->new( -fh => \*INPUT );
24 while($gene = $grail->next_prediction()) {
25 # $gene is an instance of Bio::Tools::Prediction::Gene
27 # $gene->exons() returns an array of
28 # Bio::Tools::Prediction::Exon objects
30 @exon_arr = $gene->exons();
33 @init_exons = $gene->exons('Initial');
35 @intrl_exons = $gene->exons('Internal');
37 @term_exons = $gene->exons('Terminal');
38 # singleton exons only -- should be same as $gene->exons() because
39 # there are no other exons supposed to exist in this structure
40 @single_exons = $gene->exons('Single');
43 # essential if you gave a filename at initialization (otherwise the file
49 The Grail module provides a parser for Grail gene structure prediction
57 User feedback is an integral part of the evolution of this and other
58 Bioperl modules. Send your comments and suggestions preferably to one
59 of the Bioperl mailing lists. Your participation is much appreciated.
61 bioperl-l@bioperl.org - General discussion
62 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
66 Report bugs to the Bioperl bug tracking system to help us keep track
67 the bugs and their resolution. Bug reports can be submitted via the
70 http://bugzilla.open-bio.org/
72 =head1 AUTHOR - Jason Stajich
74 Email jason-at-bioperl.org
78 The rest of the documentation details each of the object
79 methods. Internal methods are usually preceded with a _
83 # Let the code begin...
85 package Bio
::Tools
::Grail
;
88 use Bio
::Tools
::Prediction
::Gene
;
89 use Bio
::Tools
::Prediction
::Exon
;
92 use base
qw(Bio::Root::IO Bio::Root::Root);
95 my($class,@args) = @_;
97 my $self = $class->SUPER::new
(@args);
98 $self->_initialize_io(@args);
103 =head2 next_prediction
105 Title : next_prediction
106 Usage : while($gene = $grail->next_prediction()) {
109 Function: Returns the next gene structure prediction of the Grail result
110 file. Call this method repeatedly until FALSE is returned.
113 Returns : A Bio::Tools::Prediction::Gene object.
118 sub next_prediction
{
121 # get next gene structure
122 my $gene = $self->_prediction();
125 # fill in predicted protein, and if available the predicted CDS
128 # use the seq stack if there's a seq on it
129 my $seqobj = pop(@
{$self->{'_seqstack'}});
131 # otherwise read from input stream
132 ($id, $seq) = $self->_read_fasta_seq();
133 $seqobj = Bio
::PrimarySeq
->new('-seq' => $seq,
134 '-display_id' => $id,
135 '-alphabet' => "protein");
137 # check that prediction number matches the prediction number
138 # indicated in the sequence id (there may be incomplete gene
139 # predictions that contain only signals with no associated protein
140 # and CDS, like promoters, poly-A sites etc)
141 $gene->primary_tag() =~ /[^0-9]([0-9]+)$/;
143 if($seqobj->display_id() !~ /_predicted_\w+_$prednr\|/) {
144 # this is not our sequence, so push back for the next prediction
145 push(@
{$self->{'_seqstack'}}, $seqobj);
147 $gene->predicted_protein($seqobj);
148 # CDS prediction, too?
149 if($self->_has_cds()) {
150 ($id, $seq) = $self->_read_fasta_seq();
151 $seqobj = Bio
::PrimarySeq
->new('-seq' => $seq,
152 '-display_id' => $id,
153 '-alphabet' => "dna");
154 $gene->predicted_cds($seqobj);
161 =head2 _parse_predictions
163 Title : _parse_predictions()
164 Usage : $obj->_parse_predictions()
165 Function: Parses the prediction section. Automatically called by
166 next_prediction() if not yet done.
172 sub _parse_predictions
{
175 # code needs to go here
177 $self->_predictions_parsed(1);
182 Title : _prediction()
183 Usage : $gene = $obj->_prediction()
193 return unless(exists($self->{'_preds'}) && @
{$self->{'_preds'}});
194 return shift(@
{$self->{'_preds'}});
197 =head2 _add_prediction
199 Title : _add_prediction()
200 Usage : $obj->_add_prediction($gene)
207 sub _add_prediction
{
208 my ($self, $gene) = @_;
210 if(! exists($self->{'_preds'})) {
211 $self->{'_preds'} = [];
213 push(@
{$self->{'_preds'}}, $gene);
216 =head2 _predictions_parsed
218 Title : _predictions_parsed
219 Usage : $obj->_predictions_parsed
222 Returns : TRUE or FALSE
226 sub _predictions_parsed
{
227 my ($self, $val) = @_;
229 $self->{'_preds_parsed'} = $val if $val;
230 if(! exists($self->{'_preds_parsed'})) {
231 $self->{'_preds_parsed'} = 0;
233 return $self->{'_preds_parsed'};
239 Usage : $obj->_has_cds()
240 Function: Whether or not the result contains the predicted CDSs, too.
242 Returns : TRUE or FALSE
247 my ($self, $val) = @_;
249 $self->{'_has_cds'} = $val if $val;
250 if(! exists($self->{'_has_cds'})) {
251 $self->{'_has_cds'} = 0;
253 return $self->{'_has_cds'};