Skip to content

Commit

Permalink
Provided means to set DB taxonomy thru back-office
Browse files Browse the repository at this point in the history
  • Loading branch information
GuilhemSempere committed Oct 8, 2024
1 parent 902a855 commit 2705204
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 46 deletions.
9 changes: 7 additions & 2 deletions src/main/java/fr/cirad/tools/GigwaModuleManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ public String getModuleHost(String sModule) {
return MongoTemplateManager.getModuleHost(sModule);
}

@Override
public String getModuleCategory(String module) {
return Helper.nullToEmptyString(MongoTemplateManager.getTaxonId(module)) + ":" + Helper.nullToEmptyString(MongoTemplateManager.getTaxonName(module)) + ":" + Helper.nullToEmptyString(MongoTemplateManager.getSpecies(module));
}

@Override
public Collection<String> getModules(Boolean fTrueForPublicFalseForPrivateNullForBoth) {
if (fTrueForPublicFalseForPrivateNullForBoth == null)
Expand Down Expand Up @@ -205,8 +210,8 @@ public boolean updateDataSource(String sModule, boolean fPublic, boolean fHidden
}

@Override
public boolean createDataSource(String sModule, String sHost, String sSpeciesName, Long expiryDate) throws Exception {
return MongoTemplateManager.saveOrUpdateDataSource(MongoTemplateManager.ModuleAction.CREATE, sModule, false, false, sHost, sSpeciesName, expiryDate);
public boolean createDataSource(String sModule, String sHost, Long expiryDate) throws Exception {
return MongoTemplateManager.saveOrUpdateDataSource(MongoTemplateManager.ModuleAction.CREATE, sModule, false, false, sHost, null, expiryDate);
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions src/main/webapp/WEB-INF/jsp/import.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
<script type="text/javascript" src="js/bootstrap-select.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/common.js"></script>
<script type="text/javascript" src="js/moduleListCustomisation.js"></script>
<script type="text/javascript" src="js/import.js"></script>
<script type="text/javascript" src="js/dropzone.js"></script>
<script type="text/javascript" src="js/brapiV1.1_Client.js"></script>
Expand Down Expand Up @@ -133,8 +134,7 @@
<a href="https://www.ncbi.nlm.nih.gov/Taxonomy/Browser/wwwtax.cgi" target="_blank"><img id="igvTooltip" style="cursor:pointer; cursor:hand;" src="images/magnifier.gif" title="Click to find out taxon id. Specifying an id is preferred because it avoids typos."/></a>
</div>
<input type="hidden" id="ncbiTaxonIdNameAndSpecies" name="ncbiTaxonIdNameAndSpecies" />
<input id="ncbiTaxon" name="ncbiTaxon" onblur="grabNcbiTaxon($(this));" onfocus="if (isNaN($(this).attr('title'))) return; $(this).val($(this).attr('title')); $(this).removeAttr('title'); $(this).removeAttr('species');"
class="form-control text-input input-sm" style="min-width:100px; max-width:62%;" type="text" placeholder="Taxon id / name">
<input id="ncbiTaxon" name="ncbiTaxon" onclick="grabNcbiTaxon(this, prompt('Please specify NCBI taxon, preferrably by ID\n(enter blank string to clear out)'));" readonly class="form-control text-input input-sm" style="background-color:white; min-width:100px; max-width:62%;" type="text" title='Click to change selection'>
</div>
<div class="col-md-1" style="padding-right:0px;">
<input id="ploidy" name="ploidy" class="form-control text-input input-sm" type='number' step="1" min="1" placeholder="ploidy" title="Specifying ploidy is recommended for HapMap and Flapjack formats (if left blank, guessing will be attempted and import will take longer)">
Expand Down
38 changes: 0 additions & 38 deletions src/main/webapp/js/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,44 +289,6 @@ function buildHeader(token, assemblyId, individuals) {
return headers;
}

function getNcbiTaxonDetails(ncbiTaxonId)
{
var result = $.ajax({
async:false,
type:"GET",
url:"https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esummary.fcgi?db=taxonomy&retmode=json&id=" + ncbiTaxonId,
error:function(xhr, ajaxOptions, thrownError) {}
});
return result['responseJSON']['result'][ncbiTaxonId];
}

function grabNcbiTaxon(inputObj)
{
if ($(inputObj).val() == '' || isNaN($(inputObj).val()))
return;
var taxonDetails=getNcbiTaxonDetails($(inputObj).val()), taxonName=taxonDetails['scientificname'], genus=taxonDetails['genus'], species=taxonDetails['species'];
if (taxonName != null && taxonName != '')
$(inputObj).attr('title', $(inputObj).val());
if (species != null && species != '')
$(inputObj).attr('species', genus + " " + species);

$(inputObj).val(taxonName);
}

//function showGalaxyPushButton()
//{
// var galaxyInstanceUrl = $("#galaxyInstanceURL").val().trim();
// if (galaxyInstanceUrl.startsWith("http")) {
// var fileURLs = "";
// for (key in archivedDataFiles)
// fileURLs += (fileURLs == "" ? "" : " ,") + "'" + archivedDataFiles[key] + "'";
// $('#galaxyPushButton').html('<div style="display:inline; width:70px; font-weight:bold; background-color:#333333; color:white; border-radius:3px; padding:7px;"><img alt="Galaxy" height="15" src="images/logo-galaxy.png" /> Galaxy</div>&nbsp;<input style="margin-bottom:20px;" type="button" value="Send exported data to ' + galaxyInstanceUrl + '" onclick="sendToGalaxy([' + fileURLs + ']);" /><br/>');
// $("#galaxyPushButton").show();
// }
// else
// $("#galaxyPushButton").hide();
//}

function showServerExportBox(keepExportOnServer, exportFormatExtensions)
{
$("div#exportPanel").hide();
Expand Down
8 changes: 4 additions & 4 deletions src/main/webapp/js/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -582,11 +582,11 @@ function importGenotypes(importMetadataToo) {

$('#progress').data('error', false);
var taxonDetailsFieldContents = new Array();
if ($("#ncbiTaxon").attr('title') != "")
if ($("#ncbiTaxon").attr('data-id') != "")
{
taxonDetailsFieldContents.push($("#ncbiTaxon").attr('title'));
taxonDetailsFieldContents.push($("#ncbiTaxon").val() == $("#ncbiTaxon").attr('species') ? "" : $("#ncbiTaxon").val());
taxonDetailsFieldContents.push($("#ncbiTaxon").attr('species'));
taxonDetailsFieldContents.push($("#ncbiTaxon").attr('data-id'));
taxonDetailsFieldContents.push($("#ncbiTaxon").val() == $("#ncbiTaxon").attr('data-species') ? "" : $("#ncbiTaxon").val());
taxonDetailsFieldContents.push($("#ncbiTaxon").attr('data-species'));
}

$('#progressText').html("Please wait...");
Expand Down
116 changes: 116 additions & 0 deletions src/main/webapp/js/moduleListCustomisation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
var taxonCellIndex = null;

function getNcbiTaxonDetails(ncbiTaxonId, retrying)
{
var failed = false, result = $.ajax({
async:false,
type:"GET",
url:"https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esummary.fcgi?db=taxonomy&retmode=json&id=" + ncbiTaxonId,
error:function(xhr, ajaxOptions, thrownError) {
failed = true;
}
});

if (!failed)
return result['responseJSON']['result'][ncbiTaxonId];

if (retrying)
return null;

console.log("Retrying to fetch taxon from ID " + ncbiTaxonId);
return getNcbiTaxonDetails(ncbiTaxonId, true);
}

function grabNcbiTaxon(inputObj, taxonId)
{
if (taxonId == null)
return false;

if (taxonId == "" || isNaN(taxonId)) {
$(inputObj).removeAttr('data-id');
$(inputObj).removeAttr('data-species');
if (typeof setDirty != 'undefined' && $(inputObj).val() != taxonId)
setDirty($(inputObj).closest("tr").attr("id").substring(4), true);
$(inputObj).val(taxonId).attr('title', taxonId + '\n(Click to change selection)');
return;
}

try {
var taxonDetails = getNcbiTaxonDetails(taxonId), taxonName = taxonDetails['scientificname'], genus = taxonDetails['genus'], species = taxonDetails['species'];
if (taxonName != null && taxonName != '')
$(inputObj).attr('data-id', taxonId);
if (species != null && species != '')
$(inputObj).attr('data-species', genus + " " + species);

if (typeof setDirty != 'undefined' && $(inputObj).val() != taxonId)
setDirty($(inputObj).closest("tr").attr("id").substring(4), true);
$(inputObj).val(taxonName).attr('title', taxonName + '\n(Click to change selection)');
}
catch(error) {
alert("Unable to fetch NCBI taxon info for ID " + taxonId);
}
}

function customizeModuleList() {
let cell = $("#moduleTable thead th").filter(function() {
return $(this).text().trim() === "Category";
});

if (cell.length == 0)
return;

cell.text("Taxon");
taxonCellIndex = cell.index() + 1;

$("#moduleTable tbody tr td:nth-child(" + taxonCellIndex + ")").each(function() {
updateTaxonCell(this);
})
if ($("#moduleTable tbody tr td:nth-child(" + taxonCellIndex + ") input").length > 0)
cell.append('<span style="font-weight:normal; margin-left:50px; color:black;">Find NCBI IDs&nbsp;<a href="https://www.ncbi.nlm.nih.gov/Taxonomy/Browser/wwwtax.cgi" target="_blank"><img id="igvTooltip" style="cursor:pointer; cursor:hand;" src="../images/magnifier.gif" title="Click to find out taxon id. Specifying an id is preferred because it avoids typos."></a></span>');
}

function updateTaxonCell(taxonCell) {
let idTaxonSpecies = $(taxonCell).text().split(":"), inputVal = idTaxonSpecies.length < 3 ? idTaxonSpecies[0] : (idTaxonSpecies[1] != '' ? idTaxonSpecies[1]: idTaxonSpecies[2]);
if (isAdmin || permissions.has($(taxonCell).parent().attr("id").substring(4) + "$" + supervisorRole)) {
$(taxonCell).html("<input type='text' readonly='true' value=\"" + inputVal + "\" data-id='" + idTaxonSpecies[0] + "' title='" + inputVal + "\n(Click to change selection)' />");
$(taxonCell).find("input").css("width", "200px").css("font-style", "italic").css("text-align", "center").css("border", "none").css("background-color", "inherit !important").css("cursor", "pointer").on("click", function() {
grabNcbiTaxon($(this).get(), prompt("Please specify NCBI taxon, preferrably by ID\n(enter blank string to clear out)"));
});
}
else
$(taxonCell).html("<i>" + inputVal + "</i>").css("background-color", "lightgrey");
}

saveChanges = function(moduleName) { // override default function so we can account for the taxon field
let itemRow = $("#row_" + moduleName);
let setToPublic = itemRow.find(".flagCol1").prop("checked");
let setToHidden = itemRow.find(".flagCol2").prop("checked");
var taxonDetailsFieldContents = new Array();
let taxonInput = itemRow.find("td:nth-child(" + taxonCellIndex + ") input");
if (taxonInput.attr('data-id') != "")
{
taxonDetailsFieldContents.push(taxonInput.attr('data-id'));
taxonDetailsFieldContents.push(taxonInput.val() == taxonInput.attr('data-species') ? "" : taxonInput.val());
taxonDetailsFieldContents.push(taxonInput.attr('data-species'));
}
$.getJSON(moduleDetailsURL, { module:moduleName,public:setToPublic,hidden:setToHidden,category:taxonDetailsFieldContents.join(":") }, function(updated){
if (!updated)
alert("Unable to apply changes for " + moduleName);
else
{
moduleData[moduleName][modulePublicFieldName] = setToPublic;
moduleData[moduleName][moduleHiddenFieldName] = setToHidden;
setDirty(moduleName, false);
}
}).error(function(xhr) { handleError(xhr); });
}

resetFlags = function(moduleName) { // override default function so we can account for the taxon field
let itemRow = $("#row_" + moduleName);
itemRow.find(".flagCol1").prop("checked", moduleData[moduleName][modulePublicFieldName]);
itemRow.find(".flagCol2").prop("checked", moduleData[moduleName][moduleHiddenFieldName]);
let taxonCell = itemRow.find("td:nth-child(" + taxonCellIndex + ")");
taxonCell.text(moduleData[moduleName]["category"]);
updateTaxonCell(taxonCell.get());
setDirty(moduleName, false);
}

0 comments on commit 2705204

Please sign in to comment.