Commit a7bf4f29 authored by Mathieu Giraud's avatar Mathieu Giraud

Merge branch 'feature-sc/1469-get-reads-simple' into 'dev'

Get reads (simple UI)

Closes #1469 and #3733

See merge request !439
parents abc58fde 08f83493
Pipeline #68849 passed with stages
in 9 minutes and 8 seconds
......@@ -1211,14 +1211,11 @@ Clone.prototype = {
if (this.normalized_reads && this.m.normalization_mode == this.m.NORM_EXTERNAL) {
html += "<br />[" + this.getReads(this.m.samples.order[j]).toFixed(2) + "]"
}
if ($('#debug_menu').is(':visible') && (typeof this.m.db_key.config != 'undefined' )) {
html += "<br/>"
call_reads = "db.call('default/run_request', { "
call_reads += "'sequence_file_id': '" + this.m.samples.db_key[this.m.samples.order[j]] + "', "
call_reads += "'config_id' : '" + this.m.db_key.config + "', "
call_reads += "'grep_reads' : '" + this.id + "' })"
console.log(call_reads)
html += "<span class='button' onclick=\"" + call_reads + "\"> get reads </span>"
if (typeof this.m.db_key.config != 'undefined' ) {
html += "&emsp;"
var sample_set_id = this.m.samples.sequence_file_id[this.m.samples.order[j]];
call_reads = "db.get_read('" + this.id + "', "+ this.index +", " + sample_set_id + ')';
html += '<i onclick="' + call_reads + '; m.closeInfoBox()" class="icon-down" title="Download reads from this clone"></i>';
}
html += "</td>"
}
......
......@@ -125,6 +125,31 @@ Database.prototype = {
report.reportcontamination()
})
},
get_read: function(window, clone_id, sequence_file_id) {
var self = this;
var log = "Reads will be exported in a few minutes. You will be able to download them when they are ready. You can continue using the application.";
console.log({"type": "flash", "msg" : log, "priority": 2});
self.callProcess('default/run_request',
{'sequence_file_id': sequence_file_id,
'sample_set_id': self.m.sample_set_id,
'config_id': self.m.db_key.config,
'grep_reads': window},
function(a) {
// Link to result file and launch download
var path_data = DB_ADDRESS+"/results_file/download?filename=seq/clone.fa-1&results_file_id="+a.result_id
var file_name = "reads__"+clone_id+"__file_id_"+"_"+sequence_file_id+".fa"
var anchor = document.createElement('a');
anchor.setAttribute("download", file_name);
anchor.setAttribute("href", path_data);
anchor.style = 'display: none';
self.ajax_indicator_stop()
document.body.appendChild(anchor);
anchor.click();
document.body.removeChild(anchor);
});
},
/**
* request a side process to the server
......@@ -132,7 +157,8 @@ Database.prototype = {
* */
callProcess : function (page, args, callback){
var self=this;
this.temporarilyDisableClickedLink();
var arg = "";
if (typeof args != "undefined" && Object.keys(args).length)
arg = this.argsToStr(args)
......@@ -171,7 +197,6 @@ Database.prototype = {
* check if a server process is done(recursive)
* */
waitProcess: function (processId, interval, callback){
console.log("... " +processId)
var self=this;
var url = self.db_address + "default/checkProcess?processId="+processId;
......@@ -185,11 +210,12 @@ Database.prototype = {
xhrFields: {withCredentials: true},
success: function (result) {
self.connected = true;
console.log(result);
result = jQuery.parseJSON(result)
if (result.status == "COMPLETED"){
callback(result.data);
}else if(result.status == "FAILED"){
console.log({"type": "flash", "msg": "process failed", "priority": 1});
console.log({"type": "flash", "msg": "process failed:" + ((typeof result.message !== 'undefined') ? result.message: ''), "priority": 1});
}else{
setTimeout(function(){ self.waitProcess(processId, interval, callback); }, interval);
}
......@@ -214,20 +240,7 @@ Database.prototype = {
* */
call: function (page, args) {
var self = this;
try {
var event = window.event || arguments.callee.caller.arguments[0]
event.stopPropagation();
var target = event.target
if (target.getAttribute("disabled")){
return;
} else {
target.setAttribute("disabled", "disabled")
self.ajax_indicator_start();
setTimeout(function(){target.removeAttribute("disabled")}, 2000)
}
}
catch(err)
{}
this.temporarilyDisableClickedLink()
var url = self.db_address + page
if (page.substr(0,4).toLowerCase() == "http") {
......@@ -1103,6 +1116,33 @@ Database.prototype = {
tgt.empty();
$('body').css('cursor', 'default');
},
temporarilyDisableClickedLink: function() {
var self = this;
try {
var event = window.event;
if (typeof(event) === 'undefined') {
var caller = arguments.callee.caller;
while (caller != null && (caller.arguments.length == 0 ||
! (caller.arguments[0] instanceof Event)))
caller = caller.caller;
if (caller == null)
return;
event = caller.arguments[0];
}
event.stopPropagation();
var target = $(event.target)
if (target.hasClass("disabledClass")){
return;
} else {
target.addClass("disabledClass")
self.ajax_indicator_start();
setTimeout(function(){target.removeClass("disabledClass")}, 3000)
}
}
catch(err)
{}
},
validate_fileform: function (form) {
var pp_option = form.pre_process.getElementsByTagName("option");
......
......@@ -115,6 +115,8 @@ def run_request():
##TODO check
if not "sequence_file_id" in request.vars :
error += "id sequence file needed, "
elif not "sample_set_id" in request.vars:
error += "sample set ID needed, "
if not "config_id" in request.vars:
error += "id config needed, "
id_config = None
......@@ -170,18 +172,33 @@ def run_extra():
def checkProcess():
task = db.scheduler_task[request.vars["processId"]]
if task.status == "COMPLETED" :
results_file = db(db.results_file.scheduler_task_id == task.id).select().first()
msg = ''
sample_set_id = -1
if results_file:
sample_set_id = get_sample_set_id_from_results_file(results_file.id)
if not results_file or not auth.can_view_sample_set(sample_set_id):
msg = "You don't have access to this sample"
if sample_set_id > -1 and task.status == "COMPLETED" :
run = db( db.scheduler_run.task_id == task.id ).select()[0]
res = {"success" : "true",
"status" : task.status,
"data" : run.run_result,
"data" : {'run_result': run.run_result,
'result_id': results_file.id
},
"processId" : task.id}
else :
res = {"success" : "true",
"status" : task.status,
"processId" : task.id}
if len(msg) > 0:
res = {"success" : "false",
"status" : "FAILED",
"message": msg,
"processId" : task.id}
else:
res = {"success" : "true",
"status" : task.status,
"processId" : task.id}
log.error(res)
return gluon.contrib.simplejson.dumps(res, separators=(',',':'))
......
......@@ -11,14 +11,6 @@ if request.env.http_origin:
response.headers['Access-Control-Allow-Credentials'] = 'true'
response.headers['Access-Control-Max-Age'] = 86400
def get_sample_set_id(results_file_id):
sample_set_id = db((db.sequence_file.id == db.results_file.sequence_file_id)
&(db.results_file.id == results_file_id)
&(db.sample_set_membership.sequence_file_id == db.sequence_file.id)
&(db.sample_set.id == db.sample_set_membership.sample_set_id)
).select(db.sample_set_membership.sample_set_id).first().sample_set_id
return sample_set_id
## return admin_panel
def index():
if auth.is_admin():
......@@ -90,7 +82,7 @@ def run_all_patients():
## display run page result
## need ["results_file_id"]
def info():
sample_set_id = get_sample_set_id(request.vars["results_file_id"])
sample_set_id = get_sample_set_id_from_results_file(request.vars["results_file_id"])
if (auth.can_modify_sample_set(sample_set_id)):
log.info("access results file info", extra={'user_id': auth.user.id,
'record_id': request.vars["results_file_id"],
......@@ -101,7 +93,7 @@ def info():
return gluon.contrib.simplejson.dumps(res, separators=(',',':'))
def output():
sample_set_id = get_sample_set_id(request.vars["results_file_id"])
sample_set_id = get_sample_set_id_from_results_file(request.vars["results_file_id"])
if (auth.can_view_sample_set(sample_set_id)):
results_id = int(request.vars["results_file_id"])
output_directory = defs.DIR_OUT_VIDJIL_ID % results_id
......@@ -123,11 +115,11 @@ def output():
@cache.action()
def download():
sample_set_id = get_sample_set_id(request.vars["results_file_id"])
if auth.can_view_sample_set(sample_set_id):
sample_set_id = get_sample_set_id_from_results_file(request.vars["results_file_id"])
if auth.can_view_sample_set(sample_set_id) and not '..' in request.vars['filename']:
results_id = int(request.vars["results_file_id"])
directory = defs.DIR_OUT_VIDJIL_ID % results_id
filepath = directory + os.path.basename(request.vars['filename'])
filepath = directory + request.vars['filename']
try:
log.info("Downloaded results file", extra={'user_id': auth.user.id,
'record_id': request.vars["results_file_id"],
......
......@@ -174,3 +174,15 @@ def get_set_group(sid):
(db.auth_permission.name == PermissionEnum.access.value)
).select().first()
return perm.group_id
def get_sample_set_id_from_results_file(results_file_id):
'''
Return the sample set ID corresponding to a result file ID
'''
sample_set_id = db((db.sequence_file.id == db.results_file.sequence_file_id)
&(db.results_file.id == results_file_id)
&(db.sample_set_membership.sequence_file_id == db.sequence_file.id)
&(db.sample_set.id == db.sample_set_membership.sample_set_id)
).select(db.sample_set_membership.sample_set_id).first().sample_set_id
return sample_set_id
......@@ -156,6 +156,7 @@ def schedule_run(id_sequence, id_config, grep_reads=None):
filename= db.sequence_file[id_sequence].filename
res = {"redirect": "reload",
"processId": task.id,
"message": "[%s] c%s: process requested - %s %s" % (data_id, id_config, grep_reads, filename)}
log.info(res)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment