Skip to content

Commit

Permalink
Fix bug in "Healthy" BioProject filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
ttsudipto committed Sep 29, 2023
1 parent ce725b9 commit 6c6c237
Showing 1 changed file with 34 additions and 8 deletions.
42 changes: 34 additions & 8 deletions js/browse.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
var rows = null;
var healthyControlRows = null;
var subGroupRows = null;
var disease = null;
var subGroup = null;

function hideDiv(divId){
document.getElementById(divId).style.display = 'none';
}

function initializeData(dataJSON, dis) {
function initializeDiseaseWiseData(dataJSON, dis) {
rows = JSON.parse(dataJSON);
disease = dis;
healthyControlRows = new Set();
Expand All @@ -20,6 +22,11 @@ function initializeData(dataJSON, dis) {
// alert(Array.from(healthyControlRows));
}

function initializeSubGroupWiseData(dataJSON, sg) {
subGroupRows = JSON.parse(dataJSON);
subGroup = sg;
}

function getAllDiseasewiseResultHTML(divId) {
var s = '<table class="browse-result-summary" border="1"><tr><th>BioProject ID</th><th>SRA Study ID</th><th>Run Count</th><th>Group</th><th>Sub-group</th><th>Isolation Source</th><th>Biome</th><th>Assay Type</th></tr>';
for(var i=0; i<rows.length; ++i) {
Expand Down Expand Up @@ -58,6 +65,25 @@ function getFilteredDiseaseWiseResultHTML(divId) {
return s;
}

function getAllSubGroupWiseResultHTML(divId) {
var s = '<table class="browse-result-summary" border="1"><tr><th>BioProject ID</th><th>SRA Study ID</th><th>Run Count</th><th>Group</th><th>Sub-group</th><th>Isolation Source</th><th>Biome</th><th>Assay Type</th></tr>';
for(var i=0; i<subGroupRows.length; ++i) {
s += '<tr>';
s += '<td><a style="color:#003325;" target="_blank" href="bioproject_id.php?key=' + subGroupRows[i].BioProject + '">' + subGroupRows[i].BioProject + ' <img src="resource/redirect-icon.png" height="14pt" width="auto" /></a></td>';
s += '<td>' + subGroupRows[i].SRA + '</td>';
s += '<td>' + subGroupRows[i].RunCount + '</td>';
s += '<td>' + subGroupRows[i].Grp.replace(/;/g, '; ') + '</td>';
s += '<td>' + subGroupRows[i].SubGroup.replace(/;/g, '; ') + '</td>';
s += '<td>' + subGroupRows[i].IsolationSource.replace(/;/g, '; ') + '</td>';
s += '<td>' + subGroupRows[i].Biome.replace(/;/g, '; ') + '</td>';
s += '<td>' + subGroupRows[i].AssayType.replace(/;/g, '; ') + '</td>';
s += '</tr>';
}
s += '</table>';

return s;
}

function filter_diseases(resultDivId) {
var hideButton = '<center><button type="button" class="round" onclick="hideDiv(\'' + resultDivId + '\')">&#10005;</button></center>';
var resultElement = document.getElementById(resultDivId);
Expand Down Expand Up @@ -85,7 +111,7 @@ function getBioProjects(dis, resultDivId){
var httpReq = new XMLHttpRequest();
httpReq.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
initializeData(this.responseText, dis);
initializeDiseaseWiseData(this.responseText, dis);
if(document.getElementById('filter_cb') != null)
document.getElementById('filter_cb').checked = false;
filter_diseases(resultDivId);
Expand All @@ -96,23 +122,23 @@ function getBioProjects(dis, resultDivId){
httpReq.send();
}

function getSubgroupBioProjects(subGroup, resultDivId){
function getSubgroupBioProjects(sg, resultDivId){
var httpReq = new XMLHttpRequest();
httpReq.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
initializeData(this.responseText, subGroup);
initializeSubGroupWiseData(this.responseText, sg);
var resultElement = document.getElementById(resultDivId);
resultElement.style.display = 'block';
var hideButton = '<center><button type="button" class="round" onclick="hideDiv(\'' + resultDivId + '\')">&#10005;</button></center>';
var resultCountString = '<p style="margin:2px;text-align:center;">Total number of BioProjects found in the database for SubGroup = "' + subGroup + '" : ' + rows.length + '</p>';
var subgroupResultHTML = getAllDiseasewiseResultHTML('result_display');
if(rows.length <= 0)
var resultCountString = '<p style="margin:2px;text-align:center;">Total number of BioProjects found in the database for SubGroup = "' + sg + '" : ' + subGroupRows.length + '</p>';
var subgroupResultHTML = getAllSubGroupWiseResultHTML('result_display');
if(subGroupRows.length <= 0)
resultElement.innerHTML = hideButton + resultCountString;
else
resultElement.innerHTML = hideButton + resultCountString + subgroupResultHTML;
}
};
httpReq.open('GET', 'subgroup_wise_bioprojects.php?key='+ encodeURIComponent(subGroup), true);
httpReq.open('GET', 'subgroup_wise_bioprojects.php?key='+ encodeURIComponent(sg), true);
httpReq.setRequestHeader("Content-type", "text/json");
httpReq.send();
}
Expand Down

0 comments on commit 6c6c237

Please sign in to comment.