omex

omex

COMBINE Archive support.

This module provides an abstraction around the COMBINE archive. Common operations such as archive creation, archive extraction, creating archives from entries or directories, working with the manifest.xml are implemented.

When working with COMBINE archives these wrapper functions should be used. The current version has no support for metadata manipulation.

Encrypted archives can be opened, but no support for encrypting archives yet.

Classes

Name Description
EntryFormat Enum for common formats.
Manifest COMBINE archive manifest.
ManifestEntry Entry of an OMEX file listed in the manifest.xml.
Omex Combine archive class.

EntryFormat

omex.EntryFormat()

Enum for common formats.

Manifest

omex.Manifest(**data)

COMBINE archive manifest.

A manifest is a list of ManifestEntries.

Methods

Name Description
add_entry Add entry to manifest.
from_manifest Create manifest from existing manifest.xml file.
remove_entry_for_location Remove entry for given location.
to_manifest Write manifest.xml.
to_manifest_xml Create xml of manifest.
add_entry
omex.Manifest.add_entry(entry)

Add entry to manifest.

Does not check for duplication.

from_manifest
omex.Manifest.from_manifest(manifest_path)

Create manifest from existing manifest.xml file.

remove_entry_for_location
omex.Manifest.remove_entry_for_location(location)

Remove entry for given location.

to_manifest
omex.Manifest.to_manifest(manifest_path)

Write manifest.xml.

to_manifest_xml
omex.Manifest.to_manifest_xml()

Create xml of manifest.

ManifestEntry

omex.ManifestEntry()

Entry of an OMEX file listed in the manifest.xml.

This corresponds to a single file in the archive which is tracked in the manifest.xml. location: location of the entry format: full format string master: master attribute

Methods

Name Description
is_format Check if entry is of the given format_key.
is_sbgn Check if entry is SBGN.
is_sbml Check if entry is SBML.
is_sedml Check if entry is SED-ML.
is_format
omex.ManifestEntry.is_format(format_key, format)

Check if entry is of the given format_key.

is_sbgn
omex.ManifestEntry.is_sbgn()

Check if entry is SBGN.

is_sbml
omex.ManifestEntry.is_sbml()

Check if entry is SBML.

is_sedml
omex.ManifestEntry.is_sedml()

Check if entry is SED-ML.

Omex

omex.Omex()

Combine archive class.

Methods

Name Description
add_entry Add a path to the combine archive.
entries_by_format Get entries with given format in the archive.
from_directory Create a COMBINE archive from a given directory.
from_omex Read omex from path.
from_url Read omex from url.
get_path Get path for given location.
guess_format Guess format string for given file.
is_omex Check if path is an omex archive.
lookup_format Lookup format by format_key.
remove_entry_for_location Remove entry and corresponding entry_path.
to_directory Extract combine archive to output directory.
to_omex Write omex to path.
add_entry
omex.Omex.add_entry(entry_path, entry)

Add a path to the combine archive.

The corresponding ManifestEntry information is required. The entry is copied when getting added, i.e., changes to the location after adding an entry will not have any effect on the content in the archive!

entries_by_format
omex.Omex.entries_by_format(format_key)

Get entries with given format in the archive.

from_directory
omex.Omex.from_directory(directory)

Create a COMBINE archive from a given directory.

The file types are inferred, in case of existing manifest or metadata information this should be reused.

For all SED-ML files in the directory the master attribute is set to True.

from_omex
omex.Omex.from_omex(omex_path, password=None)

Read omex from path.

:param omex_path: path to omex archive :param password: password for encryption :return: Omex object

from_url
omex.Omex.from_url(omex_url, password=None)

Read omex from url.

:param url: url to omex archive :param password: password for encryption :return: Omex object

get_path
omex.Omex.get_path(location)

Get path for given location.

guess_format
omex.Omex.guess_format(path)

Guess format string for given file.

If string cannot be resolved ’’ is returned.

is_omex
omex.Omex.is_omex(omex_path)

Check if path is an omex archive.

File must be a zip archive and contain a manifest.xml.

lookup_format
omex.Omex.lookup_format(format_key)

Lookup format by format_key.

remove_entry_for_location
omex.Omex.remove_entry_for_location(location)

Remove entry and corresponding entry_path.

to_directory
omex.Omex.to_directory(output_dir)

Extract combine archive to output directory.

:param output_dir: output directory :return:

to_omex
omex.Omex.to_omex(
    omex_path,
    password=None,
    compression=zipfile.ZIP_DEFLATED,
    compresslevel=9,
)

Write omex to path.

By definition OMEX files should be zip deflated.

The compresslevel parameter controls the compression level to use when writing files to the archive. When using ZIP_STORED or ZIP_LZMA it has no effect. When using ZIP_DEFLATED integers 0 through 9 are accepted (see zlib for more information). When using ZIP_BZIP2 integers 1 through 9 are accepted (see bz2 for more information). The larger the value the better te compression

:param omex_path: :param compression: compression algorithm :param compresslevel: level of compression :return: