...
  View open merge request
Commits (44)
......@@ -193,7 +193,8 @@
</div>
<div class="menu" id="settings_menu" onmouseenter="builder.build_settings();" onmouseover=" showSelector('settingsSelector');" > settings
<div id="settingsSelector" class="selector"><div>
<div id="settingsSelector" class="selector">
<div>
<div class="menu_box">
normalization
......@@ -269,7 +270,14 @@
</div>
</div>
</div></div>
</div>
</div>
</div>
<div class="menu" id ="dlAnchorsParent" onmouseover="showSelector('dlAnchorsSelector');" onmouseout="hideSelector('dlAnchorsSelector');">Reads
<div id="dlAnchorsSelector" class="selector" style="display : none">
</div>
</div>
......@@ -344,7 +352,7 @@
<form id="form"></form>
<div id="tip-container"></div>
</body>
</html>
......@@ -1212,13 +1212,11 @@ Clone.prototype = {
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>"
html += "&emsp;"
var id_db_sample = this.m.samples.sequence_file_id[this.m.samples.order[j]]
var call_reads = "db.get_read('" + this.id + "', '"+ this.index + "', '"+ j + "', "+ id_db_sample + ')';
console.log(call_reads)
html += " <button onclick=\"" + call_reads + "\" id='btn_get_reads_"+id_db_sample+"_"+this.index+"' class='button "+db.get_reads_btn_class(id_db_sample, this.index)+"'> get reads </button>"
}
html += "</td>"
}
......
......@@ -38,6 +38,7 @@ function Database(model, address) {
this.url = []
this.m = model
this.uploader = new Uploader()
this.list_clones_with_reads_getted = []
this.build()
window.onbeforeunload = function(e){
......@@ -125,6 +126,61 @@ Database.prototype = {
report.reportcontamination()
})
},
get_reads_btn_class: function(sequence_file_id, clone_id) {
for (var i = 0; i < this.list_clones_with_reads_getted.length; i++) {
var values = this.list_clones_with_reads_getted[i]
if (values[0] == sequence_file_id && values[1] == clone_id.toString()) {
return "disabledClass"
}
}
return ""
},
get_read: function(window, clone_id, timepoint, sequence_file_id) {
var self = this;
self.ajax_indicator_start()
var log = "Reads of clone " + clone_id + " will be exported. Please wait."
console.log({"type": "flash", "msg" : log, "priority": 2});
this.list_clones_with_reads_getted.push( [sequence_file_id, clone_id] )
btn_id = "btn_get_reads_"+sequence_file_id+"_"+clone_id
document.getElementById(btn_id).classList.add("disabledClass")
// Create anchor here, so each clones/sample will have an specific anchor
// Allow to launch multiple 'get_reads'
var anchors = document.getElementById('dlAnchorsSelector')
var anchor_id = "dlAnchor_get_reads_"+sequence_file_id+"_"+clone_id
var anchor = document.createElement("a", anchor_id)
var anchorContainer = document.createElement("div", "parent_" +anchor_id)
anchor.innerHTML = "timepoint "+(Number(timepoint)+1)+"; clone "+m.clones[clone_id].name
anchor.classList.add = "disabledClass"
// anchor.style.display = "none"
anchorContainer.appendChild(anchor)
anchors.appendChild(anchorContainer)
console.log( anchor )
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) {
var anchors = document.getElementById("dlAnchor_get_reads_"+sequence_file_id+"_"+clone_id)
// 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"
anchor.setAttribute("download", file_name);
anchor.setAttribute("href", path_data);
anchor.classList.remove("disabledClass")
self.ajax_indicator_stop()
anchor.click();
// openAndFillNewTab("Your reads are ready. <a href='"+DB_ADDRESS+"/results_file/download?filename=seq/clone.fa-1&results_file_id="+a.result_id+"'>Download them</a>");
});
},
/**
* request a side process to the server
......@@ -171,7 +227,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 +240,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);
}
......
......@@ -317,6 +317,8 @@ Model.prototype = {
$("#external_normalization").show();
}
}
// Remove content of get_reads menu
$("#dlAnchorsSelector").empty()
}, //end initClones
changeCloneNotation: function(cloneNotationType) {
......
......@@ -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)
......