def test_default_start_stop():
    # Whether start or end is "." or None, attribute should always be None and
    # printing should show "."
    c = ['.', None]
    for i1 in c:
        for i2 in c:
            f = feature.Feature(start=i1, end=i2)
            assert f.start is None
            assert f.end is None
            assert f.stop is None
            assert str(f) == ".	.	.	.	.	.	.	.	", str(f)

    # Make sure zero works (protects against sloppy "if start:")
    f = feature.Feature(start=0, end=0)
    assert f.start == f.end == f.stop == 0
    assert str(f) == ".	.	.	0	0	.	.	.	", str(f)
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))
        assert result == s, result
Ejemplo n.º 3
0
 def derived_feature_generator():
     """
     Generator of items from the file that was just created...
     """
     keys = ['parent', 'seqid', 'start', 'end', 'strand',
             'featuretype', 'bin', 'attributes']
     for line in open(fout.name):
         d = dict(list(zip(keys, line.strip().split('\t'))))
         d.pop('parent')
         d['score'] = '.'
         d['source'] = 'gffutils_derived'
         d['frame'] = '.'
         d['extra'] = []
         d['attributes'] = helpers._unjsonify(d['attributes'])
         f = feature.Feature(**d)
         f.id = self._id_handler(f)
         yield f
Ejemplo n.º 4
0
 def _candidate_merges(self, f):
     """
     Identifies those features that originally had the same ID as `f`
     (according to the id_spec),  but were modified because of duplicate
     IDs.
     """
     candidates = [self._get_feature(f.id)]
     c = self.conn.cursor()
     results = c.execute(
         constants._SELECT + '''
         JOIN duplicates ON
         duplicates.newid = features.id WHERE duplicates.idspecid = ?''',
         (f.id, ))
     for i in results:
         candidates.append(
             feature.Feature(dialect=self.iterator.dialect, **i))
     return list(set(candidates))
Ejemplo n.º 5
0
 def _get_feature(self, ID):
     c = self.conn.cursor()
     results = c.execute(
         constants._SELECT + ' WHERE id = ?', (ID,)).fetchone()
     return feature.Feature(dialect=self.iterator.dialect, **results)
def test_default_feature():
    # Default Feature is 8 tab-delimited ".", with a trailing tab
    assert str(feature.Feature()) == \
    ".	.	.	.	.	.	.	.	"