system

This module classes and functions which a given set of hits and a model compute if this set satisfy the model or not

The object which check the compliance of hits to a model is MatchMaker which have 2 sub-classes for ordered and unordered replicons

MatchMaker.match method link hit to a model (macsypy.hit.ValidHit) and then check if these valid hit satisfy the quorum constraints defined in the model. According this it instanciate a macsypy.system.System or macsypy.system.RejectedCandidate for ordered replicons or macsypy.system.LikelySystem or macsypy.system.UnlikelySystem for unordered replicons

below the inheritance diagram:

Inheritance diagram of macsypy.system.AbstractSetOfHits, macsypy.system.AbstractClusterizedHits, macsypy.system.System, macsypy.system.RejectedCandidate, macsypy.system.AbstractUnordered, macsypy.system.LikelySystem, macsypy.system.UnlikelySystem

Warning

The abstract class macsypy.system.AbstractSetOfHits is controlled by the metaclass macsypy.system.MetaSetOfHits which inject on the fly several private attributes and public properties (see more in macsypy.system.MetaSetOfHits documentation)

Inheritance diagram of macsypy.system.MatchMaker, macsypy.system.OrderedMatchMaker, macsypy.system.UnorderedMatchMaker

system reference api

MatchMaker

class macsypy.system.MatchMaker(model: Model)[source]

Is an abstract class for (Odered/Unordered)MatchMaker the match class method must be implemented in concrete classes

__init__(model: Model) None[source]
__weakref__

list of weak references to the object (if defined)

_create_exchangeable_map(genes: list[ModelGene]) dict[slice(<class 'str'>, <class 'macsypy.gene.ModelGene'>, None)][source]

create a map between an exchangeable (formly homolog or analog) gene name and it’s gene reference

Parameters:

genes – The genes to get the exchangeable genes

Returns:

a dict with keys are the exchangeable gene_name and the value the reference gene

present_genes() tuple[list[str], list[str], list[str], list[str]][source]
Returns:

the lists of genes name in model which are present in the replicon (included exchangeable)

tuple of 4 lists for mandatory, accessory, neutral and forbidden

([str gene_name, …], [str gene_name], [str gene_name], [str gene_name])

sort_hits_by_status(hits: Iterable[ModelHit]) tuple[list[ModelHit], list[ModelHit], list[ModelHit], list[ModelHit]][source]

sort macsypy.hit.ModelHit according the status of the gene the hit code for.

Parameters:

hits – list of macsypy.hit.ModelHit object

Returns:

the valid hits according their status ([mandatory, ], [accessory, ], [neutral, ], [forbidden ])

Raises:

MacsypyError – when a gene is not found in the model

OrderedMatchMaker

class macsypy.system.OrderedMatchMaker(model, redundancy_penalty)[source]

check if a set of hits match the quorum for ordered replicons (ordered_replicon or gembase)

__init__(model, redundancy_penalty)[source]
match(clusters: Iterable[Cluster]) System | RejectedCandidate[source]

Check a set of clusters fill model constraints. If yes create a macsypy.system.System otherwise create a macsypy.cluster.RejectedCandidate.

Parameters:

clusters (list of macsypy.cluster.Cluster objects) – The list of cluster to check if fit the model

Returns:

either a System or a RejectedCandidates

Return type:

macsypy.system.System or macsypy.system.RejectedCandidate object

UnorderedMatchMaker

class macsypy.system.UnorderedMatchMaker(model: Model)[source]
match(hits: Iterable[ModelHit]) LikelySystem | UnlikelySystem[source]
Parameters:

hits – the hits to check

HitSystemTracker

class macsypy.system.HitSystemTracker(systems: list[System])[source]

track in which system is implied each hit

__init__(systems: list[System]) None[source]
__weakref__

list of weak references to the object (if defined)

MetaSetOfHits

class macsypy.system.MetaSetOfHits(name, bases, namespace, **kwargs)[source]

This metaclass control the AbstractSetOfHits class creation. In this metaclass we inject on the fly several attributes and properties two private attributes and one public property corresponding to each value of _supported_status class attribute defined in the concrete classes. for instance for System class

  • the attributes
    • self._mandatory

    • self._mandatory_occ

    • self._accessory

    • self._accessory_occ

    • self._neutral

    • self._neutral_occ

  • and the properties
    • mandatory

    • accessory

    • neutral

are automatically injected

The value for attributes _<status>_occ are filled by the count method which is defined in AbstractSetOfHits

__call__(*args, **kwargs)[source]

Call self as a function.

getter_maker() Callable[source]

Create a property which allow to access to the gene corresponding of the cat of the model

Parameters:

status – the type of gene category to which we create the getter

Returns:

unbound method

AbstractSetOfHits

class macsypy.system.AbstractSetOfHits(*args, **kwargs)[source]

Is the mother class of System, RejectedCandidates, LikelySystems UnlikelySystem, …

__init__(model: Model) None[source]
__weakref__

list of weak references to the object (if defined)

count() None[source]

fill structures one for supported status mandatory, accessory, … each structure count how many hit for each gene of the model mandatory_occ = { gene_name : [ModelHit, …] :return: None

property position: tuple[int, int]
Returns:

The position of the first and last hit (start: int, end:int), excluded the hit coding for loners. If the system is composed only by loners, used loners to compute position

property replicon_name: str
Returns:

The name of the replicon

Return type:

str

property wholeness: float
Returns:

a score indicating the genes ratio of the model which have at least one hit by default full system is mandatory + accessory (‘neutral’ genes do not count) but for special corner case it can be specified in model definition (xml) or on the command line

AbstractClusterizedHits

class macsypy.system.AbstractClusterizedHits(*args, **kwargs)[source]

Modelize SetOfHits that colocalize.

should be inherited

__init__(model: Model, clusters: Cluster | list[Cluster])[source]
fulfilled_function(*genes: ModelGene | str) set[str][source]
Parameters:

genes (macsypy.gene.ModelGene object or string representing the gene name) – The genes which must be tested.

Returns:

the common functions between genes and this system.

Return type:

set of string

System

class macsypy.system.System(*args, **kwargs)[source]

Modeling as system. a system is an occurrence of a given model on a replicon.

__init__(model: Model, clusters: list[Cluster], redundancy_penalty: float = 1.5) None[source]
Parameters:
__str__() str[source]

Return str(self).

get_hits_encoding_multisystem() set[MultiSystem][source]
Returns:

The hits codding for a gene taged as multi system

get_loners() set[Loner | LonerMultiSystem][source]
Returns:

The True Loners (Loner which not colocalize with another hit) belonging to the systems

get_multisystems() set[MultiSystem | LonerMultiSystem][source]
Returns:

The MultiSystem hit (comming from out system (other cluster or loner) and tag as multisystem)

property hits: list[ModelHit]
Returns:

The list of all hits that compose this system

is_compatible(other: System) bool[source]
Parameters:

other – the other systems to test compatibility

Returns:

True if other system is compatible with this one. False otherwise. Two systems are compatible if they do not share macsypy.hit.CoreHit except hit corresponding to a multi_system gene in the model.

Note

This method is used to compute the best combination of systems.

property loci_nb: int
Returns:

The number of loci of this system (loners are not considered)

Return type:

int >= 0

property loci_num: list[int]
Returns:

the number of the corresponding locus for each cluster the cluster made of only one Loner are not considered as a loci so these clusters have a negative locus_num

property multi_loci: bool
Returns:

True if the systems is encoded in multiple loci. False otherwise

occurrence() int[source]

sometimes several systems collocates so they form only one cluster so macsyfinder build only one system the occurrence is an indicator of how many systems are it’s based on the number of occurrence of each mandatory genes The multi_system genes are not take in account.

Returns:

a predict number of biologic systems

property score: float
Returns:

a score take in account * if a hit match for the gene or it is an exchangeable gene * if a hit is duplicated and already present in the system or the cluster * if a hit match for mandatory/accessory gene of the model

Return type:

float

RejectedCandidate

class macsypy.system.RejectedCandidate(*args, **kwargs)[source]

Handle a set of clusters which has been rejected during the macsypy.system.match() step This clusters (can be one) does not fill the requirements or contains forbidden genes.

__init__(model: Model, clusters: list[Cluster], reasons: list[str]) None[source]
Parameters:
__str__() str[source]
Returns:

a string representation of this RejectedCandidates

property hits: list[ModelHit]
Returns:

The list of all hits that compose this system

property reasons: list[str]
Returns:

The reason why it has been rejected

AbstractUnordered

class macsypy.system.AbstractUnordered(*args, **kwargs)[source]

Technical abstract class to factorize code share between LikelySystem and UnlikelySystem

__init__(model: Model, mandatory_hits: list[ModelHit], accessory_hits: list[ModelHit], neutral_hits: list[ModelHit], forbidden_hits: list[ModelHit]) None[source]
Parameters:
  • model – The model which has been used to build this system

  • mandatory_hits – The list of mandatory hits (encode for a gene tagged as mandatory)

  • accessory_hits – The list of accessory hits (encode for a gene tagged as accessory)

  • neutral_hits – The list of neutral hits (encode for a gene tagged as neutral)

  • forbidden_hits – The list of hits that are forbidden

property accessory_hits: list[ModelHit]
Returns:

The list of accesory hits

property allowed_hits: list[ModelHit]
Returns:

The list of allowed (mandatory, accessory, neutral) hits

property forbidden_hits: list[ModelHit]
Returns:

The list of forbidden hits

property hits: list[ModelHit]
Returns:

The list of all hits sorted by their position

property mandatory_hits: list[ModelHit]
Returns:

The list of mandatory hits

property neutral_hits: list[ModelHit]
Returns:

The list of neutral hits

LikelySystem

class macsypy.system.LikelySystem(*args, **kwargs)[source]

” Handle components that fill the quorum requirements defined in model. with no idea about genetic organization (gene cluster) so we cannot take in account forbidden genes

__str__() str[source]
Returns:

a string representation of this LikelySystem

UnlikelySystem

class macsypy.system.UnlikelySystem(*args, **kwargs)[source]

Handle components that not fill the quorum requirements defined in model.

__init__(model: Model, mandatory_hits: list[ModelHit], accessory_hits: list[ModelHit], neutral_hits: list[ModelHit], forbidden_hits: list[ModelHit], reasons: list[str]) None[source]
Parameters:
  • model – The model which has been used to build this system

  • mandatory_hits – The list of mandatory hits (encode for a gene tagged as mandatory)

  • accessory_hits – The list of accessory hits (encode for a gene tagged as accessory)

  • neutral_hits – The list of neutral hits (encode for a gene tagged as neutral)

  • forbidden_hits – The list of hits that are forbidden

  • reasons – the reasons why this set of hits has been rejected

__str__() str[source]
Returns:

a string representation of this UnlikelySystem

property reasons: list[str]
Returns:

The reasons why it probably not a system

Return type:

list of string