annotate ensembl_variant_report.py @ 2:f87fe6bc48f4 draft

planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit 6b6e5c13531bf909c4c70b7f8f9e28b4206d9068-dirty
author jjohnson
date Mon, 18 Mar 2019 21:43:34 -0400
parents a67b4de184c2
children 652d35c42bca
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
1 #!/usr/bin/env python
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
2 """
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
3 Report variants to Ensembl Transcripts
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
4
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
5 FrameShift report line
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
6 # Gene Variant Position Reference Variation Prevalence Sequencing Depth Transcript AA Position AA change AA Length Stop Codon Stop Region AA Variation
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
7 TIGD6 chr5:149374879 AAG AG 1.00 13 ENSG00000164296|ENST00000296736 345 Q344 522 A-TGA-T KRWTSSRPST*
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
8
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
9 MissSense report line
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
10 # Gene Variant Position Reference Variation Prevalence Sequencing Depth Transcript AA Position AA change AA Length Stop Codon Stop Region AA Variation
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
11 FN1 chr2:216235089 G A 1.00 7394 ENSG00000115414|ENST00000354785 2261 V2261I 2478 G-TAA TGLTRGATYN_I_IVEALKDQQR
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
12 """
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
13 import sys
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
14 import os.path
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
15 import re
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
16 import time
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
17 import optparse
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
18 from ensemblref import EnsemblRef
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
19 from Bio.Seq import reverse_complement, translate
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
20
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
21
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
22 def __main__():
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
23 #Parse Command Line
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
24 parser = optparse.OptionParser()
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
25 #I/O
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
26 parser.add_option( '-i', '--input', dest='input', default=None, help='Tabular file with peptide_sequence column' )
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
27 parser.add_option( '-s', '--format', dest='format', default='tabular', choices=['tabular','snpeff'], help='Tabular file with peptide_sequence column' )
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
28 #Columns for tabular input
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
29 parser.add_option( '-C', '--chrom_column', type='int', dest='chrom_column', default=1, help='column ordinal with Ensembl transctip ID' )
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
30 parser.add_option( '-P', '--pos_column', type='int', dest='pos_column', default=2, help='column ordinal with Ensembl transctip ID' )
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
31 parser.add_option( '-R', '--ref_column', type='int', dest='ref_column', default=3, help='column ordinal with Ensembl transctip ID' )
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
32 parser.add_option( '-A', '--alt_column', type='int', dest='alt_column', default=4, help='column ordinal with Ensembl transctip ID' )
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
33 parser.add_option( '-T', '--transcript_column', type='int', dest='transcript_column', default=1, help='column ordinal with Ensembl transctip ID' )
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
34 parser.add_option( '-F', '--dpr_column', type='int', dest='dpr_column', default=1, help='column with VCF: DPR or AD' )
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
35 parser.add_option( '-D', '--dp_column', type='int', dest='dp_column', default=1, help='column with VCF: DP' )
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
36 parser.add_option( '-g', '--gene_model', dest='gene_model', default=None, help='GTF gene model file. Used to annotate NSJ peptide entries.')
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
37 parser.add_option( '-2', '--twobit', dest='twobit', default=None, help='Reference genome in UCSC twobit format')
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
38 #Output file
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
39 parser.add_option( '-o', '--output', dest='output', default=None, help='The output report (else write to stdout)' )
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
40 #filters
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
41 parser.add_option( '-d', '--min_depth', type='int', dest='min_depth', default=None, help='Minimum read depth to report' )
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
42 parser.add_option( '-f', '--min_freq', type='float', dest='min_freq', default=None, help='Minimum variant frequency to report' )
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
43 #peptide options
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
44 parser.add_option( '-l', '--leading_aa', type='int', dest='leading_aa', default=10, help='Number AAs before missense variant' )
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
45 parser.add_option( '-t', '--trailing_aa', type='int', dest='trailing_aa', default=10, help='Number AAs after missense variant' )
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
46 parser.add_option( '-r', '--readthrough', type='int', dest='readthrough', default=0, help='' )
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
47 #
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
48 parser.add_option('--debug', dest='debug', action='store_true', default=False, help='Print debugging messages')
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
49 (options, args) = parser.parse_args()
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
50
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
51 ##INPUTS##
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
52 if options.input != None:
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
53 try:
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
54 inputPath = os.path.abspath(options.input)
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
55 inputFile = open(inputPath, 'r')
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
56 except Exception, e:
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
57 print >> sys.stderr, "failed: %s" % e
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
58 exit(2)
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
59 else:
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
60 inputFile = sys.stdin
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
61
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
62 if options.output != None:
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
63 try:
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
64 outputPath = os.path.abspath(options.output)
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
65 outputFile = open(outputPath, 'w')
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
66 except Exception, e:
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
67 print >> sys.stderr, "failed: %s" % e
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
68 exit(3)
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
69 else:
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
70 outputFile = sys.stdout
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
71
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
72 def parse_tabular():
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
73 ci = options.chrom_column - 1
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
74 pi = options.pos_column - 1
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
75 ri = options.ref_column - 1
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
76 ai = options.alt_column - 1
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
77 ti = options.transcript_column - 1
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
78 di = options.dp_column - 1
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
79 fi = options.dpr_column - 1
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
80 for linenum,line in enumerate(inputFile):
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
81 if options.debug:
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
82 print >> sys.stderr, "%d: %s\n" % (linenum,line)
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
83 if line.startswith('#'):
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
84 continue
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
85 if line.strip() == '':
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
86 continue
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
87 fields = line.rstrip('\r\n').split('\t')
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
88 transcript = fields[ti]
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
89 if not transcript:
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
90 print >> sys.stderr, "%d: %s\n" % (linenum,line)
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
91 continue
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
92 chrom = fields[ci]
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
93 pos = int(fields[pi])
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
94 ref = fields[ri]
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
95 alts = fields[ai]
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
96 dp = int(fields[di])
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
97 dpr = [int(x) for x in fields[fi].split(',')]
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
98 for i,alt in enumerate(alts.split(',')):
2
f87fe6bc48f4 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit 6b6e5c13531bf909c4c70b7f8f9e28b4206d9068-dirty
jjohnson
parents: 1
diff changeset
99 freq = float(dpr[i+1])/float(dp) if dp and dpr else \
f87fe6bc48f4 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit 6b6e5c13531bf909c4c70b7f8f9e28b4206d9068-dirty
jjohnson
parents: 1
diff changeset
100 float(dpr[i+1])/float(sum(dpr)) if dpr else None
0
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
101 yield (transcript,pos,ref,alt,dp,freq)
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
102
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
103 def parse_snpeff_vcf():
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
104 for linenum,line in enumerate(inputFile):
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
105 if line.startswith('##'):
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
106 if line.find('SnpEffVersion=') > 0:
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
107 SnpEffVersion = re.search('SnpEffVersion="?(\d+\.\d+)',line).groups()[0]
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
108 elif line.startswith('#CHROM'):
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
109 pass
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
110 else:
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
111 fields = line.strip('\r\n').split('\t')
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
112 if options.debug: print >> sys.stderr, "\n%s" % (fields)
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
113 (chrom, pos, id, ref, alts, qual, filter, info) = fields[0:8]
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
114 alt_list = alts.split(',')
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
115 pos = int(pos)
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
116 qual = float(qual)
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
117 dp = None
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
118 dpr = None
2
f87fe6bc48f4 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit 6b6e5c13531bf909c4c70b7f8f9e28b4206d9068-dirty
jjohnson
parents: 1
diff changeset
119 af = None
0
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
120 for info_item in info.split(';'):
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
121 if info_item.find('=') < 0: continue
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
122 (key, val) = info_item.split('=', 1)
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
123 if key == 'DP':
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
124 dp = int(val)
2
f87fe6bc48f4 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit 6b6e5c13531bf909c4c70b7f8f9e28b4206d9068-dirty
jjohnson
parents: 1
diff changeset
125 if key == 'DPR' or key == 'AD':
0
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
126 dpr = [int(x) for x in val.split(',')]
2
f87fe6bc48f4 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit 6b6e5c13531bf909c4c70b7f8f9e28b4206d9068-dirty
jjohnson
parents: 1
diff changeset
127 if key == 'AF':
f87fe6bc48f4 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit 6b6e5c13531bf909c4c70b7f8f9e28b4206d9068-dirty
jjohnson
parents: 1
diff changeset
128 af = [float(x) for x in val.split(',')]
0
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
129 if key in ['EFF','ANN']:
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
130 for effect in val.split(','):
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
131 if options.debug: print >> sys.stderr, "\n%s" % (effect.split('|'))
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
132 if key == 'ANN':
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
133 (alt,eff,impact,gene_name,gene_id,feature_type,transcript,biotype,exon,c_hgvs,p_hgvs,cdna,cds,aa,distance,info) = effect.split('|')
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
134 elif key == 'EFF':
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
135 (eff, effs) = effect.rstrip(')').split('(')
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
136 (impact, functional_class, codon_change, aa_change, aa_len, gene_name, biotype, coding, transcript, exon, alt) = effs.split('|')[0:11]
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
137 i = alt_list.index(alt) if alt in alt_list else 0
2
f87fe6bc48f4 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit 6b6e5c13531bf909c4c70b7f8f9e28b4206d9068-dirty
jjohnson
parents: 1
diff changeset
138 if af:
f87fe6bc48f4 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit 6b6e5c13531bf909c4c70b7f8f9e28b4206d9068-dirty
jjohnson
parents: 1
diff changeset
139 freq = af[i]
f87fe6bc48f4 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit 6b6e5c13531bf909c4c70b7f8f9e28b4206d9068-dirty
jjohnson
parents: 1
diff changeset
140 elif dpr:
f87fe6bc48f4 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit 6b6e5c13531bf909c4c70b7f8f9e28b4206d9068-dirty
jjohnson
parents: 1
diff changeset
141 freq = float(dpr[i+1])/float(dp) if dp else \
f87fe6bc48f4 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit 6b6e5c13531bf909c4c70b7f8f9e28b4206d9068-dirty
jjohnson
parents: 1
diff changeset
142 float(dpr[i+1])/float(sum(dpr))
f87fe6bc48f4 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit 6b6e5c13531bf909c4c70b7f8f9e28b4206d9068-dirty
jjohnson
parents: 1
diff changeset
143 else:
f87fe6bc48f4 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit 6b6e5c13531bf909c4c70b7f8f9e28b4206d9068-dirty
jjohnson
parents: 1
diff changeset
144 freq = None
f87fe6bc48f4 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit 6b6e5c13531bf909c4c70b7f8f9e28b4206d9068-dirty
jjohnson
parents: 1
diff changeset
145 if freq:
f87fe6bc48f4 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit 6b6e5c13531bf909c4c70b7f8f9e28b4206d9068-dirty
jjohnson
parents: 1
diff changeset
146 yield (transcript,pos,ref,alt,dp,freq)
0
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
147
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
148
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
149 #Process gene model
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
150 ens_ref = None
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
151 if options.gene_model != None:
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
152 try:
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
153 geneModelFile = os.path.abspath(options.gene_model)
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
154 twoBitFile = os.path.abspath(options.twobit)
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
155 print >> sys.stderr, "Parsing ensembl ref: %s %s" % (options.gene_model,options.twobit)
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
156 time1 = time.time()
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
157 ens_ref = EnsemblRef(geneModelFile,twoBitFile)
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
158 time2 = time.time()
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
159 print >> sys.stderr, "Parsing ensembl ref: %d seconds" % (int(time2-time1))
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
160 except Exception, e:
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
161 print >> sys.stderr, "Parsing gene model failed: %s" % e
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
162 exit(2)
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
163 try:
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
164 parse_input = parse_tabular if options.format == 'tabular' else parse_snpeff_vcf
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
165 for tid,pos1,ref,alt,dp,freq in parse_input():
1
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
166 if options.debug: print >> sys.stderr, "%s\t%d\t%s\t%s\t%d\t%f" % (tid,pos1,ref,alt,dp,freq)
0
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
167 if not tid:
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
168 continue
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
169 if options.min_depth and dp is not None and dp < options.min_depth:
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
170 continue
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
171 if options.min_freq and freq is not None and freq < options.min_freq:
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
172 continue
1
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
173 try:
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
174 ## transcript_id, pos, ref, alt, dp, dpr
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
175 tx = ens_ref.get_gtf_transcript(tid)
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
176 if not tx and tid.find('.') > 0:
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
177 tid = tid.split('.')[0]
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
178 tx = ens_ref.get_gtf_transcript(tid)
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
179 if not tx:
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
180 continue
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
181 if options.debug: print >> sys.stderr, "%s" % (tx)
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
182 coding = ens_ref.transcript_is_coding(tid)
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
183 if not coding:
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
184 continue
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
185 frame_shift = len(ref) != len(alt)
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
186 cds = ens_ref.get_cds(tid)
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
187 if options.debug or not cds: print >> sys.stderr, "cds:\n%s" % (cds)
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
188 pos0 = pos1 - 1 # zero based position
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
189 spos = pos0 if tx.gene.strand else pos0 + len(ref) - 1
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
190 alt_seq = alt if tx.gene.strand else reverse_complement(alt)
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
191 ref_seq = ref if tx.gene.strand else reverse_complement(ref)
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
192 cds_pos = ens_ref.genome_to_cds_pos(tid, spos)
2
f87fe6bc48f4 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit 6b6e5c13531bf909c4c70b7f8f9e28b4206d9068-dirty
jjohnson
parents: 1
diff changeset
193 if cds_pos is None:
f87fe6bc48f4 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit 6b6e5c13531bf909c4c70b7f8f9e28b4206d9068-dirty
jjohnson
parents: 1
diff changeset
194 continue
1
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
195 if options.debug: print >> sys.stderr, "cds_pos: %s" % (str(cds_pos))
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
196 alt_cds = cds[:cds_pos] + alt_seq + cds[cds_pos+len(ref):] if cds_pos+len(ref) < len(cds) else ''
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
197 offset = 0
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
198 if tx.gene.strand:
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
199 for i in range(min(len(ref),len(alt))):
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
200 if ref[i] == alt[i]:
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
201 offset = i
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
202 else:
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
203 break
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
204 else:
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
205 for i in range(-1,-min(len(ref),len(alt)) -1,-1):
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
206 if ref[i] == alt[i]:
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
207 offset = i
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
208 else:
0
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
209 break
1
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
210 refpep = translate(cds[:len(cds)/3*3])
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
211 pep = translate(alt_cds[:len(alt_cds)/3*3])
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
212 peplen = len(pep)
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
213 aa_pos = (cds_pos + offset) / 3
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
214 reported_stop_codon = ''
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
215 if aa_pos >= len(pep):
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
216 print >> sys.stderr, "aa_pos %d >= peptide length %d : %s %d %s %s" % (aa_pos,len(pep),tid,pos1,ref,alt)
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
217 continue
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
218 if frame_shift:
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
219 #find stop_codons
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
220 nstops = 0
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
221 stop_codons = []
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
222 for i in range(aa_pos,peplen):
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
223 if refpep[i] != pep[i]:
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
224 aa_pos = i
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
225 break
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
226 reported_peptide = pep[aa_pos:]
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
227 for i in range(aa_pos,peplen):
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
228 if pep[i] == '*':
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
229 nstops += 1
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
230 stop_codons.append("%s-%s%s" % (alt_cds[i*3-1],alt_cds[i*3:i*3+3],"-%s" % alt_cds[i*3+4] if len(alt_cds) > i*3 else ''))
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
231 if nstops > options.readthrough:
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
232 reported_peptide = pep[aa_pos:i+1]
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
233 reported_stop_codon = ','.join(stop_codons)
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
234 break
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
235 else:
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
236 reported_stop_codon = "%s-%s" % (alt_cds[peplen*3-4],alt_cds[peplen*3-3:peplen*3])
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
237 reported_peptide = "%s_%s_%s" % (pep[max(aa_pos-options.leading_aa,0):aa_pos],
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
238 pep[aa_pos],
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
239 pep[aa_pos+1:min(aa_pos+1+options.trailing_aa,len(pep))])
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
240 cs_pos = aa_pos * 3
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
241 aa_pos = (cds_pos + offset) / 3
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
242 ref_codon = cds[cs_pos:cs_pos+3]
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
243 ref_aa = translate(ref_codon)
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
244 alt_codon = alt_cds[cs_pos:cs_pos+3]
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
245 alt_aa = translate(alt_codon)
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
246 gene = tx.gene.names[0]
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
247 report_fields = [tx.gene.names[0],
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
248 '%s:%d %s' % (tx.gene.contig,pos1,'+' if tx.gene.strand else '-'),
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
249 ref_seq,
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
250 alt_seq,
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
251 "%1.2f" % freq if freq is not None else '',
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
252 str(dp),
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
253 "%s|%s" % (tx.gene.gene_id,tx.cdna_id),
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
254 "%d" % (aa_pos + 1),
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
255 "%s%d%s" % (ref_aa,aa_pos + 1,alt_aa),
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
256 "%d" % len(pep),
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
257 reported_stop_codon,
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
258 reported_peptide,
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
259 tx.get_transcript_type_name()
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
260 ]
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
261 if options.debug:
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
262 report_fields.append("%d %d %d %d %s %s" % (cds_pos, offset, cs_pos,aa_pos,ref_codon,alt_codon))
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
263 outputFile.write('\t'.join(report_fields))
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
264 if options.debug:
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
265 print >> sys.stderr, "%s %s\n%s\n%s\n%s %s" % (
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
266 cds[cs_pos-6:cs_pos], cds[cs_pos:cs_pos+15],
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
267 translate(cds[cs_pos-6:cs_pos+15]),
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
268 translate(alt_cds[cs_pos-6:cs_pos+15]),
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
269 alt_cds[cs_pos-6:cs_pos], alt_cds[cs_pos:cs_pos+15])
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
270 outputFile.write('\n')
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
271 except Exception, e:
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
272 print >> sys.stderr, "failed: %s" % e
a67b4de184c2 planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit b62e927469f96a857e880c77530c50c885ad92fc-dirty
jjohnson
parents: 0
diff changeset
273 print >> sys.stderr, "%s\t%d\t%s\t%s\t%d\t%f\t%s" % (tid,pos1,ref,alt,dp,freq,e)
0
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
274 except Exception, e:
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
275 print >> sys.stderr, "failed: %s" % e
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
276 exit(1)
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
277
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
278
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
279 if __name__ == "__main__" : __main__()
9f4ea174ce3d planemo upload for repository https://github.com/jj-umn/galaxytools/tree/master/ensembl_variant_report commit e6aa05bbbee3cc7d98f16354fc41c674f439ff1b-dirty
jjohnson
parents:
diff changeset
280