registries

The registry manage the different location where macsyfinder can find models definitions and their associated profiles.

registries API reference

class macsypy.registries.DefinitionLocation(name=None, subdefinitions=None, path=None)[source]

Manage were definitions are stored. a Model is a xml definition and associated profiles. It has 3 attributes

name: the fully qualified definitions name like TXSS/T3SS or CRISPR-cas/Typing/Cas path: the absolute path to the definitions or set of definitions subdefinitions: the subdefintions if it exists

__eq__(other)[source]

Return self==value.

__gt__(other)[source]

Return self>value.

__hash__()[source]

Return hash(self).

__init__(name=None, subdefinitions=None, path=None)[source]
__lt__(other)[source]

Return self<value.

__str__()[source]

Return str(self).

__weakref__

list of weak references to the object (if defined)

add_subdefinition(subdefinition)[source]

add new sub category of definitions to this definition

Parameters

subdefinition (DefinitionLocation object) – the new definition to add as subdefinition.

class macsypy.registries.ModelLocation(path=None, profile_dir=None, def_dir=None, profile_suffix='.hmm', relative_path=False)[source]

Handle where are store Models. Models are organized in families and sub families. each family match to a ModelLocation. a ModelLocation contains the path toward the definitions and the paths to corresponding to the profiles.

__eq__(other)[source]

Return self==value.

__gt__(other)[source]

Return self>value.

__hash__ = None
__init__(path=None, profile_dir=None, def_dir=None, profile_suffix='.hmm', relative_path=False)[source]
Parameters
  • path (str) – if it’s an installed model, path is the absolute path to a model family. otherwise path is None, and profile_dir and def_dir must be specified.

  • profile_dir (str) – the absolute path to the directory which contains the hmm profiles files.

  • def_dir (str) – The absolute path to the directory which contains the models definitions (xml files) or submodels.

  • profile_suffix (str) – the suffix of hmm files

  • relative_path (bool) – True if you want to work with relative path, False to work with absolute path.

Raise

MacsypyError if path is set and profile_dir or def_dir is set

Raise

MacsypyError if profile_dir is set but not def_dir and vice versa

__lt__(other)[source]

Return self<value.

__str__()[source]

Return str(self).

__weakref__

list of weak references to the object (if defined)

_scan_definitions(model_def=None, def_path=None)[source]

Scan recursively the definitions tree on the file model and store them.

Parameters
  • model_def (DefinitionLocation) – the current model definition to add new submodel location

  • def_path (string) – the absolute path to analyse

Returns

a definition location

Return type

DefinitionLocation object

_scan_profiles(path, profile_suffix='.hmm', relative_path=False)[source]

Store all hmm profiles associated to the model

get_all_definitions(root_def_name=None)[source]
Name root_def_name

The name of the root definition to get sub definitions. If root_def is None, return all definitions for this set of models

Parameters

root_def_name – string

Returns

the list of definitions or subdefinitions if root_def is specified for this model.

Return type

list of :class: DefinitionLocation` object

Raises

ValueError – if root_def_name does not match with any definitions

get_definition(fqn)[source]
Parameters

fqn (string.) – the fully qualified name of the definition to retrieve. it’s complete path without extension. for instance for a file with path like this: models/TXSS/defintions/T3SS.xml the name is: TXSS/T3SS for models/CRISPR-Cas/definitions/typing/CAS.xml: the name is CRISPR-Cas/typing/CAS

Returns

the definition corresponding to the given name.

Return type

a DefinitionLocation object.

Raise

valueError if fqn does not match with any model definition.

get_definitions()[source]
Returns

get_profile(name)[source]
Parameters

name (string.) – the name of the profile to retrieve (without extension).

Returns

the absolute path of the hmm profile.

Return type

string.

Raise

KeyError if name does not match with any profiles.

get_profiles_names()[source]
Returns

The list of profiles name (without extension) for this model location

Return type

str

class macsypy.registries.ModelRegistry[source]

scan canonical directories to register the different models available in global macsyfinder share data location (depending installation /usr/share/data/models) or can be overload with the location specify in the macsyfinder configuration (either in config file or command line)

__getitem__(name)[source]
Parameters

name (string) –

Returns

the model corresponding to name.

Return type

ModelLocation object.

Raises

KeyError – if name does not match any ModelLocation registered.

__init__()[source]
__str__()[source]

Return str(self).

__weakref__

list of weak references to the object (if defined)

add(model_loc)[source]
Parameters

model_loc (ModelLocation object) – the model location to add to the registry

models()[source]
Returns

the list of models

Return type

list of ModelLocation object

macsypy.registries.join_def_path(*args)[source]

join different elements of the definition path :param str args: the elements of the definition path, each elements must be a string :return: The return value is the concatenation of different elements of args with one separator :rtype: string

macsypy.registries.scan_models_dir(models_dir, profile_suffix='.hmm', relative_path=False)[source]
Parameters
  • models_dir (str) – The path to the directory where are stored the models

  • profile_suffix – the suffix of the hmm profiles

  • relative_path – True if models_dir is relative false otherwise

Returns

the list of models in models_dir

Return type

[macsypy.registries.ModelLocation, …]

macsypy.registries.split_def_name(fqn)[source]
Parameters

fqn (string) – the fully qualified de name of a DefinitionLocation object the follow the schema model_name/<def_name>*/def_name for instance CRISPR-Cas/typing/cas

Returns

the list of components of the def path [‘CRISPR-Cas’, ‘typing’, ‘cas’]

Return type

list of string