本文整理汇总了Python中skbio.metadata.IntervalMetadata类的典型用法代码示例。如果您正苦于以下问题:Python IntervalMetadata类的具体用法?Python IntervalMetadata怎么用?Python IntervalMetadata使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IntervalMetadata类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
开发者ID:ElDeveloper,项目名称:biolopy,代码行数:32,代码来源:gff3.py
示例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)
开发者ID:RNAer,项目名称:scikit-bio,代码行数:7,代码来源:test_gff3.py
示例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)
开发者ID:ElDeveloper,项目名称:biolopy,代码行数:7,代码来源:test_interval.py
示例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)
开发者ID:jakereps,项目名称:scikit-bio,代码行数:7,代码来源:_testing.py
示例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)
开发者ID:jakereps,项目名称:scikit-bio,代码行数:8,代码来源:_testing.py
示例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)
开发者ID:jakereps,项目名称:scikit-bio,代码行数:9,代码来源:_testing.py
示例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)
开发者ID:RNAer,项目名称:scikit-bio,代码行数:11,代码来源:test_dna.py
示例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)
开发者ID:RNAer,项目名称:scikit-bio,代码行数:13,代码来源:test_gff3.py
示例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)
开发者ID:RNAer,项目名称:scikit-bio,代码行数:14,代码来源:test_gff3.py
示例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)
开发者ID:RNAer,项目名称:scikit-bio,代码行数:14,代码来源:test_gff3.py
示例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)
开发者ID:ElDeveloper,项目名称:biolopy,代码行数:14,代码来源:test_grammared_sequence.py
示例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'}}]
开发者ID:jakereps,项目名称:scikit-bio,代码行数:7,代码来源:_testing.py
示例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))
开发者ID:RNAer,项目名称:scikit-bio,代码行数:20,代码来源:test_nucleotide_sequences.py
示例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)
开发者ID:RNAer,项目名称:scikit-bio,代码行数:30,代码来源:test_nucleotide_sequences.py
示例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])
开发者ID:ElDeveloper,项目名称:biolopy,代码行数:11,代码来源:test_interval.py
示例16: test_eq_basic
def test_eq_basic(self):
im1 = IntervalMetadata(self.upper_bound)
im1.add(**self.intvls[0])
obj1 = self._interval_metadata_constructor_(self.upper_bound, im1)
im2 = IntervalMetadata(self.upper_bound)
im2.add(**self.intvls[0])
obj2 = self._interval_metadata_constructor_(self.upper_bound, im2)
self.assertReallyEqual(obj1, obj2)
开发者ID:jakereps,项目名称:scikit-bio,代码行数:10,代码来源:_testing.py
示例17: test_serialize_location
def test_serialize_location(self):
imd = IntervalMetadata(9)
i1 = imd.add([(0, 1)])
self.assertEqual(_serialize_location(i1), '1')
i2 = imd.add([(0, 2)], [(True, True)])
self.assertEqual(_serialize_location(i2), '<1..>2')
i3 = imd.add([(0, 2)], [(False, True)])
self.assertEqual(_serialize_location(i3), '1..>2')
i4 = imd.add([(0, 2)], [(True, False)])
self.assertEqual(_serialize_location(i4), '<1..2')
i5 = imd.add([(0, 2), (3, 9)], metadata={'strand': '-'})
self.assertEqual(_serialize_location(i5),
'complement(join(1..2,4..9))')
i6 = imd.add([(0, 2), (3, 9)],
[(True, False), (False, True)],
metadata={'strand': '-'})
self.assertEqual(_serialize_location(i6),
'complement(join(<1..2,4..>9))')
开发者ID:RNAer,项目名称:scikit-bio,代码行数:23,代码来源:test_sequence_feature_vocabulary.py
示例18: setUp
def setUp(self):
self.multi_fp = get_data_path('gff3_multi_record')
self.single_fp = get_data_path('gff3_single_record')
intvls = [{'bounds': [(0, 4641652)],
'metadata': {'source': 'European Nucleotide Archive',
'type': 'chromosome',
'score': '.',
'strand': '.',
'ID': 'chromosome:Chromosome',
'Alias': 'U00096.3',
'Is_circular': 'true'}},
{'bounds': [(147, 148)],
'metadata': {'source': 'regulondb_feature',
'type': 'biological_region',
'score': '.',
'strand': '+',
'external_name':
'Promoter thrLp (RegulonDB:ECK120010236)',
'logic_name': 'regulondb_promoter'}},
{'bounds': [(336, 2799)],
'metadata': {'source': 'Prodigal_v2.60',
'type': 'gene',
'score': '1.8',
'strand': '+',
'phase': 0,
'ID': '1_1',
'gc_cont': '0.427'}},
{'bounds': [(336, 2799)],
'metadata': {'source': 'Prodigal_v2.60',
'type': 'CDS',
'score': '333.8',
'strand': '+',
'phase': 0,
'ID': '1_2',
'Parent': '1_1',
'rbs_motif': 'GGAG/GAGG',
'rbs_spacer': '5-10bp'}},
{'bounds': [(0, 50), (55, 100)],
'metadata': {'source': 'Prodigal_v2.60',
'type': 'gene',
'score': '1.8',
'strand': '+',
'phase': 0,
'ID': '1_1',
'gene': 'FXR receptor'}}]
self.upper_bound = 4641652
self.imd1 = IntervalMetadata(self.upper_bound)
self.imd1.add(**intvls[0])
self.imd1.add(**intvls[1])
self.imd2 = IntervalMetadata(None)
self.imd2.add(**intvls[2])
self.imd2.add(**intvls[3])
self.imd3 = IntervalMetadata(None)
self.imd3.add(**intvls[4])
self.seq_fp = get_data_path('gff3_dna')
self.seq = Sequence('ATGCATGCATGC',
metadata={'id': 'NC_1',
'description': 'species X'})
self.seq.interval_metadata.add(
[(0, 9)],
metadata={'source': 'Prodigal_v2.60',
'type': 'gene',
'score': '.',
'strand': '+',
'phase': 0,
'ID': 'gene1',
'Name': 'FXR'})
self.dna = DNA(self.seq)
开发者ID:RNAer,项目名称:scikit-bio,代码行数:73,代码来源:test_gff3.py
示例19: setUp
def setUp(self):
# test locus line
self.locus = (
(['LOCUS NC_005816 9609 bp '
'DNA circular CON 07-FEB-2015'],
{'division': 'CON', 'mol_type': 'DNA', 'shape': 'circular',
'locus_name': 'NC_005816', 'date': '07-FEB-2015',
'unit': 'bp', 'size': 9609}),
(['LOCUS SCU49845 5028 bp '
'DNA PLN 21-JUN-1999'],
{'division': 'PLN', 'mol_type': 'DNA', 'shape': None,
'locus_name': 'SCU49845', 'date': '21-JUN-1999',
'unit': 'bp', 'size': 5028}),
(['LOCUS NP_001832 360 aa '
'linear PRI 18-DEC-2001'],
{'division': 'PRI', 'mol_type': None, 'shape': 'linear',
'locus_name': 'NP_001832', 'date': '18-DEC-2001',
'unit': 'aa', 'size': 360}))
# test single record and read uppercase sequence
self.single_upper_fp = get_data_path('genbank_single_record_upper')
self.single_lower_fp = get_data_path('genbank_single_record_lower')
self.single = (
'GSREILDFK',
{'LOCUS': {'date': '23-SEP-1994',
'division': 'BCT',
'locus_name': 'AAB29917',
'mol_type': None,
'shape': 'linear',
'size': 9,
'unit': 'aa'}},
None,
Protein)
self.single_rna_fp = get_data_path('genbank_single_record')
imd = IntervalMetadata(63)
imd.add([(0, 63)],
[(False, False)],
{'db_xref': '"taxon:562"',
'mol_type': '"mRNA"',
'organism': '"Escherichia coli"',
'type': 'source',
'strand': '+',
'__location': '1..63'})
imd.add([(0, 63)],
[(False, True)],
{'phase': 0,
'db_xref': ['"taxon:562"', '"taxon:561"'],
'__location': '1..>63',
'strand': '+',
'note': '"alkaline phosphatase signal peptide"',
'protein_id': '"AAA23431.1"',
'transl_table': '11',
'translation': '"MKQSTIALAVLPLLFTPVTKA"',
'type': 'CDS'})
self.single_rna = (
'gugaaacaaagcacuauugcacuggcugucuuaccguuacuguuuaccccugugacaaaagcc',
{'ACCESSION': 'M14399',
'COMMENT': 'Original source text: E.coli, cDNA to mRNA.',
'DEFINITION': "alkaline phosphatase signal mRNA, 5' end.",
'KEYWORDS': 'alkaline phosphatase; signal peptide.',
'LOCUS': {'date': '26-APR-1993',
'division': 'BCT',
'locus_name': 'ECOALKP',
'mol_type': 'mRNA',
'shape': 'linear',
'size': 63,
'unit': 'bp'},
'SOURCE': {'ORGANISM': 'Escherichia coli',
'taxonomy': 'Bacteria; Proteobacteria; '
'Gammaproteobacteria; Enterobacteriales; '
'Enterobacteriaceae; Escherichia.'},
'VERSION': 'M14399.1'},
imd,
RNA)
# test:
# 1. multiple records in one file
# 2. lowercase sequence
# 3. DNA, RNA, Protein type
# 4. variation of formats
self.multi_fp = get_data_path('genbank_multi_records')
imd_pro = IntervalMetadata(9)
imd_pro.add([(0, 9)], [(False, False)],
{'organism': '"Bacteria"',
'type': 'source',
'strand': '+',
'__location': '1..9'},)
imd_pro.add([(0, 9)], [(False, True)],
{'__location': '1..>9',
'product': '"L-carnitine amidase"',
'strand': '+',
'type': 'Protein'})
imd_dna = IntervalMetadata(9)
imd_dna.add([(0, 9)], [(False, False)],
{'country': '"Brazil: Parana, Paranavai"',
'type': 'source',
'strand': '+',
'__location': '1..9',
'environmental_sample': ''})
#.........这里部分代码省略.........
开发者ID:ElDeveloper,项目名称:biolopy,代码行数:101,代码来源:test_genbank.py
示例20: TestIntervalMetadata
class TestIntervalMetadata(unittest.TestCase, ReallyEqualMixin):
def setUp(self):
self.upper_bound = 10
self.im_empty = IntervalMetadata(self.upper_bound)
self.im_1 = IntervalMetadata(self.upper_bound)
self.im_1_1 = Interval(
interval_metadata=self.im_1,
bounds=[(1, 2), (4, self.upper_bound)],
metadata={'gene': 'sagA', 'bound': 0})
self.im_2 = IntervalMetadata(self.upper_bound)
self.im_2_1 = Interval(
interval_metadata=self.im_2,
bounds=[(1, 2), (4, self.upper_bound)],
metadata={'gene': 'sagA', 'bound': 0})
self.im_2_2 = Interval(
interval_metadata=self.im_2,
bounds=[(3, 5)],
metadata={'gene': 'sagB', 'bound': 0, 'spam': [0]})
def test_copy_empty(self):
obs = copy(self.im_empty)
self.assertEqual(obs, self.im_empty)
self.assertIsNot(obs._intervals, self.im_empty._intervals)
self.assertIsNot(obs._interval_tree, self.im_empty._interval_tree)
def test_copy(self):
obs = copy(self.im_2)
self.assertEqual(obs, self.im_2)
self.assertIsNot(obs._intervals, self.im_2._intervals)
self.assertIsNot(obs._interval_tree, self.im_2._interval_tree)
for i in range(self.im_2.num_interval_features):
i1, i2 = obs._intervals[i], self.im_2._intervals[i]
self.assertIsNot(i1, i2)
self.assertIsNot(i1.bounds, i2.bounds)
self.assertIsNot(i1.fuzzy, i2.fuzzy)
self.assertIsNot(i1._interval_metadata, i2._interval_metadata)
self.assertIsNot(i1.metadata, i2.metadata)
for k in i1.metadata:
self.assertIs(i1.metadata[k], i2.metadata[k])
def test_deepcopy(self):
obs = deepcopy(self.im_2)
self.assertEqual(obs, self.im_2)
self.assertIsNot(obs._intervals, self.im_2._intervals)
self.assertIsNot(obs._interval_tree, self.im_2._interval_tree)
for i in range(self.im_2.num_interval_features):
i1, i2 = obs._intervals[i], self.im_2._intervals[i]
self.assertIsNot(i1, i2)
self.assertIsNot(i1.bounds, i2.bounds)
self.assertIsNot(i1.fuzzy, i2.fuzzy)
self.assertIsNot(i1.metadata, i2.metadata)
i2.metadata['spam'].append(1)
self.assertEqual(i2.metadata,
{'gene': 'sagB', 'bound': 0, 'spam': [0, 1]})
self.assertEqual(i1.metadata,
{'gene': 'sagB', 'bound': 0, 'spam': [0]})
def test_deepcopy_memo_is_respected(self):
memo = {}
deepcopy(self.im_1, memo)
self.assertGreater(len(memo), 2)
def test_init(self):
self.assertFalse(self.im_empty._is_stale_tree)
self.assertEqual(self.im_empty._intervals, [])
def test_init_upper_bound_lt_lower_bound(self):
# test that no exception is raised
IntervalMetadata(0)
with self.assertRaises(ValueError):
IntervalMetadata(-1)
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])
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)
def test_init_copy_from_empty(self):
for i in [None, 0, 9, 99, 999]:
obs = IntervalMetadata(i, self.im_empty)
exp = IntervalMetadata(i)
#.........这里部分代码省略.........
开发者ID:ElDeveloper,项目名称:biolopy,代码行数:101,代码来源:test_interval.py
注:本文中的skbio.metadata.IntervalMetadata类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论