This file is indexed.

/usr/share/perl5/Bio/Tools/Glimmer.pm is in libbio-perl-perl 1.6.923-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
#
# BioPerl module for Bio::Tools::Glimmer
#
# Please direct questions and support issues to <bioperl-l@bioperl.org> 
#
# Cared for by Jason Stajich <jason-at-bioperl-dot-org>
#
# Copyright Jason Stajich
#
# You may distribute this module under the same terms as perl itself

# POD documentation - main docs before the code

=head1 NAME

Bio::Tools::Glimmer - parser for Glimmer 2.X/3.X prokaryotic and 
GlimmerM/GlimmerHMM eukaryotic gene predictions

=head1 SYNOPSIS

   use Bio::Tools::Glimmer;

   # file
   my $parser = Bio::Tools::Glimmer->new(-file => $file);
   # filehandle:
   $parser = Bio::Tools::Glimmer->new( -fh  => \*INPUT );
   # provide a sequence identifier (Glimmer 2.X)
   my $parser = Bio::Tools::Glimmer->new(-file => $file, -seqname => seqname);
   # force format (override automatic detection)
   my $parser = Bio::Tools::Glimmer->new(-file => $file, -format => 'GlimmerM');

   # parse the results
   # note: this class is-a Bio::Tools::AnalysisResult which implements
   # Bio::SeqAnalysisParserI, i.e., $glimmer->next_feature() is the same

   while(my $gene = $parser->next_prediction()) {
       # For eukaryotic input (GlimmerM/GlimmerHMM), $gene will be an instance
       # of Bio::Tools::Prediction::Gene, which inherits off
       # Bio::SeqFeature::Gene::Transcript, and $gene->exons() will return an
       # array of Bio::Tools::Prediction::Exon objects.
       # For prokaryotic input (Glimmer2.X/Glimmer3.X), $gene will be an
       # instance of Bio::SeqFeature::Generic

       # all exons (eukaryotic only):
       @exon_arr = $gene->exons();
       # initial exons only
       @init_exons = $gene->exons('Initial');
       # internal exons only
       @intrl_exons = $gene->exons('Internal');
       # terminal exons only
       @term_exons = $gene->exons('Terminal');
   }

=head1 DESCRIPTION

This is a module for parsing Glimmer, GlimmerM and GlimmerHMM predictions.  
It will create gene objects from the prediction report which can 
be attached to a sequence using Bioperl objects, or output as GFF 
suitable for loading into Bio::DB::GFF for use with Gbrowse.

Glimmer is open source and available at
L<http://www.cbcb.umd.edu/software/glimmer/>.

GlimmerM is open source and available at 
L<http://www.tigr.org/software/glimmerm/>.

GlimmerHMM is open source and available at
L<http://www.cbcb.umd.edu/software/GlimmerHMM/>.

Note that Glimmer 2.X will only process the first
sequence in a fasta file, and the prediction report does not contain any
sort of sequence identifier

Note that Glimmer 3.X produces two output files.  This module only parses
the .predict file.


=head1 FEEDBACK

=head2 Mailing Lists

User feedback is an integral part of the evolution of this and other
Bioperl modules. Send your comments and suggestions preferably to
the Bioperl mailing list.  Your participation is much appreciated.

  bioperl-l@bioperl.org                  - General discussion
  http://bioperl.org/wiki/Mailing_lists  - About the mailing lists

=head2 Support 

Please direct usage questions or support issues to the mailing list:

I<bioperl-l@bioperl.org>

rather than to the module maintainer directly. Many experienced and 
reponsive experts will be able look at the problem and quickly 
address it. Please include a thorough description of the problem 
with code and data examples if at all possible.

=head2 Reporting Bugs

Report bugs to the Bioperl bug tracking system to help us keep track
of the bugs and their resolution. Bug reports can be submitted via
email or the web:

  https://redmine.open-bio.org/projects/bioperl/

=head1 AUTHOR - Jason Stajich

Email jason-at-bioperl-dot-org

=head1 CONTRIBUTORS

Torsten Seemann

Mark Johnson

=head1 APPENDIX

The rest of the documentation details each of the object methods.
Internal methods are usually preceded with a _

=cut


# Let the code begin...


package Bio::Tools::Glimmer;
use strict;

use Bio::Factory::FTLocationFactory;
use Bio::Tools::Prediction::Gene;
use Bio::Tools::Prediction::Exon;

use base qw(Bio::Tools::AnalysisResult);

sub _initialize_state {
    my($self,@args) = @_;

    # first call the inherited method!
    my $make = $self->SUPER::_initialize_state(@args);

    $self->{'_preds_parsed'} = 0;
    # array of pre-parsed predictions
    $self->{'_preds'} = [];
}

=head2 new

 Title   : new
 Usage   : my $obj = Bio::Tools::Glimmer->new();
 Function: Builds a new Bio::Tools::Glimmer object 
 Returns : an instance of Bio::Tools::Glimmer
 Args    : format ('Glimmer', 'GlimmerM', 'GlimmerHMM'), seqname


=cut

sub new {
  my($class,@args) = @_;

  my $self = $class->SUPER::new(@args);

  my ($format, $seqname, $seqlength, $detail) =
      $self->_rearrange([qw(FORMAT SEQNAME SEQLENGTH DETAIL)], @args);

  # override automagic format detection
  if (defined($format) &&
      (($format eq 'Glimmer')  ||
       ($format eq 'GlimmerM') ||
       ($format eq 'GlimmerHMM'))
  ) {
      $self->_format($format);
  }
  
  if (defined($detail)) {
      $self->_format('Glimmer');
      $self->_detail_file($detail);
  }
  
  # hardwire seq_id when creating gene and exon objects (Glimmer 2.X)
  $self->_seqname($seqname) if defined($seqname);
  
  # store the length of the input sequence (Glimmer 2.X)
  $self->_seqlength($seqlength) if defined($seqlength);
  
  return $self;
}

=head2 analysis_method

 Usage     : $glimmer->analysis_method();
 Purpose   : Inherited method. Overridden to ensure that the name matches
             /glimmer/i.
 Returns   : String
 Argument  : n/a

=cut

#-------------
sub analysis_method { 
#-------------
    my ($self, $method) = @_;  
    if($method && ($method !~ /glimmer/i)) {
	$self->throw("method $method not supported in " . ref($self));
    }
    return $self->SUPER::analysis_method($method);
}

=head2 next_feature

 Title   : next_feature
 Usage   : while($gene = $glimmer->next_feature()) {
                  # do something
           }
 Function: Returns the next gene structure prediction of the Glimmer result
           file. Call this method repeatedly until FALSE is returned.

           The returned object is actually a SeqFeatureI implementing object.
           This method is required for classes implementing the
           SeqAnalysisParserI interface, and is merely an alias for 
           next_prediction() at present.

 Example :
 Returns : A Bio::Tools::Prediction::Gene object.
 Args    :

=cut

sub next_feature {
    my ($self,@args) = @_;
    # even though next_prediction doesn't expect any args (and this method
    # does neither), we pass on args in order to be prepared if this changes
    # ever
    return $self->next_prediction(@args);
}

=head2 next_prediction

 Title   : next_prediction
 Usage   : while($gene = $glimmer->next_prediction()) {
                  # do something
           }
 Function: Returns the next gene structure prediction of the Glimmer result
           file. Call this method repeatedly until FALSE is returned.

 Example :
 Returns : A Bio::Tools::Prediction::Gene object.
 Args    :

=cut

sub next_prediction {
    my ($self) = @_;
    my $gene;

    # if the prediction section hasn't been parsed yet, we do this now
    $self->_parse_predictions() unless $self->_predictions_parsed();
    
    # get next gene structure
    $gene = $self->_prediction();
    return $gene;
}

=head2 _parse_predictions

 Title   : _parse_predictions()
 Usage   : $obj->_parse_predictions()
 Function: Parses the prediction section. Automatically called by
           next_prediction() if not yet done.
 Example :
 Returns : 

=cut

sub _parse_predictions {

    my ($self) = @_;

    
    my %method = (
                  'Glimmer'    => '_parse_prokaryotic',
                  'GlimmerM'   => '_parse_eukaryotic',
                  'GlimmerHMM' => '_parse_eukaryotic',
                  '_DEFAULT_'  => '_parse_eukaryotic',
              );
    
    my $format = $self->_format();
    
    if (!$format) {
        
        while (my $line = $self->_readline()) {

            if ( $line =~ /^Glimmer\S*\s+\(Version\s*\S+\)/ ) {
                $format = 'GlimmerM';
                $self->_pushback($line);
                last;
            }
            elsif ( $line =~ /^Glimmer\S*$/ ) {
                $format = 'GlimmerHMM';
                $self->_pushback($line);
                last;
            }
            elsif ($line =~ /^Putative Genes:$/) {
                $format = 'Glimmer';
                $self->_pushback($line);
                last;
            }
            elsif ($line =~ /^>(\S+)/) {
                $format = 'Glimmer';
                $self->_pushback($line);
                last;
            }
            
        }
        
    }

    my $method =
        (exists($method{$format})) ? $method{$format} : $method{'_DEFAULT_'};

    return $self->$method();
    
}


=head2 _parse_eukaryotic

 Title   : _parse_eukaryotic()
 Usage   : $obj->_parse_eukaryotic()
 Function: Parses the prediction section. Automatically called by
           next_prediction() if not yet done.
 Example :
 Returns : 

=cut

sub _parse_eukaryotic {
    my ($self) = @_;

    my ($gene,$seqname,$seqlen,$source,$lastgenenum);
    
    while(defined($_ = $self->_readline())) {
	if( /^(Glimmer\S*)\s+\(Version\s*(\S+)\)/ ) {
	    $source = "$1_$2";
	    next;
	} elsif( /^(GlimmerHMM\S*)$/ ) { # GlimmerHMM has no version
	    $source = $1;
	    next;
	} elsif(/^Sequence name:\s+(.+)$/ ) {
	    $seqname = $1;
	    next;
	} elsif( /^Sequence length:\s+(\S+)/ ) {
	    $seqlen = $1;
	    next;
	} elsif( m/^(Predicted genes)|(Gene)|\s+\#/ || /^\s+$/ ) { 
	    next;
	    
	} elsif( # GlimmerM/HMM gene-exon prediction line
		 /^\s+(\d+)\s+ # gene num
		 (\d+)\s+      # exon num
		 ([\+\-])\s+   # strand
		 (\S+)\s+      # exon type
		 (\d+)\s+(\d+) # exon start, end
		 \s+(\d+)      # exon length		 
		 /ox ) {
	    my ($genenum,$exonnum,$strand,$type,$start,$end,$len) = 
		( $1,$2,$3,$4,$5,$6,$7);
	    if( ! $lastgenenum || $lastgenenum != $genenum) {		
		$self->_add_prediction($gene) if ( $gene );
		$gene = Bio::Tools::Prediction::Gene->new
		    (
		     '-seq_id'      => $seqname,
		     '-primary_tag' => "gene",
		     '-source_tag'  => $source,
		     '-tag'         => { 'Group' => "GenePrediction$genenum"},
		     );
	    }
	    my $exon = Bio::Tools::Prediction::Exon->new
		('-seq_id'     => $seqname,
		 '-start'      => $start,
		 '-end'        => $end,
		 '-strand'     => $strand eq '-' ? '-1' : '1',
		 '-source_tag' => $source,
		 '-primary_tag'=> 'exon',
		 '-tag'         => { 'Group' => "GenePrediction$genenum"},
		 );
	    $gene->add_exon($exon,lc($type));
	    $lastgenenum = $genenum;
	}
    }
    $self->_add_prediction($gene) if( $gene );
    $self->_predictions_parsed(1);
}

=head2 _parse_prokaryotic

 Title   : _parse_prokaryotic()
 Usage   : $obj->_parse_prokaryotic()
 Function: Parses the prediction section. Automatically called by
           next_prediction() if not yet done.
 Example :
 Returns : 

=cut

sub _parse_prokaryotic {
    my ($self) = @_;

    # default value, possibly overriden later
    my $source = 'Glimmer';

    # Store the sequence length(s) here, either from the
    # seqlength arg to the constructor, or from the
    # Glimmer 3.X detail file
    my %seqlength = ( );
    
    # Glimmer 2.X does not provide a sequence identifer
    # in the prediction report (will default to unknown
    # if not specified in the seqname arg to the
    # constructor
    #
    # Glimmer 2.X does not report the length of the
    # input sequence, either (will default to undef
    # if not specified in the seqlength arg to the
    # constructor
    my $seqname = $self->_seqname();
    my $seqlength = $self->_seqlength();

    if (defined($seqlength)) {
        $seqlength{$seqname} = $seqlength
    }

    # Parse the detail file, if we have one (Glimmer 3.X)
    my $detail_file = $self->_detail_file();
    
    if (defined($detail_file)) {

        my $io = Bio::Root::IO->new(-file => $detail_file);
        my $seqname;
        
        while (defined($_ = $io->_readline())) {
            if ($_ =~ /^>(\S+)/) {
                $seqname = $1;
                next;
            }

            if (defined($seqname) && ($_ =~ /^Sequence length = (\d+)$/)) {
                $seqlength{$seqname} = $1;
                next;
            }
        }
    }
    
    my $location_factory = Bio::Factory::FTLocationFactory->new();
    
    while(defined($_ = $self->_readline())) {
        # Glimmer 3.X does provide a sequence identifier -
        # beware whitespace at the end (comes through from
        # the fasta file)
        if ($_ =~ /^Putative Genes:$/) {
            $source = 'Glimmer_2.X';
            next;
        }
        # Glimmer 3.X sequence identifier
        elsif ($_ =~ /^>(\S+)/) {
            $seqname = $1;
            $seqlength = $seqlength{$seqname};
            $source = 'Glimmer_3.X';
            next;
        }        
        elsif (
               # Glimmer 2.X prediction 
               (/^\s+(\d+)\s+      # gene num
                (\d+)\s+(\d+)\s+   # start, end
                \[([\+\-])(\d{1})\s+ # strand, frame
                /ox ) ||
               # Glimmer 3.X prediction
               (/^[^\d]+(\d+)\s+    # orf (numeric portion)
                (\d+)\s+(\d+)\s+   # start, end
                ([\+\-])(\d{1})\s+   # strand, frame
                ([\d\.]+)          # score
                /ox)) {
	    my ($genenum,$start,$end,$strand,$frame,$score) = 
		( $1,$2,$3,$4,$5,$6 );

            my $circular_prediction = 0;

            # Check for a circular prediction before we
            # start fiddling with the coordinates
            if ($strand eq '+') {
                if ($start > $end) {
                    $circular_prediction = 1;
                }
            }
            else {
                if ($start < $end) {
                    $circular_prediction = 1;
                }
            }

            if ($circular_prediction) {
                unless (defined($seqlength)) {
                    $self->throw("need to know the sequence length to handle wraparound genes");
                }
            }
            
            # Glimmer 2.X predictions do not include
            # the stop codon - this might extend the
            # prediction off either end of the sequence.
            # This works fine even on circular/wraparound
            # predictions.  
            if ($source eq 'Glimmer_2.X') {
                if ($strand eq '+') { 
                    $end += 3;
                }
                else {
                    $end -= 3;
                }
            }

            # We might have extended a Glimmer 2.X prediction
            # beyond the boundaries of the input sequence.
            # Also, Glimmer 3.X (with -X) will output predictions
            # with coordinates less than 1 or greater than the
            # length of the sequence.
            my ($fst, $fend);
            foreach my $coord ($start, $end) {
                if ($coord < 1) {
                    $coord = '<1';
                    $fst++;
                } elsif (defined($seqlength) && ($coord > $seqlength)) {
                    $coord = ">$seqlength";
                    $fend++;
                }
            }
            
            my $location_string;

            if ($circular_prediction) {
                if ($strand eq '+') {
                    $location_string = "join($start..$seqlength,1..$end)";
                }
                else {
                    $location_string = "join($start..1,$seqlength..$end)";
                }
                }
            else {
                # start must always be less than end for gene locations
                if ($strand eq '-' && !$fst && !$fend && $start > $end) {
                    ($start, $end) = ($end, $start);
                }
                $location_string = "$start..$end";
            }
            
            my $location_object =
                $location_factory->from_string($location_string);
            
            # convert glimmer's frame range from 1-3 to SeqFeature's 0-2.
            $frame--;
            
            my $gene = Bio::SeqFeature::Generic->new
                (
                 '-seq_id'      => $seqname,
                 '-location'   => $location_object,
                 '-strand'     => $strand eq '-' ? '-1' : '1',
                 '-frame'		=> $frame,
                 '-source_tag'  => $source,
                 '-display_name' => "orf$genenum",
                 '-primary_tag'=> 'gene',
                 '-tag'         => { 'Group' => "GenePrediction_$genenum"},
                 '-score'       => $score || undef
             );
            
            $self->_add_prediction($gene) 
	}
    }
    
    $self->_predictions_parsed(1);
}

=head2 _prediction

 Title   : _prediction()
 Usage   : $gene = $obj->_prediction()
 Function: internal
 Example :
 Returns : 

=cut

sub _prediction {
    my ($self) = @_;

    return unless(exists($self->{'_preds'}) && @{$self->{'_preds'}});
    return shift(@{$self->{'_preds'}});
}

=head2 _add_prediction

 Title   : _add_prediction()
 Usage   : $obj->_add_prediction($gene)
 Function: internal
 Example :
 Returns : 

=cut

sub _add_prediction {
    my ($self, $gene) = @_;

    if(! exists($self->{'_preds'})) {
	$self->{'_preds'} = [];
    }
    push(@{$self->{'_preds'}}, $gene);
}

=head2 _predictions_parsed

 Title   : _predictions_parsed
 Usage   : $obj->_predictions_parsed
 Function: internal
 Example :
 Returns : TRUE or FALSE

=cut

sub _predictions_parsed {
    my ($self, $val) = @_;

    $self->{'_preds_parsed'} = $val if $val;
    if(! exists($self->{'_preds_parsed'})) {
	$self->{'_preds_parsed'} = 0;
    }
    return $self->{'_preds_parsed'};
}

=head2 _seqname

 Title   : _seqname
 Usage   : $obj->_seqname($seqname)
 Function: internal (for Glimmer 2.X)
 Example :
 Returns : String

=cut

sub _seqname {
    my ($self, $val) = @_;

    $self->{'_seqname'} = $val if $val;
    if(! exists($self->{'_seqname'})) {
	$self->{'_seqname'} = 'unknown';
    }
    return $self->{'_seqname'};
}

=head2 _seqlength

 Title   : _seqlength
 Usage   : $obj->_seqlength($seqlength)
 Function: internal (for Glimmer 2.X)
 Example :
 Returns : String

=cut

sub _seqlength {
    my ($self, $val) = @_;

    $self->{'_seqlength'} = $val if $val;
    return $self->{'_seqlength'};
}

=head2 _format

 Title   : _format
 Usage   : $obj->_format($format)
 Function: internal
 Example :
 Returns : String

=cut

sub _format {
    my ($self, $val) = @_;

    $self->{'_format'} = $val if $val;

    return $self->{'_format'};
}

=head2 _detail_file

 Title   : _detail_file
 Usage   : $obj->_detail_file($filename)
 Function: internal (for Glimmer 3.X)
 Example :
 Returns : String

=cut

sub _detail_file {
    my ($self, $val) = @_;

    $self->{'_detail_file'} = $val if $val;
    return $self->{'_detail_file'};
}

1;