Skip to main content

Common RNA-seq normalization methods

Project description

Build Status Code Style Black Documentation Status Version on PyPI Supported Python versions Number of downloads from PyPI

Python implementation of common RNA-seq normalization methods:

  • CPM (Counts per million)

  • FPKM (Fragments per kilobase million)

  • TPM (Transcripts per million)

  • UQ (Upper quartile)

  • CUF (Counts adjusted with UQ factors)

  • TMM (Trimmed mean of M-values)

  • CTF (Counts adjusted with TMM factors)

For in-depth description of methods see documentation.

Features

  • Pure Python implementation (no need for R, etc.)

  • Compatible with Scikit-learn

  • Command line interface

  • Verbose documentation

  • Validated method implementation

Install

We recommend installing RNAnorm with pip:

pip install rnanorm

Quick start

The implemented methods can be executed from Python or from the command line.

Normalize from Python

The most common use case is to run normalization from Python:

>>> from rnanorm.datasets import load_toy_data
>>> from rnanorm import FPKM
>>> dataset = load_toy_data()
>>> # Expressions need to have genes in columns and samples in rows
>>> dataset.exp
          Gene_1  Gene_2  Gene_3  Gene_4  Gene_5
Sample_1     200     300     500    2000    7000
Sample_2     400     600    1000    4000   14000
Sample_3     200     300     500    2000   17000
Sample_4     200     300     500    2000    2000
>>> fpkm = FPKM(dataset.gtf_path).set_output(transform="pandas")
>>> fpkm.fit_transform(dataset.exp)
             Gene_1    Gene_2    Gene_3    Gene_4    Gene_5
Sample_1   100000.0  100000.0  100000.0  200000.0  700000.0
Sample_2   100000.0  100000.0  100000.0  200000.0  700000.0
Sample_3    50000.0   50000.0   50000.0  100000.0  850000.0
Sample_4   200000.0  200000.0  200000.0  400000.0  400000.0

Normalize from command line

Normalization from the command line is also supported. To list available methods and general help:

rnanorm --help

Get info about a particular method, e.g., CPM:

rnanorm cpm --help

To normalize with CPM:

rnanorm cpm exp.csv --out exp_cpm.csv

File exp.csv needs to be comma separated file with genes in columns and samples in rows. Values should be raw counts. The output is saved to exp_cpm.csv. Example of input file:

cat exp.csv
,Gene_1,Gene_2,Gene_3,Gene_4,Gene_5
Sample_1,200,300,500,2000,7000
Sample_2,400,600,1000,4000,14000
Sample_3,200,300,500,2000,17000
Sample_4,200,300,500,2000,2000

One can also provide input through standard input:

cat exp.csv | rnanorm cpm --out exp_cpm.csv

If file specified with --out already exists the command will fail. If you are sure that you wish to overwrite, use --force flag:

cat exp.csv | rnanorm cpm --force --out exp_cpm.csv

If no file is specified with --out parameter, output is printed to standard output:

cat exp.csv | rnanorm cpm > exp_cpm.csv

Methods TPM and FPKM require gene lengths. These can be provided either with GTF file or with “gene lengths” file. The later is a two columns file. The first column should include the genes in the header of exp.csv and the second column should contain gene lengths computed by union exon model:

# Use GTF file
rnanorm tpm exp.csv --gtf annotations.gtf > exp_out.csv
# Use gene lengths file
rnanorm tpm exp.csv --gene-lengths lenghts.csv > exp_out.csv

Contribute

To learn about contributing to the code base, read the Contributing section.

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

rnanorm-2.0.0.tar.gz (131.1 kB view details)

Uploaded Source

Built Distribution

rnanorm-2.0.0-py3-none-any.whl (120.2 kB view details)

Uploaded Python 3

File details

Details for the file rnanorm-2.0.0.tar.gz.

File metadata

  • Download URL: rnanorm-2.0.0.tar.gz
  • Upload date:
  • Size: 131.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.17

File hashes

Hashes for rnanorm-2.0.0.tar.gz
Algorithm Hash digest
SHA256 32fd2bdb64328011fdf30c2a2403a52c2a377352b0bff8b4c67833224bd7dffc
MD5 ba7de1a2c2ea46817164c933a874fce2
BLAKE2b-256 ae11536cfacc7de07303e8db5e2239fad7a0b08c31ab545ab6acafcab652d358

See more details on using hashes here.

File details

Details for the file rnanorm-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: rnanorm-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 120.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.17

File hashes

Hashes for rnanorm-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 30ab4f96e5357d1d93d63f646930f95315ef196f669fd3155693e756370dc787
MD5 aacb4c3fdf01457990e840380e975f5e
BLAKE2b-256 ae3d6b2a0a6b2e8c8763567aefe0bb49fa19b40d1ff604314f0eba170283d2ef

See more details on using hashes here.

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