Beispiel #1
0
    def test_constructor(self):
        class MockEntryPoint(pkg_resources.EntryPoint):
            def __init__(self, plugin):
                self.plugin = plugin

            def load(self):
                return self.plugin

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

        def mock_iter_entry_points(group):
            return [MockEntryPoint(plugin1), MockEntryPoint(plugin2)]

        with unittest.mock.patch.object(pkg_resources, 'iter_entry_points',
                                        mock_iter_entry_points):
            plugin_manager = PluginManager()

        self.assertEqual(plugin_manager.plugins, {
            'dummy-plugin': plugin1,
            'other-dummy-plugin': plugin2
        })
Beispiel #2
0
    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')
Beispiel #3
0
    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'
        )
Beispiel #4
0
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file LICENSE, distributed with this software.
# ----------------------------------------------------------------------------

import io
import os
import base64
import shutil

from qiime.plugin import Plugin, Int, Properties, SemanticType, FileFormat, DataLayout


plugin = Plugin(
    name='gba',
    version='0.0.1dev',
    website='https://github.com/ebolyen/q2-gba',
    package='q2_gba'
)


Game = SemanticType('Game', field_names='type')
GBA = SemanticType('GBA', variant_of=Game.field['type'])

plugin.register_semantic_type(Game)
plugin.register_semantic_type(GBA)


class GBAFormat(FileFormat):
    name = 'GBA'

    @classmethod
Beispiel #5
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)
Beispiel #6
0
    Bio.Phylo.write(tree, tree_out, 'newick')
    if isinstance(mapping_df, pd.DataFrame):
        mapping_out = os.path.join(dat_dir, 'mapping.txt')
        mapping_df.to_csv(mapping_out, sep='\t')


    # FEEDBACK
    print("All your files have been written to the directory", output_dir)
    print("Simply open the file index.html in a browser that has")
    print("an internet connection to view the interactive phylogram.")



plugin = Plugin(
    name='phylogram',
    version=__version__,
    website='https://github.com/ConstantinoSchillebeeckx/q2-phylogram',
    package='q2_phylogram'
)

plugin.visualizers.register_function(
    function=make_d3_phylogram,
    inputs={'tree': Phylogeny},
    parameters={'otu_metadata': qiime.plugin.Metadata},
    name='Visualize phylogram',
    description='Generate interactive visualization of your phylogenetic tree.'
)

def tree_to_biopython_tree(data_dir):
    with open(os.path.join(data_dir, 'tree.nwk'), 'r') as fh:
        return Bio.Phylo.read(fh, 'newick')
Beispiel #7
0
# ----------------------------------------------------------------------------
# Copyright (c) 2016--, Jorden Kreps.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file LICENSE, distributed with this software.
# ----------------------------------------------------------------------------

from qiime.plugin import Plugin, Int, Bool

import test_plugin
from q2_types import FeatureTable, Frequency, RelativeFrequency

plugin = Plugin(name='test-plugin',
                version=test_plugin.__version__,
                website='http://github.com/jakereps/q2-test-plugin',
                package='test_plugin')

plugin.methods.register_function(
    function=test_plugin.blocking_test,
    inputs={'table': FeatureTable[Frequency]},
    parameters={'timeout': Int},
    outputs=[('rarefied_table', FeatureTable[Frequency])],
    name='Blocking test',
    description='Set a timeout for this script to run, '
    'then try to run more things!')

plugin.methods.register_function(
    function=test_plugin.stdio_test,
    inputs={'table': FeatureTable[Frequency]},
    parameters={'number': Int},
    # index.html, tree.tre, mapping.txt (optional)
    dat_dir = os.path.join(output_dir,'dat')
    if not os.path.exists(dat_dir):
        os.makedirs(dat_dir)
    with open(os.path.join(output_dir,'index.html'), 'w') as fout:
        fout.write(index)
    tree_out = os.path.join(dat_dir,'tree.tre')
    with open(tree_out, 'w') as fout:
        fout.write("d3.jsonp.readNewick('%s');" %str(tree).strip()) # add callback around Newick string for use in cross-origin setting




plugin = Plugin(
    name='phylogram',
    version=__version__,
    website='https://github.com/ConstantinoSchillebeeckx/q2-phylogram',
    package='q2_phylogram'
)

plugin.visualizers.register_function(
    function=make_d3_phylogram,
    inputs={'tree': Phylogeny},
    parameters={'otu_metadata': qiime.plugin.Metadata},
    name='Visualize phylogram',
    description='Generate interactive visualization of your phylogenetic tree.'
)

def tree_to_skbio_tree(data_dir):
    with open(os.path.join(data_dir, 'tree.nwk'), 'r') as fh:
        return read(fh, format="newick", into=TreeNode)
Beispiel #9
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)
Beispiel #10
0
# ----------------------------------------------------------------------------
# Copyright (c) 2016--, QIIME development team.
#
# Distributed under the terms of the Modified BSD License.
#
# 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!"
Beispiel #11
0
# ----------------------------------------------------------------------------
# Copyright (c) 2016--, QIIME development team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file LICENSE, distributed with this software.
# ----------------------------------------------------------------------------

from qiime.plugin import Plugin

import q2_alignment

plugin = Plugin(name='alignment',
                version=q2_alignment.__version__,
                website='https://github.com/qiime2/q2-alignment',
                package='q2_alignment')
Beispiel #12
0
# ----------------------------------------------------------------------------
# Copyright (c) 2016--, QIIME development team.
#
# Distributed under the terms of the Modified BSD License.
#
# 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',
Beispiel #13
0
# Copyright (c) 2016--, QIIME development team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file LICENSE, distributed with this software.
# ----------------------------------------------------------------------------

from qiime.plugin import Plugin
from q2_types.tree import Phylogeny, Unrooted, Rooted
from q2_types.feature_data import FeatureData, AlignedSequence
from q2_types.feature_table import FeatureTable, Frequency

import q2_phylogeny

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

plugin.methods.register_function(
    function=q2_phylogeny.midpoint_root,
    inputs={'tree': Phylogeny[Unrooted]},
    parameters={},
    outputs=[('rooted_tree', Phylogeny[Rooted])],
    name='Midpoint root an unrooted phylogenetic tree.',
    description=("Midpoint root an unrooted phylogenetic tree."))

plugin.methods.register_function(
    function=q2_phylogeny.fasttree,
    inputs={'alignment': FeatureData[AlignedSequence]},
    parameters={},
    outputs=[('tree', Phylogeny[Unrooted])],
Beispiel #14
0
# ----------------------------------------------------------------------------
# Copyright (c) 2016--, QIIME development team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file LICENSE, distributed with this software.
# ----------------------------------------------------------------------------

from qiime.plugin import Plugin, Int

import q2_feature_table
from q2_types import (FeatureTable, Frequency, RelativeFrequency,
                      PresenceAbsence)

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

# TODO create decorator for promoting functions to workflows. This info would
# be moved to the decorator calls.
plugin.register_function(
    function=q2_feature_table.rarefy,
    # TODO use more restrictive primitive type for `depth`
    inputs={
        'table': FeatureTable[Frequency],
        'depth': Int
    },
    outputs=[('rarefied_table', FeatureTable[Frequency])],
    name='Rarefaction',
    doc="Let's rarefy!")