Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweaks to _AltRecord for possible multiple inheritance #64

Merged
merged 3 commits into from Jul 2, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 15 additions & 11 deletions vcf/model.py
@@ -1,3 +1,4 @@
from abc import ABCMeta, abstractmethod
import collections
import sys

Expand Down Expand Up @@ -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
Expand All @@ -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)

Expand All @@ -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.
Expand Down Expand Up @@ -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 + ">"
Expand Down
6 changes: 3 additions & 3 deletions vcf/parser.py
Expand Up @@ -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')
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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])
Expand Down