Skip to content

Instantly share code, notes, and snippets.

@lennax
Created July 1, 2012 17:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lennax/3029028 to your computer and use it in GitHub Desktop.
Save lennax/3029028 to your computer and use it in GitHub Desktop.
Quick example of multiple inheritance for alts
class _AltRecord(object):
def __init__(self, alt_type, **kwargs):
print "_AltRecord"
super(_AltRecord, self).__init__(**kwargs)
self.alt_type = alt_type
class _Substitution(_AltRecord):
def __init__(self, sequence, **kwargs):
print "_Substitution"
if len(sequence) == 1:
super(_Substitution, self).__init__(alt_type="SNV", **kwargs)
else:
super(_Substitution, self).__init__(alt_type="MNV", **kwargs)
self.sequence = sequence
class _Unknown(object):
def __init__(self, unknown=True, **kwargs):
print "_Unknown"
super(_Unknown, self).__init__(**kwargs)
self.unknown = unknown
class _UnknownSubs(_Unknown, _Substitution):
def __init__(self, sequence, **kwargs):
print "_UnknownSubs"
super(_UnknownSubs, self).__init__(sequence=sequence, **kwargs)
print self.sequence, self.alt_type, self.unknown
def test(cl, **kwargs):
print "MRO:", [x.__name__ for x in cl.__mro__]
print "Calls:",
cl(**kwargs)
print
if __name__ == "__main__":
#test(_AltRecord, alt_type="x")
#test(_Substitution, sequence="ATG")
#test(_Unknown)
test(_UnknownSubs, sequence="G")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment