Skip to content

Commit 2705204

Browse files
Provided means to set DB taxonomy thru back-office
1 parent 902a855 commit 2705204

File tree

5 files changed

+129
-46
lines changed

5 files changed

+129
-46
lines changed

src/main/java/fr/cirad/tools/GigwaModuleManager.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ public String getModuleHost(String sModule) {
106106
return MongoTemplateManager.getModuleHost(sModule);
107107
}
108108

109+
@Override
110+
public String getModuleCategory(String module) {
111+
return Helper.nullToEmptyString(MongoTemplateManager.getTaxonId(module)) + ":" + Helper.nullToEmptyString(MongoTemplateManager.getTaxonName(module)) + ":" + Helper.nullToEmptyString(MongoTemplateManager.getSpecies(module));
112+
}
113+
109114
@Override
110115
public Collection<String> getModules(Boolean fTrueForPublicFalseForPrivateNullForBoth) {
111116
if (fTrueForPublicFalseForPrivateNullForBoth == null)
@@ -205,8 +210,8 @@ public boolean updateDataSource(String sModule, boolean fPublic, boolean fHidden
205210
}
206211

207212
@Override
208-
public boolean createDataSource(String sModule, String sHost, String sSpeciesName, Long expiryDate) throws Exception {
209-
return MongoTemplateManager.saveOrUpdateDataSource(MongoTemplateManager.ModuleAction.CREATE, sModule, false, false, sHost, sSpeciesName, expiryDate);
213+
public boolean createDataSource(String sModule, String sHost, Long expiryDate) throws Exception {
214+
return MongoTemplateManager.saveOrUpdateDataSource(MongoTemplateManager.ModuleAction.CREATE, sModule, false, false, sHost, null, expiryDate);
210215
}
211216

212217
@Override

src/main/webapp/WEB-INF/jsp/import.jsp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
<script type="text/javascript" src="js/bootstrap-select.min.js"></script>
4545
<script type="text/javascript" src="js/bootstrap.min.js"></script>
4646
<script type="text/javascript" src="js/common.js"></script>
47+
<script type="text/javascript" src="js/moduleListCustomisation.js"></script>
4748
<script type="text/javascript" src="js/import.js"></script>
4849
<script type="text/javascript" src="js/dropzone.js"></script>
4950
<script type="text/javascript" src="js/brapiV1.1_Client.js"></script>
@@ -133,8 +134,7 @@
133134
<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>
134135
</div>
135136
<input type="hidden" id="ncbiTaxonIdNameAndSpecies" name="ncbiTaxonIdNameAndSpecies" />
136-
<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');"
137-
class="form-control text-input input-sm" style="min-width:100px; max-width:62%;" type="text" placeholder="Taxon id / name">
137+
<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'>
138138
</div>
139139
<div class="col-md-1" style="padding-right:0px;">
140140
<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)">

src/main/webapp/js/common.js

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -289,44 +289,6 @@ function buildHeader(token, assemblyId, individuals) {
289289
return headers;
290290
}
291291

292-
function getNcbiTaxonDetails(ncbiTaxonId)
293-
{
294-
var result = $.ajax({
295-
async:false,
296-
type:"GET",
297-
url:"https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esummary.fcgi?db=taxonomy&retmode=json&id=" + ncbiTaxonId,
298-
error:function(xhr, ajaxOptions, thrownError) {}
299-
});
300-
return result['responseJSON']['result'][ncbiTaxonId];
301-
}
302-
303-
function grabNcbiTaxon(inputObj)
304-
{
305-
if ($(inputObj).val() == '' || isNaN($(inputObj).val()))
306-
return;
307-
var taxonDetails=getNcbiTaxonDetails($(inputObj).val()), taxonName=taxonDetails['scientificname'], genus=taxonDetails['genus'], species=taxonDetails['species'];
308-
if (taxonName != null && taxonName != '')
309-
$(inputObj).attr('title', $(inputObj).val());
310-
if (species != null && species != '')
311-
$(inputObj).attr('species', genus + " " + species);
312-
313-
$(inputObj).val(taxonName);
314-
}
315-
316-
//function showGalaxyPushButton()
317-
//{
318-
// var galaxyInstanceUrl = $("#galaxyInstanceURL").val().trim();
319-
// if (galaxyInstanceUrl.startsWith("http")) {
320-
// var fileURLs = "";
321-
// for (key in archivedDataFiles)
322-
// fileURLs += (fileURLs == "" ? "" : " ,") + "'" + archivedDataFiles[key] + "'";
323-
// $('#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/>');
324-
// $("#galaxyPushButton").show();
325-
// }
326-
// else
327-
// $("#galaxyPushButton").hide();
328-
//}
329-
330292
function showServerExportBox(keepExportOnServer, exportFormatExtensions)
331293
{
332294
$("div#exportPanel").hide();

src/main/webapp/js/import.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -582,11 +582,11 @@ function importGenotypes(importMetadataToo) {
582582

583583
$('#progress').data('error', false);
584584
var taxonDetailsFieldContents = new Array();
585-
if ($("#ncbiTaxon").attr('title') != "")
585+
if ($("#ncbiTaxon").attr('data-id') != "")
586586
{
587-
taxonDetailsFieldContents.push($("#ncbiTaxon").attr('title'));
588-
taxonDetailsFieldContents.push($("#ncbiTaxon").val() == $("#ncbiTaxon").attr('species') ? "" : $("#ncbiTaxon").val());
589-
taxonDetailsFieldContents.push($("#ncbiTaxon").attr('species'));
587+
taxonDetailsFieldContents.push($("#ncbiTaxon").attr('data-id'));
588+
taxonDetailsFieldContents.push($("#ncbiTaxon").val() == $("#ncbiTaxon").attr('data-species') ? "" : $("#ncbiTaxon").val());
589+
taxonDetailsFieldContents.push($("#ncbiTaxon").attr('data-species'));
590590
}
591591

592592
$('#progressText').html("Please wait...");
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
var taxonCellIndex = null;
2+
3+
function getNcbiTaxonDetails(ncbiTaxonId, retrying)
4+
{
5+
var failed = false, result = $.ajax({
6+
async:false,
7+
type:"GET",
8+
url:"https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esummary.fcgi?db=taxonomy&retmode=json&id=" + ncbiTaxonId,
9+
error:function(xhr, ajaxOptions, thrownError) {
10+
failed = true;
11+
}
12+
});
13+
14+
if (!failed)
15+
return result['responseJSON']['result'][ncbiTaxonId];
16+
17+
if (retrying)
18+
return null;
19+
20+
console.log("Retrying to fetch taxon from ID " + ncbiTaxonId);
21+
return getNcbiTaxonDetails(ncbiTaxonId, true);
22+
}
23+
24+
function grabNcbiTaxon(inputObj, taxonId)
25+
{
26+
if (taxonId == null)
27+
return false;
28+
29+
if (taxonId == "" || isNaN(taxonId)) {
30+
$(inputObj).removeAttr('data-id');
31+
$(inputObj).removeAttr('data-species');
32+
if (typeof setDirty != 'undefined' && $(inputObj).val() != taxonId)
33+
setDirty($(inputObj).closest("tr").attr("id").substring(4), true);
34+
$(inputObj).val(taxonId).attr('title', taxonId + '\n(Click to change selection)');
35+
return;
36+
}
37+
38+
try {
39+
var taxonDetails = getNcbiTaxonDetails(taxonId), taxonName = taxonDetails['scientificname'], genus = taxonDetails['genus'], species = taxonDetails['species'];
40+
if (taxonName != null && taxonName != '')
41+
$(inputObj).attr('data-id', taxonId);
42+
if (species != null && species != '')
43+
$(inputObj).attr('data-species', genus + " " + species);
44+
45+
if (typeof setDirty != 'undefined' && $(inputObj).val() != taxonId)
46+
setDirty($(inputObj).closest("tr").attr("id").substring(4), true);
47+
$(inputObj).val(taxonName).attr('title', taxonName + '\n(Click to change selection)');
48+
}
49+
catch(error) {
50+
alert("Unable to fetch NCBI taxon info for ID " + taxonId);
51+
}
52+
}
53+
54+
function customizeModuleList() {
55+
let cell = $("#moduleTable thead th").filter(function() {
56+
return $(this).text().trim() === "Category";
57+
});
58+
59+
if (cell.length == 0)
60+
return;
61+
62+
cell.text("Taxon");
63+
taxonCellIndex = cell.index() + 1;
64+
65+
$("#moduleTable tbody tr td:nth-child(" + taxonCellIndex + ")").each(function() {
66+
updateTaxonCell(this);
67+
})
68+
if ($("#moduleTable tbody tr td:nth-child(" + taxonCellIndex + ") input").length > 0)
69+
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>');
70+
}
71+
72+
function updateTaxonCell(taxonCell) {
73+
let idTaxonSpecies = $(taxonCell).text().split(":"), inputVal = idTaxonSpecies.length < 3 ? idTaxonSpecies[0] : (idTaxonSpecies[1] != '' ? idTaxonSpecies[1]: idTaxonSpecies[2]);
74+
if (isAdmin || permissions.has($(taxonCell).parent().attr("id").substring(4) + "$" + supervisorRole)) {
75+
$(taxonCell).html("<input type='text' readonly='true' value=\"" + inputVal + "\" data-id='" + idTaxonSpecies[0] + "' title='" + inputVal + "\n(Click to change selection)' />");
76+
$(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() {
77+
grabNcbiTaxon($(this).get(), prompt("Please specify NCBI taxon, preferrably by ID\n(enter blank string to clear out)"));
78+
});
79+
}
80+
else
81+
$(taxonCell).html("<i>" + inputVal + "</i>").css("background-color", "lightgrey");
82+
}
83+
84+
saveChanges = function(moduleName) { // override default function so we can account for the taxon field
85+
let itemRow = $("#row_" + moduleName);
86+
let setToPublic = itemRow.find(".flagCol1").prop("checked");
87+
let setToHidden = itemRow.find(".flagCol2").prop("checked");
88+
var taxonDetailsFieldContents = new Array();
89+
let taxonInput = itemRow.find("td:nth-child(" + taxonCellIndex + ") input");
90+
if (taxonInput.attr('data-id') != "")
91+
{
92+
taxonDetailsFieldContents.push(taxonInput.attr('data-id'));
93+
taxonDetailsFieldContents.push(taxonInput.val() == taxonInput.attr('data-species') ? "" : taxonInput.val());
94+
taxonDetailsFieldContents.push(taxonInput.attr('data-species'));
95+
}
96+
$.getJSON(moduleDetailsURL, { module:moduleName,public:setToPublic,hidden:setToHidden,category:taxonDetailsFieldContents.join(":") }, function(updated){
97+
if (!updated)
98+
alert("Unable to apply changes for " + moduleName);
99+
else
100+
{
101+
moduleData[moduleName][modulePublicFieldName] = setToPublic;
102+
moduleData[moduleName][moduleHiddenFieldName] = setToHidden;
103+
setDirty(moduleName, false);
104+
}
105+
}).error(function(xhr) { handleError(xhr); });
106+
}
107+
108+
resetFlags = function(moduleName) { // override default function so we can account for the taxon field
109+
let itemRow = $("#row_" + moduleName);
110+
itemRow.find(".flagCol1").prop("checked", moduleData[moduleName][modulePublicFieldName]);
111+
itemRow.find(".flagCol2").prop("checked", moduleData[moduleName][moduleHiddenFieldName]);
112+
let taxonCell = itemRow.find("td:nth-child(" + taxonCellIndex + ")");
113+
taxonCell.text(moduleData[moduleName]["category"]);
114+
updateTaxonCell(taxonCell.get());
115+
setDirty(moduleName, false);
116+
}

0 commit comments

Comments
 (0)