1 | """ |
---|
2 | Base classes for site maskers. |
---|
3 | """ |
---|
4 | |
---|
5 | from bx.filter import * |
---|
6 | |
---|
7 | class Masker( Filter ): |
---|
8 | def __init__( self, **kwargs ): |
---|
9 | self.masked = 0 |
---|
10 | self.total = 0 |
---|
11 | Exception("Abstract class") |
---|
12 | |
---|
13 | class MaskPipeline( Pipeline ): |
---|
14 | """ |
---|
15 | MaskPipeline implements a Pipeline through which alignments can be |
---|
16 | pushed and masked. Pipelines can be aggregated. |
---|
17 | """ |
---|
18 | def get_masked( self ): |
---|
19 | masked = 0 |
---|
20 | for function in self.pipeline: |
---|
21 | try: masked += masker.masked |
---|
22 | except AttributeError: pass |
---|
23 | return masked |
---|
24 | masked = property( fget=get_masked ) |
---|
25 | |
---|
26 | def __call__( self, block ): |
---|
27 | if not block: return |
---|
28 | # push alignment block through all filters |
---|
29 | self.total += len( block.components[0].text ) |
---|
30 | for masker in self.filters: |
---|
31 | if not block: return |
---|
32 | try: m_filter = masker.__call__ |
---|
33 | except AttributeError: |
---|
34 | raise Exception("Masker in pipeline does not implement \"filter( self, block )\".") |
---|
35 | masker( block ) |
---|