# registries

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

## registries API reference

## ModelRegistry

class `macsypy.registries.``ModelRegistry`

  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)
    Parameters

      name (string) –

    Returns

      the model corresponding to name.

    Return type

      `ModelLocation` object.

    Raises

      KeyError – if name does not match any ModelLocation registered.

  `__init__`()

    Initialize self. See help(type(self)) for accurate signature.

  `__str__`()

    Return str(self).

  `__weakref__`

    list of weak references to the object (if defined)

  `add`(model_loc)
    Parameters

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

  `models`()
    Returns

      the list of models

    Return type

      list of `ModelLocation` object

## ModelLocation

class `macsypy.registries.``ModelLocation`(path=None, profile_suffix='.hmm', relative_path=False)

  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)

    Return self==value.

  `__gt__`(other)

    Return self>value.

  `__init__`(path=None, profile_suffix='.hmm', relative_path=False)
    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)

    Return self<value.

  `__str__`()

    Return str(self).

  `__weakref__`

    list of weak references to the object (if defined)

  `_scan_definitions`(parent_def=None, def_path=None)

    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)

    Store all hmm profiles associated to the model

  `get_all_definitions`(root_def_name=None)
    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 `macsypy.registries.DefinitionLocation` object

    Raises

      ValueError – if root_def_name does not match with any definitions

  `get_definition`(fqn)
    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`()
    Returns

      the list of the definitions of this modelLocation. It return the 1rst level only (not recursive). For recursive explorations see `macsypy.registries.ModelLocation.get_all_definitions()`

  `get_profile`(name)
    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`()
    Returns

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

    Return type

      str

  property `version`
    Returns

      The version of the models

## MetaDefLoc

class `macsypy.registries.``MetaDefLoc`

## DefinitionLocation

class `macsypy.registries.``DefinitionLocation`(name=None, fqn=None, subdefinitions=None, path=None)

  Manage where 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)

    Return self==value.

  `__gt__`(other)

    Return self>value.

  `__hash__`()

    Return hash(self).

  `__init__`(name=None, fqn=None, subdefinitions=None, path=None)

    Initialize self. See help(type(self)) for accurate signature.

  `__lt__`(other)

    Return self<value.

  `__str__`()

    Return str(self).

  `__weakref__`

    list of weak references to the object (if defined)

  `add_subdefinition`(subdefinition)

    add new sub category of definitions to this definition

    Parameters

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

  `all`()
    Returns

      the defintion and all recursivelly all subdefintions

  property `family_name`
    Returns

      the models family name which is the name of the package

  classmethod `root_name`(fqn)
    Parameters

      fqn (str) – the fully qualified name of a defintion

    Returns

      the root name of this definition (family name)

  classmethod `split_fqn`(fqn)
    Parameters

      fqn (str) – the fully qualified name of a defintion

    Returns

      each member of the fully qn in list.

## split_def_name

`macsypy.registries.``split_def_name`(fqn)
  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

## join_def_path

`macsypy.registries.``join_def_path`(*args)

  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

## scan_models_dir

`macsypy.registries.``scan_models_dir`(models_dir, profile_suffix='.hmm', relative_path=False)
  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`, …]