-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathiupac2random.pl
executable file
·55 lines (48 loc) · 1.53 KB
/
iupac2random.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
53
54
55
#!/usr/bin/perl
use lib $ENV{PERL5LIB};
use strict;
use warnings;
my ($infasta)=@ARGV;
my $line;
my @M=("A","C");
my @R=("A","G");
my @W=("A","T");
my @S=("C","G");
my @Y=("C","T");
my @K=("G","T");
my @B=("C","G","T");
my @D=("A","G","T");
my @H=("A","C","T");
my @V=("A","C","G");
#parse input fasta file, looking for ambiguous codes
open(INFASTA, $infasta)||die "can't open input fasta file. $!\n";
open(OUT,">$infasta.randiupac.fasta");
while($line=<INFASTA>)
{
#test if header line
if ($line=~/^>./){print OUT $line;}
else
{
if ($line=~/[MRWSYKBDHV]/)
{
#line contains an ambigous base, so go character by character
my @chars=split("",$line);
foreach(@chars)
{
if ($_=~/[ACGT]/){print OUT "$_";}
elsif ($_=~"M"){print OUT $M[rand @M];}
elsif ($_=~"R"){print OUT $R[rand @R];}
elsif ($_=~"W"){print OUT $W[rand @W];}
elsif ($_=~"S"){print OUT $S[rand @S];}
elsif ($_=~"Y"){print OUT $Y[rand @Y];}
elsif ($_=~"K"){print OUT $K[rand @K];}
elsif ($_=~"B"){print OUT $B[rand @B];}
elsif ($_=~"D"){print OUT $D[rand @D];}
elsif ($_=~"H"){print OUT $H[rand @H];}
elsif ($_=~"V"){print OUT $V[rand @V];}
else {print OUT "$_";}
}
}
else {print OUT $line;}
}
}