def g_to_n(self, g_interval):
<EOL>def _hgvs_offset(g_position, grs, gre, strand):<EOL><INDENT>"""<STR_LIT>"""<EOL>if g_position == grs or g_position == gre:<EOL><INDENT>return <NUM_LIT:0><EOL><DEDENT>mid = (grs + gre) / <NUM_LIT:2><EOL>if g_position < mid or (g_position == mid and strand == <NUM_LIT:1>):<EOL><INDENT>offset = g_position - grs<EOL><DEDENT>else:<EOL><INDENT>offset = g_position - gre<EOL><DEDENT>return offset<EOL><DEDENT>def map_g_to_n_pos(pos):<EOL><INDENT>g_ci = _hgvs_coord_to_ci(pos, pos)<EOL>frs, fre = self.im.map_ref_to_tgt(<EOL>g_ci[<NUM_LIT:0>] - self.gc_offset, g_ci[<NUM_LIT:1>] - self.gc_offset, max_extent=False)<EOL>if self.strand == -<NUM_LIT:1>:<EOL><INDENT>frs, fre = self.tgt_len - fre, self.tgt_len - frs<EOL><DEDENT>if self.strand == <NUM_LIT:1>:<EOL><INDENT>grs, gre = self.im.map_tgt_to_ref(frs, fre, max_extent=False)<EOL><DEDENT>elif self.strand == -<NUM_LIT:1>:<EOL><INDENT>grs, gre = self.im.map_tgt_to_ref((self.tgt_len - fre), (self.tgt_len - frs),<EOL>max_extent=False)<EOL><DEDENT>grs, gre = grs + self.gc_offset, gre + self.gc_offset<EOL>if frs == fre:<EOL><INDENT>start_offset = _hgvs_offset(g_ci[<NUM_LIT:0>] + <NUM_LIT:1>, grs, gre + <NUM_LIT:1>, self.strand)<EOL>end_offset = _hgvs_offset(g_ci[<NUM_LIT:1>], grs, gre + <NUM_LIT:1>, self.strand)<EOL><DEDENT>else:<EOL><INDENT>start_offset = _hgvs_offset(g_ci[<NUM_LIT:0>], grs, gre, self.strand)<EOL>end_offset = _hgvs_offset(g_ci[<NUM_LIT:1>], grs, gre, self.strand)<EOL><DEDENT>if self.strand == -<NUM_LIT:1>:<EOL><INDENT>start_offset, end_offset = self.strand * end_offset, self.strand * start_offset<EOL><DEDENT>if start_offset > <NUM_LIT:0>:<EOL><INDENT>frs -= <NUM_LIT:1><EOL><DEDENT>if end_offset < <NUM_LIT:0>:<EOL><INDENT>fre += <NUM_LIT:1><EOL><DEDENT>start_base = _ci_to_hgvs_coord(frs, fre)[<NUM_LIT:0>]<EOL>end_base = _ci_to_hgvs_coord(frs, fre)[<NUM_LIT:1>]<EOL>return start_base, start_offset, end_base, end_offset<EOL><DEDENT>start_bo = map_g_to_n_pos(g_interval.start.base)[<NUM_LIT:0>:<NUM_LIT:2>]<EOL>end_bo = start_bo if g_interval.start.base == g_interval.end.base else map_g_to_n_pos(<EOL>g_interval.end.base)[<NUM_LIT:2>:<NUM_LIT:4>]<EOL>if self.strand == -<NUM_LIT:1>:<EOL><INDENT>start_bo, end_bo = end_bo, start_bo<EOL><DEDENT>return hgvs.location.BaseOffsetInterval(<EOL>start=hgvs.location.BaseOffsetPosition(<EOL>base=start_bo[<NUM_LIT:0>], offset=start_bo[<NUM_LIT:1>], datum=Datum.SEQ_START),<EOL>end=hgvs.location.BaseOffsetPosition(<EOL>base=end_bo[<NUM_LIT:0>], offset=end_bo[<NUM_LIT:1>], datum=Datum.SEQ_START),<EOL>uncertain=g_interval.uncertain)<EOL>
convert a genomic (g.) interval to a transcript cDNA (n.) interval