-
Notifications
You must be signed in to change notification settings - Fork 1
/
get_random_allele_30.pl
119 lines (106 loc) · 2.61 KB
/
get_random_allele_30.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/usr/bin/perl
use strict;
use warnings;
#quality hash
my %quality = ("!",0,
"\"",1,
"\#",2,
"\$",3,
"%",4,
"&",5,
"\'",6,
"(",7,
")",8,
"*",9,
"+",10,
",",11,
"-",12,
".",13,
"/",14,
"0",15,
"1",16,
"2",17,
"3",18,
"4",19,
"5",20,
"6",21,
"7",22,
"8",23,
"9",24,
":",25,
";",26,
"<",27,
"=",28,
">",29,
"?",30,
"@",31,
"A",32,
"B",33,
"C",34,
"D",35,
"E",36,
"F",37,
"G",38,
"H",39,
"I",40,
"J",41,
"K",42,
);
my $i;
my $count=0;
while (<>) {
$count++;
#print "line", $count, "\n";
chomp;
my @passed =();
my $tmp = "";
my @fields=split(/\t/,$_);
my $depth = $fields[3];
my $ref = $fields[2];
my $bases = $fields[4];
my $quals = $fields[5];
$bases=~s/[\+\-][1-9]{1,}[ACTGNactgn]{1}//g;
$bases=~s/\^.//g;
#$bases=~s/\*//g;
$bases=~s/[\[\]><\$]//g;
$bases=~s/[\+\-][1-9]{1,}[ACTGNactgn]{1}//g;
for($i=0;$i<length($quals);$i++)
{
if($quality{substr($quals,$i,1)})
{
if(($quality{substr($quals,$i,1)}>=30) && (substr($bases,$i,1) ne "*")) ####Checar que la calidad
{
push(@passed,substr($bases,$i,1));
}
}else{ print next;} #print "bad qualities $quals\n";
}
if(scalar(@passed) == 0)
{
next;
}
if(scalar(@passed)==1)
{
if($passed[0] eq "." || $passed[0] eq ",")
{
print "$_\t $ref\n";
}
else
{
print "$_\t $passed[0]\n";
}
}
else
{
my $random_allele =$passed[int(rand(scalar(@passed)-1))];
# print "random allele = $random_allele \n";
if($random_allele eq "." || $random_allele eq ",")
{
print "$_\t $ref\n";
}
else
{
print "$_\t $random_allele\n";
}
}
}
exit;