本文整理匯總了Python中qiime.sdk.Artifact._from_view方法的典型用法代碼示例。如果您正苦於以下問題:Python Artifact._from_view方法的具體用法?Python Artifact._from_view怎麽用?Python Artifact._from_view使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類qiime.sdk.Artifact
的用法示例。
在下文中一共展示了Artifact._from_view方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_call_with_no_parameters
# 需要導入模塊: from qiime.sdk import Artifact [as 別名]
# 或者: from qiime.sdk.Artifact import _from_view [as 別名]
def test_call_with_no_parameters(self):
merge_mappings = self.plugin.methods['merge_mappings']
artifact1 = Artifact._from_view({'foo': 'abc', 'bar': 'def'}, Mapping,
None)
artifact2 = Artifact._from_view({'bazz': 'abc'}, Mapping, None)
result = merge_mappings(artifact1, artifact2)
self.assertIsInstance(result, Artifact)
self.assertEqual(result.type, Mapping)
provenance = result.provenance
self.assertIsInstance(provenance, Provenance)
self.assertIsInstance(provenance.execution_uuid, uuid.UUID)
self.assertTrue(
provenance.executor_reference.startswith(merge_mappings.id))
self.assertEqual(provenance.artifact_uuids, {
'mapping1': artifact1.uuid,
'mapping2': artifact2.uuid
})
self.assertEqual(provenance.parameter_references, {})
self.assertIsInstance(result.uuid, uuid.UUID)
self.assertEqual(result.view(dict),
{'foo': 'abc', 'bar': 'def', 'bazz': 'abc'})
示例2: test_load_with_archive_filepath_modified
# 需要導入模塊: from qiime.sdk import Artifact [as 別名]
# 或者: from qiime.sdk.Artifact import _from_view [as 別名]
def test_load_with_archive_filepath_modified(self):
# Save an artifact for use in the following test case.
fp = os.path.join(self.test_dir.name, 'artifact.qza')
Artifact._from_view([-1, 42, 0, 43], FourInts, None).save(fp)
# Load the artifact from a filepath then save a different artifact to
# the same filepath. Assert that both artifacts produce the correct
# views of their data.
#
# `load` used to be lazy, only extracting data when it needed to (e.g.
# when `save` or `view` was called). This was buggy as the filepath
# could have been deleted, or worse, modified to contain a different
# .qza file. Thus, the wrong archive could be extracted on demand, or
# the archive could be missing altogether. There isn't an easy
# cross-platform compatible way to solve this problem, so Artifact.load
# is no longer lazy and always extracts its data immediately. The real
# motivation for lazy loading was for quick inspection of archives
# without extracting/copying data, so that API is now provided through
# Artifact.peek.
artifact1 = Artifact.load(fp)
Artifact._from_view([10, 11, 12, 13], FourInts, None).save(fp)
artifact2 = Artifact.load(fp)
self.assertEqual(artifact1.view(list), [-1, 42, 0, 43])
self.assertEqual(artifact2.view(list), [10, 11, 12, 13])
示例3: setUp
# 需要導入模塊: from qiime.sdk import Artifact [as 別名]
# 或者: from qiime.sdk.Artifact import _from_view [as 別名]
def setUp(self):
# TODO standardize temporary directories created by QIIME
self.test_dir = tempfile.TemporaryDirectory(prefix='qiime2-temp-')
self.dummy_provenance = Provenance(
job_uuid='7e909a23-21e2-44c2-be17-0723fae91dc8',
artifact_uuids={
'input1': 'f16ca3d0-fe83-4b1e-8eea-7e35db3f6b0f',
'input2': '908dece5-db23-4562-ad03-876bb5750145',
},
parameters={
'param1': 'abc',
'param2': 100,
},
workflow_reference=(
'dummy workflow reference, see '
'https://github.com/biocore/qiime2/issues/26'
)
)
self.artifact_with_provenance = Artifact._from_view(
[-1, 42, 0, 43, 43], qiime.core.testing.TestType,
self.dummy_provenance)
self.artifact_without_provenance = Artifact._from_view(
[-1, 42, 0, 43, 43], qiime.core.testing.TestType, None)
示例4: test_async
# 需要導入模塊: from qiime.sdk import Artifact [as 別名]
# 或者: from qiime.sdk.Artifact import _from_view [as 別名]
def test_async(self):
concatenate_ints = self.plugin.methods['concatenate_ints']
concatenate_ints_markdown = \
self.plugin.methods['concatenate_ints_markdown']
artifact1 = Artifact._from_view([0, 42, 43], IntSequence1, None)
artifact2 = Artifact._from_view([99, -22], IntSequence2, None)
for method in concatenate_ints, concatenate_ints_markdown:
future = method.async(artifact1, artifact1, artifact2, 55, 1)
self.assertIsInstance(future, concurrent.futures.Future)
result = future.result()
self.assertIsInstance(result, Artifact)
self.assertEqual(result.type, IntSequence1)
provenance = result.provenance
self.assertIsInstance(provenance, Provenance)
self.assertIsInstance(provenance.execution_uuid, uuid.UUID)
self.assertTrue(
provenance.executor_reference.startswith(method.id))
self.assertEqual(provenance.artifact_uuids, {
'ints1': artifact1.uuid,
'ints2': artifact1.uuid,
'ints3': artifact2.uuid
})
self.assertEqual(provenance.parameter_references, {
'int1': '55',
'int2': '1'
})
self.assertIsInstance(result.uuid, uuid.UUID)
# Can retrieve multiple views of different type.
exp_list_view = [0, 42, 43, 0, 42, 43, 99, -22, 55, 1]
self.assertEqual(result.view(list), exp_list_view)
self.assertEqual(result.view(list), exp_list_view)
exp_counter_view = collections.Counter(
{0: 2, 42: 2, 43: 2, 99: 1, -22: 1, 55: 1, 1: 1})
self.assertEqual(result.view(collections.Counter),
exp_counter_view)
self.assertEqual(result.view(collections.Counter),
exp_counter_view)
# Accepts IntSequence1 | IntSequence2
artifact3 = Artifact._from_view([10, 20], IntSequence2, None)
future = method.async(artifact3, artifact1, artifact2, 55, 1)
result = future.result()
self.assertEqual(result.type, IntSequence1)
self.assertEqual(result.view(list),
[10, 20, 0, 42, 43, 99, -22, 55, 1])
示例5: test_call_with_multiple_outputs
# 需要導入模塊: from qiime.sdk import Artifact [as 別名]
# 或者: from qiime.sdk.Artifact import _from_view [as 別名]
def test_call_with_multiple_outputs(self):
split_ints = self.plugin.methods['split_ints']
split_ints_markdown = self.plugin.methods['split_ints_markdown']
artifact = Artifact._from_view([0, 42, -2, 43, 6], IntSequence1, None)
for method in split_ints, split_ints_markdown:
result = method(artifact)
self.assertIsInstance(result, tuple)
self.assertEqual(len(result), 2)
for output_artifact in result:
self.assertEqual(output_artifact.type, IntSequence1)
provenance = output_artifact.provenance
self.assertIsInstance(provenance, Provenance)
self.assertIsInstance(provenance.execution_uuid, uuid.UUID)
self.assertTrue(
provenance.executor_reference.startswith(method.id))
self.assertEqual(provenance.artifact_uuids, {
'ints': artifact.uuid
})
self.assertEqual(provenance.parameter_references, {})
self.assertIsInstance(output_artifact.uuid, uuid.UUID)
# Output artifacts have the same provenance.
self.assertEqual(result[0].provenance, result[1].provenance)
# Output artifacts have different UUIDs.
self.assertNotEqual(result[0].uuid, result[1].uuid)
self.assertEqual(result[0].view(list), [0, 42])
self.assertEqual(result[1].view(list), [-2, 43, 6])
示例6: test_from_view_with_provenance
# 需要導入模塊: from qiime.sdk import Artifact [as 別名]
# 或者: from qiime.sdk.Artifact import _from_view [as 別名]
def test_from_view_with_provenance(self):
artifact = Artifact._from_view([-1, 42, 0, 43], FourInts,
self.provenance)
self.assertEqual(artifact.type, FourInts)
self.assertEqual(artifact.provenance, self.provenance)
self.assertIsInstance(artifact.uuid, uuid.UUID)
self.assertEqual(artifact.view(list), [-1, 42, 0, 43])
self.assertEqual(artifact.view(list), [-1, 42, 0, 43])
示例7: test_from_view
# 需要導入模塊: from qiime.sdk import Artifact [as 別名]
# 或者: from qiime.sdk.Artifact import _from_view [as 別名]
def test_from_view(self):
artifact = Artifact._from_view(FourInts, [-1, 42, 0, 43], list,
self.provenance_capture)
self.assertEqual(artifact.type, FourInts)
# We don't know what the UUID is because it's generated within
# Artifact._from_view.
self.assertIsInstance(artifact.uuid, uuid.UUID)
self.assertEqual(artifact.view(list), [-1, 42, 0, 43])
# Can produce same view if called again.
self.assertEqual(artifact.view(list), [-1, 42, 0, 43])
示例8: test_peek
# 需要導入模塊: from qiime.sdk import Artifact [as 別名]
# 或者: from qiime.sdk.Artifact import _from_view [as 別名]
def test_peek(self):
artifact = Artifact._from_view([0, 0, 42, 1000], FourInts, None)
fp = os.path.join(self.test_dir.name, 'artifact.qza')
artifact.save(fp)
metadata = Artifact.peek(fp)
self.assertIsInstance(metadata, ResultMetadata)
self.assertEqual(metadata.type, FourInts)
self.assertIsNone(metadata.provenance)
self.assertEqual(metadata.uuid, artifact.uuid)
示例9: test_peek_with_provenance
# 需要導入模塊: from qiime.sdk import Artifact [as 別名]
# 或者: from qiime.sdk.Artifact import _from_view [as 別名]
def test_peek_with_provenance(self):
artifact = Artifact._from_view({'foo': 'bar', 'baz': 'bazz'}, Mapping,
self.provenance)
fp = os.path.join(self.test_dir.name, 'artifact.qza')
artifact.save(fp)
metadata = Artifact.peek(fp)
self.assertIsInstance(metadata, ResultMetadata)
self.assertEqual(metadata.type, Mapping)
self.assertEqual(metadata.provenance, self.provenance)
self.assertEqual(metadata.uuid, artifact.uuid)
示例10: test_load
# 需要導入模塊: from qiime.sdk import Artifact [as 別名]
# 或者: from qiime.sdk.Artifact import _from_view [as 別名]
def test_load(self):
saved_artifact = Artifact._from_view([-1, 42, 0, 43], FourInts, None)
fp = os.path.join(self.test_dir.name, 'artifact.qza')
saved_artifact.save(fp)
artifact = Artifact.load(fp)
self.assertEqual(artifact.type, FourInts)
self.assertIsNone(artifact.provenance)
self.assertEqual(artifact.uuid, saved_artifact.uuid)
self.assertEqual(artifact.view(list), [-1, 42, 0, 43])
self.assertEqual(artifact.view(list), [-1, 42, 0, 43])
示例11: test_from_view_different_type_with_multiple_view_types
# 需要導入模塊: from qiime.sdk import Artifact [as 別名]
# 或者: from qiime.sdk.Artifact import _from_view [as 別名]
def test_from_view_different_type_with_multiple_view_types(self):
artifact = Artifact._from_view([42, 42, 43, -999, 42], IntSequence1,
None)
self.assertEqual(artifact.type, IntSequence1)
self.assertIsNone(artifact.provenance)
self.assertIsInstance(artifact.uuid, uuid.UUID)
self.assertEqual(artifact.view(list), [42, 42, 43, -999, 42])
self.assertEqual(artifact.view(list), [42, 42, 43, -999, 42])
self.assertEqual(artifact.view(collections.Counter),
collections.Counter({42: 3, 43: 1, -999: 1}))
self.assertEqual(artifact.view(collections.Counter),
collections.Counter({42: 3, 43: 1, -999: 1}))
示例12: test_roundtrip
# 需要導入模塊: from qiime.sdk import Artifact [as 別名]
# 或者: from qiime.sdk.Artifact import _from_view [as 別名]
def test_roundtrip(self):
fp1 = os.path.join(self.test_dir.name, 'artifact1.qza')
fp2 = os.path.join(self.test_dir.name, 'artifact2.qza')
artifact = Artifact._from_view([-1, 42, 0, 43], FourInts,
self.provenance)
artifact.save(fp1)
artifact1 = Artifact.load(fp1)
artifact1.save(fp2)
artifact2 = Artifact.load(fp2)
self.assertEqual(artifact1.type, artifact2.type)
self.assertEqual(artifact1.provenance, artifact2.provenance)
self.assertEqual(artifact1.uuid, artifact2.uuid)
self.assertEqual(artifact1.view(list), artifact2.view(list))
self.assertEqual(artifact1.view(list), artifact2.view(list))
示例13: test_load_different_type_with_multiple_view_types
# 需要導入模塊: from qiime.sdk import Artifact [as 別名]
# 或者: from qiime.sdk.Artifact import _from_view [as 別名]
def test_load_different_type_with_multiple_view_types(self):
saved_artifact = Artifact._from_view([42, 42, 43, -999, 42],
IntSequence1, None)
fp = os.path.join(self.test_dir.name, 'artifact.qza')
saved_artifact.save(fp)
artifact = Artifact.load(fp)
self.assertEqual(artifact.type, IntSequence1)
self.assertIsNone(artifact.provenance)
self.assertEqual(artifact.uuid, saved_artifact.uuid)
self.assertEqual(artifact.view(list), [42, 42, 43, -999, 42])
self.assertEqual(artifact.view(list), [42, 42, 43, -999, 42])
self.assertEqual(artifact.view(collections.Counter),
collections.Counter({42: 3, 43: 1, -999: 1}))
self.assertEqual(artifact.view(collections.Counter),
collections.Counter({42: 3, 43: 1, -999: 1}))
示例14: test_from_view_and_save
# 需要導入模塊: from qiime.sdk import Artifact [as 別名]
# 或者: from qiime.sdk.Artifact import _from_view [as 別名]
def test_from_view_and_save(self):
fp = os.path.join(self.test_dir.name, 'artifact.qza')
# Using four-ints data layout because it has multiple files, some of
# which are in a nested directory.
artifact = Artifact._from_view([-1, 42, 0, 43], FourInts,
self.provenance)
artifact.save(fp)
with zipfile.ZipFile(fp, mode='r') as zf:
fps = set(zf.namelist())
expected = {
'artifact/VERSION',
'artifact/metadata.yaml',
'artifact/README.md',
'artifact/data/file1.txt',
'artifact/data/file2.txt',
'artifact/data/nested/file3.txt',
'artifact/data/nested/file4.txt'
}
self.assertEqual(fps, expected)
示例15: test_extract
# 需要導入模塊: from qiime.sdk import Artifact [as 別名]
# 或者: from qiime.sdk.Artifact import _from_view [as 別名]
def test_extract(self):
fp = os.path.join(self.test_dir.name, 'artifact.qza')
artifact = Artifact._from_view([-1, 42, 0, 43], FourInts,
self.provenance)
artifact.save(fp)
output_dir = os.path.join(self.test_dir.name, 'artifact-extract-test')
result_dir = Artifact.extract(fp, output_dir=output_dir)
self.assertEqual(result_dir, output_dir)
contents = [
'artifact/VERSION',
'artifact/metadata.yaml',
'artifact/README.md',
'artifact/data/file1.txt',
'artifact/data/file2.txt',
'artifact/data/nested/file3.txt',
'artifact/data/nested/file4.txt']
for fp in contents:
expected_fp = os.path.join(output_dir, fp)
self.assertTrue(os.path.exists(expected_fp),
'File %s was not extracted.' % fp)