definition_parser
The model definition parser object “DefinitionParser” instantiates Models and Genes objects from XML model definitions (see Macromolecular models). The parsing consists in three phases.
Phase 1.
For each model to parse
create the Model
add this Model to the model_bank
findall genes defined in this model what are the level in the model definition.
create the CoreGene (a Gene which is not bind to a model). For each gene name there is only one instance of CoreGene
add these CoreGene in the gene_bank
Phase 2.
For each model to search
For each Gene defined in this System:
link the gene to the model. Create a ModelGene by encapsulating CoreGene from the gene_bank It can exists at each run several ModelGene for one CoreGene
If a gene has exhangeables create them (an Exchangeable inherits from ModeleGene) and add them to the current ModelGene
For instance:
Syst_1
<system inter_gene_max_space="10">
<gene name=”A” mandatory=”1” loner="1">
<exchangeables>
<gene name=”B”>
</exchangeables>
</gene>
<system>
Syst_2
<system inter_gene_max_space="15">
<gene name=”B” mandatory=”1”>
<exchangeables>
<gene name=”C”>
</exchangeables>
</gene>
<system>
Syst_3
<system inter_gene_max_space="20">
<gene name=”c” mandatory=”1” />
<system>
With the example above:
the CoreGene A, B, C will be created
the ModelGene (Syst_1, A) (Syst_1, B), (Syst_2, B), (Syst_2, C), (Syst_3, C)
The ModeleGene (Syst_1, A), (Syst_2, B) and (Syst_3, C) are directly link to their respective Models
and where (Syst_1, B) (Syst_2, C) are exchangeables and link respectively to (Syst_1, A) and (Syst_2, B)
the ModelGene has attributes defined in the model where they appear (Syst_1, B) inter_gene_max_space=”10” (Syst_2, B) inter_gene_max_space=”15”
Note
The only “full” Systems (i.e., with all corresponding Genes created) are those to detect.
defintion_parser API reference
DefinitionParser
Module use to parse XML model defintion and create a python Model and Genes, …
- class macsypy.definition_parser.DefinitionParser(cfg: Config | NoneConfig, model_bank: ModelBank, gene_bank: GeneBank, model_registry: ModelRegistry, profile_factory: ProfileFactory)[source]
Build a Model instance from the corresponding model definition described in the XML file.
- __init__(cfg: Config | NoneConfig, model_bank: ModelBank, gene_bank: GeneBank, model_registry: ModelRegistry, profile_factory: ProfileFactory) None [source]
- Parameters:
cfg – the configuration object of this run
model_bank – the model factory
gene_bank – the gene factory
model_registry – The registry with all model location
profile_factory – The profile factory
- __weakref__
list of weak references to the object (if defined)
- _check_syntax(model_node: ElementTree, path: str) None [source]
Check if the definition does not contain logical error which is allowed by syntax and absence of explicit grammar.
- Parameters:
model_node – the node corresponding to the model
path – the path of the definition.
- Raises:
ModelInconsistencyError – if an error is encountered in the document.
- _create_model(def_loc: DefinitionLocation, model_node: ElementTree) Model [source]
- Parameters:
def_loc – the definition location to parse.
model_node – the node corresponding to the model.
- Returns:
the model corresponding to the definition location.
- _fill_gene_bank(model_node: ElementTree, model_location: ModelLocation, def_loc: DefinitionLocation) None [source]
find all gene node and add them to the gene_bank
- Parameters:
model_node – the node corresponding to the model.
model_location –
def_loc – a definition location corresponding to the ‘model’ to parse.
- _get_model_node(def_loc: DefinitionLocation) ElementTree [source]
- Parameters:
def_loc (return the node corresponding to the 'model' tag) – a definition location to parse.
- _parse_exchangeable(gene_node: ElementTree, gene_ref: ModelGene, curr_model: Model) Exchangeable [source]
Parse a xml element gene child of exchangeable and build the corresponding object
- Parameters:
gene_node – a “node” corresponding to the gene element in the XML hierarchy
gene_ref – the gene which this gene is homolog to
curr_model – the model being parsed .
- Returns:
the gene object corresponding to the node
- _parse_genes(model: Model, model_node: ElementTree) None [source]
Create genes belonging to the models. Each gene is directly added to the model in its right category (‘mandatory, accessory, …)
- Parameters:
model – the Model currently parsing
model_node – the element ‘model’
- check_consistency(models: list[Model]) None [source]
Check the consistency of the co-localization features between the different values given as an input: between XML definitions, configuration file, and command-line options.
- Parameters:
models – the list of models to check
- Raise:
macsypy.error.ModelInconsistencyError
if one test fails
(see feature)
In the different possible situations, different requirements need to be fulfilled (“mandatory_genes” and “accessory_genes” consist of lists of genes defined as such in the model definition):
If: min_mandatory_genes_required = None ; min_genes_required = None
Then: min_mandatory_genes_required = min_genes_required = len(mandatory_genes)
always True by Models design
If: min_mandatory_genes_required = value ; min_genes_required = None
Then: min_mandatory_genes_required <= len(mandatory_genes)
AND min_genes_required = min_mandatory_genes_required
always True by design
If: min_mandatory_genes_required = None ; min_genes_required = Value
Then: min_mandatory_genes_required = len(mandatory_genes)
AND min_genes_required >= min_mandatory_genes_required
AND min_genes_required <= len(mandatory_genes+accessory_genes)
to be checked
If: min_mandatory_genes_required = Value ; min_genes_required = Value
Then: min_genes_required <= len(accessory_genes+mandatory_genes)
AND min_genes_required >= min_mandatory_genes_required
AND min_mandatory_genes_required <= len(mandatory_genes)
to be checked
- parse(models_2_detect: list[DefinitionLocation]) None [source]
Parse models definition in XML format to build the corresponding Model objects, and add them to the model factory after checking its consistency. To get the model ask it to model_bank
- Parameters:
models_2_detect – a list of model definition to parse.