transform the coordinates of this elem into the other species.

    elem intersects this chain's ginterval.
    :return: a list of the type [(to_chr, start, end, elem[id]) ... ]
506961
def transform(elem, chain_CT_CQ, max_gap):
    """"""
    (chain, CT, CQ) = chain_CT_CQ
    start, end = max(elem['start'], chain.tStart) - chain.tStart, min(elem['end'], chain.tEnd) - chain.tStart

    assert np.all( (CT[:,1] - CT[:,0]) == (CQ[:,1] - CQ[:,0]) )
    to_chrom = chain.qName
    to_gab_start = chain.qStart

    start_idx = np.where( CT[:,1] > start )[0][0]
    end_idx = np.where( CT[:,0] < end )[0][-1]

    if start_idx > end_idx: #maps to a gap region on the other species
        return []

    ## apply the gap threshold
    if max_gap >= 0 and start_idx < end_idx - 1:
        if np.max(CT[(start_idx+1):end_idx,0] - CT[start_idx:(end_idx-1),1]) > max_gap or np.max(CQ[(start_idx+1):end_idx,0] - CQ[start_idx:(end_idx-1),1]) > max_gap:
            return []

    assert start < CT[start_idx, 1]
    assert  CT[end_idx, 0] < end
    to_start = CQ[start_idx, 0] + max(0, start - CT[start_idx,0]) # correct if on middle of interval
    to_end = CQ[end_idx, 1] - max(0, CT[end_idx, 1] - end)        # idem

    if start_idx == end_idx: #elem falls in a single run of matches
        slices = [(to_start, to_end)]
    else:
        slices = [(to_start, CQ[start_idx,1])]
        slices += [(CQ[i,0], CQ[i,1]) for i in range(start_idx+1, end_idx)]
        slices.append( (CQ[end_idx,0], to_end) )
    if chain.qStrand == '-':
        Sz = chain.qEnd - chain.qStart
        slices =  [(Sz-t[1], Sz-t[0]) for t in slices]
    return [(to_chrom, to_gab_start + t[0], to_gab_start + t[1], elem['id']) for t in slices]
639020
def _ci_to_hgvs_coord(s, e):
    

    def _ci_to_hgvs(c):
        return c + 1 if c >= 0 else c

    return (None if s is None else _ci_to_hgvs(s), None if e is None else _ci_to_hgvs(e) - 1)
424603
def from_etree(cls, etree_element):
        
        ins = SaltElement.from_etree(etree_element)
        # TODO: this looks dangerous, ask Stackoverflow about it!
        # convert SaltElement into SaltLayer
        ins.__class__ = SaltLayer.mro()[0]

        # add nodes and edges that belong to this layer (if any)
        for element in ('nodes', 'edges'):
            elem_list = []
            xpath_result = etree_element.xpath('@'+element)
            if xpath_result:
                val_str = xpath_result[0]
                elem_list.extend(int(elem_id)
                                 for elem_id in DIGITS.findall(val_str))
            setattr(ins, element, elem_list)
        return ins
888295
def to_ele(x):
    ""
    if sys.version < '3':
        return x if etree.iselement(x) else etree.fromstring(x, parser=parser)
    else:
        return x if etree.iselement(x) else etree.fromstring(x.encode('UTF-8'), parser=parser)
185611
def el_to_path_vector(el):
    
    path = []
    while el.parent:
        path.append(el)
        el = el.parent

    return list(reversed(path + [el]))
1108669
def _transform_in(self):
        """"""
        return np.array([
            [self.left, self.bottom, 0, 1],
            [self.right, self.top, 0, 1]])
1172838
def kml_element_name(grid_coords, elem_id="KML"):
    
    return "_".join(str(x) for x in [elem_id, grid_coords.zoom, grid_coords.x, grid_coords.y])
1322281
def combine_elem(ind1, ind2):
    """"""
    def inner(seq):
        shift = 2**16
        if seq[ind1] < 0:
            seq[ind1] += shift
        if seq[ind2] < 0:
            seq[ind2] += shift
        return (seq[ind1] << 16) | seq[ind2]
    return inner
113597
def slice(self, start, end):
        

        reverse = False
        if start > end:
            temp = start
            start = end
            end = temp
            reverse = True

        seg = self.copy()
        seg.points = seg.points[start:end+1]
        if reverse:
            seg.points = list(reversed(seg.points))

        return seg
191199
def intersects(self, other):
        ''''''
        return self.CHROM == other.CHROM and self.POS <= other.ref_end_pos() and other.POS <= self.ref_end_pos()
930848
def nodes(self):
        
        nodes = np.array(list(self.transforms.nodes()))
        return nodes
535924
def to_arange(self):
        
        arr, step = np.linspace(self.start, self.stop, self.num, self.endpoint, retstep=True)
        return Arange(self.start, self.stop+step, step)
1247962
def merge_ligolws(elem):
	
	ligolws = [child for child in elem.childNodes if child.tagName == ligolw.LIGO_LW.tagName]
	if ligolws:
		dest = ligolws.pop(0)
		for src in ligolws:
			# copy children;  LIGO_LW elements have no attributes
			map(dest.appendChild, src.childNodes)
			# unlink from parent
			if src.parentNode is not None:
				src.parentNode.removeChild(src)
	return elem
1000542
def slice_sequence(self,start,end):
     
     #find the sequence length
     l = self.length
     indexstart = start
     indexend = end
     ns = []
     tot = 0
     for r in self._rngs:
        tot += r.length
        n = r.copy()
        if indexstart > r.length:  
           indexstart-=r.length
           continue
        n.start = n.start+indexstart
        if tot > end: 
           diff = tot-end
           n.end -= diff
           tot = end
        indexstart = 0
        ns.append(n)
        if tot == end: break
     if len(ns)==0: return None
     return MappingGeneric(ns,self._options)
218989
function mergeDoctype( elem ) {
		merge( elem, function( old ) {
			utils.replaceElement( old, elem );
			destChildren[ destChildren.indexOf( old ) ] = elem;
		} );
	}
1025622
def intersects(self, e):
    
    if self.chrom != e.chrom:
      return False

    if e.start >= self.start and e.start < self.end:
      return True
    if e.end > self.start and e.end <= self.end:
      return True
    if e.start < self.start and e.end > self.end:
      return True
    return False
1148931
def last_chain(self):
        '''
        
        '''
        cols = self.columns.tolist()
        i_oid = cols.index('_oid')
        i_start = cols.index('_start')
        i_end = cols.index('_end')

        start_map = {}
        end_map = {}
        for row in self.values:
            oid = row[i_oid]
            if oid not in start_map:
                start_map[oid] = set()
                end_map[oid] = set()
            start_map[oid].add(row[i_start])
            end_map[oid].add(row[i_end])

        cutoffs = {}
        for oid in start_map:
            maxend = pd.NaT if pd.NaT in end_map[oid] else max(end_map[oid])
            ends = end_map[oid] - start_map[oid] - set([maxend])
            cutoffs[oid] = None if len(ends) == 0 else max(ends)

        vals = [row for row in self.values
                if cutoffs[row[i_oid]] is None
                or cutoffs[row[i_oid]] < row[i_start]]

        return pd.DataFrame(vals, columns=cols)