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
|
"""
Base classes for site maskers.
"""
from bx.filter import (
Filter,
Pipeline,
)
class Masker(Filter):
def __init__(self, **kwargs):
self.masked = 0
self.total = 0
Exception("Abstract class")
class MaskPipeline(Pipeline):
"""
MaskPipeline implements a Pipeline through which alignments can be
pushed and masked. Pipelines can be aggregated.
"""
def get_masked(self):
masked = 0
for masker in self.pipeline:
try:
masked += masker.masked
except AttributeError:
pass
return masked
masked = property(fget=get_masked)
def __call__(self, block):
if not block:
return
# push alignment block through all filters
self.total += len(block.components[0].text)
for masker in self.filters:
if not block:
return
try:
masker.__call__
except AttributeError:
raise Exception('Masker in pipeline does not implement "filter(self, block)".')
masker(block)
|