def bed12(self, feature, block_featuretype=['exon'],
              thick_featuretype=['CDS'], thin_featuretype=None,
              name_field='ID', color=None):
        if thick_featuretype and thin_featuretype:
            raise ValueError("Can only specify one of `thick_featuertype` or "
                             "`thin_featuretype`")
        exons = list(self.children(feature, featuretype=block_featuretype,
                                   order_by='start'))
        if len(exons) == 0:
            exons = [feature]
        feature = self[feature]
        first = exons[0].start
        last = exons[-1].stop
        if first != feature.start:
            raise ValueError(
                "Start of first exon (%s) does not match start of feature (%s)"
                % (first, feature.start))
        if last != feature.stop:
            raise ValueError(
                "End of last exon (%s) does not match end of feature (%s)"
                % (last, feature.stop))
        if color is None:
            color = '0,0,0'
        color = color.replace(' ', '').strip()
        chrom = feature.chrom
        chromStart = feature.start - 1
        chromEnd = feature.stop
        orig = constants.always_return_list
        constants.always_return_list = True
        try:
            name = feature[name_field][0]
        except KeyError:
            name = "."
        constants.always_return_list = orig
        score = feature.score
        if score == '.':
            score = '0'
        strand = feature.strand
        itemRgb = color
        blockCount = len(exons)
        blockSizes = [len(i) for i in exons]
        blockStarts = [i.start - 1 - chromStart for i in exons]
        if thick_featuretype:
            thick = list(self.children(feature, featuretype=thick_featuretype,
                                       order_by='start'))
            if len(thick) == 0:
                thickStart = feature.start
                thickEnd = feature.stop
            else:
                thickStart = thick[0].start - 1
                thickEnd = thick[-1].stop
        if thin_featuretype:
            thin = list(self.children(feature, featuretype=thin_featuretype,
                                      order_by='start'))
            if len(thin) == 0:
                thickStart = feature.start
                thickEnd = feature.stop
            else:
                thickStart = thin[0].stop
                thickEnd = thin[-1].start - 1
        tst = chromStart + blockStarts[-1] + blockSizes[-1]
        assert tst == chromEnd, "tst=%s; chromEnd=%s" % (tst, chromEnd)
        fields = [
            chrom,
            chromStart,
            chromEnd,
            name,
            score,
            strand,
            thickStart,
            thickEnd,
            itemRgb,
            blockCount,
            ','.join(map(str, blockSizes)),
            ','.join(map(str, blockStarts))]
        return '\t'.join(map(str, fields))