pydruglogics package

Subpackages

Module contents

class pydruglogics.BooleanModel(model=None, file=None, attractor_tool='mpbn', attractor_type='stable_states', mutation_type='topology', model_name='', cloned_equations=None, cloned_binary_equations=None)

Bases: object

Initializes the BooleanModel instance. :param model: An InteractionModel instance. :param file: The path to the file containing Boolean Equations in ‘.bnet’ format. :param attractor_tool: The tool to be used for attractor calculation. Possible values: ‘mpbn’, ‘pyboolnet’. :param attractor_type: The type of the attractor calculation. Possible values: ‘stable_states’, ‘trapspaces’. :param mutation_type: The type of mutation to be performed. Possible values: ‘topology’, ‘binary’, ‘balanced’. :param model_name: Name for the model. :param cloned_equations: Boolean Equations representing the model’s interactions. (only for cloning) :param cloned_binary_equations: A list representing the Mutate Boolean Model in binary representation. (only for cloning)

add_perturbations(perturbations)

Adds perturbations to the Boolean Model. :param perturbations: A list of Perturbations. :return: None

property attractor_tool: str
property attractor_type: str
property attractors: object
property binary_boolean_equations
property boolean_equations
calculate_attractors(attractor_tool, attractor_type) None

Calculate attractors based on the chosen attractor_tool and attractor_type. :param attractor_tool: Tool for attractor calculation. Possible values: ‘mpbn’, ‘pyboolnet’. :param attractor_type: Type of attractor. Possible values: ‘stable_states’, ‘trapspaces’. :return: None

calculate_global_output(model_outputs, normalized=True)

Calculates the (normalized) global output of the model. :param model_outputs: An instance containing node weights defined in the ModelOutputs class. :param normalized: Whether to normalize the global output. :return: float

clone()
from_binary(binary_representation, mutation_type: str)

Updates the Boolean Equations from a binary representation based on the mutation type. :param binary_representation: The binary representation of the Boolean Equations as a list. :param mutation_type: The type of mutation can be: ‘topology’, ‘balanced’, ‘mixed’. :return: Updated Boolean Equations as a list.

get_stable_states() object
property global_output
has_attractors() bool
has_global_output() bool
has_stable_states() bool
property model_name: str
property mutation_type: str
print()
reset_attractors() None
to_binary(mutation_type: str)

Converts the Boolean Equations to a binary representation. The representation is based on the mutation type. :param mutation_type: The type of mutation can be: ‘topology’, ‘balanced’, ‘mixed’ :return: The binary representation of the Boolean Equations as a list.

class pydruglogics.Evolution(boolean_model=None, training_data=None, model_outputs=None, ga_args=None, ev_args=None)

Bases: BooleanModelOptimizer

Initializes the Evolution class with a BooleanModel and genetic algorithm parameters. :param boolean_model: The boolean model to be evolved. :param training_data: Training data for the model. :param model_outputs: Model outputs for evaluation. :param ga_args: Dictionary containing all necessary arguments for pygad. :param ev_args: Dictionary containing all necessary arguments for running the evolution.

property best_boolean_models: List[BooleanModel]
calculate_fitness(ga_instance, solutions, solution_idx)

Calculates fitness for a batch of solutions. Each solution is evaluated in a batch, and a fitness score is returned for each. :param ga_instance: Instance of the GA. It is required by PayGAD. :param solutions: A batch of solutions (list of binary vectors). It is required by PayGAD. :param solution_idx: The index of the current solution batch. It is required by PayGAD. :return: A list of fitness values, one for each solution in the batch.

create_initial_population(population_size, num_mutations, seed=None)

Creates an initial population for the GA. :param population_size: The number of individuals in the population. :param num_mutations: The number of mutations to perform on each individual. :param seed: Seed for reproducibility. :return: List of binary vectors representing the initial population.

run()
save_to_file_models(base_folder='./results/models')
class pydruglogics.InteractionModel(interactions_file=None, model_name='', remove_self_regulated_interactions=False, remove_inputs=False, remove_outputs=False)

Bases: object

Initializes the InteractionModel from .sif file. :param interactions_file: File path to the .sif file with network interactions. :param model_name: Name for the model. An empty string by default. :param remove_self_regulated_interactions: If True, removes self-regulating interactions (source equals target).False by default. :param remove_inputs: If True, removes nodes without incoming interactions. False by default. :param remove_outputs: If True, removes nodes without outgoing interactions. False by default.

property all_targets: List[str]
get_activating_regulators(index: int) List[str]
get_inhibitory_regulators(index: int) List[str]
get_interaction(index: int) Dict
get_target(index: int) str
property interactions: List[Dict]
property model_name: str
print() None
size() int
class pydruglogics.Logger

Bases: object

classmethod set_logger(level=20, external_lib_off=True)
class pydruglogics.ModelOutputs(input_file: str = None, input_dictionary: Dict[str, float] = None)

Bases: object

get_model_output(node_name: str) float
property max_output: float
property min_output: float
property model_outputs: Dict[str, float]
property node_names: List[str]
print() None
size() int
class pydruglogics.ModelPredictions(boolean_models=None, perturbations=None, model_outputs=None, synergy_method='bliss', model_directory=None, attractor_tool=None, attractor_type=None)

Bases: object

Initializes the ModelPredictions class. :param boolean_models: List of BooleanModel instances. :param perturbations: List of perturbations to apply. :param model_outputs: Model outputs for evaluating the predictions. :param observed_synergy_scores: List of observed synergy scores. :param synergy_method: Method to check for synergy. Possible values: ‘hsa’ or ‘bliss’. :param model_directory: Directory from which to load models. (Needed only when there is no Evolution result.) :param attractor_tool: Tool to calculate attractors in models. (Needed only when loads models from directory.) :param attractor_type: Type to calculate attractors in models. (Needed only when loads models from directory.)

get_prediction_matrix()
property predicted_synergy_scores
run_simulations(parallel=True, cores=4)

Runs simulations on the Boolean Models with the perturbations, either in parallel or serially. :param parallel: Whether to run the simulations in parallel By default, True. :param cores: The number of CPU cores to use for parallel execution By default, 4. :return: None

save_to_file_predictions(base_folder='./results/predictions')
class pydruglogics.Perturbation(drug_data: List[List[str | None]] = None, perturbation_data: List[List[str]] = None)

Bases: object

property drug_effects: List[str]
property drug_names: List[str]
property drug_targets: List[List[str]]
property drugs: List[Dict[str, str]]
property perturbations: List[List[Dict[str, str]]]
print() None
class pydruglogics.PlotUtil

Bases: object

static plot_pr_curve_with_ci(pr_df, auc_pr, boot_n, plot_discrete)
static plot_roc_and_pr_curve(predicted_synergy_scores, observed_synergy_scores, synergy_method, labels=None)

Plot the ROC and PR Curves for one or multiple sets of predicted synergy scores. :param predicted_synergy_scores: Either a list of predictions for multiple models or a single set of predictions. :param observed_synergy_scores: List of observed synergy scores. :param synergy_method: Method used for synergy scoring (for plot titles). :param labels: Optional list of labels for each set of predictions. If None, default labels will be images.

class pydruglogics.TrainingData(input_file: str = None, observations: List[Tuple[List[str], float]] = None)

Bases: object

property observations: List[Dict[str, str | float]]
print() None
property response: List[str]
property responses: List[str]
size() int
property weight_sum: float
property weights: List[float]
pydruglogics.compare_two_simulations(boolean_models1: List, boolean_models2: List, observed_synergy_scores: List[str], model_outputs: Any, perturbations: Any, synergy_method: str = 'bliss', label1: str = 'Models 1', label2: str = 'Models 2', normalized: bool = True, plot: bool = True, save_result: bool = True) None

Compares ROC and PR curves for two sets of evolution results. By default, normalization of the first result is applied. :param boolean_models1: List of the best Boolean Models for the first simulation set. :param boolean_models2: List of the best Boolean Models for the second simulation set. :param observed_synergy_scores: List of observed synergy scores for comparison. :param model_outputs: Model outputs for evaluation. :param perturbations: List of perturbations to apply to the models. :param synergy_method: Method to check for synergy (‘hsa’ or ‘bliss’). :param label1: Label for the first simulation result. :param label2: Label for the second simulation result. :param normalized: Whether to normalize the first result. :param plot: Whether to display the ROC and PR curves. :param save_result: Whether to save the results. :return: None

pydruglogics.execute(train_params: Dict[str, Any] | None = None, predict_params: Dict[str, Any] | None = None) None

Execute training and/or prediction based on the provided parameters.

pydruglogics.sampling_with_ci(boolean_models: List, observed_synergy_scores: List[str], model_outputs: Any, perturbations: Any, synergy_method: str = 'bliss', repeat_time: int = 10, sub_ratio: float = 0.8, boot_n: int = 1000, confidence_level: float = 0.9, plot: bool = True, plot_discrete: bool = False, save_result: bool = True, with_seeds: bool = True, seeds: int = 42) None

Performs sampling with confidence interval calculation and plot the PR curve. :param boolean_models: List of BooleanModel instances. :param observed_synergy_scores: List of observed synergy scores. :param model_outputs: Model outputs for evaluation. :param perturbations: List of perturbations to apply to the models. :param synergy_method: Method to check for synergy (‘hsa’ or ‘bliss’). :param repeat_time: Number of times to repeat sampling. :param sub_ratio: Proportion of models to sample in each iteration. :param boot_n: Number of bootstrap resampling iterations for confidence intervals. :param confidence_level: Confidence level for confidence interval calculations. :param plot: Whether to display the PR curve. :param plot_discrete: Whether to plot discrete points on the PR curve. :param save_result: Whether to save the results to a .tab file. :param with_seeds: Whether to use a fixed seed for reproducibility. :param seeds: Seed value for random number generation to ensure reproducibility. :return: None

pydruglogics.train(*args, **kwargs)