aprile.model
- class aprile.model.Aprile(gdata, device='cpu')
Bases:
object
APRILE: explaning polypharmacy side effect using a pre-trained APRILE-Pred model
- Parameters
device (str) – ‘cpu’ or ‘cuda’, for running APRILE-Explainer
- enrich_go(pp_left_index)
gene ontology enrichment analysis
- explain_list(drug_list_1, drug_list_2, side_effect_list, regularization=2, if_auto_tuning=True, if_pred=True)
generate explanation for a list of adverse drug events
- explain_query(query, if_auto_tuning=True, regularization=2)
generate explanation for a AprileEQuery query
- get_prediction_test(threshold=0.5)
generate predictions for DDIs in the testing set
- Parameters
threshold (float, optional) – the threshold of probability scores for DDIs. Defaults to 0.5.
- Returns
prediction results
- Return type
- get_prediction_train(threshold=0.5)
generate predictions for DDIs in the training set
- Parameters
threshold (float, optional) – the threshold of probability scores for DDIs. Defaults to 0.5.
- Returns
prediction results
- Return type
- predict(drug1, drug2, side_effect, threshold=0.5)
Predict the probability of DDIs
- Parameters
drug1 (list) – a list of drug
drug2 (list) – a list of drug pairing drug1
side_effect (list) – a list of side effect
threshold (float, optional) – for probability. Defaults to 0.5.
- Raises
ValueError – None of DDIs meets the threshold
- Returns
prediction results
- Return type
- class aprile.model.AprileExplainer(model, data, device)
Bases:
object
Explain APRILE-Predictor’s predictions by given a small set of drug targets and protein-protein interactions
- explain(drug_list_1, drug_list_2, side_effect_list, regularization=1)
- class aprile.model.AprileGCN(in_channels, out_channels, improved=False, cached=False, bias=True, **kwargs)
Bases:
torch_geometric.nn.conv.message_passing.MessagePassing
- Graph convolutional neural network [1] with edge weights/masks.
[1]: “Semi-supervised Classification with Graph Convolutional Networks” <https://arxiv.org/abs/1609.02907> (ICLR 2017) paper.
Note
For more information please see Pytorch Geomertic’s nn.GCNConv docs.
- Parameters
in_channels (int) – size of each inputs samples
out_channels ([type]) – size of each outputs samples
improved (bool, optional) – Defaults to False.
cached (bool, optional) – Defaults to False.
bias (bool, optional) – Defaults to True.
- forward(x, edge_index, edge_weight=None)
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- message(x_j, norm)
Constructs messages from node \(j\) to node \(i\) in analogy to \(\phi_{\mathbf{\Theta}}\) for each edge in
edge_index
. This function can take any argument as input which was initially passed topropagate()
. Furthermore, tensors passed topropagate()
can be mapped to the respective nodes \(i\) and \(j\) by appending_i
or_j
to the variable name, .e.g.x_i
andx_j
.
- static norm(edge_index, num_nodes, edge_weight, improved=False, dtype=None)
Add self-loops and apply symmetric normalization
- reset_parameters()
- update(aggr_out)
Updates node embeddings in analogy to \(\gamma_{\mathbf{\Theta}}\) for each node \(i \in \mathcal{V}\). Takes in the output of aggregation as first argument and any argument which was initially passed to
propagate()
.
- class aprile.model.AprilePredModel(pp, pd, mip)
Bases:
torch.nn.modules.module.Module
Aprile-Pred model structure
- class aprile.model.AprilePredictorPretrained(data_path)
Bases:
object
Make adverse polypharmacy reactions using a pre-trained predictor
- Parameters
data_path (str) – the path of pre-trained Aprile-Predictor
- predict(drug1, drug2, side_effect, device='cpu', threshold=0.5)
- class aprile.model.AprileQuery(drug1, drug2, side_effect, regularization=2)
Bases:
object
A class for quering APRILE’s prediction and expalanition results
- Parameters
drug1 (list) – a list of drug
drug2 (list) – a list of drug pairing with drug1
side_effect (list) – a list of side effect caused by drug pairs
regularization (int, optional) – the coefficient for control the size of explanation. Defaults to 2.
- get_GOEnrich_table()
get Gene Ontology analysis results
- Returns
significant GOs, genes and additional mappings
- Return type
pandas.DataFrame
- get_pred_table()
generate the prediction results
- Returns
DDIs, probability, PIU, PPIU and additional mappings
- Return type
pandas.DataFrame
- get_query()
get query details
- get_subgraph(if_show=True, save_path=None, prot_graph_dict=None, drug_name_dict=None)
Visualize explanation
- Parameters
if_show (bool, optional) – if print the figure. Defaults to True.
save_path (str, optional) – the path to save figure. Defaults to None.
- Returns
DDIs and their mechanisms
- Return type
matplotlib.pyplot.figure()
- static load_from_pkl(file)
load a query from a pickle file
- Parameters
file (str) – the file’s path
- Return type
- set_enrich_result(goea_results_sig, geneid2symbol)
- set_exp_result(pp_index, pp_weight, pd_index, pd_weight)
- set_pred_result(probability, piu_score, ppiu_score, drug_idx_to_id, drug_idx_to_name, side_effect_idx_to_name)
- to_pickle(file)
save the current query to a pickle file
- Parameters
file (str) – the path to save the object
- class aprile.model.MultiInnerProductDecoder(in_dim, num_et)
Bases:
torch.nn.modules.module.Module
DistMult tensor factorization for side effect prediction,
- Parameters
in_dim (int) – the dimension of drug feature
num_et (int) – the number of side effect
- forward(z, edge_index, edge_type, sigmoid=True)
forward propagation to predict {(drug, drug, side_effect)}
- Parameters
z (torch.Tensor) – drug features
edge_index (torch.Tensor) – sparse representation of DDIs
edge_type (torch Tensor) – side effect associated with each edge index
sigmoid (bool, optional) – if apply Sigmoid. Defaults to True.
- Returns
probability of DDIs with associated
- Return type
torch tensor
- class aprile.model.PD(protein_dim, d_dim_prot, n_drug, d_dim_feat=32)
Bases:
torch.nn.modules.module.Module
Drug representation module
- Parameters
protein_dim (int) – the size of protein embeddings
d_dim_prot (int) – the size of drug embeddings for the related pharmacogenomic information
n_drug (int) – the number of drugs
d_dim_feat (int, optional) – the size of drug feature embeddings. Defaults to 32.
- forward(x, pd_edge_index, edge_weight=None)
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- reset_parameters()
- class aprile.model.PP(in_dim, nhid_list)
Bases:
torch.nn.modules.module.Module
Protein representation module
- Parameters
in_dim (int) – the size of each input samples
nhid_list (list) – the size of each intermediary embeddings and outputs
- forward(x, pp_edge_index, edge_weight)
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- reset_parameters()