corneto.methods package#
Subpackages#
Submodules#
corneto.methods.carnival module#
- corneto.methods.carnival.read_dataset(zip_path)#
Extracts and processes a graph and its vertex attributes from a zipped dataset.
The function reads two CSV files from a specified zipfile: ‘pkn.csv’ and ‘data.csv’. The ‘pkn.csv’ contains graph edges with three columns: ‘source’, ‘interaction’, and ‘target’. The ‘interaction’ column uses integers to denote the type of interaction (1 for activation, -1 for inhibition). The ‘data.csv’ file contains vertex attributes with three columns: ‘vertex’, ‘value’, and ‘type’, where ‘value’ can be a continuous measure such as from a t-statistic in differential expression, and ‘type’ categorizes vertices as either inputs (‘P’ for perturbation) or outputs (‘M’ for measurement).
- Parameters:
zip_path (str) – The file path to the zip file containing the dataset.
- Returns:
- A tuple containing:
Graph: A graph object initialized with edges from ‘pkn.csv’. Each edge is defined by a source, a target, and an interaction type.
dict: A dictionary mapping each protein (vertex) to a tuple of (‘type’, ‘value’), where ‘type’ is either ‘P’ or ‘M’ and ‘value’ represents the continuous state of the protein.
- Return type:
- Raises:
FileNotFoundError – If the zip file cannot be found at the provided path.
KeyError – If expected columns are missing in the CSV files, indicating incorrect or incomplete data.
Example
>>> graph, vertex_attrs = read_dataset('path/to/dataset.zip') >>> print(graph.shape) # Shape of the imported graph ([vertices, edges]) >>> print(vertex_attrs) # Displays protein attributes
- corneto.methods.carnival.preprocess_graph(priorKnowledgeNetwork, perturbations, measurements)#
- corneto.methods.carnival.runVanillaCarnival(perturbations, measurements, priorKnowledgeNetwork, betaWeight=0.2, solver=None, backend_options={}, solve=True, verbose=True, **kwargs)#
- corneto.methods.carnival.runInverseCarnival(measurements, priorKnowledgeNetwork, betaWeight=0.2, solver=None, solve=True, **kwargs)#
- corneto.methods.carnival.heuristic_carnival(priorKnowledgeNetwork, perturbations, measurements, restricted_search=False, prune=True, verbose=True, max_time=None, max_edges=None)#
- corneto.methods.carnival.get_result(P, G, condition='c0', exclude_dummies=True)#
- corneto.methods.carnival.get_selected_edges(P, G, condition='c0', exclude_dummies=True)#
- corneto.methods.carnival.reachability_graph(G, input_nodes, output_nodes, subset_edges=None, verbose=True, early_stop=False, expand_outputs=True, max_printed_outputs=10)#
- corneto.methods.carnival.bfs_search(G, initial_dict, final_dict, max_time=None, queue_max_size=None, subset_edges=None, max_edges=None, verbose=True)#
- corneto.methods.carnival.create_flow_carnival_v4(G, exp_list, lambd=0.2, exclusive_vertex_values=True, upper_bound_flow=1000, penalty_on='signal', slack_reg=False, set_perturbation_values=True, fix_input_values=True, backend=<corneto.backend._cvxpy_backend.CvxpyBackend object>)#
- corneto.methods.carnival.create_flow_carnival_v3(G, exp_list, lambd=0.2, exclusive_vertex_values=True, upper_bound_flow=1000, backend=<corneto.backend._cvxpy_backend.CvxpyBackend object>)#
- corneto.methods.carnival.create_flow_carnival_v2(G, exp_list, lambd=0.2)#
- corneto.methods.carnival.create_flow_carnival(G, exp_list, lambd=0.2)#
- corneto.methods.carnival.runCARNIVAL_AcyclicFlow(G, exp_list, betaWeight=0.2, solver=None, verbosity=False)#
- Parameters:
betaWeight (float)
- corneto.methods.carnival.runCARNIVAL_Flow_Acyclic(G, exp_list, betaWeight=0.2, solver=None, verbosity=False)#
- Parameters:
betaWeight (float)
- corneto.methods.carnival.runCARNIVAL_Flow_Acyclic_Signal(G, exp_list, betaWeight=0.2, solver=None, verbosity=False)#
- Parameters:
betaWeight (float)
- corneto.methods.carnival.milp_carnival(G, perturbations, measurements, beta_weight=0.2, max_dist=None, penalize='edges', use_perturbation_weights=False, interaction_graph_attribute='interaction', disable_acyclicity=False, backend=<corneto.backend._cvxpy_backend.CvxpyBackend object>)#
Improved port of the original Carnival R method.
This implementation uses the CORNETO backend capabilities to create a MILP problem. However, it does not use the flow formulation and multi-sample capabilities of the novel method implemented in CORNETO. This method is kept for compatibility with the original Carnival R method and for comparison purposes.
NOTE: Since the method is decoupled from specific solvers, the default pool of solutions generated using CPLEX is not available.
- Parameters:
G – The graph object representing the network.
perturbations – A dictionary of perturbations applied to specific vertices in the graph.
measurements – A dictionary of measured values for specific vertices in the graph.
beta_weight (
float
(default:0.2
)) – The weight for the regularization term in the objective function.max_dist (default:
None
) – The maximum distance allowed for vertex positions in the graph.penalize (default:
'edges'
) – The type of regularization to apply (‘nodes’, ‘edges’, or ‘both’).use_perturbation_weights (default:
False
) – Whether to use perturbation weights in the objective function.interaction_graph_attribute (default:
'interaction'
) – The attribute name for the interaction type in the graph.disable_acyclicity (default:
False
) – Whether to disable the acyclicity constraint in the optimization.backend (default:
<corneto.backend._cvxpy_backend.CvxpyBackend object at 0x7fb1b4d3ced0>
) – The backend engine to use for the optimization.
- Returns:
The optimization problem object.
corneto.methods.shortest_path module#
- corneto.methods.shortest_path.create_multisample_shortest_path(G, source_target_nodes, edge_weights=None, solver=None, backend=<corneto.backend._cvxpy_backend.CvxpyBackend object>, lam=0.0)#
- corneto.methods.shortest_path.shortest_path(G, s, t, edge_weights=None, integral_path=True, create_flow_graph=True, backend=<corneto.backend._cvxpy_backend.CvxpyBackend object>)#
- corneto.methods.shortest_path.solve_shortest_path(G, s, t, edge_weights=None, solver=None, backend=<corneto.backend._cvxpy_backend.CvxpyBackend object>, integer_tolerance=1e-06, solver_kwargs=None)#
corneto.methods.signaling module#
- corneto.methods.signaling.create_flow_graph(g, conditions, pert_id='P', meas_id='M', longitudinal_samples=False)#
- corneto.methods.signaling.signflow_constraints(g, backend=<corneto.backend._cvxpy_backend.CvxpyBackend object>, signal_implies_flow=True, flow_implies_signal=False, dag=True, use_flow_indicators=True, eps=0.001)#
- corneto.methods.signaling.default_sign_loss(conditions, problem, l0_edges=0.0, l0_vertices=0.0, l1_flow=0.0, ub_loss=None, lb_loss=None)#
- corneto.methods.signaling.signflow(g, conditions, signal_implies_flow=True, flow_implies_signal=False, dag=True, l0_penalty_edges=0.0, l1_penalty_flow=0.0, l0_penalty_vertices=0.0, ub_loss=None, lb_loss=None, use_flow_indicators=True, eps=0.001, backend=<corneto.backend._cvxpy_backend.CvxpyBackend object>)#
- corneto.methods.signaling.expand_graph_for_flows(G, exp_list)#
Add edges to the perturbed and measured nodes in graph G to make flow possible.
- Parameters:
G (BaseGraph)
corneto.methods.steiner module#
- corneto.methods.steiner.exact_steiner_tree(G, terminals, edge_weights=None, root=None, tolerance=0.001, strict_acyclic=False, flow_name='_flow', in_flow_edge_type=EdgeType.DIRECTED, out_flow_edge_type=EdgeType.DIRECTED, backend=<corneto.backend._cvxpy_backend.CvxpyBackend object>, flow_injected=10)#
- corneto.methods.steiner.create_exact_multi_steiner_tree(G, terminal_per_condition, edge_weights_per_condition=None, root_vertices=None, tolerance=0.001, strict_acyclic=False, lam=0.01, flow_name='flow', backend=<corneto.backend._cvxpy_backend.CvxpyBackend object>)#
- Parameters:
G (BaseGraph)
backend (Backend)