Miscellaneous Utilities

Plugins

qiime2.plugins.available_plugins()

Utilities

qiime2.util.duplicate(src, dst)

Alternative to shutil.copyfile, this will use os.link when possible.

See shutil.copyfile for documention. Only src and dst are supported. Unlike copyfile, this will not overwrite the destination if it exists.

qiime2.util.redirected_stdio(stdout=None, stderr=None)

Testing

class qiime2.plugin.testing.TestPluginBase(methodName='runTest')

Test harness for simplifying testing QIIME 2 plugins.

TestPluginBase extends unittest.TestCase, with a few extra helpers and assertions.

package

The name of the plugin package to be tested.

Type

str

test_dir_prefix

The prefix for the temporary testing dir created by the harness.

Type

str

assertRegisteredSemanticType(semantic_type)

Test assertion for ensuring a plugin’s semantic type is registered.

Fails if the semantic type requested is not found in the Plugin Manager.

Parameters

semantic_type (A Semantic Type) – The Semantic Type to test the presence of.

assertSemanticTypeRegisteredToFormat(semantic_type, exp_format)
Test assertion for ensuring a semantic type is registered to a

format.

Fails if the semantic type requested is not registered to the format specified with exp_format. Also fails if the semantic type isn’t registered to any format.

Parameters
  • semantic_type (A Semantic Type) – The Semantic Type to check for.

  • exp_format (A Format) – The Format to check that the Semantic Type is registed on.

get_data_path(filename)

Convenience method for getting a data asset while testing.

Test data stored in the data/ dir local to the running test can be accessed via this method.

Parameters

filename (str) – The name of the file to look up.

Returns

filepath – The materialized filepath to the requested test data.

Return type

str

get_transformer(from_type, to_type)

Convenience method for getting a registered transformer.

Parameters
  • from_type (A View Type) – The View type of the source data.

  • to_type (A View Type) – The View type to transform to.

Returns

transformer – The registered tranformer from from_type to to_type.

Return type

A Transformer Function

setUp()

Test runner setup hook.

If overriding this hook in a test, call __super__ to invoke this method in the overridden hook, otherwise the harness might not work as expected.

tearDown()

Test runner teardown hook.

If overriding this hook in a test, call __super__ to invoke this method in the overridden hook, otherwise the harness might not work as expected.

transform_format(source_format, target, filename=None, filenames=None)

Helper utility for loading data and transforming it.

Combines several other utilities in this class, will load files from data/, as source_format, then transform to the target view.

Parameters
  • source_format (A Format) – The Format to load the data as.

  • target (A View Type) – The View Type to transform the data to.

  • filename (str) – The name of the file to load from data. Use this for formats that use a single file in their format definition. Mutually exclusive with the filenames parameter.

  • filenames (list[str]) – The names of the files to load from data. Use this for formats that use multiple files in their format definition. Mutually exclusive with the filename parameter.

Returns

  • input (A Format) – The data loaded from data as the specified source_format.

  • obs (A View Type) – The loaded data, transformed to the specified target view type.