# Path: gffutils/parser.py
# class Quoter(collections.defaultdict):
#     def __missing__(self, b):
# def _reconstruct(keyvals, dialect, keep_order=False,
#                  sort_attribute_values=False):
#     def sort_key(x):
# def _split_keyvals(keyval_str, dialect=None):
#     def _unquote_quals(quals, dialect):
# 
# Path: gffutils/feature.py
# class Feature(object):
#     def __init__(self, seqid=".", source=".", featuretype=".",
#                  start=".", end=".", score=".", strand=".", frame=".",
#                  attributes=None, extra=None, bin=None, id=None, dialect=None,
#                  file_order=None, keep_order=False,
#                  sort_attribute_values=False):
#     def calc_bin(self, _bin=None):
#     def __repr__(self):
#     def __getitem__(self, key):
#     def __setitem__(self, key, value):
#     def __str__(self):
#     def __unicode__(self):
#     def __hash__(self):
#     def __eq__(self, other):
#     def __ne__(self, other):
#     def __len__(self):
#     def chrom(self):
#     def chrom(self, value):
#     def stop(self):
#     def stop(self, value):
#     def astuple(self, encoding=None):
#     def sequence(self, fasta, use_strand=True):
# def feature_from_line(line, dialect=None, strict=True, keep_order=False):
# 
# 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/constants.py
# SCHEMA = """
# 
# CREATE TABLE features (
#     id text,
#     seqid text,
#     source text,
#     featuretype text,
#     start int,
#     end int,
#     score text,
#     strand text,
#     frame text,
#     attributes text,
#     extra text,
#     bin int,
#     primary key (id)
#     );
# 
# CREATE TABLE relations (
#     parent text,
#     child text,
#     level int,
#     primary key (parent, child, level)
#     );
# 
# CREATE TABLE meta (
#     dialect text,
#     version text
#     );
# 
# CREATE TABLE directives (
#     directive text
#     );
# 
# CREATE TABLE autoincrements (
#     base text,
#     n int,
#     primary key (base)
#     );
# 
# CREATE TABLE duplicates (
#     idspecid text,
#     newid text,
#     primary key (newid)
#     );
# 
# 
# """
# _SELECT = "SELECT " \
#     + ', '.join(_keys) \
#     + ", features.rowid as file_order FROM features "
# _INSERT = "INSERT INTO features (" \
#     + ', '.join(_keys) + ") VALUES (" + ','.join(list('?' * len(_keys))) + ")"
# _UPDATE = "UPDATE features SET " + _update_clause + " WHERE id = ?"
# INDEXES = []


from gffutils import parser, feature, helpers, constants
        import pybedtools

def test_feature_from_line():
    # spaces and tabs should give identical results
    line1 = "chr2L	FlyBase	exon	7529	8116	.	+	.	Name=CG11023:1;Parent=FBtr0300689,FBtr0300690"
    line2 = "chr2L FlyBase exon 7529 8116 . + . Name=CG11023:1;Parent=FBtr0300689,FBtr0300690"
    assert feature.feature_from_line(line1, strict=False, keep_order=True) == \
            feature.feature_from_line(line2, strict=False, keep_order=True)


def test_default_feature():
    # Default Feature is 8 tab-delimited ".", with a trailing tab
    assert str(feature.Feature()) == \
    ".	.	.	.	.	.	.	.	"


def test_attributes_representations():
    # These different ways of supplying attributes should yield identical
    # results:
    s = ".	.	.	.	.	.	.	.	ID=asdf"
    for item in (
        '{"ID": ["asdf"]}',
        dict(ID=["asdf"]),
        "ID=asdf"
    ):

# Path: gffutils/parser.py
# class Quoter(collections.defaultdict):
#     def __missing__(self, b):
# def _reconstruct(keyvals, dialect, keep_order=False,
#                  sort_attribute_values=False):
#     def sort_key(x):
# def _split_keyvals(keyval_str, dialect=None):
#     def _unquote_quals(quals, dialect):
# 
# Path: gffutils/feature.py
# class Feature(object):
#     def __init__(self, seqid=".", source=".", featuretype=".",
#                  start=".", end=".", score=".", strand=".", frame=".",
#                  attributes=None, extra=None, bin=None, id=None, dialect=None,
#                  file_order=None, keep_order=False,
#                  sort_attribute_values=False):
#     def calc_bin(self, _bin=None):
#     def __repr__(self):
#     def __getitem__(self, key):
#     def __setitem__(self, key, value):
#     def __str__(self):
#     def __unicode__(self):
#     def __hash__(self):
#     def __eq__(self, other):
#     def __ne__(self, other):
#     def __len__(self):
#     def chrom(self):
#     def chrom(self, value):
#     def stop(self):
#     def stop(self, value):
#     def astuple(self, encoding=None):
#     def sequence(self, fasta, use_strand=True):
# def feature_from_line(line, dialect=None, strict=True, keep_order=False):
# 
# 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/constants.py
# SCHEMA = """
# 
# CREATE TABLE features (
#     id text,
#     seqid text,
#     source text,
#     featuretype text,
#     start int,
#     end int,
#     score text,
#     strand text,
#     frame text,
#     attributes text,
#     extra text,
#     bin int,
#     primary key (id)
#     );
# 
# CREATE TABLE relations (
#     parent text,
#     child text,
#     level int,
#     primary key (parent, child, level)
#     );
# 
# CREATE TABLE meta (
#     dialect text,
#     version text
#     );
# 
# CREATE TABLE directives (
#     directive text
#     );
# 
# CREATE TABLE autoincrements (
#     base text,
#     n int,
#     primary key (base)
#     );
# 
# CREATE TABLE duplicates (
#     idspecid text,
#     newid text,
#     primary key (newid)
#     );
# 
# 
# """
# _SELECT = "SELECT " \
#     + ', '.join(_keys) \
#     + ", features.rowid as file_order FROM features "
# _INSERT = "INSERT INTO features (" \
#     + ', '.join(_keys) + ") VALUES (" + ','.join(list('?' * len(_keys))) + ")"
# _UPDATE = "UPDATE features SET " + _update_clause + " WHERE id = ?"
# INDEXES = []


# Path: gffutils/test/feature_test.py
from gffutils import parser, feature, helpers, constants
        import pybedtools


def test_feature_from_line():
    # spaces and tabs should give identical results
    line1 = "chr2L	FlyBase	exon	7529	8116	.	+	.	Name=CG11023:1;Parent=FBtr0300689,FBtr0300690"
    line2 = "chr2L FlyBase exon 7529 8116 . + . Name=CG11023:1;Parent=FBtr0300689,FBtr0300690"
    assert feature.feature_from_line(line1, strict=False, keep_order=True) == \
            feature.feature_from_line(line2, strict=False, keep_order=True)


def test_default_feature():
    # Default Feature is 8 tab-delimited ".", with a trailing tab
    assert str(feature.Feature()) == \
    ".	.	.	.	.	.	.	.	"


def test_attributes_representations():
    # These different ways of supplying attributes should yield identical
    # results:
    s = ".	.	.	.	.	.	.	.	ID=asdf"
    for item in (
        '{"ID": ["asdf"]}',
        dict(ID=["asdf"]),
        "ID=asdf"
    ):

        result = str(feature.Feature(attributes=item))