This file is indexed.

/usr/lib/perl5/TFBS/PatternGen.pm is in libtfbs-perl 0.5.svn.20100421-1build1.

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
# TFBS module for TFBS::PatternGen
#
# Copyright Boris Lenhard
# 
# You may distribute this module under the same terms as perl itself
#

# POD

=head1 NAME

TFBS::PatternGen - a base class for pattern generators


=head1 DESCRIPTION

TFBS::PatternGen is a base classs providing methods common to all pattern generating
modules. It is meant to be inherited by a concrete pattern generator, which must have its own
constructor.

=cut


package TFBS::PatternGen;

# Object preamble - inherits from TFBS::PatternGenI;
use vars qw(@ISA);
use strict;
use TFBS::PatternGenI;
# use TFBS::PatternGen::_Motif_;
use Bio::Seq;
use Bio::SeqIO;
use Carp;

@ISA = qw(TFBS::PatternGenI);

sub new  {
    confess("TFBS::PatterGen is a base class for particular pattern generators".
            "and cannot be instantiated itself.");
}


=head2 pattern

 Title   : pattern
 Usage   : my $pattern_obj = $patterngen->pattern()
 Function: retrieves a pattern object produced by the pattern generator
 Returns : a pattern object (currently available pattern generators
	   return a TFBS::Matrix::PFM object)
 Args    : none
 Warning : If a pattern generator produces more than one pattern,
	   this method call returns only the first one and prints
	   a warning on STDERR, In those cases you should use
	   I<all_patterns> or I<patternSet> methods.
	

=cut

sub pattern {
    my ($self, %args) =@_;
    my @PFMs = $self->_motifs_to_patterns(%args);
    if (scalar(@PFMs) > 1) {
	$self->warn("The pattern generator produced multiple patterns. ".
		    "Please use patternSet method to retrieve a set object, ".
		    "or all_patterns method to retrieve an array of patterns"); 
    }
    return $PFMs[0];
}

=head2 patternSet

 Title   : patternSet
 Usage   : my $patternSet = $patterngen->patternSet()
 Function: retrieves a pattern set object containing all the patterns
	   produced by the pattern generator
 Returns : a pattern set object (currently available pattern generators
	   return a TFBS::MatrixSet object)
 Args    : none

=cut


sub patternSet {
    my ($self, %args) = @_;
    my @PFMs = $self->_motifs_to_patterns(%args);
    my $set = TFBS::MatrixSet->new();
    $set->add_matrix(@PFMs);
    return $set;
}

=head2 all_patterns

 Title   : all_patterns
 Usage   : my @patterns = $patterngen->all_patterns()
 Function: retrieves an array of pattern objects
	   produced by the pattern generator
 Returns : an array of pattern set objects (currently available 
	   pattern generators return an array of
	   TFBS::Matrix::PFM objects)
 Args    : none

=cut


sub all_patterns {
    my ($self, %args) = @_;
    my @patterns = $self->_motifs_to_patterns(%args);
    return @patterns;
}

sub _create_seq_set  {
    my ($self, %args) = @_;
    my (@raw_set, @final_set);

    if ($args{-seq_list}) {
	@raw_set = @{$args{-seq_list}};
    }
    elsif ($args{-seq_stream} ) {
	while (my $seqobj = $args{-seq_stream}->next_seq()) {
	    push @raw_set, $seqobj;
	}
    }
    elsif ($args{-seq_file} )  {
	my $seqstream = Bio::SeqIO->new(-file=>$args{-seq_file},
					-format=>"fasta");
	while (my $seqobj = $seqstream->next_seq()) {
	    push @raw_set, $seqobj;
	}
    }
	
    foreach my $seqobj (@raw_set)  {
	my $i = 1; #for unnamed sequences
	if (ref($seqobj))  {
	    my $seqstring;
	    eval { $seqstring = $seqobj->seq() };
	    if ($@) { 
		$self->throw("Invalid sequence object passed in -seq_set.");
	    } 
	    else  {
		_validate_seq(uc $seqstring) 
		    or $self->throw("Illegal character(s) in sequence: $seqstring");
	    }
	    push @final_set, $seqobj;
	}
	else  {
	    my $seqstring = $seqobj;
	    _validate_seq(uc $seqstring) 
		or $self->throw("Illegal character(s) in sequence: $seqstring");
	    push @final_set, Bio::Seq->new(-seq=>$seqstring,
					   -ID=>"unnamed".$i++,
					   -type=>"dna");
	}
    }
    
    $self->{'seq_set'} = \@final_set;
    return 1;
}


sub _motifs_to_patterns  {
    my ($self, %args) = @_;
    my $i = 1;
    my @patterns;
    my %params = ( -name => "motif",
		   -ID   => "motif",
		   -class => "unknown",
		   %args);
    foreach my $motif (@{ $self->{'motifs'} }) {
	push @patterns, $motif->pattern(-name => $params{-name}.$i,
				-ID   => $params{-ID}."#".$i,
				-class => $params{-class});
	$i++;
    }
    return @patterns;
}


sub _validate_seq  {
    # a utility function
    my $sequence = uc $_[0];
    $sequence=~ s/[ACGTN]//g;
    return ($sequence eq "" ? 1 : 0);
}

sub _check_seqs_for_uniform_length  {
    my $self = shift;
    my $reflength = $self->{'seq_set'}->[-1]->length();
    foreach my $seqobj ( @{ $self->{'seq_set'} } )  {
	if ($seqobj->length() != $reflength)  {
	    $self->throw(ref($self). "object has received sequences of unequal length");
	}
    }
}


sub all_motifs  {
    return @{$_[0]->{'motifs'}} if $_[0]->{'motifs'};
}