Permalink
Browse files

Merge pull request #64 from lennax/lenna

Tweaks to _AltRecord for possible multiple inheritance
  • Loading branch information...
2 parents 2b85497 + 99d3453 commit 6e91990ed39573a2eec6cea8788b3c5d120b2df7 James Casbon committed Jul 2, 2012
Showing with 18 additions and 14 deletions.
  1. +15 −11 vcf/model.py
  2. +3 −3 vcf/parser.py
View
@@ -1,3 +1,4 @@
+from abc import ABCMeta, abstractmethod
import collections
import sys
@@ -408,13 +409,16 @@ def is_monomorphic(self):
class _AltRecord(object):
'''An alternative allele record: either replacement string, SV placeholder, or breakend'''
+ __metaclass__ = ABCMeta
- def __init__(self, type):
+ def __init__(self, type, **kwargs):
+ super(_AltRecord, self).__init__(**kwargs)
#: String to describe the type of variant, by default "SNV" or "MNV", but can be extended to any of the types described in the ALT lines of the header (e.g. "DUP", "DEL", "INS"...)
self.type = type
+ @abstractmethod
def __str__(self):
- assert False, "_AltRecord is an abstract class, you should be using a subclass instead"
+ raise NotImplementedError
def __eq__(self, other):
return self.type == other.type
@@ -423,11 +427,11 @@ def __eq__(self, other):
class _Substitution(_AltRecord):
'''A basic ALT record, where a REF sequence is replaced by an ALT sequence'''
- def __init__(self, nucleotides):
+ def __init__(self, nucleotides, **kwargs):
if len(nucleotides) == 1:
- super(_Substitution, self).__init__("SNV")
+ super(_Substitution, self).__init__(type="SNV", **kwargs)
else:
- super(_Substitution, self).__init__("MNV")
+ super(_Substitution, self).__init__(type="MNV", **kwargs)
#: Alternate sequence
self.sequence = str(nucleotides)
@@ -450,8 +454,8 @@ def __eq__(self, other):
class _Breakend(_AltRecord):
'''A breakend which is paired to a remote location on or off the genome'''
- def __init__(self, chr, pos, orientation, remoteOrientation, connectingSequence, withinMainAssembly):
- super(_Breakend, self).__init__("BND")
+ def __init__(self, chr, pos, orientation, remoteOrientation, connectingSequence, withinMainAssembly, **kwargs):
+ super(_Breakend, self).__init__(type="BND", **kwargs)
#: The chromosome of breakend's mate.
self.chr = str(chr)
#: The coordinate of breakend's mate.
@@ -499,15 +503,15 @@ def __eq__(self, other):
class _SingleBreakend(_Breakend):
'''A single breakend'''
- def __init__(self, orientation, connectingSequence):
- super(_SingleBreakend, self).__init__(None, None, orientation, None, connectingSequence, None)
+ def __init__(self, orientation, connectingSequence, **kwargs):
+ super(_SingleBreakend, self).__init__(None, None, orientation, None, connectingSequence, None, **kwargs)
class _SV(_AltRecord):
'''An SV placeholder'''
- def __init__(self, type):
- super(_SV, self).__init__(type)
+ def __init__(self, type, **kwargs):
+ super(_SV, self).__init__(type, **kwargs)
def __str__(self):
return "<" + self.type + ">"
View
@@ -179,7 +179,7 @@ def __init__(self, fsock=None, filename=None, compressed=False, prepend_chr=Fals
or files are attempted to be recogized by the file extension, or gzipped
can be forced with ``compressed=True``
"""
- super(VCFReader, self).__init__()
+ super(Reader, self).__init__()
if not (fsock or filename):
raise Exception('You must provide at least fsock or filename')
@@ -405,7 +405,7 @@ def _parse_samples(self, samples, samp_fmt, site):
return samp_data
- def parseALT(self, str):
+ def _parse_alt(self, str):
if re.search('[\[\]]', str) is not None:
# Paired breakend
items = re.split('[\[\]]', str)
@@ -448,7 +448,7 @@ def next(self):
ID = None
ref = row[3]
- alt = self._map(self.parseALT, row[4].split(','))
+ alt = self._map(self._parse_alt, row[4].split(','))
try:
qual = int(row[5])

0 comments on commit 6e91990

Please sign in to comment.