-
Notifications
You must be signed in to change notification settings - Fork 0
/
viewAllPromotersByGenes.php
executable file
·204 lines (174 loc) · 8.42 KB
/
viewAllPromotersByGenes.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
203
204
<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
<?php
$TITLE = "Soybean Genomic Variations Explorer";
include '../config.php';
include './php/pdoResultFilter.php';
?>
<!-- Get and process the variables -->
<?php
$gene_name_1 = $_GET['gene_name_1'];
$upstream_length_1 = $_GET['upstream_length_1'];
if (is_string($gene_name_1)) {
$temp_gene_arr = preg_split("/[;, \n]+/", $gene_name_1);
$gene_arr = array();
for ($i = 0; $i < count($temp_gene_arr); $i++) {
if (!empty(trim($temp_gene_arr[$i]))) {
array_push($gene_arr, trim($temp_gene_arr[$i]));
}
}
} elseif (is_array($gene_name_1)) {
$temp_gene_arr = $gene_name_1;
$gene_arr = array();
for ($i = 0; $i < count($temp_gene_arr); $i++) {
if (!empty(trim($temp_gene_arr[$i]))) {
array_push($gene_arr, trim($temp_gene_arr[$i]));
}
}
}
if (is_string($upstream_length_1)) {
$upstream_length = intval(trim($upstream_length_1));
} elseif (is_int($upstream_length_1)) {
$upstream_length = $upstream_length_1;
} elseif (is_float($upstream_length_1)) {
$upstream_length = intval($upstream_length_1);
} else {
$upstream_length = 2000;
}
?>
<!-- Back button -->
<a href="/SoybeanGenVarX/"><button> < Back </button></a>
<br />
<br />
<!-- Query gene regions from database -->
<?php
$query_str = "SELECT * FROM mViz_Soybean_GFF";
$query_str = $query_str . " WHERE (Name IN ('";
for ($i = 0; $i < count($gene_arr); $i++) {
if ($i < (count($gene_arr)-1)){
$query_str = $query_str . $gene_arr[$i] . "', '";
} else {
$query_str = $query_str . $gene_arr[$i];
}
}
$query_str = $query_str . "'));";
$stmt = $PDO->prepare($query_str);
$stmt->execute();
$result = $stmt->fetchAll();
$gene_result_arr = pdoResultFilter($result);
?>
<!-- Calculate promoter start and end -->
<?php
for ($i = 0; $i < count($gene_result_arr); $i++) {
if ($gene_result_arr[$i]['Strand'] == '+') {
$gene_result_arr[$i]['Promoter_End'] = $gene_result_arr[$i]['Start']-1;
$gene_result_arr[$i]['Promoter_Start'] = ((($gene_result_arr[$i]['Promoter_End']-$upstream_length) > 0) ? ($gene_result_arr[$i]['Promoter_End']-$upstream_length) : 1);
} elseif ($gene_result_arr[$i]['Strand'] == '-') {
$gene_result_arr[$i]['Promoter_Start'] = $gene_result_arr[$i]['End']+1;
$gene_result_arr[$i]['Promoter_End'] = $gene_result_arr[$i]['Promoter_Start'] + $upstream_length;
}
}
?>
<!-- Get binding TFs -->
<?php
for ($i = 0; $i < count($gene_result_arr); $i++) {
// Display gene, gene region, and promoter region
echo "<p><b>Queried Gene: </b>" . $gene_result_arr[$i]['Name'] . " (" . $gene_result_arr[$i]['Chromosome'] . ": " . $gene_result_arr[$i]['Start'] . " - " . $gene_result_arr[$i]['End'] . ") (" . $gene_result_arr[$i]['Strand'] . ")</p>";
echo "<p><b>Promoter Region: </b>" . $gene_result_arr[$i]['Promoter_Start'] . " - " . $gene_result_arr[$i]['Promoter_End'] . "</p>";
echo "<br />";
// Get binding TFs
// $query_str = "
// SELECT M.Gene, MS.Chromosome, MS.Start, MS.End, MS.Strand, MS.Name AS Binding_TF, TF.TF_Family,
// MS.Sequence AS Gene_Binding_Sequence, GROUP_CONCAT(DISTINCT GD.Position ORDER BY GD.Position ASC SEPARATOR ', ') AS Variant_Position FROM (
// SELECT Motif, Gene FROM mViz_Soybean_Motif WHERE Gene = '" . $gene_result_arr[$i]['Name'] . "'
// ) AS M
// INNER JOIN (
// SELECT Chromosome, Start, End, Strand, Name, Sequence FROM mViz_Soybean_" . $gene_result_arr[$i]['Chromosome'] . "_Motif_Sequence
// WHERE (Chromosome = '" . $gene_result_arr[$i]['Chromosome'] . "')
// AND (
// (Start BETWEEN " . $gene_result_arr[$i]['Promoter_Start'] . " AND " . $gene_result_arr[$i]['Promoter_End'] . " )
// OR
// (End BETWEEN " . $gene_result_arr[$i]['Promoter_Start'] . " AND " . $gene_result_arr[$i]['Promoter_End'] . ")
// )
// ) AS MS
// ON M.Motif = MS.Name
// LEFT JOIN mViz_Soybean_TF AS TF
// ON MS.Name = TF.TF
// LEFT JOIN (
// SELECT DISTINCT Position FROM mViz_Soy1066_" . $gene_result_arr[$i]['Chromosome'] . "_genotype_data
// WHERE (Position BETWEEN " . $gene_result_arr[$i]['Promoter_Start'] . " AND " . $gene_result_arr[$i]['Promoter_End'] . ")
// ) AS GD
// ON (GD.Position BETWEEN MS.Start AND MS.End)
// GROUP BY M.Gene, MS.Chromosome, MS.Start, MS.End, MS.Strand, Binding_TF, TF.TF_Family, Gene_Binding_Sequence
// ORDER BY Start, End;
// ";
// Get binding TFs (Optimized MySQL query string)
$query_str = "
SELECT M.Gene, MS.Chromosome, MS.Start, MS.End, MS.Strand, MS.Name AS Binding_TF, TF.TF_Family,
MS.Sequence AS Gene_Binding_Sequence, GROUP_CONCAT(DISTINCT GD.Position ORDER BY GD.Position ASC SEPARATOR ', ') AS Variant_Position
FROM mViz_Soybean_Motif AS M
INNER JOIN mViz_Soybean_" . $gene_result_arr[$i]['Chromosome'] . "_Motif_Sequence AS MS
ON M.Motif = MS.Name
LEFT JOIN mViz_Soybean_TF AS TF
ON MS.Name = TF.TF
LEFT JOIN (
SELECT DISTINCT Position
FROM mViz_Soy1066_" . $gene_result_arr[$i]['Chromosome'] . "_genotype_data
WHERE (Position BETWEEN " . $gene_result_arr[$i]['Promoter_Start'] . " AND " . $gene_result_arr[$i]['Promoter_End'] . ")
) AS GD
ON (GD.Position BETWEEN MS.Start AND MS.End)
WHERE (M.Gene = '" . $gene_result_arr[$i]['Name'] . "') AND (MS.Chromosome = '" . $gene_result_arr[$i]['Chromosome'] . "')
AND (
(MS.Start BETWEEN " . $gene_result_arr[$i]['Promoter_Start'] . " AND " . $gene_result_arr[$i]['Promoter_End'] . " )
OR
(MS.End BETWEEN " . $gene_result_arr[$i]['Promoter_Start'] . " AND " . $gene_result_arr[$i]['Promoter_End'] . ")
)
GROUP BY M.Gene, MS.Chromosome, MS.Start, MS.End, MS.Strand, Binding_TF, TF.TF_Family, Gene_Binding_Sequence
ORDER BY Start, End;
";
$stmt = $PDO->prepare($query_str);
$stmt->execute();
$result = $stmt->fetchAll();
$motif_result_arr = pdoResultFilter($result);
if (isset($motif_result_arr) && !empty($motif_result_arr)){
echo "<div style='width:auto; height:auto; overflow:scroll; max-height:1000px;'>";
echo "<table style='text-align:center; border:3px solid #000;'>";
// Table header
echo "<tr>";
foreach ($motif_result_arr[0] as $key => $value) {
echo "<th style=\"border:1px solid black; min-width:80px;\">" . $key . "</th>";
}
echo "</tr>";
// Table body
for ($j = 0; $j < count($motif_result_arr); $j++) {
$tr_bgcolor = ($j % 2 ? "#FFFFFF" : "#DDFFDD");
echo "<tr bgcolor=\"" . $tr_bgcolor . "\">";
foreach ($motif_result_arr[$j] as $key => $value) {
if ($key == "Binding_TF") {
echo "<td style=\"border:1px solid black; min-width:80px;\"><a href=\"javascript:void(0);\" onclick=\"getMotifWeblogo('" . $value . "', '" . $gene_result_arr[$i]['Name'] . "', '" . $gene_result_arr[$i]['Chromosome'] . "', '" . $motif_result_arr[$j]['Start'] . "', '" . $motif_result_arr[$j]['End'] . "', '" . $motif_result_arr[$j]['Gene_Binding_Sequence'] . "')\">" . $value . "</a></td>";
} else {
echo "<td style=\"border:1px solid black; min-width:80px;\">" . $value . "</td>";
}
}
echo "</tr>";
}
echo "</table>";
echo "</div>";
echo "<br />";
// Div tags for selected motif, weblogo, and motif sequence table
echo "<div id=\"" . $gene_result_arr[$i]['Name'] . "_b\" style='width:auto; height:auto; overflow:visible; max-height:1000px;'></div>";
echo "<div id=\"" . $gene_result_arr[$i]['Name'] . "_weblogo\" style='width:auto; height:auto; overflow:visible; max-height:1000px;'></div>";
echo "<div id=\"" . $gene_result_arr[$i]['Name'] . "_detail_table\" style='width:auto; height:auto; overflow:visible; max-height:1000px;'></div>";
echo "<br />";
echo "<br />";
} else {
// Display no motif message if none is found
echo "<div style='width:auto; height:auto; overflow:visible; max-height:1000px;'>";
echo "No binding TF found in our database!!!";
echo "</div>";
echo "<br />";
echo "<br />";
}
}
?>
<script type="text/javascript" language="javascript" src="./js/getMotifWeblogo.js"></script>
<?php include '../footer.php'; ?>