chiron

A basecaller for Oxford Nanopore Technologies' sequencers

https://github.com/haotianteng/chiron

Science Score: 23.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
  • .zenodo.json file
  • DOI references
    Found 2 DOI reference(s) in README
  • Academic publication links
  • Committers with academic emails
    1 of 13 committers (7.7%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (12.3%) to scientific vocabulary
Last synced: 11 months ago · JSON representation

Repository

A basecaller for Oxford Nanopore Technologies' sequencers

Basic Info
  • Host: GitHub
  • Owner: haotianteng
  • License: other
  • Language: Python
  • Default Branch: master
  • Homepage:
  • Size: 210 MB
Statistics
  • Stars: 121
  • Watchers: 12
  • Forks: 53
  • Open Issues: 9
  • Releases: 10
Created about 9 years ago · Last pushed about 3 years ago
Metadata Files
Readme License

README.md

License: MPL 2.0 PyPI Downloads Downloads-Month Downloads-Week

Chiron

A basecaller for Oxford Nanopore Technologies' sequencers

Using a deep learning CNN+RNN+CTC structure to establish end-to-end basecalling for the nanopore sequencer.
Built with TensorFlow and python 2.7.

If you found Chiron useful, please consider to cite:

Haotian Teng, Minh Duc Cao, Michael B Hall, Tania Duarte, Sheng Wang, Lachlan J M Coin; Chiron: translating nanopore raw signal directly into nucleotide sequence using deep learning, GigaScience, Volume 7, Issue 5, 1 May 2018, giy037, https://doi.org/10.1093/gigascience/giy037

DNA basecall: python chiron/entry.py call -i <input_fast5_folder> -o <output_folder> -m chiron/model/DNA_default -p dna-pre RNA basecall: python chiron/entry.py call -i <input_fast5_folder> -o <output_folder> -m chiron/model/RNA_default -p rna-pre --mode rna


Table of contents

If you would like to do this, the best options would be virtualenv, the more user-friendly virtualenvwrapper, or through anaconda. After installing one of these and activating the virtual environment you will be installing Chiron into, continue with the rest of the installation instructions as normal.

To install with pip:

pip install chiron This will install Chiron, and h5py (required for reading in .fast5 files). Tensorflow need to be install in addition by: pip install tensorflow==1.15
or GPU version:
pip install tensorflow-gpu==1.15

Install from Source

git clone https://github.com/haotianteng/chiron.git cd Chiron You will also need to install dependencies. python setup.py install For CPU-version: pip install tensorflow==1.15 For GPU-version(Nvidia GPU required):
Install CUDA
Install cuDNN
Install tensorflow gpu version
pip install tensorflow-gpu==1.15 And then add the Chiron into PYTHONPATH,for convinience you can add it to the .bashrc export PYTHONPATH=[Path to Chiron/Chiron]:$PYTHONPATH For alternate/detailed installation instructions for TensorFlow, see the documentation.

Basecall

If installed from pip:

An example call to Chiron to run basecalling is:
``` chiron call -i -o -m

```

If installed from Github:

All Chiron functionality can be run from entry.py in the Chiron folder. (You might like to also add the path to Chiron into your PATH for ease of running).

``` python chiron/entry.py call -i -o -m

```

Test run

We provide 5 sample fast5 files for DNA(courtesy of nanonet) and 5 sample files for RNA in the GitHub repository and two models (DNAdefault and RNAdefault) which you can run a test on. These are located in chiron/example_data/. From inside the Chiron repository: python chiron/entry.py call -i chiron/example_folder/ -o <output_folder> -m chiron/model/DNA_default --preset dna-pre And from v0.5 we have provide a good RNA model for the direct-RNA basecall.
python chiron/entry.py call -i <input_fast5_folder> -o <output_folder> -m chiron/model/RNA_default --mode rna --preset rna-pre You can reduce the batch size(defualt is 400) if you have limited RAM/GPU-RAM or extend it, bigger batch size has (very)slightly better result and faster inference speed.
python chiron/entry.py call -i <input_fast5_folder> -o <output_folder> -m chiron/model/RNA_default --mode rna --preset rna-pre -b 200 Any arguments provided afterward will override the argument in the preset, preset arguments values are:
DNA preset arguments value(dna-pre): 'start':0,'batchsize':400,'segmentlen':400,'jump':390,'threads':0,'beam':30
RNA preset arguments value(rna-pre): 'start':0,'batchsize':300,'segmentlen':2000,'jump':1900,'threads':0,'beam':30

Preprocess

For better RNA basecalling result, the fast5 files can be preproceesd using BoostNano, which is a tool developed by me to segment and remove the polyA and adapter tail.

Decoder choice

(From v0.3)
Beam search decoder: chiron call -i -o --beam
Greedy decoder: chiron call -i -o --beam 0

Beam Seach decoder give a higher accuracy, and larger beam width can furthur improve the accuracy. Greedy decoder give a faster decoding speed than the beam search decoder:

| Device | Greedy decoder rate(bp/s) | Beam Search decoder rate(bp/s), beam_width=50 |
| --- | --- | --- |
| CPU | 21 | 17 |
| GPU | 1652 | 1204 |

Output

chiron call will create five folders in <output_folder> called raw, result, segments, meta, and reference.

  • result: fastq/fasta files with the same name as the fast5 file they contain the basecalling result for. To create a single, merged version of these fasta files, try something like paste --delimiter=\\n --serial result/*.fasta > merged.fasta
  • raw: Contains a file for each fast5 file with it's raw signal. This file format is an list of integers. i.e 544 554 556 571 563 472 467 487 482 513 517 521 495 504 500 520 492 506 ...
  • segments: Contains the segments basecalled from each fast5 file.
  • meta: Contains the meta information for each read (read length, basecalling rate etc.). Each file has the same name as it's fast5 file.
  • reference: Contains the reference sequence (if any).

Output format

With -e flag to output fastq file(default) with quality score or fasta file.
Example:
chiron call -i -o -e fastq

chiron call -i -o -e fasta

Training

The default DNA model trained on R9.4 protocol with a mix of Lambda and E.coli dataset, and the default RNA model is trained on R9.4 direct RNA kit (-200mV configuration). If the basecalling result is not satisfying, you can train a model on your own training data set.

Hardware request:

Recommend training on GPU with TensorFlow - usually 8GB RAM (GPU) is required.

Prepare training data set.

Using raw.py script to extract the signal and label from the re-squiggled fast5 file. (For how to re-squiggle fast5 file, check Tombo re-squiggle)

If installed from pip:

chiron export -i <fast5 folder> -o <output_folder>

or directly use the raw.py script in utils.

python chiron/utils/raw.py --input <fast5 folder> --output <output_folder> --mode dna

This will generate a tfrecord file for training when using the chironrcnntrain.py and chiron_input.py pipeline.

python chiron/utils/file_batch.py --input <fast5 folder> --output <output folder> --length 400 --mode dna

This will generate several binary .bin file for training when using the chirontrain.py and chironqueue_input.py pipeline.

Train a model

source activate tensorflow

If installed from pip:

chiron train --data_dir <signal_label folder> --log_dir <model_log_folder> --model_name <saved_model_name>

or run directly by

python chiron/chiron_rcnn_train.py --data_dir <signal_label folder/ tfrecord file> --log_dir <model_log>

Training parameters

Following parameters can be passed to Chiron when training

data_dir(Required): The folder containing your signal and label files.
log_dir(Required): The folder where you want to save the model.
model_name(Required): The name of the model. The record will be stored in the directory log_dir/model_name/ tfrecord: File name of tfrecord. Default is train.tfrecords. sequence_len: The length of the segment you want to separate the sequence into. Longer length requires larger RAM.
batch_size: The batch size.
step_rate: Learning rate of the optimizer.
max_step: Maximum step of the optimizer.
k_mer: Chiron supports learning based on k-mer instead of a single nucleotide, this should be an odd number, even numbers will cause an error.
retrain: If this is a new model, or you want to load the model you trained before. The model will be loaded from log_dir/model_name/

Train on Google Cloud ML engine

local testing

Before training the model on cloud ml engine, please check if it is working on local machine or not by following commands

``` gcloud ml-engine local train \ --module-name chiron.utils.raw \ --package-path chiron.utils/ \ -- --input inputfast5folder \ --output output

gcloud ml-engine local train \ --module-name chiron.chironrcnntrain \ --package-path chiron/ ```

If it is working well, please go to next step.

create a new bucket

BUCKET_NAME=chiron-ml REGION=us-central1 gsutil mb -l $REGION gs://$BUCKET_NAME

Use gsutil to copy the fast5 files to your Cloud Storage bucket

gsutil cp -r raw_fast_folder gs://$BUCKET_NAME/fast5-data

Train model on google cloud ML engine

JOB_NAME=chiron_single_1 OUTPUT_PATH=gs://$BUCKET_NAME/$JOB_NAME INPUT_PATH=gs://$BUCKET_NAME/train_tfdata gcloud ml-engine jobs submit training $JOB_NAME \ --staging-bucket gs://chiron-ml \ --module-name chiron.chiron_rcnn_train \ --package-path chiron/ \ --region $REGION \ --config config.yaml \ -- \ --data_dir gs://$BUCKET_NAME/train_tfdata \ --cache_dir gs://$BUCKET_NAME/cache/train.hdf5 \ --log_dir gs://$BUCKET_NAME/GVM_model

Distributed training on Google Cloud ML Engine

Configure

Change configure.yaml according to GCloud Docs For example the following configuremultigpu.yaml:

trainingInput: scaleTier: CUSTOM masterType: standard_p100 workerType: standard_p100 parameterServerType: large_model workerCount: 3 parameterServerCount: 3

Will enable 3 workers + 1 master worker with one P-100 GPU in each worker.

Transfer fast5 files

FAST5_FOLDER=/my/fast5/ OTUPUT_FOLDER=/my/file_batch/ SEGMENT_LEN=512

Transfer fast5 to file batch python utils/file_batch.py --input $FAST5_FOLDER --output $OUTPUT_FOLDER --length $SEGMENT_LEN Copy to Google Cloud gsutil cp -r $OUTPUT_FOLDER gs://$BUCKET_NAME/file_batch

Submit training request

JOB_NAME=chiron_multi_4 DATA_BUCKET=chiron-training-data MODEL_BUCKET=chiron-model REGION=us-central1 MODEL_NAME=test_model1 GPU_NUM=4 gcloud ml-engine jobs submit training ${JOB_NAME} \ --runtime-version 1.6 \ --staging-bucket gs://chiron-model/ \ --module-name chiron.chiron_multi_gpu_train \ --package-path chiron \ --region $REGION \ --config config_multi_gpu.yaml \ -- \ -i gs://$DATA_BUCKET/file_batch \ -o gs://$MODEL_BUCKET/ \ -m ${MODEL_NAME} \ -n ${GPU_NUM}

Owner

  • Name: Haotian Teng
  • Login: haotianteng
  • Kind: user
  • Location: Pittsburgh, PA
  • Company: Carnegie Mellon University

Haotian Teng Fields of interest: Machine learning algorithm, biological neural network, computational biology

GitHub Events

Total
  • Issues event: 1
  • Watch event: 1
  • Issue comment event: 1
Last Year
  • Issues event: 1
  • Watch event: 1
  • Issue comment event: 1

Committers

Last synced: over 2 years ago

All Time
  • Total Commits: 401
  • Total Committers: 13
  • Avg Commits per committer: 30.846
  • Development Distribution Score (DDS): 0.207
Past Year
  • Commits: 4
  • Committers: 1
  • Avg Commits per committer: 4.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Haotian Teng h****g@g****m 318
mbhall88 m****8@g****m 29
Neven Miculinic n****c@g****m 21
Allen Day a****y@a****m 10
h****g@H****n 7
leeyamkeng l****0@g****m 5
Haotian Teng h****2@1****m 3
Puneith Kaul p****h@g****m 2
Haotian Teng h****g@i****u 2
Jeroen Van Goey j****y@g****m 1
etheleon p****k@g****m 1
Haotian Teng h****n@l****n 1
Puneith Kaul p****h 1

Issues and Pull Requests

Last synced: 11 months ago

All Time
  • Total issues: 76
  • Total pull requests: 28
  • Average time to close issues: about 1 month
  • Average time to close pull requests: about 1 month
  • Total issue authors: 43
  • Total pull request authors: 10
  • Average comments per issue: 2.96
  • Average comments per pull request: 0.61
  • Merged pull requests: 9
  • Bot issues: 0
  • Bot pull requests: 12
Past Year
  • Issues: 1
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 1
  • Pull request authors: 0
  • Average comments per issue: 1.0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • huangnengCSU (7)
  • ardakdemir (6)
  • mbhall88 (5)
  • qianlou (5)
  • pcjedi (4)
  • paru16 (3)
  • lab-rat-kid (3)
  • nmiculinic (3)
  • emdyess (2)
  • qhli1 (2)
  • nbathreya (2)
  • rbutleriii (2)
  • tarunaaggarwal (2)
  • varma-k (1)
  • AEDWIP (1)
Pull Request Authors
  • dependabot[bot] (12)
  • nmiculinic (6)
  • haotianteng (3)
  • pcjedi (1)
  • mbhall88 (1)
  • Albbi (1)
  • lpryszcz (1)
  • cangfengzhe (1)
  • BioGeek (1)
  • ccoulombe (1)
Top Labels
Issue Labels
enhancement (5) bug (4) question (1)
Pull Request Labels
dependencies (12)

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 104 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 0
  • Total versions: 14
  • Total maintainers: 1
pypi.org: chiron

A deep neural network basecaller for nanopore sequencing.

  • Versions: 14
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 104 Last month
Rankings
Forks count: 5.7%
Stargazers count: 6.5%
Dependent packages count: 10.0%
Average: 24.2%
Downloads: 31.5%
Dependent repos count: 67.4%
Maintainers (1)
Last synced: 11 months ago

Dependencies

requirements.txt pypi
  • Markdown ==2.6.11
  • absl-py ==0.7.1
  • astor ==0.7.1
  • bleach ==3.3.0
  • gast ==0.2.0
  • grpcio ==1.11.0
  • h5py ==2.7.1
  • html5lib ==0.9999999
  • numpy ==1.14.2
  • pandas ==0.22.0
  • patsy ==0.5.0
  • protobuf ==3.5.2.post1
  • python-dateutil ==2.7.2
  • pytz ==2018.4
  • scipy ==1.0.1
  • six ==1.11.0
  • statsmodels ==0.8.0
  • termcolor ==1.1.0
  • tqdm ==4.23.0
setup.py pypi
  • biopython >=1.73
  • h5py >=2.7.0
  • mappy >=2.10.0
  • numpy >=1.13.3
  • packaging >=18.0
  • scipy >=1.0.1
  • statsmodels >=0.8.0
  • tqdm >=4.23.0