forked from bioinfo-ut/PlasmidSeeker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
make_mutations.pl
53 lines (40 loc) · 839 Bytes
/
make_mutations.pl
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
# For making random mutations to plasmid fna files
# USAGE: make_mutations.pl [plasmid fna] [mutations number]
use warnings;
use strict;
open (FILE,"<",$ARGV[0]);
my $read;
my $char;
my $flag = 0;
my $count;
my @nucl = ("A","C","G","T");
my @plasmid = <FILE>;
my $head = shift @plasmid;
my $fna;
foreach(@plasmid) {
chomp;
$fna .= $_;
}
my $total = length($fna);
close FILE;
#Mutation locations
my %mutations;
for(my $i=1;$i<=$ARGV[1];$i++) {
$mutations{int(rand($total))} = 1;
}
foreach(keys %mutations) {
print STDERR "mut: $_, ";
my $nc = substr($fna,$_,1,);
my $new = $nucl[rand @nucl];
while($nc eq $new) { $new = $nucl[rand @nucl]; }
print STDERR "$nc -> $new\n";
substr($fna,$_,1,$new);
}
my $i = 0;
print $head;
while($i<$total) {
my $line = substr($fna,$i,80);
print "$line\n";
$i+=80;
}
#print "$fna\n";