Ejemplo n.º 1
0
    def test_typevars(self):
        T, U, V, W, X = TypeMap({
            (Foo, Bar, Str % Choices('A', 'B')): (C1[Foo], C1[Bar]),
            (Foo | Bar, Foo, Str): (C1[Bar], C1[Foo])
        })

        scope = {}
        T1 = ast_to_type(T.to_ast(), scope=scope)
        U1 = ast_to_type(U.to_ast(), scope=scope)
        V1 = ast_to_type(V.to_ast(), scope=scope)
        W1 = ast_to_type(W.to_ast(), scope=scope)
        X1 = ast_to_type(X.to_ast(), scope=scope)

        self.assertEqual(len(scope), 1)
        self.assertEqual(scope[id(T.mapping)], [T1, U1, V1, W1, X1])

        self.assertEqual(T1.mapping.lifted, T.mapping.lifted)

        self.assertIs(T1.mapping, U1.mapping)
        self.assertIs(U1.mapping, V1.mapping)
        self.assertIs(V1.mapping, W1.mapping)
        self.assertIs(W1.mapping, X1.mapping)
Ejemplo n.º 2
0
from .plugin import dummy_plugin, C1, C2, C3, Foo, Bar, Baz, EchoFormat
from qiime2.plugin import (TypeMap, TypeMatch, Properties, Visualization, Bool,
                           Choices)


def constrained_input_visualization(output_dir: str, a: EchoFormat,
                                    b: EchoFormat):
    with open(os.path.join(output_dir, 'index.html'), 'w') as fh:
        fh.write("<p>%s</p>" % a.path.read_text())
        fh.write("<p>%s</p>" % b.path.read_text())


T, U, V = TypeMap({
    (Foo, Foo): Visualization,
    (Bar, Bar): Visualization,
    (Baz, Baz): Visualization,
    (C1[Foo], C1[Foo]): Visualization,
    (C1[Bar], C1[Bar]): Visualization,
    (C1[Baz], C1[Baz]): Visualization
})
dummy_plugin.visualizers.register_function(
    function=constrained_input_visualization,
    inputs={
        'a': T,
        'b': U
    },
    parameters={},
    name="Constrained Input Visualization",
    description="Ensure Foo/Bar/Baz match")
del T, U, V

Ejemplo n.º 3
0
    output_descriptions={
        'grouped_table':
        'A table that has been grouped along the given '
        '`axis`. IDs on that axis are replaced by values in '
        'the `metadata` column.'
    },
    name="Group samples or features by a metadata column",
    description="Group samples or features in a feature table using metadata "
    "to define the mapping of IDs to a group.")

i_table, p_overlap_method, o_table = TypeMap({
    (FeatureTable[Frequency], Str % Choices(
         sorted(q2_feature_table.overlap_methods()))):
    FeatureTable[Frequency],
    (
        FeatureTable[RelativeFrequency],
        # We don't want to allow summing of RelativeFrequency tables, so remove
        # that option from the overlap methods
        Str % Choices(sorted(q2_feature_table.overlap_methods() - {'sum'}))):
    FeatureTable[RelativeFrequency]
})

plugin.methods.register_function(
    function=q2_feature_table.merge,
    inputs={'tables': List[i_table]},
    parameters={'overlap_method': p_overlap_method},
    outputs=[('merged_table', o_table)],
    input_descriptions={
        'tables': 'The collection of feature tables to be merged.',
    },
    parameter_descriptions={
Ejemplo n.º 4
0
    description=(
        'Filter sequences by length with VSEARCH. For a combination of global '
        'and conditional taxonomic filtering, see filter_seqs_length_by_taxon.'
    ),
    citations=[citations['rognes2016vsearch']])

INCLUDE_SPECIES_LABELS_DESCRIPTION = (
    'Include species rank labels in taxonomy output. Note: species-labels may '
    'not be reliable in all cases.')

_SILVA_VERSIONS = ['128', '132', '138']
_SILVA_TARGETS = ['SSURef_NR99', 'SSURef', 'LSURef']

version_map, target_map, _ = TypeMap({
    (Str % Choices('128', '132'), Str % Choices('SSURef_NR99', 'SSURef', 'LSURef')):
    Visualization,
    (Str % Choices('138'), Str % Choices('SSURef_NR99', 'SSURef')):
    Visualization,
})

plugin.pipelines.register_function(
    function=get_silva_data,
    inputs={},
    parameters={
        'version': version_map,
        'target': target_map,
        'include_species_labels': Bool,
        'download_sequences': Bool
    },
    outputs=[('silva_sequences', FeatureData[RNASequence]),
             ('silva_taxonomy', FeatureData[Taxonomy])],
    input_descriptions={},
Ejemplo n.º 5
0
    'sensitivity':
    'Bowtie2 alignment sensitivity. See bowtie2 manual for '
    'details.',
    'ref_gap_open_penalty':
    'Reference gap open penalty.',
    'ref_gap_ext_penalty':
    'Reference gap extend penalty.',
    'exclude_seqs':
    'Exclude sequences that align to reference. Set this '
    'option to False to exclude sequences that do not align '
    'to the reference database.'
}

P_method, P_left_justify, _ = TypeMap({
    (Str % Choices("blast", "blastn-short"), Bool % Choices(False)):
    Visualization,
    (Str % Choices("vsearch"), Bool):
    Visualization,
})

plugin.methods.register_function(
    function=exclude_seqs,
    inputs=seq_inputs,
    parameters={
        'method': P_method,
        'perc_identity': Float % Range(0.0, 1.0, inclusive_end=True),
        'evalue': Float,
        'perc_query_aligned': Float,
        'threads': Int % Range(1, None),
        'left_justify': P_left_justify,
    },
    outputs=[('sequence_hits', FeatureData[Sequence]),
Ejemplo n.º 6
0
    'example, if we are missing the genus label for '
    '\'f__Pasteurellaceae; g__\'then the \'f__\' rank will be propagated to '
    'become: \'f__Pasteurellaceae; g__Pasteurellaceae\'.')

RANK_DESCRIPTION = ('List of taxonomic ranks for building a taxonomy from the '
                    'SILVA Taxonomy database. Use \'include_species_labels\' '
                    'to append the organism name as the species label. '
                    "[default: '" + "', '".join(DEFAULT_RANKS) + "']")

_SILVA_VERSIONS = ['128', '132', '138', '138.1']
_SILVA_TARGETS = ['SSURef_NR99', 'SSURef', 'LSURef_NR99', 'LSURef']

version_map, target_map, _ = TypeMap({
    (Str % Choices('128', '132'), Str % Choices('SSURef_NR99', 'SSURef', 'LSURef')):
    Visualization,
    (Str % Choices('138'), Str % Choices('SSURef_NR99', 'SSURef')):
    Visualization,
    (Str % Choices('138.1'), Str % Choices('SSURef_NR99', 'SSURef', 'LSURef_NR99', 'LSURef')):
    Visualization,
})

plugin.pipelines.register_function(
    function=get_silva_data,
    inputs={},
    parameters={
        'version': version_map,
        'target': target_map,
        'include_species_labels': Bool,
        'rank_propagation': Bool,
        'ranks': List[Str % Choices(ALLOWED_RANKS)],
        'download_sequences': Bool
    },
Ejemplo n.º 7
0
    case_transformer = {
        'upper': str.upper,
        'lower': str.lower,
        'invert': str.swapcase,
    }[capitalization]

    for i, line in enumerate(contents, 0):
        contents[i] = case_transformer(line)

    return contents


sort_ascending, sort_descending, out_text = TypeMap({
    (Bool % Choices([False]), Bool % Choices([False])):
    IceCream,
    (Bool % Choices([True]), Bool % Choices([False])):
    IceCream,
    (Bool % Choices([False]), Bool % Choices([True])):
    IceCream,
})

plugin.methods.register_function(
    function=sprinkle,
    inputs={
        'icecream': IceCream,
    },
    parameters={
        'capitalization': Str % Choices(['upper', 'lower', 'invert']),
        'sort_ascending': sort_ascending,
        'sort_descending': sort_descending,
    },
    outputs={('modified', out_text)},