def variant_context_w_alignment(am, var, margin=<NUM_LIT:20>, tx_ac=None):
from uta_align.align.algorithms import align, cigar_alignment<EOL>fh = full_house(am, var, tx_ac=tx_ac)<EOL>tm = am._fetch_AlignmentMapper(fh['<STR_LIT:n>'].ac, fh['<STR_LIT:g>'].ac, am.alt_aln_method)<EOL>strand = tm.strand<EOL>span_g = _ival_to_span(fh['<STR_LIT:g>'].posedit.pos)<EOL>span_g = (span_g[<NUM_LIT:0>] - margin, span_g[<NUM_LIT:1>] + margin)<EOL>ival_g = Interval(SimplePosition(span_g[<NUM_LIT:0>]), SimplePosition(span_g[<NUM_LIT:1>]))<EOL>ival_n = tm.g_to_n(ival_g)<EOL>assert ival_n.start.offset == <NUM_LIT:0> and ival_n.end.offset == <NUM_LIT:0>, "<STR_LIT>"<EOL>span_n = _ival_to_span(ival_n)<EOL>ival_c = tm.g_to_c(ival_g)<EOL>span_c = _ival_to_span(ival_c)<EOL>seq_gt = am.hdp.get_seq(fh['<STR_LIT:g>'].ac, span_g[<NUM_LIT:0>] - <NUM_LIT:1>, span_g[<NUM_LIT:1>])<EOL>seq_gb = complement(seq_gt)<EOL>seq_n = am.hdp.get_seq(fh['<STR_LIT:n>'].ac, span_n[<NUM_LIT:0>] - <NUM_LIT:1>, span_n[<NUM_LIT:1>])<EOL>if strand == <NUM_LIT:1>:<EOL><INDENT>a = align(bytes(seq_gt), bytes(seq_n), b'<STR_LIT>', extended_cigar=True)<EOL><DEDENT>else:<EOL><INDENT>seq_n = '<STR_LIT>'.join(reversed(seq_n))<EOL>a = align(bytes(seq_gb), bytes(seq_n), b'<STR_LIT>', extended_cigar=True)<EOL><DEDENT>aseq_gt, _ = cigar_alignment(seq_gt, a.query, a.cigar, hide_match=False)<EOL>aseq_gb, aseq_n = cigar_alignment(seq_gb, a.query, a.cigar, hide_match=False)<EOL>aln_str = _reformat_aln_str(cigar_alignment(a.ref, a.query, a.cigar, hide_match=True)[<NUM_LIT:1>])<EOL>s_dir = '<STR_LIT:>>' if strand == <NUM_LIT:1> else '<STR_LIT:<>'<EOL>lines = [<EOL>[<EOL><NUM_LIT:1>,<EOL><NUM_LIT:0>,<EOL>seq_line_fmt(<EOL>var=fh['<STR_LIT:c>'],<EOL>span=span_c if strand == <NUM_LIT:1> else list(reversed(span_c)),<EOL>content='<STR_LIT>',<EOL>dir=s_dir),<EOL>],<EOL>[<EOL><NUM_LIT:2>,<EOL><NUM_LIT:0>,<EOL>seq_line_fmt(<EOL>var=fh['<STR_LIT:n>'],<EOL>span=span_n if strand == <NUM_LIT:1> else list(reversed(span_n)),<EOL>content=aseq_n,<EOL>dir=s_dir),<EOL>],<EOL>[<EOL><NUM_LIT:3>,<EOL><NUM_LIT:0>,<EOL>_line_fmt.format(pre='<STR_LIT>', content=aln_str, post=a.cigar.to_string(), comment='<STR_LIT>'),<EOL>],<EOL>[<EOL><NUM_LIT:4>,<EOL><NUM_LIT:1>,<EOL>seq_line_fmt(var=fh['<STR_LIT:g>'], span=span_g, content=aseq_gt, dir='<STR_LIT:>>'),<EOL>],<EOL>[<EOL><NUM_LIT:4>,<EOL><NUM_LIT:2>,<EOL>seq_line_fmt(var=fh['<STR_LIT:g>'], span=span_g, content=aseq_gb, dir='<STR_LIT:<>'),<EOL>],<EOL>[<EOL><NUM_LIT:5>,<EOL><NUM_LIT:0>,<EOL>pointer_line(var=fh['<STR_LIT:g>'], span=span_g),<EOL>],<EOL>]<EOL>if strand == -<NUM_LIT:1>:<EOL><INDENT>lines.sort(key=lambda e: (-e[<NUM_LIT:0>], e[<NUM_LIT:1>]))<EOL><DEDENT>return '<STR_LIT:\n>'.join(r[<NUM_LIT:2>] for r in lines)<EOL>
This module is experimental. It requires the uta_align package from pypi.