Anneal Core

Package contents

ANNEAL: rnA cNvs iNferEnce And cLustering (with Pyro)

A set of Pyro models and an interface for simultaneous CNV clustering and inference

anneal.Interface module

Standardize models execution.

The core of the package just provides class with functions to make every model behave in the same way

class congas.Interface.Interface(model=None, optimizer=None, loss=None, inf_type=<class 'pyro.infer.svi.SVI'>)[source]

Bases: object

The interface class for all the congas models.

Basically it takes a model, am optimizer and a loss function and provides a functions to run the inference and get the parameters back masking the differences between models.

initialize_model(data)[source]
learned_parameters()[source]

Return all the estimated parameter values

Calls the right set of function for retrieving learned parameters according to the model type If posterior=True all the other parameters are just passed to inference_categorical_posterior()

Parameters:posterior – learn posterior assignement (if false estimate MAP via Viterbi-like MAP inference)
Returns:parameter:value dictionary
Return type:dict
run(steps, param_optimizer={'lr': 0.05}, param_loss=None, seed=3, MAP=False)[source]

This function runs the inference of non-categorical parameters

This function performs a complete inference cycle for the given tuple(model, optimizer, loss, inference modality). For more info about the parameters for the loss and the optimizer look at Optimization. and Loss.

Not all the the combinations Optimize-parameters and Loss-parameters have been tested, so something may not work (please open an issue on the GitHub page).

Parameters:
  • steps (int) – Number of steps
  • param_optimizer (dict) – A dictionary of paramaters:value for the optimizer
  • param_loss (dict) – A dictionary of paramaters:value for the loss function
  • seed (int) – seed to be passed to pyro.set_rng_seed
  • MAP (bool) – Perform learn a Delta distribution over the outer layer of the model graph
  • verbose (bool) – show loss for each step, if false the functions just prints a progress bar
  • BAF (torch.tensor) – if provided use BAF penalization in the loss
Returns:

loss (divided by sample size) for each step

Return type:

list

set_loss(loss)[source]
set_model(model)[source]
set_model_params(param_dict)[source]
set_optimizer(optimizer)[source]

anneal.utils module

Utils class

A set of utils function to run automatically an enetire inference cycle, plotting and saving results.

congas.utils.dict_to_tensor(dict)[source]
congas.utils.load_simulation_seg(dir, prefix)[source]

Read data from companion R package simulation

A function to read the

Parameters:
  • dir – directory where the simulation files are stored
  • prefix

Returns:

congas.utils.log_sum_exp(args)[source]
congas.utils.plot_loss(loss, save=False, output='run1')[source]
congas.utils.run_analysis(data_dict, model, optim=<function ClippedAdam>, elbo=<class 'pyro.infer.traceenum_elbo.TraceEnum_ELBO'>, inf_type=<class 'pyro.infer.svi.SVI'>, steps=500, lr=0.01, param_dict={}, MAP=True, seed=3)[source]

Run an entire analysis with the minimum amount of parameters

Simple function to run an entire step of inference and get the learned parameters back, less customizable than using directly the Interface , but still should satisfy most of hte user. Look at the R interface for even a easier

Parameters:
  • data_dict – dictionary with parameters
  • model – a model from one in congas.models
  • optim – an optimizer from pyro.optim
  • elbo – a loss function from pyro.infer
  • inf_type – SVI or NUTS (Hemiltonian MCMC)
  • steps – number of inference steps
  • lr – learning rate
  • param_dict – parameters for the model, look at the model documentation if you want to change them
  • MAP – perform MAP over the last layer of random variable in the model or learn the parameters of the distribution
  • seed – seed for pyro.set_rng_seed
  • step_post – steps if learning also posterior probabilities
Returns:

dictionary of parameters:value list: loss (divided by sample size) for every time step (not the one for posteriors)

Return type:

dict

congas.utils.write_results(params, prefix, new_dir=False, dir_pref=None)[source]

Write parameters

This function writes the parameters appending a prefix and optionally in a new directory

Parameters:
  • params – parameters dictionary
  • prefix – prefix to append to the filenames
  • new_dir – create a new directory or use an exsisting ones
  • dir_pref – name of the directory