latex.py 3.17 KB
Newer Older
1 2 3
#!/usr/bin/env python
# -*- coding: utf-8 -*-

Mathieu Giraud's avatar
Mathieu Giraud committed
4
from __future__ import print_function
5
import fuse
6
import analysis
7 8
import sys
import argparse
9
import re
10

11
parser = argparse.ArgumentParser(description = 'Output a LaTeX table for clones in .vidjil files')
12
parser.add_argument('--min-ratio', '-r', type=float, default=.01, help='minimal reads ratio of the clone (%(default).3f)')
13
parser.add_argument('--min', '-m', type=int, default=1, help='minimal number of reads in the clone (%(default)d)')
Mathieu Giraud's avatar
Mathieu Giraud committed
14
parser.add_argument('--top', '-t', type=int, default=5, help='maximal number of clones to display (%(default)d)')
15
parser.add_argument('--sample', '-s', type=int, default=0, help='sample number (%(default)d)')
16
parser.add_argument('--analysis', '-a', action='store_true', help='filter clones tagged in the relevant .analysis file (experimental, hardcoded)')
17

18 19 20 21
parser.add_argument('--verbose', '-v', action='store_true', help='verbose output')
parser.add_argument('file', nargs='+', help='''.vidjil files''')


22 23
# data.vidjil/pat-0119--PAR--sched-0900...
regex_filename = re.compile('.*pat-(.*)--sched')
24 25 26

def main():

Mathieu Giraud's avatar
Mathieu Giraud committed
27
    print('%%%%', ' '.join(sys.argv))
28 29 30 31 32
    args = parser.parse_args()

    for i in args.file:
        data = fuse.ListWindows()
        data.load(i, False, verbose = args.verbose)
33

34 35 36 37 38
        if data.d['samples'].d['number'] < args.sample + 1:
            print("! no sample %d in %s'" % (args.sample, i))
            continue
        sample = args.sample

39 40 41
        m = regex_filename.match(i)
        i_short = m.group(1) if m else i

42 43 44 45
        if args.analysis:
            # TODO: hardcoded for output of links.py
            # should be more flexible
            ii = 'data.vidjil/' + 'pat-' + i_short +'.analysis'
46
            data_analysis = analysis.Analysis(data)
47
            data_analysis.load(ii)
48
            data_analysis.cluster_stats()
49 50 51 52 53

            if str(data_analysis.d['samples']['run_timestamp']) == str(data.d['samples'].d['run_timestamp']):
                print("%% timestamps: OK")
            else:
                print("%% timestamps: XXX", i, data.d['samples'].d['run_timestamp'], "instead of", data_analysis.d['samples']['run_timestamp'])
54 55 56
        else:
            data_analysis = None

57
        print('%s %% %s' % (i_short, i))
Mathieu Giraud's avatar
Mathieu Giraud committed
58
        print('%%  ', data.d["reads"])
59
        segmented_reads = data.d['reads'].d['segmented'][sample]
60

61
        out = []
62
        for w in data:
63 64 65 66 67 68
            if data_analysis:
                tag = data_analysis.tag_of_clone(w)
                if not tag:
                    continue
            else:
                tag = ''
69
            reads = w.d['reads'][sample]
70 71
            ratio = float(reads)/segmented_reads
            if reads >= args.min and ratio >= args.min_ratio:
72 73
                out += [(-reads, w, tag)]
        for bla, w, tag in sorted(out[:args.top]):
74
            segmented_reads_germline = data.d['reads'].d['germline'][w.d['germline']][sample]
75
            print(w.latex(base_germline=segmented_reads_germline, base=segmented_reads, tag=tag))
76 77
        if not out:
            print(r'\\')
78

79 80 81 82
        if data_analysis:
            for c in data_analysis.missing_clones(data):
                print('%% !! %s' % c)

Mathieu Giraud's avatar
Mathieu Giraud committed
83
        print(r'  \hline')
84 85 86 87 88

if  __name__ =='__main__':
    main()