5 bp_mutate.pl - randomly mutagenize a single protein or DNA sequence
9 ./bp_mutate.pl -p 25 -i test.fa -n 5 -f swiss -o muts.swiss
13 ./bp_mutate.pl --percent=25 --input=test.fa --number=5 -output=x.fa
17 Randomly mutagenize a single protein or DNA sequence one or more times.
18 Specify percentage mutated and number of resulting mutant sequences.
19 Print mutagenized sequences to STDOUT or write to an output file.
22 -p|--percent Percent mutagenized
23 -n|--number Number of mutant sequences created
24 -o|--output Output file (optional)
25 -f|--format Output format (default: fasta)
30 User feedback is an integral part of the evolution of this and other
31 Bioperl scripts. Send your comments and suggestions to the Bioperl
32 mailing list. Your participation is much appreciated.
34 bioperl-l@bioperl.org - General discussion
35 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
39 Report bugs to the Bioperl bug tracking system to help us keep track
40 of the bugs and their resolution. Bug reports can be submitted via the
43 https://github.com/bioperl/bioperl-live/issues
47 Brian Osborne, bosborne at alum.mit.edu
56 my ( $help, $in_file, $percent, $out_file, $number );
58 my @dna = qw(a g c t);
59 my @amino = qw(a c d e f g h i k l m n p q r s t v w y);
63 "p|percent:i" => \
$percent,
64 "n|number:i" => \
$number,
65 "o|output:s" => \
$out_file,
66 "f|format:s" => \
$format,
67 "i|input:s" => \
$in_file
70 usage
() if ( $help || !$percent || !$in_file || !$number || $percent > 100 );
72 # Seed the random number generator. "time|$$" combines the
73 # current time with the current process id
76 my $seqio = Bio
::SeqIO
->new( -file
=> $in_file );
77 my $seqobj = $seqio->next_seq;
78 my $num_mut = percent_to_num
($percent);
81 # don't keep a mutant that's already been made
82 while ( $number > $#seq_arr + 1 ) {
83 my $mut_seq = mutate_all
( $seqobj, $num_mut );
84 push @seq_arr, $mut_seq unless ( grep /$mut_seq/, @seq_arr );
87 foreach my $mut_seq (@seq_arr) {
88 my $name = $seqobj->display_id . "-${percent}_percent-$number";
89 my $outseq = Bio
::Seq
->new(
92 -desc
=> $seqobj->desc
94 my %args = ( -format
=> $format );
95 $args{-file
} = ">>$out_file" if $out_file;
96 my $seqio = Bio
::SeqIO
->new(%args);
97 $seqio->write_seq($outseq);
101 # mutagenize the sequence, one-by-one
103 my ( $seq_obj, $num ) = @_;
104 my $type = $seq_obj->alphabet;
105 my $str = $seq_obj->seq;
107 # store the mutagenized positions in $positions
109 for ( my $i = 0 ; $i < $num_mut ; ++$i ) {
110 ( $str, $positions ) = mutate_one
( $str, $type, $positions );
115 # mutagenize one position
117 my ( $str, $type, $positions ) = @_;
118 my ( $position, $new_char );
120 # pick a random position in the sequence, checking
121 # that the position isn't already mutagenized
123 $position = random_position
($str);
124 } until ( $positions !~ /\b$position\b/ );
125 $positions .= "$position ";
126 my $current_char = substr( $str, $position, 1 );
128 # pick a random char that's not the existing char
130 $new_char = random_char
($type);
131 } until ( $new_char ne $current_char );
132 substr( $str, $position, 1, $new_char );
133 ( $str, $positions );
136 # randomly select a position in the sequence
137 sub random_position
{
139 int( rand( length($string) ) );
142 # randomly select one of the chars depending on alphabet
146 ?
return $amino[ rand @amino ]
147 : return $dna[ rand @dna ];
152 int( $percent / 100 * length( $seqobj->seq ) );
156 exec( 'perldoc', $0 );