本文整理汇总了Python中skbio.metadata.IntervalMetadata类的典型用法代码示例。如果您正苦于以下问题:Python IntervalMetadata类的具体用法?Python IntervalMetadata怎么用?Python IntervalMetadata使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IntervalMetadata类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _parse_record
def _parse_record(lines, length):
'''Parse the lines into a IntervalMetadata object.'''
interval_metadata = IntervalMetadata(length)
for line in lines:
columns = line.split('\t')
# there should be 9 columns
if len(columns) != 9:
raise GFF3FormatError(
'do not have 9 columns in this line: "%s"' % line)
# the 1st column is seq ID for every feature. don't store
# this repetitive information
metadata = {'source': columns[1],
'type': columns[2],
'score': columns[5],
'strand': columns[6]}
phase = columns[7]
# phase value can only be int or '.'
try:
metadata['phase'] = int(phase)
except ValueError:
if phase != '.':
raise GFF3FormatError(
'unknown value for phase column: {!r}'.format(phase))
metadata.update(_parse_attr(columns[8]))
start, end = columns[3:5]
bounds = [(int(start)-1, int(end))]
interval_metadata.add(bounds, metadata=metadata)
return interval_metadata
示例2: test_raise_subregion
def test_raise_subregion(self):
im = IntervalMetadata(None)
im.add([(0, 3), (7, 9)], metadata={'type': 'gene'})
with io.StringIO() as fh:
with self.assertRaises(GFF3FormatError):
_serialize_interval_metadata(
im, seq_id='a', fh=fh, skip_subregion=False)
示例3: test_init_copy_from
def test_init_copy_from(self):
for i in [None, 99, 999]:
obs = IntervalMetadata(i, self.im_1)
exp = IntervalMetadata(i)
exp.add(bounds=[(1, 2), (4, self.upper_bound)],
metadata={'gene': 'sagA', 'bound': 0})
self.assertEqual(obs, exp)
示例4: test_constructor_interval_metadata_len
def test_constructor_interval_metadata_len(self):
for n in 1, 2, 3:
im = IntervalMetadata(n)
im.add([(0, 1)], metadata={'a': 'b'})
obj = self._interval_metadata_constructor_(n, im)
self.assertTrue(obj.has_interval_metadata())
self.assertIsInstance(obj.interval_metadata, IntervalMetadata)
示例5: test_ne_only_one_is_empty
def test_ne_only_one_is_empty(self):
im1 = IntervalMetadata(self.upper_bound)
im1.add(**self.intvls[0])
obj1 = self._interval_metadata_constructor_(self.upper_bound, im1)
obj2 = self._interval_metadata_constructor_(self.upper_bound)
self.assertReallyNotEqual(obj1, obj2)
示例6: test_eq_populated_differently
def test_eq_populated_differently(self):
im1 = IntervalMetadata(self.upper_bound)
im1.add(**self.intvls[0])
obj1 = self._interval_metadata_constructor_(self.upper_bound, im1)
obj2 = self._interval_metadata_constructor_(self.upper_bound)
obj2.interval_metadata.add(**self.intvls[0])
self.assertReallyEqual(obj1, obj2)
示例7: test_transcribe_preserves_all_metadata
def test_transcribe_preserves_all_metadata(self):
im = IntervalMetadata(4)
im.add([(0, 2)], metadata={'gene': 'p53'})
exp = RNA('AGUU', metadata={'foo': 'bar'},
positional_metadata={'foo': range(4)},
interval_metadata=im)
seq = DNA('AGTT', metadata={'foo': 'bar'},
positional_metadata={'foo': range(4)},
interval_metadata=im)
self.assertEqual(seq.transcribe(), exp)
示例8: test_interval_metadata_to_gff3_missing_field
def test_interval_metadata_to_gff3_missing_field(self):
exp = 'ctg123\t.\tgene\t1\t9\t.\t.\t.\tID=gene00001;Name=EDEN'
imd = IntervalMetadata(9)
imd.add([(0, 9)], metadata={
'type': 'gene', 'ID': 'gene00001', 'Name': 'EDEN'})
with io.StringIO() as fh:
_interval_metadata_to_gff3(imd, fh, seq_id='ctg123')
# only compare the uncommented lines because the comments are not
# stored in IntervalMetadata
obs = [i for i in fh.getvalue().splitlines()
if not i.startswith('#')]
self.assertEqual([exp], obs)
示例9: test_interval_metadata_to_gff3_multiple_values
def test_interval_metadata_to_gff3_multiple_values(self):
# test multiple values of db_xref are correctly serialized
exp = 'ctg123\t.\tgene\t1\t9\t.\t.\t.\tDbxref=GO:000152,GO:001234'
imd = IntervalMetadata(9)
imd.add([(0, 9)], metadata={
'type': 'gene', 'db_xref': ['GO:000152', 'GO:001234']})
with io.StringIO() as fh:
_interval_metadata_to_gff3(imd, fh, seq_id='ctg123')
# only compare the uncommented lines because the comments are not
# stored in IntervalMetadata
obs = [i for i in fh.getvalue().splitlines()
if not i.startswith('#')]
self.assertEqual([exp], obs)
示例10: test_interval_metadata_to_gff3_escape
def test_interval_metadata_to_gff3_escape(self):
# test escape of reserved char in GFF3
exp = 'ctg123\t.\tgene\t1\t9\t.\t.\t.\tID=a%3B%3D%26%2Cb'
imd = IntervalMetadata(9)
imd.add([(0, 9)], metadata={
'type': 'gene', 'ID': 'a;=&,b'})
with io.StringIO() as fh:
_interval_metadata_to_gff3(imd, fh, seq_id='ctg123')
# only compare the uncommented lines because the comments are not
# stored in IntervalMetadata
obs = [i for i in fh.getvalue().splitlines()
if not i.startswith('#')]
self.assertEqual([exp], obs)
示例11: test_init_nondefault_parameters
def test_init_nondefault_parameters(self):
im = IntervalMetadata(8)
im.add([(1, 8)], metadata={'gene': 'p53'})
seq = ExampleGrammaredSequence(
'.-ABCXYZ',
metadata={'id': 'foo'},
positional_metadata={'quality': range(8)},
interval_metadata=im)
npt.assert_equal(seq.values, np.array('.-ABCXYZ', dtype='c'))
self.assertEqual(seq.metadata, {'id': 'foo'})
assert_data_frame_almost_equal(seq.positional_metadata,
pd.DataFrame({'quality': range(8)}))
self.assertEqual(seq.interval_metadata, im)
示例12: _set_up
def _set_up(self):
self.upper_bound = 9
self.im = IntervalMetadata(self.upper_bound)
self.intvls = [
{'bounds': [(0, 1), (2, 9)], 'metadata': {'gene': 'sagA'}},
{'bounds': [(0, 1)], 'metadata': {'gene': ['a'],
'product': 'foo'}}]
示例13: test_complement_without_reverse_non_empty
def test_complement_without_reverse_non_empty(self):
for (constructor, seq_str, comp_str,
qual) in self.all_combos_comp_qual:
comp = constructor(seq_str).complement()
self.assertEqual(comp, constructor(comp_str))
im = IntervalMetadata(len(seq_str))
im.add([(0, 1)], metadata={'gene': 'p53'})
comp = constructor(
seq_str,
metadata={'id': 'foo', 'description': 'bar'},
positional_metadata={'quality': qual},
interval_metadata=im).complement()
self.assertEqual(
comp,
constructor(
comp_str,
metadata={'id': 'foo', 'description': 'bar'},
positional_metadata={'quality': qual},
interval_metadata=im))
示例14: test_complement_with_reverse_non_empty
def test_complement_with_reverse_non_empty(self):
for (constructor, seq_str, rev_comp_str,
qual) in self.all_combos_rev_comp_qual:
rc = constructor(seq_str).complement(reverse=True)
self.assertEqual(rc, constructor(rev_comp_str))
length = len(seq_str)
im = IntervalMetadata(length)
im.add([(0, 1)], metadata={'gene': 'p53'})
im_rc = IntervalMetadata(length)
im_rc.add([(length-1, length)], metadata={'gene': 'p53'})
original = constructor(
seq_str,
metadata={'id': 'foo', 'description': 'bar'},
positional_metadata={
'quality': qual},
interval_metadata=im)
rc = original.complement(reverse=True)
self.assertEqual(
rc,
constructor(
rev_comp_str,
metadata={'id': 'foo', 'description': 'bar'},
positional_metadata={'quality':
list(qual)[::-1]},
interval_metadata=im_rc))
# assert the original object is not changed
self.assertIsNot(original.interval_metadata, im)
self.assertEqual(original.interval_metadata, im)
示例15: test_upper_bound_is_none
def test_upper_bound_is_none(self):
im = IntervalMetadata(None)
# should not raise error
im.add([(0, 1000000000)])
self.assertIsNone(im.upper_bound)
with self.assertRaisesRegex(
TypeError, r'upper bound is `None`'):
im._reverse()
with self.assertRaisesRegex(
TypeError, r'upper bound is `None`'):
IntervalMetadata.concat([self.im_1, im])