links.py 2.42 KB
Newer Older
1 2 3 4 5 6 7 8 9

import defs
import datetime

patient_id = 10


our_id = 0

10 11
print "### Sequences"

12 13 14 15 16
for res in db(db.patient.id == db.sequence_file.patient_id).select():
    our_id += 1
    print "ln -s %s/%-20s %5s.fa" % (defs.DIR_SEQUENCES, res.sequence_file.data_file, our_id),
    print "\t", "# seq-%04d" % res.sequence_file.id, "%-20s" % res.sequence_file.filename,
    print "\t", "# pat-%04d (%s %s)" % (res.patient.id, res.patient.first_name, res.patient.last_name)
17 18 19 20

print "### Results"


21 22
def last_result_by_file():
  for seq in db(db.sequence_file).select():
23 24 25 26 27 28 29 30 31 32 33 34
    print "===", "seq-%d" % seq.id, "\t", seq.sampling_date, "\t", seq.filename, seq.data_file
    res_with_file = []

    for res in db((db.results_file.sequence_file_id == seq.id) & (db.patient.id == seq.patient_id)).select(orderby=db.results_file.run_date):
       print "   ", "sched-%d" % res.results_file.scheduler_task_id, "\t", res.results_file.run_date, "\t", res.results_file.data_file
       if res.results_file.data_file:
              res_with_file += [res]

    if not res_with_file:
        continue

    # Takes the last result
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
    yield (res_with_file[-1], seq)


def last_result_by_first_point_by_patient():
    res_by_pat = {}

    for res in db((db.patient.id == db.sequence_file.patient_id)
                  & (db.results_file.sequence_file_id == db.sequence_file.id)).select(#groupby=db.patient.id,
                                                                                      orderby=db.patient.id|db.sequence_file.sampling_date|~db.results_file.run_date):

        # Remeber only the first element
        if not str(res.patient.id) in res_by_pat:
            res_by_pat[str(res.patient.id)] = (res, res.sequence_file)

    for pat in res_by_pat:
        yield res_by_pat[pat]




# for (res, seq) in last_result_by_file():
for (res, seq) in last_result_by_first_point_by_patient():
57 58 59 60 61
    our_id = "pat-%04d--%s--sched-%04d--seq-%04d--%s" % (res.patient.id, res.patient.last_name[:3],
                                                         res.results_file.scheduler_task_id,
                                                         seq.id, seq.sampling_date)

    print "ln -s %s/%-20s %5s.vidjil" % (defs.DIR_RESULTS, res.results_file.data_file, our_id),
62
    print "\t", "# seq-%04d" % seq.id, "%-20s" % seq.filename, "%-10s" % seq.sampling_date,
63 64 65
    print "\t", "# pat-%04d (%s %s)" % (res.patient.id, res.patient.first_name, res.patient.last_name)


Mathieu Giraud's avatar
Mathieu Giraud committed
66 67
log.debug("=== links.py completed ===")