This file is indexed.

/usr/share/perl5/Bio/SeqEvolution/DNAPoint.pm is in libbio-perl-perl 1.7.2-2.

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
#
# BioPerl module for Bio::SeqEvolution::DNAPoint
#
# Please direct questions and support issues to <bioperl-l@bioperl.org> 
#
# Cared for by Heikki Lehvaslaiho <heikki at bioperl dot org>
#
# Copyright Heikki Lehvaslaiho
#
# You may distribute this module under the same terms as perl itself

# POD documentation - main docs before the code

=head1 NAME

Bio::SeqEvolution::DNAPoint - evolve a sequence by point mutations

=head1 SYNOPSIS

  # $seq is a Bio::PrimarySeqI to mutate
  $evolve = Bio::SeqEvolution::Factory->new (-rate => 5,
                                             -seq => $seq,
                                             -identity => 50
                                             );
  $newseq = $evolve->next_seq;


=head1 DESCRIPTION

Bio::SeqEvolution::DNAPoint implements the simplest evolution model:
nucleotides change by point mutations, only. Transition/transversion
rate of the change, rate(), can be set.

The new sequences are named with the id of the reference sequence
added with a running number. Placing a new sequence into a factory to
be evolved resets that counter. It can also be called directly with
L<reset_sequence_counter>.

The default sequence type returned is Bio::PrimarySeq. This can be
changed to any Bio::PrimarySeqI compliant sequence class.

Internally the probability of the change of one nucleotide is mapped
to scale from 0 to 100. The probability of the transition occupies
range from 0 to some value. The remaining range is divided equally
among the two transversion nucleotides. A random number is then
generated to pick up one change.

Not that the default transition/transversion rate, 1:1, leads to
observed transition/transversion ratio of 1:2 simply because there is
only one transition nucleotide versus two transversion nucleotides.

=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 the
web:

  https://github.com/bioperl/bioperl-live/issues

=head1 AUTHOR

  Heikki Lehvaslaiho E<lt>heikki at bioperl dot orgE<gt>

=head1 CONTRIBUTORS

Additional contributor's names and emails here

=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::SeqEvolution::DNAPoint;
use strict;
use Bio::Root::Root;
use Bio::SeqEvolution::Factory;

use Bio::Variation::DNAMutation;
use Bio::Variation::Allele;
use Bio::SimpleAlign;

use base qw(Bio::SeqEvolution::Factory);


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

    $self->SUPER::_initialize(@args);
    my %param = @args;
    @param{ map { lc $_ } keys %param } = values %param; # lowercase keys

    exists $param{'-rate'} && $self->rate($param{'-rate'});

    $self->_init_mutation_engine;
}


sub _init_mutation_engine {
    my $self = shift;

    # arrays of possible changes have transitions as first items
    my %changes;
    $self->{'_changes'}->{'a'} = ['t', 'c', 'g'];
    $self->{'_changes'}->{'t'} = ['a', 'c', 'g'];
    $self->{'_changes'}->{'c'} = ['g', 'a', 't'];
    $self->{'_changes'}->{'g'} = ['c', 'a', 't'];


    # given the desired rate, find out where cut off points need to be
    # when random numbers are generated from 0 to 100
    # we are ignoring identical mutations (e.g. A->A) to speed things up
    my $bin_size = 100/($self->rate + 2);
    $self->{'_transition'} = 100 - (2*$bin_size);
    $self->{'_first_transversion'} = $self->{'_transition'} + $bin_size;

    $self->_init_alignment;
}

sub _init_alignment {
    my $self = shift;

    # put the initial sequence into the alignment object
    $self->{'_align'} = Bio::SimpleAlign->new(-verbose => -1);
    return unless $self->seq;
    $self->{'_ori_locatableseq'} = Bio::LocatableSeq->new(-id => 'ori',
                                                         -seq=> $self->seq->seq);
    $self->{'_mut_locatableseq'} = Bio::LocatableSeq->new(-id => 'mut',
                                                         -seq=> $self->seq->seq);
    $self->{'_align'}->add_seq($self->{'_ori_locatableseq'});
    $self->{'_align'}->add_seq($self->{'_mut_locatableseq'});
}

=head2 seq

 Title   : seq
 Usage   : $obj->seq($newval)
 Function: Set the sequence object for the original sequence
 Returns : The sequence object
 Args    : newvalue (optional)

Setting this will reset mutation and generated mutation counters.

=cut

sub seq{
   my $self = shift;

   if (@_) {
       my $seq = shift;
       $self->throw('Need a valid Bio::PrimarySeqI, not [', ref($seq), ']')
           unless $seq->isa('Bio::PrimarySeqI');
       
       $self->throw('Only nucleotide sequences are supported')
           if $seq->alphabet eq 'protein';
       $self->throw('No ambiquos nucleotides allowed in the input sequence')
           if $seq->seq =~ m/[^acgt]/;

       $self->{'_seq'} = $seq;

       # unify the look of sequence strings and cache the information
       $self->{'_ori_string'} = lc $seq->seq; # lower case
       $self->{'_ori_string'} =~ s/u/t/; # simplyfy our life; modules should deal with the change anyway
       $self->{'_seq_length'} = $seq->length;

       $self->reset_sequence_counter;
   }
   return $self->{'_seq'};
}

=head2 set_mutated_seq

  Title   : seq_mutated_seq
  Usage   : $obj->set_mutated_seq($newval)
  Function: In case of mutating a sequence with multiple evolvers, this
  Returns : set_mutated_seq
  Args    : newvalue (optional)

=cut

sub set_mutated_seq {
    my $self = shift;

    if (@_) {
        my $seq = shift;
        $self->throw('Need a valid Bio::PrimarySeqI, not [', ref($seq), ']')
            unless $seq->isa('Bio::PrimarySeqI');
        $self->throw('Only nucleotide sequences are supported')
            if $seq->alphabet eq 'protein';
        $self->throw('No ambiquos nucleotides allowed in the input sequence')
            if $seq->seq =~ m/[^acgt]/;

        $self->{'_seq_mutated'} = $seq;

        # unify the look of sequence strings and cache the information
        $self->{'_mut_string'} = lc $seq->seq; # lower case
        $self->{'_mut_string'} =~ s/u/t/; # simplyfy our life; modules should deal with the change anyway


        $self->reset_sequence_counter;
    }
    #set returned sequence to be the last mutated string
    $self->{'_seq'}->seq($self->{'_mut_string'});
    return $self->{'_seq'};
}


=head2 rate

  Title   : rate
  Usage   : $obj->rate($newval)
  Function: Set the transition/transversion rate.
  Returns : value of rate
  Args    : newvalue (optional)

Transition/transversion ratio is an observed attribute of an sequence
comparison. We are dealing here with the transition/transversion rate
that we set for our model of sequence evolution.

Note that we are using standard nucleotide alphabet and that there can
there is only one transition versus two possible transversions. Rate 2
is needed to have an observed transition/transversion ratio of 1.

=cut

sub rate{
   my $self = shift;
   if (@_) {
       $self->{'_rate'} = shift @_;
       $self->_init_mutation_engine;
   }
   return $self->{'_rate'} || 1;
}

=head2 next_seq

  Title   : next_seq
  Usage   : $obj->next_seq
  Function: Evolve the reference sequence to desired level
  Returns : A new sequence object mutated from the reference sequence
  Args    : -

=cut

sub next_seq {
    my $self = shift;
    $self->{'_mut_string'} = $self->{'_ori_string'};
    $self->reset_mutation_counter;

    $self->{'_mutations'} = [];

    while (1) {
        # find the location in the string to change
        my $loc = int (rand length($self->{'_mut_string'})) + 1;

        $self->mutate($loc); # for modularity

        # stop evolving if any of the limit has been reached
        last if $self->identity && $self->get_alignment_identity <= $self->identity;
        last if $self->pam &&  100*$self->get_mutation_counter/$self->{'_seq_length'} >= $self->pam;
        last if $self->mutation_count &&  $self->get_mutation_counter >= $self->mutation_count;
    }
    $self->_increase_sequence_counter;

    my $type = $self->seq_type;
    return $type->new(-id => $self->seq->id.  "-". $self->get_sequence_counter,
                      -description => $self->seq->description,
                      -seq => $self->{'_mut_string'}
                     )
}

=head2 mutate

  Title   : mutate
  Usage   : $obj->mutate
  Function: mutate the sequence at the given location according to the model
  Returns : true
  Args    : integer, start location of the mutation, required argument

Called from next_seq().

=cut

sub mutate {
    my $self = shift;
    my $loc = shift;
    $self->throw('the first argument is the location of the mutation') unless $loc;

    # nucleotide to change
    my $oldnuc = substr $self->{'_mut_string'}, $loc-1, 1;
    my $newnuc;


    # find the nucleotide it is changed to
    my $choose = rand(100);     # scale is 0-100
    if ($choose < $self->{'_transition'} ) {
        $newnuc =  $self->{'_changes'}->{$oldnuc}[0];
    } elsif ($choose < $self->{'_first_transversion'} ) {
        $newnuc =  $self->{'_changes'}->{$oldnuc}[1];
    } else {
        $newnuc =  $self->{'_changes'}->{$oldnuc}[2];
    }

    # do the change
    substr $self->{'_mut_string'}, $loc-1, 1 , $newnuc;
    $self->_increase_mutation_counter;
    $self->{'_mut_locatableseq'}->seq($self->{'_mut_string'});

    print STDERR "$loc$oldnuc>$newnuc\n" if $self->verbose > 0;

    push @{$self->{'_mutations'}}, "$loc$oldnuc>$newnuc";
}


1;