File: make_mutations.pl

package info (click to toggle)
plasmidseeker 1.3%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid
  • size: 248 kB
  • sloc: perl: 520; sh: 41; makefile: 12
file content (53 lines) | stat: -rw-r--r-- 839 bytes parent folder | download | duplicates (3)
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
# 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";