Created
July 1, 2012 17:27
-
-
Save lennax/3029028 to your computer and use it in GitHub Desktop.
Quick example of multiple inheritance for alts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
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