js.sorta-result-anonymous.js Maven / Gradle / Ivy
(function($, molgenis) {
"use strict";
var NOT_AVAILABLE = 'N/A';
var container = null;
var THRESHOLD = 100;
molgenis.SortaAnonymous = function SortaAnonymous(form_container){
container = form_container;
};
molgenis.SortaAnonymous.prototype.renderPage = function(){
container.children('div.row:gt(0)').remove();
var divContainerThreshold = $('').addClass('row').css('margin-bottom','15px').appendTo(container);
$('').addClass('col-md-offset-3 col-md-4').append('Current threshold : ' + THRESHOLD + '%').css('padding-left','0px').appendTo(divContainerThreshold);
var thresholdUpdateButton = $('').attr('type','button').addClass('btn btn-default').text('Update');
var inputGroupButton = $('').addClass('input-group-btn').append(thresholdUpdateButton);
var thresholdValue = $('');
var divContainerButtonFormGroup = $('').addClass('input-group pull-right').append(inputGroupButton).append(thresholdValue);
$('').addClass('col-md-2').css('padding-right','0px').append(divContainerButtonFormGroup).appendTo(divContainerThreshold);
var divContainerSummary = $('').addClass('row').appendTo(container);
var divContainerSummaryCenterStyleWell = $('').addClass('col-md-offset-3 col-md-6 well').appendTo(divContainerSummary);
var divContainerMatchButton = $('').addClass('row').appendTo(divContainerSummaryCenterStyleWell);
var matchButon = $('').attr('type', 'button').addClass('btn btn-primary pull-right').text('Show');
var matchSpanContainer = $('');
$('').addClass('col-md-12').append('Total number of match results is ').append(matchSpanContainer).append(matchButon).appendTo(divContainerMatchButton);
var divContainerUnMatchButton = $('').addClass('row').prepend('
').appendTo(divContainerSummaryCenterStyleWell);
var unmatchButon = $('').attr('type', 'button').addClass('btn btn-info pull-right').text('Show');
var unmatchSpanContainer = $('');
$('').addClass('col-md-12').append('Total number of unmatch results is ').append(unmatchSpanContainer).append(unmatchButon).appendTo(divContainerUnMatchButton);
var divContainerDownloadButton = $('').addClass('row').prepend('
').appendTo(divContainerSummaryCenterStyleWell);
var downloadButton = $('').attr('type', 'button').addClass('btn btn-primary').text('Download');
var backToFrontPageButton = $('').attr('type', 'button').addClass('btn btn-default').html('New task ').append(' ');
$('').addClass('col-md-2').append(downloadButton).appendTo(divContainerDownloadButton);
$('').addClass('col-md-2').append(backToFrontPageButton).appendTo(divContainerDownloadButton);
$(backToFrontPageButton).click(function(){
container.attr({
'action' : molgenis.getContextUrl(),
'method' : 'GET'
}).submit();
});
$(downloadButton).click(function(){
container.attr({
'action' : molgenis.getContextUrl() + '/download/',
'method' : 'GET'
}).submit();
});
$(inputGroupButton).click(function(){
var customThreshold = Number($(thresholdValue).val());
if(customThreshold && customThreshold !== THRESHOLD){
THRESHOLD = customThreshold;
molgenis.SortaAnonymous.prototype.renderPage();
}
});
$(thresholdValue).keydown(function(e){
if(e.keyCode === 13){
$(inputGroupButton).click();
}
});
getMatchResults(function(matchedResults){
var perfectMatches = [];
var partialMatches = [];
$.each(matchedResults, function(index, matchedResult){
if(matchedResult.ontologyTerm.length > 0){
var matchedScore = matchedResult.ontologyTerm[0].Combined_Score;
if(matchedScore && matchedScore.toFixed(2) >= THRESHOLD){
perfectMatches.push(matchedResult);
}else{
partialMatches.push(matchedResult);
}
}else{
partialMatches.push(matchedResult);
}
});
matchSpanContainer.html('' + perfectMatches.length + '');
unmatchSpanContainer.html('' + partialMatches.length + '');
matchButon.click(function(){
renderMatchedResultTable(perfectMatches, true);
});
unmatchButon.click(function(){
renderMatchedResultTable(partialMatches, false);
}).click();
});
function getMatchResults(callback){
$.ajax({
type : 'GET',
url : molgenis.getContextUrl() + '/retrieve',
contentType : 'application/json',
success : function(matchedResults) {
if(callback !== null && typeof callback === 'function'){
callback(matchedResults)
}
}
});
}
function renderMatchedResultTable(matches, isMatched){
if($('#sorta-result-table')){
$('#sorta-result-table').remove();
}
var divContainerMatchResult = $('').attr('id', 'sorta-result-table').addClass('row').appendTo(container);
if(matches.length > 0){
var adjustedScoreHoverover = $('Adjusted score ?').css({'cursor':'pointer'}).popover({
'title' : 'Explanation',
'content' : 'Adjusted scores are derived from the original scores (lexical similarity) combined with the weight of the words (inverse document frequency)
',
'placement' : 'top',
'trigger' : 'hover',
'html' : true
});
var tableTitle = $('').css('font-size','20px').append('' + (isMatched ? 'Matched results' : 'Unmatched results') + '');
var table = $('
').addClass('table');
var tableHeader = $(' ').appendTo(table);
$(' ').append('Input term').appendTo(tableHeader);
$(' ').append('Ontologgy terms').appendTo(tableHeader);
$(' ').append('Score').appendTo(tableHeader);
$(' ').append(adjustedScoreHoverover).appendTo(tableHeader);
$(' ').append('Match').appendTo(tableHeader);
$.each(matches, function(index, match){
var row = $(' ').appendTo(table);
var firstOntologyTerm = match.ontologyTerm ? match.ontologyTerm[0] : null;
$(' ').append(getInputTermInfo(match.inputTerm)).appendTo(row);
$(' ').append(getOntologyTermInfo(firstOntologyTerm)).appendTo(row);
$(' ').append(getMatchScore(firstOntologyTerm)).appendTo(row);
$(' ').append(getMatchAdjustedScore(firstOntologyTerm)).appendTo(row);
$(' ').append(firstOntologyTerm ? '' : NOT_AVAILABLE).appendTo(row);
row.find('button:eq(0)').click(function(){
var clearButton = $('').attr('type','button').addClass('btn btn-danger pull-right').css({'margin-top':'-10px','margin-bottom':'10px'}).text('Clear').insertBefore(table);
table.find('tr:not(:first-child)').hide();
table.find('tr >th:last-child').hide();
table.append(renderCandidateMatchTable(match));
clearButton.click(function(){
table.find('tr:visible:not(:first-child)').remove();
table.find('tr').show();
table.find('th').show();
$(this).remove();
});
});
});
$('').addClass('col-md-offset-1 col-md-10').append(tableTitle).append(table).appendTo(divContainerMatchResult);
}else{
$('').addClass('col-md-offset-3 col-md-6').text('No matches are found!').appendTo(divContainerMatchResult);
}
return divContainerMatchResult;
}
function renderCandidateMatchTable(match, table){
var items = [];
if(match.ontologyTerm){
$.each(match.ontologyTerm, function(index, candidateMatch){
if(index >= 10) return;
var candidateMatchRow = $(' ');
$(' ').append(index == 0 ? getInputTermInfo(match.inputTerm) : '').appendTo(candidateMatchRow);
$(' ').append(getOntologyTermInfo(candidateMatch)).appendTo(candidateMatchRow);
$(' ').append(getMatchScore(candidateMatch)).appendTo(candidateMatchRow);
$(' ').append(getMatchAdjustedScore(candidateMatch)).appendTo(candidateMatchRow);
items.push(candidateMatchRow);
});
}
return items;
}
function getInputTermInfo(inputTerm){
var inputTermDiv = $('');
$.map(inputTerm, function(val, key){
inputTermDiv.append(key + ' : ' + val).append('
');
});
return inputTermDiv;
}
function getOntologyTermInfo(ontologyTerm){
var inputTermDiv = $('');
if(ontologyTerm){
var divContainerOTName = getOntologyTermName(ontologyTerm);
var divContainerOTSynonym = getOntologyTermSynonyms(ontologyTerm);
var divContainerOTAnnotation = getOntologyTermAnnotations(ontologyTerm);
inputTermDiv.append(divContainerOTName).append(divContainerOTSynonym).append(divContainerOTAnnotation);
}else{
inputTermDiv.append(NOT_AVAILABLE);
}
return inputTermDiv;
}
function getOntologyTermName(ontologyTerm){
return $('').append('Name : ').append('' + ontologyTerm.ontologyTermName + '');
}
function getOntologyTermAnnotations(ontologyTerm){
var divContainerOTAnnotations = [];
if(ontologyTerm.ontologyTermDynamicAnnotation.length > 0){
var annotationMap = {};
$.each(ontologyTerm.ontologyTermDynamicAnnotation, function(index, annotation){
if(!annotationMap[annotation.name]){
annotationMap[annotation.name] = [];
}
annotationMap[annotation.name].push(annotation.value);
});
$.map(annotationMap, function(val, key){
divContainerOTAnnotations.push($('').append(key + ' : ' + val.join(', ')));
});
}
return divContainerOTAnnotations;
}
function getOntologyTermSynonyms(ontologyTerm){
var divContainerOTSynonym = $('Synonym : ');
if(ontologyTerm){
var synonyms = [];
$.each(ontologyTerm.ontologyTermSynonym, function(index, ontologyTermSynonym){
synonyms.push(ontologyTermSynonym.ontologyTermSynonym);
});
if(synonyms.length == 1){
divContainerOTSynonym.append(synonyms.join());
}else{
divContainerOTSynonym.addClass('show-popover').append('' + synonyms.length + ' synonyms, see more details').popover({
'content' : synonyms.join('
'),
'placement' : 'auto',
'trigger': 'hover',
'html' : true
});
}
}else{
divContainerOTSynonym.append(NOT_AVAILABLE);
}
return divContainerOTSynonym;
}
function getMatchScore(ontologyTerm){
return ontologyTerm ? $('').append(ontologyTerm.Score.toFixed(2) + '%') : NOT_AVAILABLE;
}
function getMatchAdjustedScore(ontologyTerm){
return ontologyTerm ? $('').append(ontologyTerm.Combined_Score.toFixed(2) + '%') : NOT_AVAILABLE;
}
};
}($, window.top.molgenis = window.top.molgenis || {}));
© 2015 - 2025 Weber Informatics LLC | Privacy Policy