Exemplo n.º 1
0
    def test_writer_transformer(self):
        # `Artifact._from_view` invokes transformer that handles `dataframe` ->
        # `WinnowedFormat` with all input, because the `WinnowedDirectoryFormat` has
        # been registered as the directory format for the semantic type.
        artifact = Artifact._from_view(Winnowed, [(exp_featureOrdering, exp_auc, exp_permanova)],
                                       list, archive.ImportProvenanceCapture())

        # Test that the directory and file format can be read again.
        got_featureOrdering, got_auc, got_permanova = artifact.view( list )[0]
        pd.testing.assert_frame_equal(
            got_featureOrdering.astype(str),
            exp_featureOrdering.astype(str),
            check_dtype=False
        ) # Avoid checking values since reading df stores as objects while, hard coding in does not
        # ex) bool(False) == Object(False) in pandas is False although the values function the same.
        pd.testing.assert_frame_equal(
            got_auc.astype(str),
            exp_auc.astype(str),
            check_dtype=False
        )
        pd.testing.assert_frame_equal(
            got_permanova.astype(str),
            exp_permanova.astype(str),
            check_dtype=False
        )
Exemplo n.º 2
0
    def setUp(self):
        # Ignore the returned dummy plugin object, just run this to verify the
        # plugin exists as the tests rely on it being loaded.
        get_dummy_plugin()

        # TODO standardize temporary directories created by QIIME 2
        self.test_dir = tempfile.TemporaryDirectory(prefix='qiime2-test-temp-')
        self.provenance_capture = archive.ImportProvenanceCapture()
 def test_writer_transformer(self):
     for type in IntSequence1, IntSequence2:
         # `Artifact._from_view` invokes transformer that handles `list` ->
         # `SingleIntFormat`, because the `SingleIntDirectoryFormat` has
         # been registered as the directory format for the semantic type.
         # We didn't define a `SingleIntDirectoryFormat` ->
         # `SingleIntFormat` tranformer because
         # `model.SingleFileDirectoryFormat` handles that transformation for
         # us.
         artifact = Artifact._from_view(type, [1, 2, 42, -999, 42, 0], list,
                                        archive.ImportProvenanceCapture())
         # Test that the directory and file format can be read again.
         self.assertEqual(artifact.view(list), [1, 2, 42, -999, 42, 0])
 def test_writer_transformer(self):
     # `Artifact._from_view` invokes transformer that handles `dict` ->
     # `MappingFormat`, because the `MappingDirectoryFormat` has
     # been registered as the directory format for the semantic type.
     # We didn't define a `MappingDirectoryFormat` ->
     # `MappingFormat` tranformer because
     # `model.SingleFileDirectoryFormat` handles that transformation for
     # us.
     artifact = Artifact._from_view(Mapping, {
         'abc': 'cat',
         'def': 'dog'
     }, dict, archive.ImportProvenanceCapture())
     # Test that the directory and file format can be read again.
     self.assertEqual(artifact.view(dict), {'abc': 'cat', 'def': 'dog'})
Exemplo n.º 5
0
    def import_data(cls, type, view, view_type=None):
        type_, type = type, __builtins__['type']

        is_format = False
        if isinstance(type_, str):
            type_ = qiime2.sdk.parse_type(type_)

        if isinstance(view_type, str):
            view_type = qiime2.sdk.parse_format(view_type)
            is_format = True

        if view_type is None:
            if type(view) is str or isinstance(view, pathlib.PurePath):
                is_format = True
                pm = qiime2.sdk.PluginManager()
                output_dir_fmt = pm.get_directory_format(type_)
                if pathlib.Path(view).is_file():
                    if not issubclass(output_dir_fmt,
                                      model.SingleFileDirectoryFormatBase):
                        raise qiime2.plugin.ValidationError(
                            "Importing %r requires a directory, not %s" %
                            (output_dir_fmt.__name__, view))
                    view_type = output_dir_fmt.file.format
                else:
                    view_type = output_dir_fmt
            else:
                view_type = type(view)

        format_ = None
        md5sums = None
        if is_format:
            path = pathlib.Path(view)
            if path.is_file():
                md5sums = {path.name: util.md5sum(path)}
            elif path.is_dir():
                md5sums = util.md5sum_directory(path)
            else:
                raise qiime2.plugin.ValidationError(
                    "Path '%s' does not exist." % path)
            format_ = view_type

        provenance_capture = archive.ImportProvenanceCapture(format_, md5sums)
        return cls._from_view(type_,
                              view,
                              view_type,
                              provenance_capture,
                              validate_level='max')
Exemplo n.º 6
0
 def make_provenance_capture(self):
     # importing visualizations is not supported, but we do that here to
     # simplify testing machinery
     return archive.ImportProvenanceCapture()
Exemplo n.º 7
0
 def make_provenance_capture(self):
     # You can't actually import a visualization, but I won't tell
     # visualization if you don't...
     return archive.ImportProvenanceCapture()
Exemplo n.º 8
0
 def setUp(self):
     prefix = "qiime2-test-temp-"
     self.temp_dir = tempfile.TemporaryDirectory(prefix=prefix)
     self.provenance_capture = archive.ImportProvenanceCapture()