-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMerge_CPD_DB.pl
129 lines (111 loc) · 2.65 KB
/
Merge_CPD_DB.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
#use warnings;
use Sort::Naturally 'nsort';
#die;
#input in this order
#pathbank, pubchem, hmdb, kegg, biocyc, chebi
$inPB = "PATHBANK_CPD_DB.txt";
$inPC = "PUBCHEM_CPD_DB.txt";
$inHM = "HMDB_CPD_DB.txt";
$inKG = "KEGG_CPD_DB.txt";
$inBC = "BIOCYC_CPD_DB.txt";
$inCH = "CHEBI_CPD_DB.txt";
open(INPB, $inPB)||die;
open(INPC, $inPC)||die;
open(INHM, $inHM)||die;
open(INKG, $inKG)||die;
open(INBC, $inBC)||die;
open(INCH, $inCH)||die;
print "INPUT PATHBANK\n";
$on=0;
while(<INPB>){
if($_!~/\w/){next;}
if($_ =~ /CPD\tFORMULA/i){next;}
$_=uc($_);
$_=~s/[\n\r]+//;
@stuff=split("\t", $_);
$cpd=$stuff[0];
for my $i (0..12){ $HoA{$cpd}[$i] = $stuff[$i];}
# if($on%100000==0){last;}
#$on++;
}
$time=localtime;
print "INPUT HMDB on $on time $time\n";
while(<INHM>){
if($_!~/\w/){next;}
if($_ =~ /^CPD\t/i){next;}
$_=uc($_);
$_=~s/[\n\r]+//;
@stuff=split("\t", $_);
$cpd=$stuff[0];
for my $i (0..12){ $HoA{$cpd}[$i] = $stuff[$i];}
# if($on%100000==0){last;}
#$on++;
}
$time=localtime;
print "INPUT PUBCHEM on $on time $time\n";
while(<INPC>){
if($_!~/\w/){next;}
if($_ =~ /^CPD\t/i){next;}
$_=uc($_);
$_=~s/[\n\r]+//;
@stuff=split("\t", $_);
$cpd=$stuff[0];
for my $i (0..12){ $HoA{$cpd}[$i] = $stuff[$i];}
#can use below to fill in missing info
#if(exists($HoA{$cpd})){
# if($HoA{$cpd}[1] eq $stuff[1] && $stuff[1]=~/\w/){
# for my $i (0..12){
# if($HoA{$cpd}[$i]!~/\w/ && $stuff[$i]=~/\w/){ $HoA{$cpd}[$i]=$stuff[$i];}
#} } }
#else{ for my $i (0..12){ $HoA{$cpd}[$i] = $stuff[$i]; }}
# if($on%100000==0){last;}
#$on++;
}
$time=localtime;
print "INPUT KEGG on $on time $time\n";
while(<INKG>){
if($_!~/\w/){next;}
if($_ =~ /^CPD\t/i){next;}
$_=uc($_);
$_=~s/[\n\r]+//;
@stuff=split("\t", $_);
$cpd=$stuff[0];
for my $i (0..12){ $HoA{$cpd}[$i] = $stuff[$i];}
# if($on%100000==0){last;}
#$on++;
}
$time=localtime;
print "INPUT BIOCYC on $on time $time\n";
while(<INBC>){
if($_!~/\w/){next;}
if($_ =~ /^CPD\t/i){next;}
$_=uc($_);
$_=~s/[\n\r]+//;
@stuff=split("\t", $_);
$cpd=$stuff[0];
for my $i (0..12){ $HoA{$cpd}[$i] = $stuff[$i];}
# if($on%100000==0){last;}
#$on++;
}
$time=localtime;
print "INPUT CHEBI on $on time $time\n";
while(<INCH>){
if($_!~/\w/){next;}
if($_ =~ /^CPD\t/i){next;}
$_=uc($_);
$_=~s/[\n\r]+//;
@stuff=split("\t", $_);
$cpd=$stuff[0];
for my $i (0..12){ $HoA{$cpd}[$i] = $stuff[$i];}
# if($on%100000==0){last;}
#$on++;
}
open(OUTPUT, ">", "MERGED_CPD_DB.txt")||die;
print OUTPUT "cpd\tsrc\tform\tmass\tchar\ttcdb\tname\tkegg\tchebi\thmdb\tpubch\tinchi\tbioc\n";
foreach $cpd (sort(keys %HoA)){
print OUTPUT "$cpd\t";
foreach $i (1 .. 12){
print OUTPUT "$HoA{$cpd}[$i]\t";
}
print OUTPUT "\n";
}