Given an interval [start:end] and a particular transcript,
    return the start offset of the interval relative to the
    chromosomal positions of the transcript.
552233
def interval_offset_on_transcript(start, end, transcript):
    
    # ensure that start_pos:end_pos overlap with transcript positions
    if start > end:
        raise ValueError(
            "start_pos %d shouldn't be greater than end_pos %d" % (
                start, end))
    if start > transcript.end:
        raise ValueError(
            "Range %d:%d starts after transcript %s (%d:%d)" % (
                start,
                end,
                transcript,
                transcript.start,
                transcript.end))
    if end < transcript.start:
        raise ValueError(
            "Range %d:%d ends before transcript %s (%d:%d)" % (
                start,
                end,
                transcript,
                transcript.start,
                transcript.end))
    # trim the start position to the beginning of the transcript
    if start < transcript.start:
        start = transcript.start
    # trim the end position to the end of the transcript
    if end > transcript.end:
        end = transcript.end
    # return earliest offset into the spliced transcript
    return min(
        transcript.spliced_offset(start),
        transcript.spliced_offset(end))
122243
function ( obj, start, offset ) {
		var result = [],
		    i      = start - 1,
		    nth    = start + offset,
		    max    = obj.length;

		if ( max > 0 ) {
			while ( ++i < nth && i < max ) {
				result.push( obj[i] );
			}
		}

		return result;
	}
475175
function (start, end) {
      var r, rlen, c, clen, output = [], row;
      rlen = Math.max(start.row, end.row);
      clen = Math.max(start.col, end.col);
      for (r = Math.min(start.row, end.row); r <= rlen; r++) {
        row = [];
        for (c = Math.min(start.col, end.col); c <= clen; c++) {
          row.push(datamap.get(r, datamap.colToProp(c)));
        }
        output.push(row);
      }
      return output;
    }
1031468
public static int getCDSLength(GeneChromosomePosition chromPos) {

		List<Integer> exonStarts = chromPos.getExonStarts();
		List<Integer> exonEnds = chromPos.getExonEnds();

		int cdsStart = chromPos.getCdsStart();
		int cdsEnd = chromPos.getCdsEnd();

		int codingLength;
		if (chromPos.getOrientation().equals('+'))
			codingLength = ChromosomeMappingTools.getCDSLengthForward(exonStarts, exonEnds, cdsStart, cdsEnd);
		else
			codingLength = ChromosomeMappingTools.getCDSLengthReverse(exonStarts, exonEnds, cdsStart, cdsEnd);
		return codingLength;
	}
871287
def n_to_g(self, n_interval):
        """"""

        assert self.strand in [1, -1], "strand = " + str(self.strand) + "; must be 1 or -1"

        if self.strand == 1:
            frs, fre = _hgvs_coord_to_ci(n_interval.start.base, n_interval.end.base)
            start_offset, end_offset = n_interval.start.offset, n_interval.end.offset
        elif self.strand == -1:
            frs, fre = _hgvs_coord_to_ci(n_interval.start.base, n_interval.end.base)
            fre, frs = self.tgt_len - frs, self.tgt_len - fre
            start_offset, end_offset = self.strand * n_interval.end.offset, self.strand * n_interval.start.offset

        # returns the genomic range start (grs) and end (gre)
        grs, gre = self.im.map_tgt_to_ref(frs, fre, max_extent=False)
        grs, gre = grs + self.gc_offset, gre + self.gc_offset
        gs, ge = grs + start_offset, gre + end_offset
        return hgvs.location.Interval(
            start=hgvs.location.SimplePosition(
                _ci_to_hgvs_coord(gs, ge)[0], uncertain=n_interval.start.uncertain),
            end=hgvs.location.SimplePosition(
                _ci_to_hgvs_coord(gs, ge)[1], uncertain=n_interval.end.uncertain),
            uncertain=n_interval.uncertain)
671876
def from_interbase_coordinates(contig, start, end=None):
        '''
        
        '''
        typechecks.require_string(contig)
        typechecks.require_integer(start)
        if end is None:
            end = start + 1
        typechecks.require_integer(end)
        contig = pyensembl.locus.normalize_chromosome(contig)
        return Locus(contig, start, end)
377201
def distance_between(self, string, start, end):
        """"""
        count = 0
        started = False

        for line in string.split("\n"):

            if self.scan_line(line, start) and not started:
                started = True

            if self.scan_line(line, end):
                return count

            if started:
                count += 1

        return count
676387
def g_to_n(self, g_interval):
        """"""

        grs, gre = g_interval.start.base - 1 - self.gc_offset, g_interval.end.base - 1 - self.gc_offset
        # frs, fre = (f)orward (r)na (s)tart & (e)nd; forward w.r.t. genome
        frs, frs_offset, frs_cigar = self._map(
            from_pos=self.ref_pos, to_pos=self.tgt_pos, pos=grs, base="start")
        fre, fre_offset, fre_cigar = self._map(
            from_pos=self.ref_pos, to_pos=self.tgt_pos, pos=gre, base="end")

        if self.strand == -1:
            frs, fre = self.tgt_len - fre - 1, self.tgt_len - frs - 1
            frs_offset, fre_offset = -fre_offset, -frs_offset

        # The returned interval would be uncertain when locating at alignment gaps
        return hgvs.location.BaseOffsetInterval(
            start=hgvs.location.BaseOffsetPosition(
                base=frs + 1, offset=frs_offset, datum=Datum.SEQ_START),
            end=hgvs.location.BaseOffsetPosition(
                base=fre + 1, offset=fre_offset, datum=Datum.SEQ_START),
            uncertain=frs_cigar in 'DI' or fre_cigar in 'DI')
754595
def slice_sequence(self,start,end,directionless=False):
     
     if end > self.length: end = self.length
     if start < 0: start = 0
     if not directionless and self.direction == '-': 
        newend = self.length-start
        newstart = self.length-end
        end = newend
        start = newstart
     #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 Transcript(ns,self._options)
843024
def __findFirstMissing(self, array, start, end):
        
        if (start > end):
            return end + 1

        if (start != array[start]):
            return start

        mid = int((start + end) / 2)

        if (array[mid] == mid):
            return self.__findFirstMissing(array, mid + 1, end)

        return self.__findFirstMissing(array, start, mid)
225406
def n_to_c(self, n_interval):
        """"""

        if self.cds_start_i is None:    # cds_start_i defined iff cds_end_i defined; see assertion above
            raise HGVSUsageError(
                "CDS is undefined for {self.tx_ac}; cannot map to c. coordinate (non-coding transcript?)"
                .format(self=self))
        if n_interval.start.base <= 0 or n_interval.end.base > self.tgt_len:
            raise HGVSError("The given coordinate is outside the bounds of the reference sequence.")

        # start
        if n_interval.start.base <= self.cds_start_i:
            cs = n_interval.start.base - (self.cds_start_i + 1)
            cs_datum = Datum.CDS_START
        elif n_interval.start.base > self.cds_start_i and n_interval.start.base <= self.cds_end_i:
            cs = n_interval.start.base - self.cds_start_i
            cs_datum = Datum.CDS_START
        else:
            cs = n_interval.start.base - self.cds_end_i
            cs_datum = Datum.CDS_END
        # end
        if n_interval.end.base <= self.cds_start_i:
            ce = n_interval.end.base - (self.cds_start_i + 1)
            ce_datum = Datum.CDS_START
        elif n_interval.end.base > self.cds_start_i and n_interval.end.base <= self.cds_end_i:
            ce = n_interval.end.base - self.cds_start_i
            ce_datum = Datum.CDS_START
        else:
            ce = n_interval.end.base - self.cds_end_i
            ce_datum = Datum.CDS_END

        c_interval = hgvs.location.BaseOffsetInterval(
            start=hgvs.location.BaseOffsetPosition(
                base=cs, offset=n_interval.start.offset, datum=cs_datum),
            end=hgvs.location.BaseOffsetPosition(
                base=ce, offset=n_interval.end.offset, datum=ce_datum),
            uncertain=n_interval.uncertain)
        return c_interval
597574
public int determineMedian(List<Intervalable> intervals)
    {
        int start = -1;
        int end = -1;
        for (Intervalable interval : intervals)
        {
            int currentStart = interval.getStart();
            int currentEnd = interval.getEnd();
            if (start == -1 || currentStart < start)
            {
                start = currentStart;
            }
            if (end == -1 || currentEnd > end)
            {
                end = currentEnd;
            }
        }
        return (start + end) / 2;
    }
995211
def _update_offsets(start_x, spacing, terminations, offsets, length):
    '''
    '''
    return (start_x + spacing[0] * terminations / 2.,
            offsets[1] + spacing[1] * 2. + length)
1094138
def _get_start_end(self, start=None, end=None, size=None):
        
        if (start,end) == (None,None) and self._buf == {}:
            raise EmptyIntelHexError
        if size is not None:
            if None not in (start, end):
                raise ValueError("tobinarray: you can't use start,end and size"
                                 " arguments in the same time")
            if (start, end) == (None, None):
                start = self.minaddr()
            if start is not None:
                end = start + size - 1
            else:
                start = end - size + 1
                if start < 0:
                    raise ValueError("tobinarray: invalid size (%d) "
                                     "for given end address (%d)" % (size,end))
        else:
            if start is None:
                start = self.minaddr()
            if end is None:
                end = self.maxaddr()
            if start > end:
                start, end = end, start
        return start, end
545865
def range(self, start, end, desc=False):
        
        if not self:
            return []

        if desc:
            return reversed(self._scores[len(self) - end - 1:len(self) - start])
        else:
            return self._scores[start:end + 1]
710411
def n2s(self, offset, length):
        """"""
        s = ''
        for dummy in range(length):
            if self.endian == 'I':
                s += chr(offset & 0xFF)
            else:
                s = chr(offset & 0xFF) + s
            offset = offset >> 8
        return s
50347
function Interval(sourceString, startIdx, endIdx) {
  this.sourceString = sourceString;
  this.startIdx = startIdx;
  this.endIdx = endIdx;
}