Package: ponyo
ponyoAlexandra J. Lee and Casey S. Greene 2020University of PennsylvaniaThis repository is named after the the characterPonyo, from Hayao Miyazaki's animated filmPonyo, as she uses her magic to simulate a human appearance after getting a sample of human blood.
The method simulates new gene expression data by training a generative neural network on existing gene expression data to learn a representation of gene expression patterns.InstallationThis package can be installed using pip:pip install ponyoTypes of simulationsThere are 3 types of simulations that ponyo implements:NameDescriptionSimulation by random samplingThis approach simulates gene expression data by randomly sampling from the latent space distribution. The function to run this approach is divided into 2 components:simulate_by_random_samplingis a wrapper which loads VAE trained models from directory specified byvae_model_dirparam andrun_sample_simulationwhich runs the simulation. Note:simulate_by_random_samplingassumes the files are organized as described above. If this directory organization doesn't apply to you, then you can directly userun_sample_simulationby passing in your pre-trained VAE model files. An example of how to use this can be foundhere.Simulation by latent transformationThis approach simulates gene expression data by encoding experiments into the latent space and then shifting samples from that experiment in the latent space. Unlike the "Simulation by random sampling" approach, this method accounts for experiment level information by shifting samples from the same experiment together. The function to run this approach is divided into 2 components:simulate_by_latent_transformationis a wrapper which loads VAE trained models from directory specified by thevae_model_dirparam andrun_latent_transformation_simulationwhich runs the simulation. Note:simulate_by_latent_transformationassumes the files are organized as described above. If this directory organization doesn't apply to you, then you can directly userun_latent_transformation_simulationby passing in your VAE model trained usingrun_tybalt_traininginvae.py.There are 3 flavors of this approach:1.simulate_by_latent_transforminputs a dataset with multiple experiments (these are your template experiments) and then it outputs the same number of new simulated experiments that are created by shifting a randomly sampled template experiment. This simulation generates a collection of different types of experiments. An example of how to use this can be foundhere.2.shift_template_experimentwhich inputs a single template experiment, which is an experiment included within the dataset used to train the VAE model. This simulation outputs multiple simulated experiments based on the one template by shifting that template experiment to different locations in the latent space. This simulation generates a collection of experiments of a similar design type. An example for how to use this can be foundhere.3.embed_shift_template_experimentwhich performs the same simulation approach asshift_template_experimenthowever this is using a template experiment that is not contained within the training dataset. An example for how to use this can be foundhere.How to useExample notebooks using ponyo on test data can be found inexamplesAdditionally, this method has been used insimulate-expression-compendiaandgeneric-expression-patternsrepositories.Setting random seedsTo keep the VAE training deterministic, you will need to set multiple random seeds:numpy randompython randomtensorflow randomFor an example of this, seeexample notebooksConfiguration fileThe tables lists the core parameters required to generate simulated data using modules fromponyo.Parameters required forall simulation types:NameDescriptionbase_dirstr: Root directory containing analysis subdirectories. By default the path is one level up from where the scripts are run.local_dirstr: Parent directory on local machine to store intermediate resultsraw_compenium_filenamestr: File storing raw gene expression datanormalized_compendium_filenamestr: File storing normalized gene expression data. This file is generated bynormalize_expression_data().scaler_transform_filenamestr: Python pickle file to store mapping from normalized to raw gene expression range. This file is generated bynormalize_expression_data().vae_model_dirstr:  The location where the VAE model files (.h5) are stored.learning_ratefloat: Step size used for gradient descent. In other words, it's how quickly the  methods is learningbatch_sizestr: Training is performed in batches. So this determines the number of samples to consider at a given timeepochsint: Number of times to train over the entire input datasetkappafloat: How fast to linearly ramp up KL lossintermediate_dimint: Size of the hidden layerlatent_dimint: Size of the bottleneck layerepsilon_stdfloat: Standard deviation of Normal distribution to sample latent spacevalidation_fracfloat: Fraction of input samples to use to validate for VAE trainingtraining_stats_dirstr: Directory containing the VAE training log files.num_simulatedint: The number of samples (for simulation by random sampling approach) or experiments (for all latent transformation approaches) to simulate.Additional parameters required forall latent transformation approaches:NameDescriptionproject_idint: The experiment id to use as a template experiment. This <project_id> corresponds to a group of samples that were used to test an single hypothesis. This parameter is needed if using eithershift_template_experimentorembed_shift_template_experimentapproaches. If usingshift_template_experiment, the id is pulled from the <metadata_experiment_colname> column of the <metadata_filename>. If usingembed_shift_template_experiment, the id is used to name the simulated files generated.is_recount2bool: True is the compendium dataset being used is recount2. This will determine how experiment ids are parsed for latent transformation approaches.Additional parameters required forsimulate_by_latent_transformandshift_template_experimentsimulation types only:NameDescriptionmetadata_filenamestr: File containing metadata associated with data. This file maps samples to a given experiment.metadata_delimiter"," or "\t" to denote the delimiter used in the metadata file.metadata_experiment_colnamestr: Column header that contains experiment id that maps expression data and metadata. This parameter needed if using either latent transformation approaches.metadata_sample_colnamestr: Column header that contains sample id that maps expression data and metadata. This parameter needed if using either latent transformation approaches.experiment_ids_filenamestr: File containing list of experiment ids that have gene expression data available.Additional parameters required forshift_template_experimentandembed_shift_template_experimentsimulation type only:NameDescriptionsimulated_data_dirstr:  The location where the simulated experiments are stored.Additional parameters required forembed_shift_template_experimentsimulation type only:NameDescriptionraw_template_filenamestr: Downloaded template gene expression data file. The input dataset should be a matrix that is sample x gene. The file should tab-delimited. The gene ids need to be consistent between the template and compendium datasets. The input dataset should be generated using the same platform as the model you plan to use (i.e. RNA-seq or array). The expression values are expected to have been uniformly processed and can be estimated counts (RNA-seq) or log2 expression (array).mapped_template_filenamestr: Template gene expression data filename. This file is generated by scale transforming the data using the scaler_transform_filename. The gene ids of the template file and the compendium file are matched.normalized_template_filenamestr: Normalized template gene expression data filename.For guidance on setting VAE training prameters, see configurations used insimulate-expression-compendiaandgeneric-expression-patternsrepositoriesAcknowledgementsWe would like to thank Marvin Thielk for adding coverage to tests and Ben Heil for contributing code to add more flexibility.