Exemplo n.º 1
0
    def dolayout(self, scaleFactor, spacing):
        # coordinates are in pixels not base pairs
        self.rows = [None]

        self._annos = []
        for part in self.chromPartsCollection:
            segmentStart = self.scale.partsToStartPixels[part.id]

            for segment in variants.mergedSegments(part.segments):
                curWidth = len(segment)
                curAnnos = self.annotationSet.getAnnotations(segment.chrom,
                                                             segment.start,
                                                             segment.end,
                                                             clip=True)
                if segment.strand == "-":
                    curAnnos = sorted(curAnnos,
                                      key=lambda x: x.end,
                                      reverse=True)

                for anno in curAnnos:
                    start = max(anno.start, segment.start)
                    end = min(anno.end, segment.end)

                    start = self._topixels(start, segment, segmentStart)
                    end = self._topixels(end, segment, segmentStart)
                    if end < start:
                        start, end = end, start
                    textLength = len(
                        anno.label
                    ) * self.rowheight / 1.0 * scaleFactor * spacing
                    rowNum = self.findRow(start, end + textLength)

                    anno.coords = {}
                    anno.coords["row"] = rowNum
                    anno.coords["start"] = start
                    anno.coords["end"] = end
                    anno.coords[
                        "strand"] = anno.strand if segment.strand == "+" else utilities.switchStrand(
                            anno.strand)
                    anno.coords["segment"] = segment
                    anno.coords["segmentStart"] = segmentStart

                    self._annos.append(anno)

                segmentStart += self.scale.relpixels(curWidth)
Exemplo n.º 2
0
    def dolayout(self, scaleFactor, spacing):
        # coordinates are in pixels not base pairs
        self.rows = [None]

        self._annos = []
        for part in self.chromPartsCollection:
            segmentStart = self.scale.partsToStartPixels[part.id]

            for segment in variants.mergedSegments(part.segments):
                curWidth = len(segment)
                curAnnos = self.annotationSet.getAnnotations(segment.chrom, segment.start, segment.end, clip=True)
                if segment.strand == "-":
                    curAnnos = sorted(curAnnos, key=lambda x:x.end, reverse=True)

                for anno in curAnnos:
                    start = max(anno.start, segment.start)
                    end = min(anno.end, segment.end)

                    start = self._topixels(start, segment, segmentStart)
                    end = self._topixels(end, segment, segmentStart)
                    if end < start:
                        start, end = end, start
                    textLength = len(anno.name)*self.rowheight/1.0*scaleFactor*spacing
                    rowNum = self.findRow(start, end+textLength)

                    anno.coords = {}
                    anno.coords["row"] = rowNum
                    anno.coords["start"] = start
                    anno.coords["end"] = end
                    anno.coords["strand"] = anno.strand if segment.strand=="+" else utilities.switchStrand(anno.strand)
                    anno.coords["segment"] = segment
                    anno.coords["segmentStart"] = segmentStart

                    self._annos.append(anno)

                segmentStart += self.scale.relpixels(curWidth)
Exemplo n.º 3
0
    def __str__(self):
        return "(" + self._chr + ":" + str(self.start()) + "-" + str(
            self.end()) + self._strand + ")"


if __name__ == '__main__':
    # loci = [Locus("chr1", 10, 20, "+"),
    #         Locus("chr1", 18, 22, "+"),
    #         Locus("chr1", 22, 25, "+"),
    #         Locus("chr1", 27, 30, "+"),
    #         Locus("chr1", 28, 31, "+"),
    #         Locus("chr1", 35, 40, "+"),
    #         Locus("chr1", 42, 45, "+"),
    #         Locus("chr1", 43, 44, "+")]

    # print unionLoci(loci)

    from svviz.variants import Segment, mergedSegments
    segments = [
        Segment("chr100", 1, 3, "+", 0),
        Segment("chr100", 5, 9, "+", 1),
        Segment("chr100", 11, 15, "+", 2),
        Segment("chr100", 17, 19, "+", 3),
        Segment("chr100", 21, 31, "+", 4),
        Segment("chr100", 33, 34, "+", 5)
    ]

    print segments
    print mergedSegments(segments)
Exemplo n.º 4
0
    def __str__(self):
        return "(" + self._chr + ":" + str(self.start()) + "-" + str(
            self.end()) + self._strand + ")"


if __name__ == '__main__':
    # loci = [Locus("chr1", 10, 20, "+"),
    #         Locus("chr1", 18, 22, "+"),
    #         Locus("chr1", 22, 25, "+"),
    #         Locus("chr1", 27, 30, "+"),
    #         Locus("chr1", 28, 31, "+"),
    #         Locus("chr1", 35, 40, "+"),
    #         Locus("chr1", 42, 45, "+"),
    #         Locus("chr1", 43, 44, "+")]

    # print unionLoci(loci)

    from svviz.variants import Segment, mergedSegments
    segments = [
        Segment("chr100", 1, 3, "+", 0),
        Segment("chr100", 5, 9, "+", 1),
        Segment("chr100", 11, 15, "+", 2),
        Segment("chr100", 17, 19, "+", 3),
        Segment("chr100", 21, 31, "+", 4),
        Segment("chr100", 33, 34, "+", 5)
    ]

    print(segments)
    print(mergedSegments(segments))
Exemplo n.º 5
0
    
    def __repr__(self):
        return "Locus%s"%str(self)

    def __str__(self):
        return "(" + self._chr +":" + str(self.start()) + "-" + str(self.end()) + self._strand + ")"

if __name__ == '__main__':
    # loci = [Locus("chr1", 10, 20, "+"),
    #         Locus("chr1", 18, 22, "+"),
    #         Locus("chr1", 22, 25, "+"),
    #         Locus("chr1", 27, 30, "+"),
    #         Locus("chr1", 28, 31, "+"),
    #         Locus("chr1", 35, 40, "+"),
    #         Locus("chr1", 42, 45, "+"),
    #         Locus("chr1", 43, 44, "+")]

    # print unionLoci(loci)

    from svviz.variants import Segment, mergedSegments
    segments = [Segment("chr100", 1,3, "+", 0),
                Segment("chr100", 5, 9, "+", 1), 
                Segment("chr100", 11, 15, "+", 2), 
                Segment("chr100", 17, 19, "+", 3), 
                Segment("chr100", 21, 31, "+", 4),
                Segment("chr100", 33, 34, "+", 5)]

    print(segments)
    print(mergedSegments(segments))

Exemplo n.º 6
0
    
    def __repr__(self):
        return "Locus%s"%str(self)

    def __str__(self):
        return "(" + self._chr +":" + str(self.start()) + "-" + str(self.end()) + self._strand + ")"

if __name__ == '__main__':
    # loci = [Locus("chr1", 10, 20, "+"),
    #         Locus("chr1", 18, 22, "+"),
    #         Locus("chr1", 22, 25, "+"),
    #         Locus("chr1", 27, 30, "+"),
    #         Locus("chr1", 28, 31, "+"),
    #         Locus("chr1", 35, 40, "+"),
    #         Locus("chr1", 42, 45, "+"),
    #         Locus("chr1", 43, 44, "+")]

    # print unionLoci(loci)

    from svviz.variants import Segment, mergedSegments
    segments = [Segment("chr100", 1,3, "+", 0),
                Segment("chr100", 5, 9, "+", 1), 
                Segment("chr100", 11, 15, "+", 2), 
                Segment("chr100", 17, 19, "+", 3), 
                Segment("chr100", 21, 31, "+", 4),
                Segment("chr100", 33, 34, "+", 5)]

    print segments
    print mergedSegments(segments)