コード例 #1
0
class TestPlugin(unittest.TestCase):
    def setUp(self):
        # TODO standardize temporary directories created by QIIME
        self.test_dir = tempfile.TemporaryDirectory(prefix='qiime2-temp-')

        self.markdown_fp = os.path.join(self.test_dir.name,
                                        'dummy_markdown_workflow.md')
        with open(self.markdown_fp, 'w') as markdown_fh:
            markdown_fh.write(markdown_template)

        self.plugin = Plugin(name='dummy-plugin',
                             version='0.4.2',
                             website='www.dummy-plugin-hub.com',
                             package='dummy_plugin')

    def tearDown(self):
        self.test_dir.cleanup()

    def test_constructor(self):
        self.assertEqual(self.plugin.name, 'dummy-plugin')
        self.assertEqual(self.plugin.version, '0.4.2')
        self.assertEqual(self.plugin.website, 'www.dummy-plugin-hub.com')
        self.assertEqual(self.plugin.package, 'dummy_plugin')
        self.assertEqual(self.plugin.workflows, {})

    def test_register_function(self):
        self.assertEqual(self.plugin.workflows, {})

        self.plugin.register_function(
            name='Dummy function',
            function=dummy_function,
            inputs={},
            outputs=[('answer', Int)],
            doc='Computes the answer to life, the universe, and everything')

        self.plugin.register_function(
            name='Dummy function',
            function=other_dummy_function,
            inputs={},
            outputs=[('answer', Int)],
            doc='Computes the answer to life, the universe, and everything')

        workflows = {
            'dummy_function':
            Workflow(signature=Signature(name='Dummy function',
                                         inputs={},
                                         outputs=collections.OrderedDict([
                                             ('answer', Int)
                                         ])),
                     template=expected_dummy_function_template,
                     id_='dummy_function'),
            'other_dummy_function':
            Workflow(signature=Signature(name='Dummy function',
                                         inputs={},
                                         outputs=collections.OrderedDict([
                                             ('answer', Int)
                                         ])),
                     template=expected_other_dummy_function_template,
                     id_='other_dummy_function')
        }

        self.assertEqual(self.plugin.workflows, workflows)

    def test_register_workflow(self):
        self.assertEqual(self.plugin.workflows, {})

        with unittest.mock.patch.object(pkg_resources,
                                        'resource_filename',
                                        return_value=self.markdown_fp):
            self.plugin.register_workflow(self.markdown_fp)

        workflows = {
            'dummy_markdown_workflow':
            Workflow(signature=Signature(name='Dummy markdown workflow',
                                         inputs={
                                             'param1': Int,
                                             'param2': Int
                                         },
                                         outputs=collections.OrderedDict([
                                             ('the_sum', Int)
                                         ])),
                     template=frontmatter.parse(markdown_template)[1],
                     id_='dummy_markdown_workflow')
        }

        self.assertEqual(self.plugin.workflows, workflows)

    def test_register_function_and_workflow(self):
        self.assertEqual(self.plugin.workflows, {})

        self.plugin.register_function(
            name='Dummy function',
            function=dummy_function,
            inputs={},
            outputs=[('answer', Int)],
            doc='Computes the answer to life, the universe, and everything')

        with unittest.mock.patch.object(pkg_resources,
                                        'resource_filename',
                                        return_value=self.markdown_fp):
            self.plugin.register_workflow(self.markdown_fp)

        workflows = {
            'dummy_function':
            Workflow(signature=Signature(name='Dummy function',
                                         inputs={},
                                         outputs=collections.OrderedDict([
                                             ('answer', Int)
                                         ])),
                     template=expected_dummy_function_template,
                     id_='dummy_function'),
            'dummy_markdown_workflow':
            Workflow(signature=Signature(name='Dummy markdown workflow',
                                         inputs={
                                             'param1': Int,
                                             'param2': Int
                                         },
                                         outputs=collections.OrderedDict([
                                             ('the_sum', Int)
                                         ])),
                     template=frontmatter.parse(markdown_template)[1],
                     id_='dummy_markdown_workflow')
        }

        self.assertEqual(self.plugin.workflows, workflows)
コード例 #2
0
ファイル: plugin_setup.py プロジェクト: ebolyen/q2-diversity
# The full license is in the file LICENSE, distributed with this software.
# ----------------------------------------------------------------------------

from qiime.plugin import Plugin, Str

import q2_diversity
from q2_types import FeatureTable, Frequency, DistanceMatrix, Phylogeny

plugin = Plugin(
    name='diversity',
    version=q2_diversity.__version__,
    website='https://github.com/qiime2-plugins/q2-diversity',
    package='q2_diversity'
)

# TODO create decorator for promoting functions to workflows. This info would
# be moved to the decorator calls.
plugin.register_function(
    function=q2_diversity.beta_diversity,
    # TODO require a uniform sampling effort FeatureTable when predicates exist
    inputs={'metric': Str,
            'feature_table': FeatureTable[Frequency],
            # TODO this is optional; how do we handle that here?
            'phylogeny': Phylogeny},
    outputs=[('distance_matrix', DistanceMatrix)],
    name='Beta diversity',
    doc="Let's compute some pairwise distances!"
)

plugin.register_workflow('workflows/feature_table_to_pcoa.md')
コード例 #3
0
ファイル: test_plugin.py プロジェクト: gblanchard4/qiime2
class TestPlugin(unittest.TestCase):
    def setUp(self):
        # TODO standardize temporary directories created by QIIME
        self.test_dir = tempfile.TemporaryDirectory(prefix='qiime2-temp-')

        self.markdown_fp = os.path.join(self.test_dir.name,
                                        'dummy_markdown_workflow.md')
        with open(self.markdown_fp, 'w') as markdown_fh:
            markdown_fh.write(markdown_template)

        self.plugin = Plugin(
            name='dummy-plugin',
            version='0.4.2',
            website='www.dummy-plugin-hub.com',
            package='dummy_plugin'
        )

    def tearDown(self):
        self.test_dir.cleanup()

    def test_constructor(self):
        self.assertEqual(self.plugin.name, 'dummy-plugin')
        self.assertEqual(self.plugin.version, '0.4.2')
        self.assertEqual(self.plugin.website, 'www.dummy-plugin-hub.com')
        self.assertEqual(self.plugin.package, 'dummy_plugin')
        self.assertEqual(self.plugin.workflows, {})

    def test_register_function(self):
        self.assertEqual(self.plugin.workflows, {})

        self.plugin.register_function(
            name='Dummy function',
            function=dummy_function,
            inputs={},
            outputs=[('answer', Int)],
            doc='Computes the answer to life, the universe, and everything'
        )

        self.plugin.register_function(
            name='Dummy function',
            function=other_dummy_function,
            inputs={},
            outputs=[('answer', Int)],
            doc='Computes the answer to life, the universe, and everything'
        )

        workflows = {
            'dummy_function':
                Workflow(
                    signature=Signature(
                        name='Dummy function',
                        inputs={},
                        outputs=collections.OrderedDict([('answer', Int)])),
                    template=expected_dummy_function_template,
                    id_='dummy_function'
                ),
            'other_dummy_function':
                Workflow(
                    signature=Signature(
                        name='Dummy function',
                        inputs={},
                        outputs=collections.OrderedDict([('answer', Int)])),
                    template=expected_other_dummy_function_template,
                    id_='other_dummy_function'
                )
        }

        self.assertEqual(self.plugin.workflows, workflows)

    def test_register_workflow(self):
        self.assertEqual(self.plugin.workflows, {})

        with unittest.mock.patch.object(pkg_resources, 'resource_filename',
                                        return_value=self.markdown_fp):
            self.plugin.register_workflow(self.markdown_fp)

        workflows = {
            'dummy_markdown_workflow':
                Workflow(
                    signature=Signature(
                        name='Dummy markdown workflow',
                        inputs={'param1': Int, 'param2': Int},
                        outputs=collections.OrderedDict([('the_sum', Int)])),
                    template=frontmatter.parse(markdown_template)[1],
                    id_='dummy_markdown_workflow'
                )
        }

        self.assertEqual(self.plugin.workflows, workflows)

    def test_register_function_and_workflow(self):
        self.assertEqual(self.plugin.workflows, {})

        self.plugin.register_function(
            name='Dummy function',
            function=dummy_function,
            inputs={},
            outputs=[('answer', Int)],
            doc='Computes the answer to life, the universe, and everything'
        )

        with unittest.mock.patch.object(pkg_resources, 'resource_filename',
                                        return_value=self.markdown_fp):
            self.plugin.register_workflow(self.markdown_fp)

        workflows = {
            'dummy_function':
                Workflow(
                    signature=Signature(
                        name='Dummy function',
                        inputs={},
                        outputs=collections.OrderedDict([('answer', Int)])),
                    template=expected_dummy_function_template,
                    id_='dummy_function'
                ),
            'dummy_markdown_workflow':
                Workflow(
                    signature=Signature(
                        name='Dummy markdown workflow',
                        inputs={'param1': Int, 'param2': Int},
                        outputs=collections.OrderedDict([('the_sum', Int)])),
                    template=frontmatter.parse(markdown_template)[1],
                    id_='dummy_markdown_workflow'
                )
        }

        self.assertEqual(self.plugin.workflows, workflows)
コード例 #4
0
#
# The full license is in the file LICENSE, distributed with this software.
# ----------------------------------------------------------------------------

from qiime.plugin import Plugin, Str

import q2_diversity
from q2_types import FeatureTable, Frequency, DistanceMatrix, Phylogeny

plugin = Plugin(name='diversity',
                version=q2_diversity.__version__,
                website='https://github.com/qiime2-plugins/q2-diversity',
                package='q2_diversity')

# TODO create decorator for promoting functions to workflows. This info would
# be moved to the decorator calls.
plugin.register_function(
    function=q2_diversity.beta_diversity,
    # TODO require a uniform sampling effort FeatureTable when predicates exist
    inputs={
        'metric': Str,
        'feature_table': FeatureTable[Frequency],
        # TODO this is optional; how do we handle that here?
        'phylogeny': Phylogeny
    },
    outputs=[('distance_matrix', DistanceMatrix)],
    name='Beta diversity',
    doc="Let's compute some pairwise distances!")

plugin.register_workflow('workflows/feature_table_to_pcoa.md')