-
Notifications
You must be signed in to change notification settings - Fork 1
/
keywordSearchQuery.php
executable file
·184 lines (104 loc) · 5.34 KB
/
keywordSearchQuery.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
<?php
// Start the session
ini_set('display_errors', 1);
error_reporting(1);
require("config.php");
$namer= $_POST['namer'];
$keyword= $_POST['keyword'];
$speciesName= $_POST['species'];
$minLength= $_POST['minLength'];
$maxLength= $_POST['maxLength'];
$sstart= $_POST['sstart'];
$ssend= $_POST['ssend'];
$subloc= $_POST['subloc'];
$outfile = "tmp/".$namer."_KeywordQuery.txt";
$accessionsFound = array();
$link = mysqli_connect('localhost:3306', DB_USER, DB_PASSWORD) or die('Could not connect to mysql');
$link->set_charset("utf8");
mysqli_select_db($link,'trustdb') or die('Could not select database');
$query = 'SELECT * FROM oldNewPuccinia WHERE oldAccesion LIKE "%'.$keyword.'%"';
$result = mysqli_query($link,$query) or die('Query failed: ' . mysqli_error($link));
while($queryResult = mysqli_fetch_array($result, MYSQLI_ASSOC)){
if(!in_array($queryResult['newAccesion'],$accessionsFound)){
array_push($accessionsFound,$queryResult['newAccesion']);
}
}
mysqli_free_result($result);
$query = 'SELECT * FROM proteinDescription WHERE locus_tag LIKE "%'.$keyword.'%" OR accession LIKE "%'.$keyword.'%" OR description LIKE "%'.$keyword.'%"';
$result = mysqli_query($link,$query) or die('Query failed: ' . mysqli_error($link));
while ($queryResult = mysqli_fetch_array($result, MYSQLI_ASSOC)){
if(!in_array($queryResult['accession'],$accessionsFound)){
array_push($accessionsFound,$queryResult['accession']);
}
}
mysqli_free_result($result);
###HPI
$query = 'SELECT * FROM HPIinterolog WHERE hostProtein LIKE "%'.$keyword.'%"';
$result = mysqli_query($link,$query) or die('Query failed: ' . mysqli_error($link));
while ($queryResult = mysqli_fetch_array($result, MYSQLI_ASSOC)){
if(!in_array($queryResult['pathogenProtein'],$accessionsFound)){
array_push($accessionsFound,$queryResult['pathogenProtein']);
}
}
mysqli_free_result($result);
### Effectors
$query = 'SELECT * FROM effectors WHERE description LIKE "%'.$keyword.'%" OR accessions LIKE "%'.$keyword.'%"';
$result = mysqli_query($link,$query) or die('Query failed: ' . mysqli_error($link));
while ($queryResult = mysqli_fetch_array($result, MYSQLI_ASSOC)){
if(!in_array($queryResult['locusAlt'],$accessionsFound)){
array_push($accessionsFound,$queryResult['locusAlt']);
}
}
mysqli_free_result($result);
###Localization
$query = 'SELECT * FROM localizations WHERE location LIKE "%'.$keyword.'%" OR location="'.trim($subloc).'"';
if($subloc=="ALL"){
$query = 'SELECT * FROM localizations WHERE location LIKE "%'.$keyword.'%"';
}
$result = mysqli_query($link,$query) or die('Query failed: ' . mysqli_error($link));
while ($queryResult = mysqli_fetch_array($result, MYSQLI_ASSOC)){
if(!in_array($queryResult['accession'],$accessionsFound)){
array_push($accessionsFound,$queryResult['accession']);
}
}
mysqli_free_result($result);
# GO & Domain
$query = 'SELECT * FROM ipscan_go WHERE signatureAccesion LIKE "%'.$keyword.'%" OR signatureDescription LIKE "%'.$keyword.'%" OR interproAcc LIKE "%'.$keyword.'%" OR interproDesc LIKE "%'.$keyword.'%"';
$result = mysqli_query($link,$query) or die('Query failed: ' . mysqli_error($link));
while ($queryResult = mysqli_fetch_array($result, MYSQLI_ASSOC)){
if(!in_array($queryResult['accession'],$accessionsFound)){
array_push($accessionsFound,$queryResult['accession']);
}
}
mysqli_free_result($result);
# Final Description Query & SubLoc
$query = 'SELECT * FROM proteinDescription NATURAL JOIN localizations WHERE accession IN ("'.implode('","', $accessionsFound).'") AND length BETWEEN '.$minLength.' AND '.$maxLength.' AND sstart >='.$sstart.' AND send <='.$ssend.' AND location="'.trim($subloc).'" AND species="'.$speciesName.'"';
if($subloc=="ALL"){
$query = 'SELECT * FROM proteinDescription WHERE accession IN ("'.implode('","', $accessionsFound).'") AND length BETWEEN '.$minLength.' AND '.$maxLength.' AND sstart >='.$sstart.' AND send <='.$ssend.' AND species="'.$speciesName.'"';
if($speciesName=="ALL"){
$query ='SELECT * FROM proteinDescription WHERE accession IN ("'.implode('","', $accessionsFound).'") AND length BETWEEN '.$minLength.' AND '.$maxLength.' AND sstart >='.$sstart.' AND send <='.$ssend;
}
} elseif($speciesName=="ALL"){
$query ='SELECT * FROM proteinDescription NATURAL JOIN localizations WHERE accession IN ("'.implode('","', $accessionsFound).'") AND length BETWEEN '.$minLength.' AND '.$maxLength.' AND sstart >='.$sstart.' AND send <='.$ssend.' AND location="'.trim($subloc).'" ';
}
$tabularFile = fopen($outfile, "w") or die("Unable to open file!");
$result = mysqli_query($link,$query) or die('Query failed: ' . mysqli_error($link));
while ($queryResult = mysqli_fetch_array($result, MYSQLI_ASSOC)){
$species = $queryResult['species'];
$replicon = $queryResult['chromosome'];
$repliconAccesion = $queryResult['accesionNCBI'];
$accession = $queryResult['accession'];
$coordinates = $queryResult['sstart']."-".$queryResult['send'];
$length = $queryResult['length'];
$description = $queryResult['description'];
$genename = $queryResult['geneid'];
$locus_new = $queryResult['locus_tag'];
$line = $species."\t". $replicon."\t". $repliconAccesion."\t". $accession."\t". $coordinates."\t". $length."\t". $description. "\t".$genename."\t".$locus_new."\t";
fwrite($tabularFile, $line);
fwrite($tabularFile, PHP_EOL);
}
mysqli_free_result($result);
fclose($tabularFile);
mysqli_close($link);
print_r($namer);
?>