# 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 on installation /usr/share/data/models) or can be overloaded with the location specify in the macsyfinder configuration (either in config file or command line)

  __getitem__(name: str) → ModelLocation
    Parameters:

      name

    Returns:

      the model corresponding to name.

    Raises:

      KeyError – if name does not match any ModelLocation registered.

  __init__() → None
  __str__() → str

    Return str(self).

  __weakref__

    list of weak references to the object

  add(model_loc: ModelLocation) → None
    Parameters:

      model_loc – the model location to add to the registry

  models() → list[ModelLocation]
    Returns:

      the list of models

## ModelLocation

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

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

  __eq__(other: ModelLocation) → bool

    Return self==value.

  __gt__(other: ModelLocation) → bool

    Return self>value.

  __init__(path: str = None, profile_suffix: str = '.hmm', relative_path: bool = False) → None
    Parameters:

      - path – if it’s an installed model, path is the absolute path to a model family.

      - profile_suffix – the suffix of hmm files

      - relative_path – True if you want to work with relative path, False to work with absolute path.

  __lt__(other: ModelLocation) → bool

    Return self<value.

  __str__() → str

    Return str(self).

  __weakref__

    list of weak references to the object

  _scan_definitions(parent_def: DefinitionLocation = None, def_path: str = None) → DefinitionLocation

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

    Parameters:

      - parent_def – the current model definition to add new submodel location

      - def_path – the absolute path to analyse

    Returns:

      a definition location

  _scan_profiles(path: str, profile_suffix: str = '.hmm', relative_path: bool = False) → dict[slice(<class 'str'>, <class 'str'>, None)]

    Store all hmm profiles associated to the model

    Parameters:

      - path – the path to a directory containing hmm profiles

      - profile_suffix – the extension of hmm profile file

      - relative_path – True if the path is relative, False otherwise.

    Returns:

      all profiles found in the path

  get_all_definitions(root_def_name: str = None) → list[DefinitionLocation]
    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

    Returns:

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

    Raises:

      ValueError – if root_def_name does not match with any definitions

  get_definition(fqn: str) → DefinitionLocation
    Parameters:

      fqn – 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.

    Raise:

      valueError if fqn does not match with any model definition.

  get_definitions() → list[DefinitionLocation]
    Returns:

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

  get_profile(name: str) → str
    Parameters:

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

    Returns:

      the absolute path of the hmm profile.

    Raise:

      KeyError if name does not match with any profiles.

  get_profiles_names() → list[str]
    Returns:

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

  property version: str
    Returns:

      The version of the models

## MetaDefLoc

class macsypy.registries.MetaDefLoc

## DefinitionLocation

class macsypy.registries.DefinitionLocation(name: str | None = None, fqn: str | None = None, subdefinitions: DefinitionLocation | None = None, path: str | None = 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 subdefinitions if it exists

  __eq__(other: DefinitionLocation) → bool

    Return self==value.

  __gt__(other: DefinitionLocation) → bool

    Return self>value.

  __hash__() → int

    Return hash(self).

  __init__(name: str | None = None, fqn: str | None = None, subdefinitions: DefinitionLocation | None = None, path: str | None = None) → None
  __lt__(other: DefinitionLocation) → bool

    Return self<value.

  __str__() → str

    Return str(self).

  __weakref__

    list of weak references to the object

  add_subdefinition(subdefinition: DefinitionLocation) → None

    add new sub category of definitions to this definition

    Parameters:

      subdefinition – the new definition to add as subdefinition.

  all() → list[DefinitionLocation]
    Returns:

      the definition and all recursively all subdefinitions

  property family_name: str
    Returns:

      the models family name which is the name of the package

  classmethod root_name(fqn: str) → str
    Parameters:

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

    Returns:

      the root name of this definition (family name)

  classmethod split_fqn(fqn: str) → list[str]
    Parameters:

      fqn – the fully qualified name of a definition

    Returns:

      each member of the fully qn in list.

## split_def_name

macsypy.registries.split_def_name(fqn: str) → list[str]
  Parameters:

    fqn – 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’]

## join_def_path

macsypy.registries.join_def_path(*args: str) → str

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

## scan_models_dir

macsypy.registries.scan_models_dir(models_dir: str, profile_suffix: str = '.hmm', relative_path: bool = False) → list[ModelLocation]
  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`, …]

Fork me on GitHub