-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.php
202 lines (190 loc) · 6.71 KB
/
db.php
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
<?php
$dbConfigFileName = "config/config_db.xml";
$allRunAttributes = array(
"Run"=>"Run ID",
"Experiment"=>"Experiment ID",
"BioSample"=>"BioSample ID",
"BioProject"=>"BioProject ID",
"Bases"=>"Number of Bases",
"Bytes"=>"Number of Bytes",
"Country"=>"Country",
"AssayType"=>"Assay Type",
"Biome"=>"Biome",
"IsolationSource"=>"Isolation Source",
"LibraryLayout"=>"Library Layout",
"VariableRegion"=>"Variable Region",
"Instrument"=>"Instrument",
"Year"=>"Year",
"Grp"=>"Disease",
"SubGroup"=>"Disease Sub-group",
"Gender"=>"Gender",
"Age"=>"Age",
"SmokingStatus"=>"Smoking Status",
"Therapeutics"=>"Therapeutics",
"Comorbidity"=>"Comorbidity",
"ProcessedReads"=>"Processed Reads (%)",
);
$allBioProjectAttributes = array(
"BioProject"=>"BioProject ID",
"SRA"=>"SRA Study ID",
// "Grp"=>"Disease",
"SubGroup"=>"Disease(s)",
"IsolationSource"=>"Isolation Source",
"Biome"=>"Biome",
"AssayType"=>"Assay Type",
"Instrument"=>"Instrument",
"LibraryLayout"=>"Library Layout",
"Year"=>"Year",
"ProcessedRuns"=>"Processed Runs",
"VariableRegion"=>"Variable Region",
"PMID"=>"PMID",
"Country"=>"Country",
);
$bacteriaTaxaAttributes = array(
"Taxa" => "Taxa",
"NCBITaxaID" => "NCBI Taxa ID",
"Domain" => "Taxa Domain",
"TaxaLevel" => "Taxa Level",
"BiofilmFormation" => "Biofilm Formation",
"BiofilmFormationEvidence" => "Biofilm Formation Evidence",
"GramStain" => "Gram Stain",
"GramStainEvidence" => "Gram Stain Evidence",
"SporeFormation" => "Spore Formation",
"SporeFormationEvidence" => "Spore Formation Evidence",
"Aerophilicity" => "Aerophilicity",
"AerophilicityEvidence" => "Aerophilicity Evidence",
"GenomeSize" => "Genome Size",
"GenomeSizeEvidence" => "Genome Size Evidence",
"CodingGenes" => "Coding Genes",
"CodingGenesEvidence" => "Coding Genes Evidence",
"AntimicrobialResistance" => "Antimicrobial Resistance",
"AntimicrobialResistanceEvidence" => "Antimicrobial Resistance Evidence",
"AntimicrobialSensitivity" => "Antimicrobial Sensitivity",
"AntimicrobialSensitivityEvidence" => "Antimicrobial Sensitivity Evidence",
"Shape" => "Shape",
"ShapeEvidence" => "Shape Evidence",
);
$virusTaxaAttributes = array(
"Taxa" => "Taxa",
"NCBITaxaID" => "NCBI Taxa ID",
"Domain" => "Taxa Domain",
"TaxaLevel" => "Taxa Level",
"Capsid" => "Capsid",
"Envelop" => "Envelop",
"Virion" => "Virion",
"GeneticMaterial" => "Genetic Material",
"Host" => "Host",
"Pathogenic" => "Pathogenic",
"InfectsTheLungs" => "Infects the lungs",
);
$eukaryotaTaxaAttributes = array(
"Taxa" => "Taxa",
"NCBITaxaID" => "NCBI Taxa ID",
"Domain" => "Taxa Domain",
"TaxaLevel" => "Taxa Level",
"BiofilmFormation" => "Biofilm Formation",
"BiofilmFormationEvidence" => "Biofilm Formation Evidence",
"SporeFormation" => "Spore Formation",
"SporeFormationEvidence" => "Spore Formation Evidence",
"Ploidy" => "Ploidy",
"Mycelium" => "Mycelium",
"Host" => "Host",
"Pathogenic" => "Pathogenic",
"InfectsTheLungs" => "Infects the lungs",
);
$archaeaTaxaAttributes = array(
"Taxa" => "Taxa",
"NCBITaxaID" => "NCBI Taxa ID",
"Domain" => "Taxa Domain",
"TaxaLevel" => "Taxa Level",
"GramStain" => "Gram Stain",
"GramStainEvidence" => "Gram Stain Evidence",
"SporeFormation" => "Spore Formation",
"SporeFormationEvidence" => "Spore Formation Evidence",
"Aerophilicity" => "Aerophilicity",
"AerophilicityEvidence" => "Aerophilicity Evidence",
"GenomeSize" => "Genome Size",
"GenomeSizeEvidence" => "Genome Size Evidence",
"CodingGenes" => "Coding Genes",
"CodingGenesEvidence" => "Coding Genes Evidence",
"AntimicrobialSensitivity" => "Antimicrobial Sensitivity",
"AntimicrobialSensitivityEvidence" => "Antimicrobial Sensitivity Evidence",
"Shape" => "Shape",
"ShapeEvidence" => "Shape Evidence",
);
$viewAttributes = array(
"run.Run",
"run.BioProject",
"disease.Grp",
"run.SubGroup",
"run.Biome",
"run.Instrument",
"run.AssayType",
"run.LibraryLayout",
"run.VariableRegion",
"run.ProcessedReads",
"run.Country",
"run.Year",
);
$viewBioProjectAttributes = array(
"BioProject",
"Grp",
"SubGroup",
"ProcessedRuns",
"Biome",
"AssayType",
"LibraryLayout",
);
$defaultSortAttribute = "run.Run";
function getDBParams() {
global $dbConfigFileName;
$xmlData = simplexml_load_file($dbConfigFileName);
$server = $xmlData->server;
$uname = $xmlData->uname;
$pass = $xmlData->pass;
$dbname = $xmlData->dbname;
return array("server"=>$server, "uname"=>$uname, "pass"=>$pass, "dbname"=>$dbname);
}
function connect() {
$dbParams = getDBParams();
// $conn = new mysqli($server, $uname, $pass, $dbname);
$conn = new mysqli($dbParams["server"], $dbParams["uname"], $dbParams["pass"], $dbParams["dbname"]);
return $conn;
}
function closeConnection($conn) {
$conn->close();
}
function execute_and_fetch_assoc($stmt, $types = false, $params = false) {
if (!$stmt->execute()) {
return false;
}
$stmt->store_result();
// get column names
$metadata = $stmt->result_metadata();
$fields = $metadata->fetch_fields();
$results = [];
$ref_results = [];
foreach($fields as $field){
$results[$field->name]=null;
$ref_results[]=&$results[$field->name];
}
call_user_func_array(array($stmt, 'bind_result'), $ref_results);
$data = array();
$i=0;
while ($stmt->fetch()) {
$c = 0;
$new_res = array();
foreach($results as $f => $v) {
$new_res[$f] = $v;
$c++;
}
// echo implode(",", $new_res);
array_push($data, $new_res);
}
// echo count($data);
// foreach($data as $d)
// echo implode(",", $d)."<br/>";
$stmt->free_result();
return $data;
}
?>