Skip to main content

Deep learning for predicting CpG methylation

Project description

DeepCpG: Deep neural networks for predicting single-cell DNA methylation

|Version| |License| |PyPI| |Docs| |DOI| |Tweet|

.. |Version| image::

.. |License| image::

.. |PyPI| image::

.. |Docs| image::

.. |DOI| image::

.. |Tweet| image::

DeepCpG [1]_ is a deep neural network for predicting the methylation state of CpG dinucleotides in multiple cells. It allows to accurately impute incomplete DNA methylation profiles, to discover predictive sequence motifs, and to quantify the effect of sequence mutations. (`Angermueller et al, 2017 <>`_).

**Please help to improve DeepCpG**, by reporting bugs, typos in notebooks and documentation, or any ideas on how to make things better. You can submit an `issue <>`_ or send me an `email <>`_.

.. figure:: docs/source/fig1.png
:width: 640 px
:align: left
:alt: DeepCpG model architecture and applications

**DeepCpG model architecture and applications.**

\(a\) Sparse single-cell CpG profiles as obtained from scBS-seq or scRRBS-seq. Methylated CpG sites are denoted by ones, unmethylated CpG sites by zeros, and question marks denote CpG sites with unknown methylation state (missing data). (b) DeepCpG model architecture. The DNA model consists of two convolutional and pooling layers to identify predictive motifs from the local sequence context, and one fully connected layer to model motif interactions. The CpG model scans the CpG neighborhood of multiple cells (rows in b), using a bidirectional gated recurrent network (GRU), yielding compressed features in a vector of constant size. The Joint model learns interactions between higher-level features derived from the DNA- and CpG model to predict methylation states in all cells. (c, d) The trained DeepCpG model can be used for different downstream analyses, including genome-wide imputation of missing CpG sites (c) and the discovery of DNA sequence motifs that are associated with DNA methylation levels or cell-to-cell variability (d).

.. [1] Angermueller, Christof, Heather J. Lee, Wolf Reik, and Oliver Stegle. *DeepCpG: Accurate Prediction of Single-Cell DNA Methylation States Using Deep Learning.* Genome Biology 18 (April 11, 2017): 67. doi:10.1186/s13059-017-1189-z.

Table of contents
* `News`_
* `Installation`_
* `Getting started`_
* `Examples`_
* `Model Zoo`_
* `FAQ`_
* `Content`_
* `Changelog`_
* `Contact`_


* **181201**: DeepCpG 1.0.7 released!
* **180224**: DeepCpG 1.0.6 released!
* **171112**: Keras 2 is now the main Keras version (release 1.0.5).
* **170412**: New `notebook <./examples/notebooks/stats/index.ipynb>`_ on predicting inter-cell statistics!
* **170414**: Added ` <./scripts/>`_ and `dcpg_eval_perf.Rmd <./R/dcpg_eval_perf.Rmd>`_ for evaluating and visualizing prediction performances! Find an example in `this notebook <./examples/notebooks/basics/index.ipynb#Evaluating-prediction-performances>`_!
* **170412**: New `notebook <./examples/notebooks/stats/index.ipynb>`_ on predicting inter-cell statistics!
* **170410**: New `notebook <./examples/notebooks/snp/index.ipynb>`_ on estimating mutation effects!
* **170406**: A short description of all `DeepCpG scripts <>`_!
* **170404**: New guide on creating and analyzing DeepCpG data `released <>`_!
* **170404**: Training on continuous data, e.g. from bulk experiments, now `supported <>`_!


The easiest way to install DeepCpG is to use ``PyPI``:

.. code:: bash

pip install deepcpg

Alternatively, you can checkout the repository,

.. code:: bash

git clone

and then install DeepCpG using ````:

.. code:: bash

python install

Getting started

1. Store known CpG methylation states of each cell into a tab-delimted file with the following columns:

* Chromosome (without chr)
* Position of the CpG site on the chromosome starting with one
* Binary methylation state of the CpG sites (0=unmethylation, 1=methylated)


.. code::

1 3000827 1.0
1 3001007 0.0
1 3001018 1.0
Y 90829839 1.0
Y 90829899 1.0
Y 90829918 0.0

2. Run ```` to create the input data for DeepCpG:

.. code:: bash
--cpg_profiles ./cpg/cell1.tsv ./cpg/cell2.tsv ./cpg/cell3.tsv
--dna_files ./dna/mm10
--cpg_wlen 50
--dna_wlen 1001
--out_dir ./data

``./cpg/cell[123].tsv`` store the methylation data from step 1., ``./dna`` contains the DNA database, e.g. `mm10 <>`_ for mouse or `hg38 <>`_ for human, and output data files will be stored in ``./data``.

3. Fine-tune a pre-trained model or train your own model from scratch with ````:

.. code:: bash
--val_data ./data/c{13,14,15,16,17,18,19}_*.h5
--dna_model CnnL2h128
--cpg_model RnnL1
--joint_model JointL2h512
--nb_epoch 30
--out_dir ./model

This command uses chromosomes 1-3 for training and 10-13 for validation. ``---dna_model``, ``--cpg_model``, and ``--joint_model`` specify the architecture of the CpG, DNA, and Joint model, respectively (see manuscript for details). Training will stop after at most 30 epochs and model files will be stored in ``./model``.

4. Use ```` to impute methylation profiles and evaluate model performances.

.. code:: bash
--model_files ./model/model.json ./model/model_weights_val.h5
--out_data ./eval/data.h5
--out_report ./eval/report.tsv

This command predicts missing methylation states on all chromosomes and evaluates prediction performances using known methylation states. Predicted states will be stored in ``./eval/data.h5`` and performance metrics in ``./eval/report.tsv``.

5. Export imputed methylation profiles to HDF5 or bedGraph files:

.. code:: bash
-o ./eval/hdf
-f hdf


You can find example notebooks and scripts on how to use DeepCpG in `/examples <examples/>`_. R scripts and Rmarkdown files for downstream analyses are stored in `/R <R/>`_.


The `DeepCpG documentation <>`_ provides information on training, hyper-parameter selection, and model architectures.

Model Zoo

You can download pre-trained models from the `DeepCpG model zoo <docs/source/>`_.


**Why am I getting warnings 'No CpG site at position X!' when using ``?**
This means that some sites in ``--cpg_profile`` files are not CpG sites, i.e. there is no CG dinucleotide at the given position in the DNA sequence. Make sure that ``--dna_files`` point to the correct genome and CpG sites are correctly aligned. Since DeepCpG currently does not support allele-specific methylation, data from different alleles must be merged (recommended) or only one allele be used.

**How can I train models on one or more GPUs?**
DeepCpG use the `Keras <>`_ deep learning library, which supports `Theano <>`_ or `Tensorflow <>`_ as backend. If you are using Tensorflow, DeepCpG will automatically run on all available GPUs. If you are using Theano, you have to set the flag `device=GPU` in the `THEANO_FLAGS` environment variable.

.. code:: bash


You can find more information about Keras backends `here <>`_, and about parallelization `here <>`_.

* ``/deepcpg/``: Source code
* ``/docs``: Documentation
* ``/examples/``: Examples on how to use DeepCpG
* ``/R``: R scripts and Rmarkdown files for downstream analyses
* ``/script/``: Executable DeepCpG scripts
* ``/tests``: Test files


* Add support for Keras >=2.2.0.

* Add support for Keras 2.1.4 and Tensorflow 1.5.0
* Minor bug-fixes.

Uses Keras 2 as main Keras version.

Adds evaluation scripts and notebooks, improves documentation, and fixes minor bugs.
+ Adds ` <>`_ and R markdown files for computing and visualizing performance metrics genome-wide and in annotated contexts.
+ Adds ` <>`_ for computing mutation effects.
+ Adds notebooks on computing mutation effects and predicting inter-cell statistics.
+ Adds documentation of `DeepCpG scripts <>`_.
+ Adds integration tests.
+ Includes minor bug-fixes.

Extends ````, updates documentation, and fixes minor bugs.
+ Extends ```` to support bedGraph and TSV input files.
+ Enables training on continuous methylation states.
+ Adds `documentation <>`_ about creating and analyzing Data.
+ Updates documentation of `scripts <>`_ and `library <>`_.

* Christof Angermueller
* `@cangermueller <>`_

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

deepcpg-1.0.7.tar.gz (81.2 kB view hashes)

Uploaded Source

Built Distribution

deepcpg-1.0.7-py3-none-any.whl (81.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page