def import_data(cls, type, view, view_type=None): type_, type = type, __builtins__['type'] if isinstance(type_, str): type_ = qiime.sdk.parse_type(type_) if isinstance(view_type, str): view_type = qiime.sdk.parse_format(view_type) if view_type is None: if type(view) is str or isinstance(view, pathlib.PurePath): pm = qiime.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 ValueError("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) return cls._from_view(type_, view, view_type)
def __eq__(self, other): return ( type(self) is type(other) and self.inputs == other.inputs and self.parameters == other.parameters and self.outputs == other.outputs )
def __eq__(self, other): # Checking the UUID is mostly sufficient but requiring an exact type # match makes it safer in case `other` is a subclass or a completely # different type that happens to have a `.uuid` property. We want to # ensure (as best as we can) that the UUIDs we are comparing are linked # to the same type of QIIME 2 object. return (type(self) == type(other) and self.uuid == other.uuid)
def __eq__(self, other): # Checking the UUID is mostly sufficient but requiring an exact type # match makes it safer in case `other` is a subclass or a completely # different type that happens to have a `.uuid` property. We want to # ensure (as best as we can) that the UUIDs we are comparing are linked # to the same type of QIIME 2 object. return ( type(self) == type(other) and self.uuid == other.uuid )
def _from_view(cls, view, type_, provenance): """ Parameters ---------- view : Python object View to serialize. type_ : qiime.plugin.Type Concrete semantic type of the artifact. provenance : qiime.sdk.Provenance Artifact provenance. """ if not cls._is_valid_type(type_): raise TypeError( "An artifact requires a concrete semantic type, not type %r." % type_) if provenance is not None and not isinstance(provenance, qiime.sdk.Provenance): raise TypeError( "`provenance` must be None or an instance of " "qiime.sdk.Provenance.") data_layout = cls._get_data_layout(type_) view_type = type(view) # TODO better error handling for when `view` cannot be written to # `type_` data layout. writer = data_layout.writers[view_type] writer = functools.partial(writer, view) artifact = cls.__new__(cls) artifact._archiver = qiime.core.archiver.Archiver( uuid.uuid4(), type_, provenance, data_initializer=writer) return artifact
def _from_view(cls, view, type_, provenance): """ Parameters ---------- view : Python object View to serialize. type_ : qiime.plugin.Type Concrete semantic type of the artifact. provenance : qiime.sdk.Provenance Artifact provenance. """ cls._assert_valid_type(type_) data_layout = cls._get_data_layout(type_) view_type = type(view) # TODO better error handling for when `view` cannot be written to # `type_` data layout. writer = data_layout.writers[view_type] writer = functools.partial(writer, view) artifact = cls.__new__(cls) artifact._archiver = qiime.core.archiver.Archiver( uuid.uuid4(), type_, provenance, data_initializer=writer) return artifact
def import_data(cls, type, view, view_type=None): type_, type = type, __builtins__['type'] is_format = False if isinstance(type_, str): type_ = qiime.sdk.parse_type(type_) if isinstance(view_type, str): view_type = qiime.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 = qiime.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 ValueError("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 ValueError("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)
def load(cls, filepath): """Factory for loading Artifacts and Visualizations.""" archiver = archive.Archiver.load(filepath) if Artifact._is_valid_type(archiver.type): result = Artifact.__new__(Artifact) elif Visualization._is_valid_type(archiver.type): result = Visualization.__new__(Visualization) else: raise TypeError( "Cannot load filepath %r into an Artifact or Visualization " "because type %r is not supported." % (filepath, archiver.type)) if type(result) is not cls and cls is not Result: raise TypeError( "Attempting to load %s with `%s.load`. Use `%s.load` instead." % (type(result).__name__, cls.__name__, type(result).__name__)) result._archiver = archiver return result
def load(cls, filepath): """Factory for loading Artifacts and Visualizations.""" archiver = qiime.core.archiver.Archiver.load(filepath) if Artifact._is_valid_type(archiver.type): result = Artifact.__new__(Artifact) elif Visualization._is_valid_type(archiver.type): result = Visualization.__new__(Visualization) else: raise TypeError( "Cannot load filepath %r into an Artifact or Visualization " "because type %r is not supported." % (filepath, archiver.type)) if type(result) is not cls and cls is not Result: raise TypeError( "Attempting to load %s with `%s.load`. Use `%s.load` instead." % (type(result).__name__, cls.__name__, type(result).__name__)) result._archiver = archiver return result
def import_data(cls, type, view, view_type=None): type_, type = type, __builtins__['type'] if isinstance(type_, str): type_ = qiime.sdk.parse_type(type_) if isinstance(view_type, str): view_type = qiime.core.util.parse_format(view_type) if view_type is None: if type(view) is str or isinstance(view, pathlib.PurePath): pm = qiime.sdk.PluginManager() output_dir_fmt = pm.get_directory_format(type_) if pathlib.Path(view).is_file() and issubclass( output_dir_fmt, model.SingleFileDirectoryFormatBase): view_type = output_dir_fmt.file.format else: view_type = output_dir_fmt else: view_type = type(view) provenance = ("This artifact was generated by importing data from an " "external source.") return cls._from_view(type_, view, view_type, provenance)