def filter_transcript(gene_dict, transcript_dict):
    """
	For each coding gene, only one principal transcript is selected for meta-analysis
	"""
    filter_tids = []
    for gobj in gene_dict.values():
        if gobj.chrom in ('chrM', 'chrMT', 'M', 'MT'):
            continue
        select_tid = None
        if gobj.principal_transcripts:
            if len(gobj.principal_transcripts) == 1:
                tid = gobj.principal_transcripts[0]
                if transcript_dict[tid].startcodon and transcript_dict[tid
                    ].stopcodon:
                    select_tid = tid
            else:
                for tid in gobj.principal_transcripts:
                    if transcript_dict[tid].startcodon and transcript_dict[tid
                        ].stopcodon:
                        if select_tid:
                            if transcript_dict[tid].length > transcript_dict[
                                select_tid].length:
                                select_tid = tid
                        else:
                            select_tid = tid
        elif gobj.transcripts:
            levels = set([transcript_dict[tid].attr.get('level', None) for
                tid in gobj.transcripts])
            if len(levels) > 1:
                level = list(sorted(levels))[0]
            else:
                level = list(levels)[0]
            for tid in gobj.transcripts:
                if transcript_dict[tid].attr.get('level', None):
                    if transcript_dict[tid].attr['level'] == level:
                        if transcript_dict[tid].startcodon and transcript_dict[
                            tid].stopcodon:
                            if select_tid:
                                if transcript_dict[tid
                                    ].length > transcript_dict[select_tid
                                    ].length:
                                    select_tid = tid
                            else:
                                select_tid = tid
                elif transcript_dict[tid].startcodon and transcript_dict[tid
                    ].stopcodon:
                    if select_tid:
                        if transcript_dict[tid].length > transcript_dict[
                            select_tid].length:
                            select_tid = tid
                    else:
                        select_tid = tid
        if select_tid:
            filter_tids.append(select_tid)
    return set(filter_tids)
