Пример #1
0
    def _make_ref_map(self):
        if self.aln_map and self.aln_loc is not None:
            return

        ref_record = self._cached
        record_start = ref_record["dnafrag_start"]
        record_end = ref_record["dnafrag_end"]
        record_strand = ref_record["dnafrag_strand"]

        block_loc = self.genome.make_location(
            coord_name=ref_record["name"],
            start=record_start,
            end=record_end,
            strand=record_strand,
            ensembl_coord=True,
        )

        ref_location = self.parent.ref_location
        relative_start = ref_location.start - block_loc.start
        relative_end = relative_start + len(ref_location)
        if block_loc.strand != 1:
            relative_start = len(block_loc) - relative_end
            relative_end = relative_start + len(ref_location)

        aln_map, aln_loc = cigar.slice_cigar(self.cigar_line,
                                             relative_start,
                                             relative_end,
                                             by_align=False)

        self.aln_map = aln_map
        self.aln_loc = aln_loc
        region_loc = ref_location.copy()
        region_loc.strand = block_loc.strand
        region = self.genome.get_region(region=region_loc)
        self._cached["region"] = region
Пример #2
0
    def test_slice_cigar(self):
        """test slicing cigars"""
        for start, end in self.slices:
            # test by_align = True
            map1, loc1 = slice_cigar(self.cigar_text, start, end)
            ori1 = self.aln_seq[start:end]
            if loc1:
                slicealn1 = self.seq[loc1[0] : loc1[1]].gapped_by_map(map1)
                assert ori1 == slicealn1
            else:
                assert map1.length == len(ori1)

            # test by_align = False
            map2, loc2 = slice_cigar(self.cigar_text, start, end, by_align=False)
            slicealn2 = self.seq[start:end].gapped_by_map(map2)
            ori2 = self.aln_seq[loc2[0] : loc2[1]]
            assert slicealn2 == ori2
Пример #3
0
    def _make_map_from_ref(self):
        # this is the 'other' species
        if self.aln_loc and self.aln_map is not None:
            return

        record = self._cached
        aln_map, aln_loc = cigar.slice_cigar(
            self.cigar_line,
            self.parent.cigar_start,
            self.parent.cigar_end,
            by_align=True,
        )
        if not aln_loc:
            self._cached["region"] = self.NULL_VALUE
            return

        self.aln_map = aln_map
        self.aln_loc = aln_loc  # probably unnecesary to store??

        # we make a loc for the aligned region
        block_loc = self.genome.make_location(
            coord_name=record["name"],
            start=record["dnafrag_start"],
            end=record["dnafrag_end"],
            strand=record["dnafrag_strand"],
            ensembl_coord=True,
        )
        relative_start = aln_loc[0]
        relative_end = aln_loc[1]
        # new location with correct length ensembl_start
        loc = block_loc.copy()
        loc.end = loc.start + (relative_end - relative_start)

        if block_loc.strand != 1:
            shift = len(block_loc) - relative_end
        else:
            shift = relative_start
        loc = loc.shifted(shift)
        region = self.genome.get_region(region=loc)
        self._cached["region"] = region