-
Notifications
You must be signed in to change notification settings - Fork 17
/
VCF.py
69 lines (56 loc) · 1.64 KB
/
VCF.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import re
from GenomeCoordinate import GenomeCoord
class VCFCol:
names=['CHROM',
'POS',
'ID',
'REF',
'ALT',
'QUAL',
'FILTER',
'INFO',
'FORMAT',
'SAMPLE']
CHROM=0
POS=1
ID=2
REF=3
ALT=4
QUAL=5
FILTER=6
INFO=7
FORMAT=8
SAMPLE=9
#---
@staticmethod
def get_info (E, name):
elements = E[VCFCol.INFO].split(';')
for ele in elements:
if re.search (name+'=', ele):
fields = ele.split('=')
return fields[1]
return None
#####################################################################
class VcfRecord:
def __init__ ( self, E, sample, index = None ):
self.coord = GenomeCoord ( E[VCFCol.CHROM], E[VCFCol.POS] )
self.E = E
self.sample= sample # from which sample this call is from; setup from the beginning and will be passed on
self.index = index # from which file the record coming from
def get_record ( self ):
return '\t'.join(self.E)
def __getitem__ ( self, id ):
return self.E[id]
def __str__ ( self ):
return str (self.coord)
def __eq__ ( self, other ):
return self.coord == other.coord
def __gt__ ( self, other ):
return self.coord > other.coord
def __lt__ ( self, other ):
return self.coord < other.coord
def __ge__ ( self, other ):
return self.coord >= other.coord
def __le__ ( self, other ):
return self.coord <= other.coord
# ------------------------------------------------------------------- |