-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgen_errors.pl
More file actions
executable file
·41 lines (30 loc) · 843 Bytes
/
gen_errors.pl
File metadata and controls
executable file
·41 lines (30 loc) · 843 Bytes
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
#!/usr/bin/perl -w
use strict;
use Bio::SeqIO;
my $error = 0.01;
my $times = $ARGV[1] or die "USAGE: perl gen_errors.pl genome.fas TIMES(replicate X times)\n";
for (my $j = 0; $j < $times; $j++) {
my $seqio_obj = Bio::SeqIO->new(-file => $ARGV[0], -format => "fasta" );
my @nucl = ("A", "C", "G", "T");
while (my $seq_obj = $seqio_obj->next_seq ) {
my $seq = $seq_obj->seq;
my $id = $seq_obj->display_id;
my $freq = 0;
for (my $i = 0; $i <= $seq_obj->length; $i++){
if (rand() <= $error){
$freq = $freq + 1;
}
}
# print "$freq\n";
for (my $i = 1; $i <= $freq; $i++) {
my $mutloc = int(rand($seq_obj->length));
my $ref = substr($seq,$mutloc,1);
my $mut = $ref;
while ($mut eq $ref) {
$mut = $nucl[rand @nucl];
}
substr($seq,$mutloc,1) = $mut;
}
print ">$id\n$seq\n";
}
}