-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgene.php
171 lines (122 loc) · 5.68 KB
/
gene.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
<!-- HEADER -->
<?php include_once realpath("header.php");?>
<?php include_once realpath("$root_path/easy_gdb/tools/common_functions.php");?>
<!-- HELP -->
<div class="margin-20">
<a class="float-right" href="help/00_help.php"><i class='fa fa-info' style='font-size:20px;color:#229dff'></i> Help</a>
</div>
<div class="page_container">
<br><br>
<?php
if ($file_database){
$gene_name = trim($_GET["name"]);
$annot_file = $annotations_path."/".trim($_GET["annot"]);
// list($gene_name, $annot_file) = explode("@", trim($_GET["name"]));
if (file_exists("$json_files_path/tools/annotation_links.json")) {
$annot_json_file = file_get_contents("$json_files_path/tools/annotation_links.json");
$annotation_hash = json_decode($annot_json_file, true);
}
$quoted_search = 0;
if (preg_match('/^".+"$/', $name)) {
$quoted_search = 1;
}
$search_input = test_input2($gene_name);
echo "<div class=\"card bg-light\"><div class=\"card-body\">$search_input</div></div><br>\n";
if (!$rm_jb_frame) {
include_once realpath("$easy_gdb_path/jb_frame_file.php");
}
include_once realpath("$easy_gdb_path/annot_desc_file.php");
include_once realpath("$easy_gdb_path/gene_seq.php");
include_once realpath("$easy_gdb_path/tools/common_functions.php");
$all_datasets = get_dir_and_files($annotations_path); // call the function
asort($all_datasets);
$dir_counter = 0;
$data_counter = count($all_datasets);
foreach ($all_datasets as $annot_dataset) {
if (is_dir($annotations_path."/".$annot_dataset)){ // get dirs and print categories
$dir_counter++;
}
}
// CHECK ANNOTATION FILES
if ($dir_counter) {
foreach ($all_datasets as $dirs_and_files) {
if (is_dir($annotations_path."/".$dirs_and_files)){ // get dirs and print categories
$all_dir_datasets = get_dir_and_files($annotations_path."/".$dirs_and_files); // call the function
$dir_name = str_replace("_"," ",$dirs_and_files);
sort($all_dir_datasets);
foreach ($all_dir_datasets as $annot_dataset) {
if ( !preg_match('/\.php$/i', $annot_dataset) && !is_dir($annotations_path.'/'.$dirs_and_files.'/'.$annot_dataset) && !preg_match('/\.json$/i', $annot_dataset) && file_exists( $annotations_path.'/'.$dirs_and_files.'/'.$annot_dataset)) {
$data_set_name = preg_replace('/\.[a-z]{3}$/',"",$annot_dataset);
$data_set_name = str_replace("_"," ",$data_set_name);
}//if preg_match
}//foreach all_dir
}//if is_dir
}// foreach dir
}//if dir_counter
else {
foreach ($all_datasets as $dataset) {
$dataset_name = preg_replace('/\.[a-z]{3}$/',"",$dataset);
$dataset_name = str_replace("_"," ",$dataset_name);
}
}
}
else {
echo "<div class=\"card bg-light\">";
echo "<div id=\"query_gene\" class=\"card-body\">".test_input($_GET["name"])."</div>";
echo "</div>";
$current_version = $max_version;
// Connecting, selecting database
include_once realpath ("$conf_path/database_access.php");
$dbconn = pg_connect(getConnectionString())
or die('Could not connect: ' . pg_last_error());
$gene_name = test_input($_GET["name"]);
// $search_input = $gene_name;
// $gene_name_displayed = $gene_name;
// echo "\n\n<br><br><h1>GENE NAME: $gene_name</h1><br><br>\n\n";
// Performing SQL query
$query = "SELECT * FROM gene FULL OUTER JOIN annotation_version USING(annotation_version_id) FULL OUTER JOIN species USING(species_id) WHERE gene_name='".pg_escape_string($gene_name)."'";
// $query = "SELECT * FROM gene WHERE gene_name='".pg_escape_string($gene_name)."'";
// $query = "SELECT gene_id,gene_version FROM gene join gene_version ON (gene.gene_version_id=gene_version.gene_version_id) WHERE gene_name='".pg_escape_string($gene_name)."'";
$res = pg_query($query) or die("The gene $gene_name was not found in the database. Please, check the spelling carefully or try to find it in the search tool.");
// $res = pg_query($query) or die('Query failed: ' . pg_last_error());
$ori_gene_name = $gene_name;
if (pg_num_rows($res) == 0) {
$gene_name = preg_replace("/$/", ".1", $gene_name);
$query = "SELECT * FROM gene FULL OUTER JOIN annotation_version USING(annotation_version_id) FULL OUTER JOIN species USING(species_id) WHERE gene_name='".pg_escape_string($gene_name)."'";
$res = pg_query($query) or die("The gene $gene_name was not found in the database. Please, check the spelling carefully or try to find it in the search tool.");
if (pg_num_rows($res) == 0) {
echo "\n\n<br><br><h3>The gene $ori_gene_name was not found in the database. Please, check the spelling carefully or try to find it in the search tool.</h3><br><br>\n\n";
}
}
if (pg_num_rows($res) > 0) {
$gene_row = pg_fetch_array($res,0,PGSQL_ASSOC);
if ($gene_row) {
$gene_id = $gene_row["gene_id"];
$species_id= $gene_row["species_id"];
$species_name = $gene_row["species_name"];
$annot_version = $gene_row["annotation_version"];
if (!$rm_jb_frame) {
include_once 'jb_frame.php';
}
include_once 'annot_desc.php';
include_once 'gene_seq.php';
}
}
// Free resultset
// pg_free_result($res);
// Closing connection
pg_close($dbconn);
}
?>
<br>
<br>
</div>
<?php include_once 'footer.php';?>
<script>
var query_gene = "<?php echo $gene_name ?>";
var sps_name = "<?php echo $species_name ?>";
var annot_v = "<?php echo $annot_version ?>";
document.getElementById('query_gene').innerHTML = query_gene+" <i>"+sps_name+"</i> v"+annot_v;
// document.getElementById('query_gene').innerHTML = query_gene;
// document.getElementById('query_gene').style.display = "block";
</script>