Example #1
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
     try:
         aln_map, aln_loc = cigar.slice_cigar(self.cigar_line,
                                         self.parent.CigarStart,
                                         self.parent.CigarEnd,
                                         by_align=True)
         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.makeLocation(CoordName=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
         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.getRegion(region=loc)
     except IndexError: # TODO ask Hua where these index errors occur
         region = None
     self._cached['Region'] = region
Example #2
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.makeLocation(CoordName=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.getRegion(region=region_loc)
     self._cached['Region'] = region
    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
        try:
            aln_map, aln_loc = cigar.slice_cigar(self.cigar_line,
                                                 self.parent.CigarStart,
                                                 self.parent.CigarEnd,
                                                 by_align=True)
            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.makeLocation(
                CoordName=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
            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.getRegion(region=loc)
        except IndexError:  # TODO ask Hua where these index errors occur
            region = None
        self._cached['Region'] = region
    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.makeLocation(CoordName=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.getRegion(region=region_loc)
        self._cached['Region'] = region
Example #5
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]].gappedByMap(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].gappedByMap(map2)
         ori2 = self.aln_seq[loc2[0]:loc2[1]]
         assert slicealn2 == ori2
Example #6
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]].gappedByMap(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].gappedByMap(map2)
         ori2 = self.aln_seq[loc2[0]:loc2[1]]
         assert slicealn2 == ori2