Commit d8b27c4d authored by Marc Duez's avatar Marc Duez
Browse files

server : task.py, database store result of fuse.py

parent 30cc8a15
......@@ -70,9 +70,21 @@ def run_request():
config_id = request.vars['config_id'],
status = 'pending'
)
## create or update fuse file state
id_patient = db.sequence_file[request.vars["sequence_file_id"]].patient_id
row = db( ( db.fused_file.config_id == request.vars["config_id"] ) &
( db.fused_file.patient_id == id_patient )
).select()
if len(row) > 0 : ## update
fuse_id = row[0].id
else: ## create
fuse_id = db.fused_file.insert(patient_id = id_patient,
config_id = request.vars['config_id'])
##add task to scheduller
scheduler.queue_task('run', [request.vars["sequence_file_id"],request.vars["config_id"], data_id]
scheduler.queue_task('run', [request.vars["sequence_file_id"],request.vars["config_id"], data_id, fuse_id]
, repeats = 1, timeout = 6000)
res = {"success": "true" , "msg": "request added" }
......@@ -87,8 +99,7 @@ def run_request():
return gluon.contrib.simplejson.dumps(res2, separators=(',',':'))
def result():
def get_data():
import time
import gluon.contrib.simplejson
from subprocess import Popen, PIPE, STDOUT
......@@ -104,24 +115,15 @@ def result():
if not "config_id" in request.vars:
error += "id config needed, "
output_file = "result_patient_"+request.vars["patient_id"]+"_config_"+request.vars["config_id"]
files = ""
query = db( ( db.patient.id == db.sequence_file.patient_id )
& ( db.data_file.sequence_file_id == db.sequence_file.id )
& ( db.patient.id == request.vars["patient_id"] )
& ( db.data_file.config_id == request.vars["config_id"] )
).select( orderby=db.sequence_file.sampling_date )
query = db( ( db.fused_file.patient_id == request.vars["patient_id"] )
& ( db.fused_file.config_id == request.vars["config_id"] )
).select()
for row in query :
files += " applications/vidjil/uploads/"+row.data_file.data_file
fused_file = "applications/vidjil/uploads/"+row.fused_file
if error == "" :
cmd = "python ../fuse.py -o "+output_file+" -t 100 "+files
p = Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True)
p.wait()
f = open(output_file, "r")
f = open(fused_file, "r")
output=f.readlines()
f.close()
......
# coding: utf8
def run_vidjil(id_file, id_config, id_data):
def run_vidjil(id_file, id_config, id_data, id_fuse):
import time, datetime
from subprocess import Popen, PIPE, STDOUT, os
......@@ -10,10 +10,15 @@ def run_vidjil(id_file, id_config, id_data):
upload_folder = vidjil_path + '/server/web2py/applications/vidjil/uploads/'
out_folder = vidjil_path + '/out/'
cmd = "rm -rf "+out_folder
p = Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True)
p.wait()
## filepath du fichier de séquence
row = db(db.sequence_file.id==id_file).select()
filename = row[0].data_file
seq_file = upload_folder+filename
id_patient = row[0].patient_id
## config de vidjil
vidjil_cmd = db.config[id_config].command
......@@ -21,9 +26,10 @@ def run_vidjil(id_file, id_config, id_data):
## commande complete
cmd = vidjil_path+'/vidjil ' + vidjil_cmd + ' -o ' + out_folder + ' -G ' + germline_folder + vidjil_germline + ' '+ seq_file
## execute la commande vidjil
p = Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True)
p.wait()
output = p.stdout.read()
## récupération du fichier data.json généré
......@@ -38,6 +44,28 @@ def run_vidjil(id_file, id_config, id_data):
data_file = stream
)
## relance fuse.py
output_file = out_folder+"result"
files = ""
query = db( ( db.patient.id == db.sequence_file.patient_id )
& ( db.data_file.sequence_file_id == db.sequence_file.id )
& ( db.patient.id == id_patient )
& ( db.data_file.config_id == id_config )
).select( orderby=db.sequence_file.sampling_date )
for row in query :
files += " applications/vidjil/uploads/"+row.data_file.data_file
cmd = "python ../fuse.py -o "+output_file+" -t 100 -g "+vidjil_germline+" "+files
p = Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True)
p.wait()
fuse_filepath = os.path.abspath(output_file)
stream = open(fuse_filepath, 'rb')
db.fused_file[id_fuse] = dict(fuse_date = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d'),
fused_file = stream)
db.commit()
## l'output de Vidjil est stocké comme resultat pour l'ordonnanceur
......
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