File: core.py

package info (click to toggle)
python-bx 0.13.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,000 kB
  • sloc: python: 17,136; ansic: 2,326; makefile: 24; sh: 8
file content (47 lines) | stat: -rw-r--r-- 1,130 bytes parent folder | download
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)