def getUTRExonFromFile(bedfile, utr=35):
    """Only Extract UTR regions from input bed file (must be 12-column). output is 6-column bed format.
	When utr=35 [default], extract both 5' and 3' UTR. When utr=3, only extract 3' UTR. When utr=5,
	only extract 5' UTR"""
    ret_lst = []
    for line in open(bedfile, 'r'):
        if line.startswith('#'):
            continue
        if line.startswith('track'):
            continue
        if line.startswith('browser'):
            continue
        fields = line.rstrip('\r\n').split()
        chrom = fields[0]
        strand = fields[5]
        txStart = int(fields[1])
        txEnd = int(fields[2])
        cdsStart = int(fields[6])
        cdsEnd = int(fields[7])
        exon_start = list(map(int, fields[11].rstrip(',').split(',')))
        exon_start = list(map(lambda x: x + txStart, exon_start))
        exon_end = list(map(int, fields[10].rstrip(',').split(',')))
        exon_end = list(map(lambda x, y: x + y, exon_start, exon_end))
        chrom = chrom + ':' + strand
        if utr == 35 or utr == 5:
            for st, end in zip(exon_start, exon_end):
                if st < cdsStart:
                    utr_st = st
                    utr_end = min(end, cdsStart)
                    ret_lst.append([chrom, utr_st, utr_end])
        if utr == 35 or utr == 3:
            for st, end in zip(exon_start, exon_end):
                if end > cdsEnd:
                    utr_st = max(st, cdsEnd)
                    utr_end = end
                    ret_lst.append([chrom, utr_st, utr_end])
    return ret_lst
