# Path: gffutils/helpers.py
# HERE = os.path.dirname(os.path.abspath(__file__))
#     _QUERY = ("{_SELECT} {OTHER} {EXTRA} {FEATURETYPE} "
#               "{LIMIT} {STRAND} {ORDER_BY}")
# def example_filename(fn):
# def infer_dialect(attributes):
# def _choose_dialect(dialects):
# def make_query(args, other=None, limit=None, strand=None, featuretype=None,
#                extra=None, order_by=None, reverse=False,
#                completely_within=False):
# def _bin_from_dict(d):
# def _jsonify(x):
# def _unjsonify(x, isattributes=False):
# def _feature_to_fields(f, jsonify=True):
# def _dict_to_fields(d, jsonify=True):
# def asinterval(feature):
# def merge_attributes(attr1, attr2):
# def dialect_compare(dialect1, dialect2):
# def sanitize_gff_db(db, gid_field="gid"):
#     def sanitized_iterator():
# def sanitize_gff_file(gff_fname,
#                       in_memory=True,
#                       in_place=False):
# def annotate_gff_db(db):
# def is_gff_db(db_fname):
# def to_unicode(obj, encoding='utf-8'):
# def canonical_transcripts(db, fasta_filename):
# def get_gff_db(gff_fname,
#                ext=".db"):


import os
import pybedtools
import six
from pybedtools import featurefuncs
from gffutils import helpers
    _override = os.environ.get('GFFUTILS_USES_BEDTOOLS_227_OR_LATER', None)
    if _override is not None:
        if _override == 'true':
            bedtools_227_or_later = True
        elif _override == 'false':
            bedtools_227_or_later = False
        else:
            raise ValueError(
                "Unknown value for GFFUTILS_USES_BEDTOOLS_227_OR_LATER "
                "environment variable: {0}".format(_override))

    if bedtools_227_or_later:
        _merge_kwargs = dict(o='distinct', s=True, c='4,5,6')
    else:
        _merge_kwargs = dict(o='distinct', s=True, c='4')

    if merge_kwargs is not None:
        _merge_kwargs.update(merge_kwargs)

    def gen():
        """
        Generator of pybedtools.Intervals representing TSSes.
        """
        for gene in db.features_of_type('gene'):
            for transcript in db.children(gene, level=1):
                if transcript.strand == '-':
                    transcript.start = transcript.stop
                else:
                    transcript.stop = transcript.start
                transcript.featuretype = transcript.featuretype + '_TSS'

# Path: gffutils/helpers.py
# HERE = os.path.dirname(os.path.abspath(__file__))
#     _QUERY = ("{_SELECT} {OTHER} {EXTRA} {FEATURETYPE} "
#               "{LIMIT} {STRAND} {ORDER_BY}")
# def example_filename(fn):
# def infer_dialect(attributes):
# def _choose_dialect(dialects):
# def make_query(args, other=None, limit=None, strand=None, featuretype=None,
#                extra=None, order_by=None, reverse=False,
#                completely_within=False):
# def _bin_from_dict(d):
# def _jsonify(x):
# def _unjsonify(x, isattributes=False):
# def _feature_to_fields(f, jsonify=True):
# def _dict_to_fields(d, jsonify=True):
# def asinterval(feature):
# def merge_attributes(attr1, attr2):
# def dialect_compare(dialect1, dialect2):
# def sanitize_gff_db(db, gid_field="gid"):
#     def sanitized_iterator():
# def sanitize_gff_file(gff_fname,
#                       in_memory=True,
#                       in_place=False):
# def annotate_gff_db(db):
# def is_gff_db(db_fname):
# def to_unicode(obj, encoding='utf-8'):
# def canonical_transcripts(db, fasta_filename):
# def get_gff_db(gff_fname,
#                ext=".db"):


# Path: gffutils/pybedtools_integration.py
import os
import pybedtools
import six
from pybedtools import featurefuncs
from gffutils import helpers

    _override = os.environ.get('GFFUTILS_USES_BEDTOOLS_227_OR_LATER', None)
    if _override is not None:
        if _override == 'true':
            bedtools_227_or_later = True
        elif _override == 'false':
            bedtools_227_or_later = False
        else:
            raise ValueError(
                "Unknown value for GFFUTILS_USES_BEDTOOLS_227_OR_LATER "
                "environment variable: {0}".format(_override))

    if bedtools_227_or_later:
        _merge_kwargs = dict(o='distinct', s=True, c='4,5,6')
    else:
        _merge_kwargs = dict(o='distinct', s=True, c='4')

    if merge_kwargs is not None:
        _merge_kwargs.update(merge_kwargs)

    def gen():
        """
        Generator of pybedtools.Intervals representing TSSes.
        """
        for gene in db.features_of_type('gene'):
            for transcript in db.children(gene, level=1):
                if transcript.strand == '-':
                    transcript.start = transcript.stop
                else:
                    transcript.stop = transcript.start
                transcript.featuretype = transcript.featuretype + '_TSS'

                yield helpers.asinterval(transcript)