annotate_leafcutter_events.py 1.57 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
#!/usr/bin/python

### GAD PIPELINE ###
## annotate_leafcutter_events.py
## Description : annotate a SJ file with omim entries
## Usage : python annotate_leafcutter_events -i <leafcutter report> -o <output file> -d <omim file>
## Output : a tabulated leafcutter file including omim annotation
## Requirements : python 2.7, leafcutter output files

## Author : Emilie.Tisserant@u-bourgogne.fr, yannis.duffourd@u-bourgogne.fr
## Creation Date : 20170331
## last revision date : 20201021
## Known bugs : None

import getopt
import os
import sys


# Options
try:
    opts, args = getopt.getopt(sys.argv[1:], 'd:i:o:')
    for opt, arg in opts:
        if opt in ("-d"):
            omim = arg
        elif opt in ("-i"):
            filein = arg
        elif opt in ("-o"):
            sys.stdout = open(arg, 'w')
except getopt.GetoptError:
    print 'usage : '
    sys.exit(1)


omim_dict = {}
stream = open(omim, 'r')
for line in stream:
    line = line.strip()
    tabs = line.split('\t')
    omim_dict[tabs[0]] = tabs[1]
stream.close()


#Annotate variants
stream = open(filein, 'r')
for line in stream:
    line = line.strip()
    tabs = line.split('\t')
    if not line.startswith('cluster'):
        genelist = []
        gl = tabs[6].split(",")
        tag = 0
        for g in gl:
            if g in omim_dict:
                genelist.append(omim_dict[g])
                tag += 1
            else:
                genelist.append(".")
        if tag > 0:
            print line+"\t"+",".join(genelist)
        else:
            print line+"\t."
    else:
        print line+"\tOMIM"
stream.close()