def split_fusion_transcript(annotation_path, transcripts):
    """
    Finds the breakpoint in the fusion transcript and splits the 5' donor from the 3' acceptor

    :param str annotation_path: Path to transcript annotation file
    :param dict transcripts: Dictionary of fusion transcripts
    :return: 5' donor sequences and 3' acceptor sequences
    :rtype: tuple
    """
    annotation = collections.defaultdict(dict)

    forward = 'ACGTN'
    reverse = 'TGCAN'
    trans = string.maketrans(forward, reverse)

    # Pull in assembled transcript annotation
    five_pr_splits = collections.defaultdict(dict)
    three_pr_splits = collections.defaultdict(dict)

    regex = re.compile(r'ID=(?P<ID>.*);Name=(?P<Name>.*);Target=(?P<Target>.*)\s(?P<start>\d+)\s(?P<stop>\d+)')

    with open(annotation_path, 'r') as gff:
        for line in gff:
            print(line)
            if line.startswith('#'):
                _, eyd, fusion = line.strip().split()
                fusion, start_stop = fusion.split(':')
                left_break, right_break = start_stop.split('-')

                annotation[fusion][eyd] = {}
                annotation[fusion][eyd]['left_break'] = left_break
                annotation[fusion][eyd]['right_break'] = right_break

            else:
                line = line.strip().split('\t')
                fusion = line[0]
                strand = line[6]
                block_start = line[3]
                block_stop = line[4]
                attr = line[8]
                m = regex.search(attr)
                if m:
                    transcript_id = m.group('Name')

                    rb = any([block_start == annotation[fusion][transcript_id]['right_break'],
                              block_stop == annotation[fusion][transcript_id]['right_break']])

                    lb = any([block_start == annotation[fusion][transcript_id]['left_break'],
                              block_stop == annotation[fusion][transcript_id]['left_break']])

                    if strand == '-' and rb:
                        transcript_split = int(m.group('stop')) + 1   # Off by one
                        # Take the reverse complement to orient transcripts from 5' to 3'
                        five_seq = transcripts[transcript_id][transcript_split:]
                        five_pr_splits[fusion][transcript_id] = five_seq.translate(trans)[::-1]
                        three_seq = transcripts[transcript_id][:transcript_split]
                        three_pr_splits[fusion][transcript_id] = three_seq.translate(trans)[::-1]

                    elif strand == '+' and lb:
                        transcript_split = int(m.group('stop'))
                        s1 = transcripts[transcript_id][:transcript_split]
                        five_pr_splits[fusion][transcript_id] = s1
                        s2 = transcripts[transcript_id][transcript_split:]
                        three_pr_splits[fusion][transcript_id] = s2

    return five_pr_splits, three_pr_splits
def split_fusion_transcript ( annotation_path , transcripts ) : annotation = collections . defaultdict ( dict ) forward = 'ACGTN' reverse = 'TGCAN' trans = string . maketrans ( forward , reverse ) five_pr_splits = collections . defaultdict ( dict ) three_pr_splits = collections . defaultdict ( dict ) regex = re . compile ( r'ID=(?P<ID>.*);Name=(?P<Name>.*);Target=(?P<Target>.*)\s(?P<start>\d+)\s(?P<stop>\d+)' ) with open ( annotation_path , 'r' ) as gff : for line in gff : print ( line ) if line . startswith ( '#' ) : _ , eyd , fusion = line . strip ( ) . split ( ) fusion , start_stop = fusion . split ( ':' ) left_break , right_break = start_stop . split ( '-' ) annotation [ fusion ] [ eyd ] = { } annotation [ fusion ] [ eyd ] [ 'left_break' ] = left_break annotation [ fusion ] [ eyd ] [ 'right_break' ] = right_break else : line = line . strip ( ) . split ( '\t' ) fusion = line [ 0 ] strand = line [ 6 ] block_start = line [ 3 ] block_stop = line [ 4 ] attr = line [ 8 ] m = regex . search ( attr ) if m : transcript_id = m . group ( 'Name' ) rb = any ( [ block_start == annotation [ fusion ] [ transcript_id ] [ 'right_break' ] , block_stop == annotation [ fusion ] [ transcript_id ] [ 'right_break' ] ] ) lb = any ( [ block_start == annotation [ fusion ] [ transcript_id ] [ 'left_break' ] , block_stop == annotation [ fusion ] [ transcript_id ] [ 'left_break' ] ] ) if strand == '-' and rb : transcript_split = int ( m . group ( 'stop' ) ) + 1 five_seq = transcripts [ transcript_id ] [ transcript_split : ] five_pr_splits [ fusion ] [ transcript_id ] = five_seq . translate ( trans ) [ : : - 1 ] three_seq = transcripts [ transcript_id ] [ : transcript_split ] three_pr_splits [ fusion ] [ transcript_id ] = three_seq . translate ( trans ) [ : : - 1 ] elif strand == '+' and lb : transcript_split = int ( m . group ( 'stop' ) ) s1 = transcripts [ transcript_id ] [ : transcript_split ] five_pr_splits [ fusion ] [ transcript_id ] = s1 s2 = transcripts [ transcript_id ] [ transcript_split : ] three_pr_splits [ fusion ] [ transcript_id ] = s2 return five_pr_splits , three_pr_splits
Finds the breakpoint in the fusion transcript and splits the 5' donor from the 3' acceptor

    :param str annotation_path: Path to transcript annotation file
    :param dict transcripts: Dictionary of fusion transcripts
    :return: 5' donor sequences and 3' acceptor sequences
    :rtype: tuple