-
Notifications
You must be signed in to change notification settings - Fork 5
/
pharmgkb_stage2.pl
executable file
·136 lines (132 loc) · 2.74 KB
/
pharmgkb_stage2.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/usr/bin/perl
=head1 USAGE
echo '
CREATE DATABASE `pharmgkb` DEFAULT CHARACTER SET ASCII COLLATE ascii_general_ci;
' | mysql -uroot -p
(
set -e
set -o pipefail
echo "
DROP TABLE IF EXISTS pharmgkb.pharmgkb;
CREATE TABLE pharmgkb.pharmgkb (
chrom char(5),
pos int(10),
rsid char(16),
genotype char(3),
gene varchar(32),
amino_acid_change varchar(12),
pubmed_id varchar(64),
webresource varchar(255),
name char(48),
evidence text,
annotation text,
genes text,
drugs text,
drugclasses text,
diseases text,
unique(rsid,genotype,gene,amino_acid_change,annotation(177)),
index(rsid),
index(gene,amino_acid_change)
);
" | mysql -uroot -p
cat ~/Variant_annotation_filtered_allele_flipped{,_errs}.txt | ./pharmgkb_stage2.pl > ~/pharmgkb_import.tmp
echo "
DELETE FROM pharmgkb;
LOAD DATA LOCAL INFILE '~/pharmgkb_import.tmp'
INTO TABLE pharmgkb
FIELDS TERMINATED BY '\t'
LINES TERMINATED BY '\n';
" | mysql -uupdater -p pharmgkb
)
=cut
while (<>)
{
chomp;
my @F = split ("\t");
if ($F[0] =~ /^chr[XY\d]+:\d+/)
{
unshift @F, "", "";
}
if ($F[2] =~ /^(chr[XY\d]+):(\d+)(?: \((rs\d+)\))?/)
{
my $chr = $1;
my $pos = $2;
my $rsid = $3;
my ($pubmedid) = $F[4] =~ /PubMed ID:([\d,]+)/;
my ($webresource) = $F[4] =~ /Web Resource:(\S+)/;
my $genotype = "";
my @gene = ();
my @amino_acid_change = ();
if ($F[0] =~ /^([ACGT])(\s.*)?$/)
{
$genotype = $1;
if ($F[3] =~ /(\w+):\s*([a-z]{3}\d+[a-z]{3})/i)
{
push @gene, $1;
push @amino_acid_change, $2;
}
else
{
push @gene, "";
push @amino_acid_change, "";
}
}
elsif ($F[0] =~ /^([a-z]{3}\d+[a-z]{3})$/i)
{
push @gene, "";
push @amino_acid_change, $1;
if ($F[3] =~ /(\w+):\s*\Q$amino_acid_change\E/)
{
$gene[-1] = $1;
}
}
else
{
while ($F[3] =~ m{\b(\w+):\s*
((([a-z]{3}\d+[a-z]{3}|
\d+[a-z]{3}>[a-z]{3}|
[A-Z]\d+[A-Z]|
\d+[A-Z][>\/]?[A-Z]
)
([,;\s]+|$)
)+)}xig)
{
my $gene = $1;
for (split /[,;\s]/, $2)
{
if (/^[a-z]{3}\d+[a-z]{3}$/i ||
/^\d+[a-z]{3}>[a-z]{3}$/i ||
(/^([A-Z])\d+([A-Z])$/i && "$1$2" =~ /[^ACGT]/i) ||
(/^\d+([A-Z])[>\/]?([A-Z])$/i && "$1$2" =~ /[^ACGT]/i)
)
{
push @amino_acid_change, $_;
push @gene, $gene;
}
}
}
if (!@gene)
{
warn "skip: $_\n" if $ENV{'DEBUG'};
next;
}
}
while (@gene)
{
my $gene = shift @gene;
my $aa = shift @amino_acid_change;
print (join ("\t",
$chr, $pos, $rsid, $genotype, $gene, $aa,
$pubmedid, $webresource, @F[3..8]),
"\n");
}
}
elsif (/^\s*(\#.*|)$/ || /^(Amino Acid Records|Nucleotide Records)/)
{
;
}
else
{
print STDERR "skip: $_\n" if $ENV{DEBUG};
}
}