예제 #1
0
파일: base.py 프로젝트: wkopp/CoolBox
    def __add__(self, other):
        from ..track.base import Track
        from ..frame.base import FrameBase
        from ..feature import Feature

        if isinstance(other, Track):
            result = copy(other)
            result.append_coverage(self)
            return result
        elif isinstance(other, FrameBase):
            result = copy(other)
            if len(result.tracks) > 1:
                first = list(result.tracks.values())[0]
                first.append_coverage(self, pos='bottom')
            return result
        elif isinstance(other, Feature):
            result = copy(self)
            result.properties.update(other.properties)
            return result
        elif isinstance(other, Coverage):
            stack = CoverageStack([self, other])
            return stack
        elif isinstance(other, CoverageStack):
            result = copy(other)
            result.to_bottom(self)
            return result
        else:
            raise TypeError(op_err_msg(self, other))
예제 #2
0
    def __add__(self, other):
        from .track.base import Track
        from .frame.base import FrameBase
        from .coverage.base import Coverage
        from .coverage.base import CoverageStack

        if (isinstance(other, Track) or not isinstance(other, FrameBase)
                and isinstance(other, Coverage)):
            result = copy(other)
            result.properties.update(self.properties)
            return result
        elif isinstance(other, FrameBase):
            result = copy(other)
            if len(result.tracks) != 0:
                first = list(result.tracks.values())[0]
                first.properties.update(self.properties)
            return result
        elif isinstance(other, CoverageStack):
            result = copy(other)
            if len(result.coverages) != 0:
                first = result.coverages[0]
                first.properties.update(self.properties)
            return result
        else:
            raise TypeError(op_err_msg(self, other))
예제 #3
0
파일: base.py 프로젝트: nvictus/CoolBox
    def __mul__(self, other):
        """
        Examples
        --------
        >>> from coolbox.core.track import XAxis, BigWig
        >>> from coolbox.core.coverage import HighLights
        >>> from coolbox.core.feature import Color

        Rule: Frame * Feature == Frame
        >>> f = XAxis() + BigWig("tests/test_data/bigwig_chrx_2e6_5e6.bw")
        >>> f = f * Color("#ff9c9c")
        >>> assert all([track.properties['color'] == '#ff9c9c' for track in f.tracks.values()])

        Rule: Frame * Coverage == Frame
        >>> cov = HighLights([('chr1', 1000, 2000)])
        >>> f = f * cov
        >>> assert all([track.coverages[0] is cov for track in f.tracks.values()])

        """
        from ..coverage.base import Coverage
        from ..feature import Feature

        if isinstance(other, Coverage):
            result = copy(self)
            result.add_cov_to_tracks(other)
            return result
        elif isinstance(other, Feature):
            result = copy(self)
            result.add_feature_to_tracks(other)
            return result
        else:
            raise TypeError(op_err_msg(self, other, op='*'))
예제 #4
0
파일: base.py 프로젝트: wkopp/CoolBox
    def __add__(self, other):
        from ..track.base import Track
        from ..frame.base import FrameBase
        from ..feature import Feature

        if isinstance(other, Coverage):
            result = copy(self)
            result.to_top(other)
            return result
        elif isinstance(other, Track):
            result = copy(other)
            result.pile_coverages(self.coverages, pos='bottom')
            return result
        elif isinstance(other, FrameBase):
            result = copy(other)
            if len(result.tracks) != 0:
                first = list(result.tracks.values())[0]
                first.pile_coverages(self.coverages, pos='bottom')
            return result
        elif isinstance(other, Feature):
            result = copy(self)
            if len(result.coverages) != 0:
                last = result.coverages[-1]
                last.properties.update(other.properties)
            return result
        else:
            raise TypeError(op_err_msg(self, other))
예제 #5
0
    def __add__(self, other):
        from ..frame import Frame
        from ..coverage.base import Coverage
        from ..coverage.base import CoverageStack
        from ..feature import Feature

        if isinstance(other, Track):
            result = Frame()
            result.add_track(self)
            result.add_track(other)
            return result
        elif isinstance(other, Frame):
            result = copy(other)
            result.add_track(self, pos='head')
            return result
        elif isinstance(other, Feature):
            result = copy(self)
            return other.__add__(result)
        elif isinstance(other, Coverage):
            result = copy(self)
            result.append_coverage(other)
            return result
        elif isinstance(other, CoverageStack):
            result = copy(self)
            result.pile_coverages(other.coverages, pos='top')
            return result
        else:
            raise TypeError(op_err_msg(self, other))
예제 #6
0
파일: feature.py 프로젝트: pythseq/CoolBox
    def __add__(self, other):
        from .track import Track
        from .frame import Frame
        from .coverage import Coverage
        from .coverage import CoverageStack

        if isinstance(other, Track):
            result = copy(other)
            result.properties[self.key] = self.value
            return result
        elif isinstance(other, Frame):
            result = copy(other)
            if len(result.tracks) != 0:
                first = list(result.tracks.values())[0]
                first.properties[self.key] = self.value
            return result
        elif isinstance(other, Coverage):
            result = copy(other)
            result.properties[self.key] = self.value
            return result
        elif isinstance(other, CoverageStack):
            result = copy(other)
            if len(result.coverages) != 0:
                first = result.coverages[0]
                first[self.key] = self.value
            return result
        else:
            raise TypeError(op_err_msg(self, other))
예제 #7
0
파일: base.py 프로젝트: wkopp/CoolBox
 def __mul__(self, other):
     from ..frame.base import FrameBase
     if isinstance(other, FrameBase):
         result = copy(other)
         result.add_cov_to_tracks(self)
         return result
     else:
         raise TypeError(op_err_msg(self, other, op='*'))
예제 #8
0
    def __add__(self, other):
        from .frame import Frame

        if isinstance(other, Frame):
            result = copy(other)
            result.properties[self.key] = self.value
            return result
        else:
            raise TypeError(op_err_msg(self, other))
예제 #9
0
    def __add__(self, other):
        from .frame.base import FrameBase

        if not isinstance(other, FrameBase):
            raise TypeError(op_err_msg(self, other))

        properties = self.properties.copy()
        properties.update(other.properties)
        result = copy(other)
        result.properties = properties
        return result
예제 #10
0
파일: browser.py 프로젝트: pythseq/CoolBox
    def __add__(self, other):
        """

        >>>

        """
        from .frame import Frame
        if isinstance(other, Frame):
            return Browser(other,
                           reference_genome=self.ref,
                           widgets_box=self.type)
        else:
            raise TypeError(op_err_msg(self, other, op="+"))
예제 #11
0
파일: base.py 프로젝트: nvictus/CoolBox
    def __add__(self, other):
        """
        Examples
        --------
        >>> from coolbox.api import *
        >>> frame1 = Frame()
        >>> frame2 = Frame()

        Rule: Frame + Track == Frame
        >>> frame3 = (frame1 + XAxis())
        >>> isinstance(frame3, Frame)
        True
        >>> len(frame3.tracks)
        1

        Rule: Frame + Frame == Frame
        >>> isinstance(frame1 + frame2, Frame)
        True

        Rule: Frame + Feature == Frame
        >>> f = XAxis() + BigWig("tests/test_data/bigwig_chrx_2e6_5e6.bw")
        >>> f = f + Color('#66ccff')
        >>> isinstance(f, Frame)
        True
        >>> 'color' not in list(f.tracks.values())[0].properties
        True
        >>> list(f.tracks.values())[1].properties['color']
        '#66ccff'

        Rule: Frame + Coverage == Frame
        >>> f = XAxis() + BigWig("tests/test_data/bigwig_chrx_2e6_5e6.bw")
        >>> highlight = HighLights([("chr1", 1000, 2000), ("chr2", 3000, 4000)])
        >>> f = f + highlight
        >>> isinstance(f, Frame)
        True
        >>> len(list(f.tracks.values())[0].coverages)
        0
        >>> list(f.tracks.values())[1].coverages[0] is highlight
        True

        Rule: Frame + CoverageStack == Frame
        >>> cov_stack = HighLights([("chr1", 1000, 2000)]) + HighLights([("chr1", 4000, 6000)])
        >>> f = XAxis() + XAxis()
        >>> f = f + cov_stack
        >>> isinstance(f, Frame)
        True
        >>> len(list(f.tracks.values())[0].coverages)
        0
        >>> len(list(f.tracks.values())[1].coverages)
        2

        Rule: Frame + WidgetsPanel == Browser
        >>> f = XAxis() + XAxis()
        >>> bsr = f + WidgetsPanel()
        >>> isinstance(bsr, Browser)
        True

        >>> f + 1 # error operation
        Traceback (most recent call last):
        ...
        TypeError: unsupported operand type(s) for +: '<class 'coolbox.core.frame.Frame'>' and '<class 'int'>'


        """
        from ..track.base import Track
        from ..feature import Feature, FrameFeature
        from ..coverage.base import Coverage, CoverageStack
        from ..browser import WidgetsPanel, Browser

        result = copy(self)

        if isinstance(other, Track):
            result.add_track(other)
            return result
        elif isinstance(other, FrameBase):
            for track in other.tracks.values():
                result.add_track(track)
            result.properties.update(other.properties)
            return result
        elif isinstance(other, FrameFeature):
            result.properties.update(other.properties)
            return result
        elif isinstance(other, Feature):
            if len(result.tracks) != 0:
                last = list(result.tracks.values())[-1]
                last.properties.update(other.properties)
            return result
        elif isinstance(other, Coverage):
            if len(result.tracks) != 0:
                last = list(result.tracks.values())[-1]
                last.append_coverage(other)
            return result
        elif isinstance(other, CoverageStack):
            if len(result.tracks) != 0:
                last = list(result.tracks.values())[-1]
                last.pile_coverages(other.coverages, pos='top')
            return result
        elif isinstance(other, WidgetsPanel):
            return Browser(self,
                           reference_genome=other.ref,
                           widgets_box=other.type)
        else:
            raise TypeError(op_err_msg(self, other))