annotate ngsutils/support/dbsnp.py @ 0:4e4e4093d65d draft

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
author iuc
date Wed, 11 Nov 2015 13:04:07 -0500
parents
children 7a68005de299
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
1 '''
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
2 Support package for processing a dbSNP tabix dump from UCSC.
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
3 '''
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
4
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
5 import pysam
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
6 import collections
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
7 import sys
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
8 from ngsutils.support import revcomp
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
9
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
10
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
11 class SNPRecord(collections.namedtuple('SNPRecord', '''bin
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
12 chrom
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
13 chromStart
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
14 chromEnd
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
15 name
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
16 score
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
17 strand
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
18 refNCBI
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
19 refUCSC
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
20 observed
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
21 molType
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
22 clazz
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
23 valid
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
24 avHet
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
25 avHetSE
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
26 func
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
27 locType
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
28 weight
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
29 exceptions
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
30 submitterCount
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
31 submitters
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
32 alleleFreqCount
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
33 alleles
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
34 alleleNs
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
35 alleleFreqs
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
36 bitfields
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
37 ''')):
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
38 __slots__ = ()
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
39
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
40 @property
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
41 def alleles(self):
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
42 alts = []
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
43 for alt in self.observed.split('/'):
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
44 if alt != '-' and self.strand == '-':
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
45 alt = revcomp(alt)
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
46
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
47 alts.append(alt)
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
48
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
49 return alts
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
50
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
51 @property
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
52 def snp_length(self):
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
53 return self.chromEnd - self.chromStart
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
54
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
55
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
56 def autotype(ar, length=26):
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
57 out = []
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
58 for el in ar:
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
59 val = None
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
60 try:
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
61 val = int(el)
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
62 except:
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
63 try:
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
64 val = float(el)
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
65 except:
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
66 val = el
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
67
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
68 out.append(val)
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
69
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
70 if len(out) < 12:
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
71 raise TypeError("Invalid dbSNP file! We need at least 12 columns to work with.")
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
72
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
73 while len(out) < length:
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
74 out.append(None)
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
75 return out
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
76
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
77
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
78 class DBSNP(object):
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
79 def __init__(self, fname):
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
80 self.dbsnp = pysam.Tabixfile(fname)
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
81 self.asTup = pysam.asTuple()
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
82
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
83 def fetch(self, chrom, pos):
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
84 'Note: pos is 0-based'
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
85
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
86 # Note: tabix the command uses 1-based positions, but
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
87 # pysam.Tabixfile uses 0-based positions
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
88
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
89 for tup in self.dbsnp.fetch(chrom, pos, pos + 1, parser=self.asTup):
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
90 snp = SNPRecord._make(autotype(tup))
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
91 if snp.chromStart == pos:
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
92 yield snp
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
93
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
94 def close(self):
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
95 self.dbsnp.close()
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
96
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
97 def dump(self, chrom, op, pos, base, snp, exit=True):
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
98 print
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
99 print ' ->', op, chrom, pos, base
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
100 print snp
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
101 print snp.alleles
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
102 if exit:
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
103 sys.exit(1)
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
104
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
105 def is_valid_variation(self, chrom, op, pos, seq, verbose=False):
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
106 for snp in self.fetch(chrom, pos):
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
107 if not '/' in snp.observed or snp.clazz not in ['single', 'mixed', 'in-del', 'insertion', 'deletion']:
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
108 # these are odd variations that we can't deal with... (microsatellites, tooLongToDisplay members, etc)
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
109 continue
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
110
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
111 if op == 0:
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
112 if snp.clazz in ['single', 'mixed'] and seq in snp.alleles:
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
113 return True
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
114 # elif verbose:
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
115 # for alt in snp.alleles:
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
116 # if len(alt) > 1:
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
117 # self.dump(chrom, op, pos, seq, snp, False)
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
118
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
119 elif op == 1:
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
120 if snp.clazz in ['insertion', 'mixed', 'in-del']:
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
121 if seq in snp.alleles:
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
122 if len(seq) > 1 and verbose:
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
123 self.dump(chrom, op, pos, seq, snp, False)
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
124 return True
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
125
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
126 if verbose:
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
127 if len(seq) > 1:
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
128 self.dump(chrom, op, pos, seq, snp, False)
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
129 else:
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
130 for alt in snp.alleles:
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
131 if len(alt) > 1:
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
132 self.dump(chrom, op, pos, seq, snp, False)
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
133
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
134 elif op == 2:
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
135 if snp.clazz in ['deletion', 'mixed', 'in-del']:
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
136 if '-' in snp.alleles and seq in snp.alleles:
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
137 if len(seq) > 1 and verbose:
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
138 self.dump(chrom, op, pos, seq, snp, False)
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
139 return True
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
140
4e4e4093d65d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 09194687c74a424732f8b0c017cbb942aad89068
iuc
parents:
diff changeset
141 return False