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
property attractor_type
property attractors
property binary_boolean_equations
property boolean_equations
calculate_attractors(attractor_tool, attractor_type)

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)

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()
property global_output
has_attractors()
has_global_output()
has_stable_states()
property model_name
property mutation_type
print()
reset_attractors()
to_binary(mutation_type)

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
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
get_activating_regulators(index)
get_inhibitory_regulators(index)
get_interaction(index)
get_target(index)
property interactions
property model_name
print()
size()
class pydruglogics.Logger

Bases: object

classmethod set_logger(level=20, external_lib_off=True)
class pydruglogics.ModelOutputs(input_file=None, input_dictionary=None)

Bases: object

get_model_output(node_name)
property max_output
property min_output
property model_outputs
property node_names
print()
size()
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=None, perturbation_data=None)

Bases: object

property drug_effects
property drug_names
property drug_targets
property drugs
property perturbations
print()
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=None, observations=None)

Bases: object

property observations
print()
property response
property responses
size()
property weight_sum
property weights
pydruglogics.compare_two_simulations(boolean_models1, boolean_models2, observed_synergy_scores, model_outputs, perturbations, synergy_method='bliss', label1='Models 1', label2='Models 2', normalized=True, plot=True, save_result=True)

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=None, predict_params=None)

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

pydruglogics.sampling_with_ci(boolean_models, observed_synergy_scores, model_outputs, perturbations, synergy_method='bliss', repeat_time=10, sub_ratio=0.8, boot_n=1000, confidence_level=0.9, plot=True, plot_discrete=False, save_result=True, with_seeds=True, seeds=42)

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)