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:

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)

system reference api
MatchMaker
- class macsypy.system.MatchMaker(model: Model)[source]
Is an abstract class for (Ordered|Unordered)MatchMaker the match class method must be implemented in concrete classes.
- __weakref__
list of weak references to the object
- _create_exchangeable_map(genes: list[macsypy.gene.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[macsypy.hit.ModelHit], list[macsypy.hit.ModelHit], list[macsypy.hit.ModelHit], list[macsypy.hit.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)
- match(clusters: Iterable[Cluster]) macsypy.system.System | macsypy.system.RejectedCandidate [source]
Check a set of clusters fill model constraints. If yes create a
macsypy.system.System
otherwise create amacsypy.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
ormacsypy.system.RejectedCandidate
object
UnorderedMatchMaker
- class macsypy.system.UnorderedMatchMaker(model: Model)[source]
- match(hits: Iterable[ModelHit]) macsypy.system.LikelySystem | macsypy.system.UnlikelySystem [source]
- Parameters
hits – the hits to check
HitSystemTracker
- class macsypy.system.HitSystemTracker(systems: list[macsypy.system.System])[source]
track in which system is implied each hit
- __init__(systems: list[macsypy.system.System]) None [source]
- __weakref__
list of weak references to the object
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
AbstractSetOfHits
- class macsypy.system.AbstractSetOfHits(*args, **kwargs)[source]
Is the mother class of System, RejectedCandidates, LikelySystems UnlikelySystem, …
- __weakref__
list of weak references to the object
- 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: macsypy.cluster.Cluster | list[macsypy.cluster.Cluster])[source]
- fulfilled_function(*genes: macsypy.gene.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[macsypy.cluster.Cluster], redundancy_penalty: float = 1.5) None [source]
- Parameters
model (
macsypy.model.Model
object) – The model which has been used to build this systemclusters (list of
macsypy.cluster.Cluster
objects) – The list of cluster that form this system
- get_hits_encoding_multisystem() set[macsypy.hit.MultiSystem] [source]
- Returns
The hits codding for a gene taged as multi system
- get_loners() set[macsypy.hit.Loner | macsypy.hit.LonerMultiSystem] [source]
- Returns
The True Loners (Loner which not colocalize with another hit) belonging to the systems
- get_multisystems() set[macsypy.hit.MultiSystem | macsypy.hit.LonerMultiSystem] [source]
- Returns
The MultiSystem hit (comming from out system (other cluster or loner) and tag as multisystem)
- property hits: list[macsypy.hit.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[macsypy.cluster.Cluster], reasons: list[str]) None [source]
- Parameters
model –
clusters – list of clusters. These Clusters should be created with
macsypy.cluster.Cluster
ofmacsypy.hit.ModelHit
objectsreasons – the reason why these clusters have been rejected
- property hits: list[macsypy.hit.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[macsypy.hit.ModelHit], accessory_hits: list[macsypy.hit.ModelHit], neutral_hits: list[macsypy.hit.ModelHit], forbidden_hits: list[macsypy.hit.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[macsypy.hit.ModelHit]
- Returns
The list of accesory hits
- property allowed_hits: list[macsypy.hit.ModelHit]
- Returns
The list of allowed (mandatory, accessory, neutral) hits
- property forbidden_hits: list[macsypy.hit.ModelHit]
- Returns
The list of forbidden hits
- property hits: list[macsypy.hit.ModelHit]
- Returns
The list of all hits sorted by their position
- property mandatory_hits: list[macsypy.hit.ModelHit]
- Returns
The list of mandatory hits
- property neutral_hits: list[macsypy.hit.ModelHit]
- Returns
The list of neutral hits
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[macsypy.hit.ModelHit], accessory_hits: list[macsypy.hit.ModelHit], neutral_hits: list[macsypy.hit.ModelHit], forbidden_hits: list[macsypy.hit.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
- property reasons: list[str]
- Returns
The reasons why it probably not a system
- Return type
list of string