forked from rahimrajwani/Search-in-MTB-genomes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReterive_seq_from_reference.php
218 lines (187 loc) · 7.81 KB
/
Reterive_seq_from_reference.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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
<?php
session_start();
?>
<head>
<?php
echo file_get_contents("header.html");
?>
</head>
<body>
<?php
//CASE1: IF THE SESSION IS LOADED AND PROCESS IS RUNNING..
if ($_SESSION['loaded'] && file_exists( "/proc/".$_SESSION['pid'])) {
print "<p align=\"CENTER\"> <b> <br/><br/> Your request to search is well received. <br/><br/> In most cases, the results will be available on the current page within five minutes. The current page will be automatically refreshed after every 5 seconds to see if there is any update on your result. </b></p> <br/>";
$_SESSION['Time_now'] = microtime(true);
$_SESSION['Timpe_since_query_submitted'] = $_SESSION['Time_now'] - $_SESSION['Time_start'];
print "<p align=\"CENTER\"> <b> Time passed since query received : ". $_SESSION['Timpe_since_query_submitted'] ." seconds </b></p> <br/>";
echo("<meta http-equiv='refresh' content='5'>");
}
//CASE3: IF THE SESSION IS NOT LOADED..EVERYTHING NEEDS TO BE SET FOR THE FIRST TIME..
if (!$_SESSION['loaded']){
session_start();
$_SESSION['loaded'] = true;
$_SESSION['Time_start'] = microtime(true);
//Taking input
$position = htmlspecialchars($_GET['refeseq_position']);
$variation = htmlspecialchars($_GET['variant_nucleotide']);
$seq_length = 20;
$sessionid = session_id();
// The main search command to run
$cmd = "bash Searchinmtbgenomes_SNP '$position' '$variation' '$sessionid'";
//The remaining processing
$command = $cmd . ' > /dev/null 2>&1 & echo $!; ';
$_SESSION['pid'] = exec($command);
//Printing
print "<p align=\"CENTER\"> <b> <br/><br/> Your request to search is well received. <br/><br/> In most cases, the results will be available on the current page within five minutes. The current page will be automatically refreshed after every 5 seconds to see if there is any update on your result. </b></p> <br/>";
echo("<meta http-equiv='refresh' content='5'>");
}
//CASE2: IF THE SESSION IS LODADED BUT PROCESS IS COMPLETED..
if ($_SESSION['loaded'] && !file_exists( "/proc/".$_SESSION['pid'])) {
$_SESSION['Time_end'] = microtime(true);
$_SESSION['Execution_time'] = $_SESSION['Time_end'] - $_SESSION['Time_start'];
$sessionid = session_id();
//Preparing data for summary
$Current_number_of_genomes = shell_exec("grep -c -P -v '^#' Database/assembly_summary.txt");
$date = date('Y-m-d');
$Number_of_positive_genomes = (int)(shell_exec("grep -c -P -v '^#' tmp/'$sessionid'.annotated.txt"));
$Number_of_negative_genomes = (int)($Current_number_of_genomes - $Number_of_positive_genomes);
?>
<!--Load the AJAX API-->
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
//DRAWING THE PIE CHART FOR PRESENCE/ABSENCE
google.charts.load('current', {'packages':['corechart']});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Order', 'Amount'],
['Genomes positive', parseInt('<?php echo $Number_of_positive_genomes; ?>')],
['Genomes negative', parseInt('<?php echo $Number_of_negative_genomes; ?>')]
]);
var options = {
legend: {position: 'bottom'},
chartArea: {width:'100%',height:'75%'},
pieHole: 0.4,
width: 250,
height: 200,
};
var chart = new google.visualization.PieChart(document.getElementById('piechart'));
chart.draw(data, options);
}
</script>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load('current', {'packages':['line']});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = new google.visualization.DataTable();
data.addColumn('string', 'Year of isolation for strains');
data.addColumn('number', 'Count');
data.addRows([
<?php echo shell_exec("bash Isolation_year.sh '$sessionid'");
?>
]);
var options = {
legend: {position: 'none'},
chartArea: {width:'100%',height:'100%'},
width: 250,
height: 200,
axes: {
x: {
0: {side: 'botttom'},
}
},
};
var chart = new google.charts.Line(document.getElementById('line_top_x'));
chart.draw(data, google.charts.Line.convertOptions(options));
}
</script>
<script type="text/javascript">
google.charts.load('current', {
'packages':['geochart'],
// Note: you will need to get a mapsApiKey for your project.
// See: https://developers.google.com/chart/interactive/docs/basic_load_libs#load-settings
'mapsApiKey': 'AIzaSyD-9tSrke72PouQMnMX-a7eZSW0jkFMBWY'
});
google.charts.setOnLoadCallback(drawRegionsMap);
function drawRegionsMap() {
var data = google.visualization.arrayToDataTable([
['Country', 'Number of strains'],
<?php echo shell_exec("bash Geolocation.sh '$sessionid'");
?>
]);
var options = {};
var chart = new google.visualization.GeoChart(document.getElementById('regions_div'));
chart.draw(data, options);
}
</script>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load('current', {'packages':['table']});
google.charts.setOnLoadCallback(drawTable);
function drawTable() {
var data = new google.visualization.DataTable();
data.addColumn('string', 'Assembly accession');
data.addColumn('string', 'Bioproject');
data.addColumn('string', 'Biosample');
data.addColumn('string', 'Assembly level');
data.addColumn('string', 'Date of collection');
data.addColumn('string', 'Place of isolation');
data.addColumn('string', 'Disease');
data.addColumn('string', 'Clinical specimen');
data.addRows([
<?php
//Reads the Table
$tab = "\t";
$fp = fopen('tmp/'.$sessionid.'.annotated.txt', 'r');
while ( !feof($fp) )
{
$line = fgets($fp, 2048);
$line = trim($line); //Don't read last empty line
if ($line != "") {
$data_txt = str_getcsv($line, $tab);
//Get First Line of Data over here
$Assembly = $data_txt[0];
$Bioproject = $data_txt[1];
$Biosample = $data_txt[2];
$level = $data_txt[3];
$Date_of_collection = $data_txt[4];
$Place_of_isolation = $data_txt[5];
$Disease = $data_txt[6];
$Clinical_specimen = $data_txt[7];
print "['".$Assembly."','".$Bioproject."','".$Biosample."','".$level."','".$Date_of_collection."','".$Place_of_isolation."','".$Disease."','".$Clinical_specimen."'],";
}
//exit;
}
fclose($fp);
?>
]);
var table = new google.visualization.Table(document.getElementById('table_div'));
table.draw(data, {showRowNumber: true, width: '100%', height: '60%'});
}
</script>
<div class='Figures_container'>
<div id="piechart" style="width: 250px; height: 200px" ></div> <br/>
<div id="line_top_x" style="width: 250px; height: 200px" ></div><br/>
<div id="regions_div" style="width: 250px; height: 200px"></div><br/>
</div>
<div class='Table_container'>
<div id="table_div"></div>
</div>
<div id="clear"></div><br/><br/>
<?php
//Final remarks after chart
echo '<p align=\"CENTER\"><a href="http://www.searchinmtbgenomes.com/tmp/'.$sessionid.'.annotated.txt">Download the list of genomes positive for the query</a><br/>';
echo "The search was completed in ". $_SESSION['Execution_time'] . " seconds</b>.</p>";
?>
<?php
//Close the session
session_unset();
session_destroy();
session_write_close();
session_regenerate_id(true);
$_POST = array();
}
?>
</body>
<?php echo file_get_contents("footer.html"); ?>