Commit 1bba34fa authored by Vidjil Team's avatar Vidjil Team Committed by HERBERT Ryan
Browse files

XXXX choses qui trainaient dans ~/git/prod-server/ XXX

parent 3b641b92
......@@ -364,7 +364,7 @@ def upload():
db.sequence_file[request.vars["id"]] = dict(data_file = db.sequence_file.data_file.store(f.file, f.filename))
else :
db.sequence_file[request.vars["id"]] = dict(data_file2 = db.sequence_file.data_file.store(f.file, f.filename))
mes += "upload finished"
mes += "upload finished (%s)" % (f.filename)
except IOError as e:
if str(e).find("File name too long") > -1:
error += 'Your filename is too long, please shorten it.'
......
......@@ -45,6 +45,16 @@ def print_analysis_file(res):
print_config_info(res.config_id)
print rbx_link(res.patient_id, res.config_id)
def print_orphan_files(directory, prefix_filename, db_field):
total_size = 0
nb_files = 0
for f in os.listdir(directory):
if f.startswith(prefix_filename) and os.path.isfile(directory+f)\
and db(db_field == f).count() == 0:
print f
total_size += os.path.getsize(directory+f)
nb_files += 1
print "%d bytes could be removed from %d files" % (total_size, nb_files)
print "** Missing sequences **"
for res in db(db.sequence_file).select():
......@@ -52,14 +62,13 @@ for res in db(db.sequence_file).select():
print_sequence_file(res)
print "** Orphan sequence files **"
total_size = 0
nb_files = 0
for f in os.listdir(defs.DIR_SEQUENCES):
if os.path.isfile(defs.DIR_SEQUENCES+f) and db(db.sequence_file.data_file == f).count() == 0:
print f
total_size += os.path.getsize(defs.DIR_SEQUENCES+f)
nb_files += 1
print "%d bytes could be removed from %d files" % (total_size, nb_files)
print_orphan_files(defs.DIR_SEQUENCES, "sequence_file.data_file", db.sequence_file.data_file)
print "** Orphan result files **"
print_orphan_files(defs.DIR_RESULTS, "results_file.data_file", db.results_file.data_file)
print "** Orphan fused files **"
print_orphan_files(defs.DIR_RESULTS, "fused_file.fused_file", db.fused_file.fused_file)
print "** Missing results **"
for res in db(db.results_file).select():
......
......@@ -2,34 +2,61 @@ from __future__ import print_function
import os.path
import sys
import defs
import argparse
def print_fuse_from_sequence_filename(substring):
def get_fused_files_from_sequence_filename(substring):
seq_ids = db(db.sequence_file.filename.contains(substring)).select(db.sequence_file.id)
for id in seq_ids:
fused_files=db(db.fused_file.sequence_file_list.contains('%d_' % id.id)).select()
for fused in fused_files:
sequence_file_ids = fused.sequence_file_list.split('_')
sequence_file_ids.pop() # Remove last (empty)
result_filenames = []
sequence_filenames = []
for seq_id in sequence_file_ids:
results = db((db.results_file.config_id == fused.config_id)\
& (db.results_file.sequence_file_id == seq_id)).select(orderby=~db.results_file.id, limitby=(0,1))
def get_fused_files_from_fused_filename(filename):
fused_file = db(db.fused_file.fused_file == filename).select()
if len(fused_file) == 0:
print("Warning no corresponding file found for %s" % filename, file=sys.stderr)
return fused_file
def print_fuse_files(fused_files):
for fused in fused_files:
sequence_file_ids = fused.sequence_file_list.split('_')
sequence_file_ids.pop() # Remove last (empty)
result_filenames = []
sequence_filenames = []
for seq_id in sequence_file_ids:
results = db((db.results_file.config_id == fused.config_id)\
& (db.results_file.sequence_file_id == seq_id)).select(orderby=~db.results_file.id, limitby=(0,1))
if len(results) > 0:
result_filenames.append(results[0].data_file)
sequence_filenames.append(db.sequence_file[seq_id].filename)
if len(result_filenames) == 0:
print("# No result for fused file: %s)" % (fused))
else:
results = ' '.join([defs.DIR_RESULTS+'{0}'.format(f) for f in result_filenames])
patient_id = str(db((db.sequence_file.id == id.id) & (db.sample_set_membership.sequence_file_id == db.sequence_file.id) & (db.patient.sample_set_id == db.sample_set_membership.sample_set_id)).select(db.patient.id).first().id)
comments = ' '.join(sequence_filenames)+' (patientID: ' + patient_id +')'\
+' http://rbx.vidjil.org/browser/?patient=%s&config=%s' % (patient_id, fused.config_id)
print ("python %s/fuse.py -o %s/%s -t 100 %s # %s" % (os.path.abspath(defs.DIR_FUSE),\
defs.DIR_RESULTS, fused.fused_file, results, comments))
comments = ' '.join(sequence_filenames)
print ("python %s/fuse.py -o %s/%s -t 100 %s # %s http://rbx.vidjil.org/browser/index.html?sample_set_id=%d&config=%d"
% (os.path.abspath(defs.DIR_FUSE), defs.DIR_RESULTS,
fused.fused_file, results, comments,
fused.sample_set_id, fused.config_id))
parser = argparse.ArgumentParser(description='Display commands to be launched so that fuse files can be regenerated (they will be overwritten by the displayed commands). The script does not launch any command. It just displays the commands to be launched.')
parser.add_argument('-s', '--sequence', action='store_true', help='The [names] will be part of sequence original filename(s)')
parser.add_argument('-f', '--fuse', action='store_true', help='The [names] will be exact fused filenames to relaunch')
parser.add_argument('names', nargs='+', help='The [names] described above')
args = parser.parse_args()
if len(sys.argv) == 1 or sys.argv[0] == "-h" or sys.argv[0] == "--help":
print("Usage: %s <substring>\n\nThe script just print fuse command to be launched. It doesn't launch any command.\n\nWarning the provided commands are designed to overwrite fused files" % sys.argv[0])
if args.sequence:
if args.fuse:
print ("You cannot launch both -f and -s")
exit(1)
for sequence_filename in args.names:
print_fuse_files(get_fused_files_from_fused_filename(sequence_filename))
elif args.fuse:
print("%d fused files" % len(args.names), file=sys.stderr)
for fused_filename in args.names:
print(fused_filename, file=sys.stderr)
print_fuse_files(get_fused_files_from_fused_filename(fused_filename))
else:
print("You must specify -f or -s")
exit(1)
print_fuse_from_sequence_filename(sys.argv[1])
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