Skip to main content

Variant annotation in Python

Project description

Tests Coverage Status PyPI PyPI downloads

Varcode

Varcode is a library for working with genomic variant data in Python and predicting the impact of those variants on protein sequences.

Installation

You can install varcode using pip:

pip install varcode

You can install required reference genome data through PyEnsembl as follows:

# Downloads and installs the Ensembl releases (75 and 76)
pyensembl install --release 75 76

Example

import varcode

# Load TCGA MAF containing variants from their
variants = varcode.load_maf("tcga-ovarian-cancer-variants.maf")

print(variants)
### <VariantCollection from 'tcga-ovarian-cancer-variants.maf' with 6428 elements>
###  -- Variant(contig=1, start=69538, ref=G, alt=A, genome=GRCh37)
###  -- Variant(contig=1, start=881892, ref=T, alt=G, genome=GRCh37)
###  -- Variant(contig=1, start=3389714, ref=G, alt=A, genome=GRCh37)
###  -- Variant(contig=1, start=3624325, ref=G, alt=T, genome=GRCh37)
###  ...

# you can index into a VariantCollection and get back a Variant object
variant = variants[0]

# groupby_gene_name returns a dictionary whose keys are gene names
# and whose values are themselves VariantCollections
gene_groups = variants.groupby_gene_name()

# get variants which affect the TP53 gene
TP53_variants = gene_groups["TP53"]

# predict protein coding effect of every TP53 variant on
# each transcript of the TP53 gene
TP53_effects = TP53_variants.effects()

print(TP53_effects)
### <EffectCollection with 789 elements>
### -- PrematureStop(variant=chr17 g.7574003G>A, transcript_name=TP53-001, transcript_id=ENST00000269305, effect_description=p.R342*)
### -- ThreePrimeUTR(variant=chr17 g.7574003G>A, transcript_name=TP53-005, transcript_id=ENST00000420246)
### -- PrematureStop(variant=chr17 g.7574003G>A, transcript_name=TP53-002, transcript_id=ENST00000445888, effect_description=p.R342*)
### -- FrameShift(variant=chr17 g.7574030_7574030delG, transcript_name=TP53-001, transcript_id=ENST00000269305, effect_description=p.R333fs)
### ...

premature_stop_effect = TP53_effects[0]

print(str(premature_stop_effect.mutant_protein_sequence))
### 'MEEPQSDPSVEPPLSQETFSDLWKLLPENNVLSPLPSQAMDDLMLSPDDIEQWFTEDPGPDEAPRMPEAAPPVAPAPAAPTPAAPAPAPSWPLSSSVPSQKTYQGSYGFRLGFLHSGTAKSVTCTYSPALNKMFCQLAKTCPVQLWVDSTPPPGTRVRAMAIYKQSQHMTEVVRRCPHHERCSDSDGLAPPQHLIRVEGNLRVEYLDDRNTFRHSVVVPYEPPEVGSDCTTIHYNYMCNSSCMGGMNRRPILTIITLEDSSGNLLGRNSFEVRVCACPGRDRRTEEENLRKKGEPHHELPPGSTKRALPNNTSSSPQPKKKPLDGEYFTLQIRGRERFEMF'

print(premature_stop_effect.aa_mutation_start_offset)
### 341

print(premature_stop_effect.transcript)
### Transcript(id=ENST00000269305, name=TP53-001, gene_name=TP53, biotype=protein_coding, location=17:7571720-7590856)

print(premature_stop_effect.gene.name)
### 'TP53'

If you are looking for a quick start guide, you can check out this iPython book that demonstrates simple use cases of Varcode.

Further reading

Feature guides live in docs/:

  • Genotypes and sample-aware queries — per-sample zygosity on multi-sample VCFs (Genotype, Zygosity, VariantCollection.for_sample, .heterozygous_in, .homozygous_alt_in). New in 2.3.
  • CSV round-trip and metadata headersto_csv / from_csv on both collection types, with #-prefixed provenance headers. New in 2.1, refined in 2.2.
  • Error handlingReferenceMismatchError, SampleNotFoundError, and the raise_on_error=False escape hatch.

See CHANGELOG.md for the release history.

Effect Types

Effect type Description
AlternateStartCodon Replace annotated start codon with alternative start codon (e.g. "ATG>CAG").
ComplexSubstitution Insertion and deletion of multiple amino acids.
Deletion Coding mutation which causes deletion of amino acid(s).
ExonLoss Deletion of entire exon, significantly disrupts protein.
ExonicSpliceSite Mutation at the beginning or end of an exon, may affect splicing.
FivePrimeUTR Variant affects 5' untranslated region before start codon.
FrameShiftTruncation A frameshift which leads immediately to a stop codon (no novel amino acids created).
FrameShift Out-of-frame insertion or deletion of nucleotides, causes novel protein sequence and often premature stop codon.
IncompleteTranscript Can't determine effect since transcript annotation is incomplete (often missing either the start or stop codon).
Insertion Coding mutation which causes insertion of amino acid(s).
Intergenic Occurs outside of any annotated gene.
Intragenic Within the annotated boundaries of a gene but not in a region that's transcribed into pre-mRNA.
IntronicSpliceSite Mutation near the beginning or end of an intron but less likely to affect splicing than donor/acceptor mutations.
Intronic Variant occurs between exons and is unlikely to affect splicing.
NoncodingTranscript Transcript doesn't code for a protein.
PrematureStop Insertion of stop codon, truncates protein.
Silent Mutation in coding sequence which does not change the amino acid sequence of the translated protein.
SpliceAcceptor Mutation in the last two nucleotides of an intron, likely to affect splicing.
SpliceDonor Mutation in the first two nucleotides of an intron, likely to affect splicing.
StartLoss Mutation causes loss of start codon, likely result is that an alternate start codon will be used down-stream (possibly in a different frame).
StopLoss Loss of stop codon, causes extension of protein by translation of nucleotides from 3' UTR.
Substitution Coding mutation which causes simple substitution of one amino acid for another.
ThreePrimeUTR Variant affects 3' untranslated region after stop codon of mRNA.

Coordinate System

Varcode currently uses a "base counted, one start" genomic coordinate system, to match the Ensembl annotation database. We are planning to switch over to "space counted, zero start" (interbase) coordinates, since that system allows for more uniform logic (no special cases for insertions). To learn more about genomic coordinate systems, read this blog post.

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

varcode-4.0.6.tar.gz (179.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

varcode-4.0.6-py3-none-any.whl (128.6 kB view details)

Uploaded Python 3

File details

Details for the file varcode-4.0.6.tar.gz.

File metadata

  • Download URL: varcode-4.0.6.tar.gz
  • Upload date:
  • Size: 179.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.6

File hashes

Hashes for varcode-4.0.6.tar.gz
Algorithm Hash digest
SHA256 6eadc02dd8d86215a82cca3462ec27e0920a2a60f44abe8cf501eba1368515b8
MD5 8b7cc3adc9e77b2ce6f9118702db07cf
BLAKE2b-256 f96cc99c369c71d9c0f8ceef074047f36a9e3efc2050aa52f5e339699b2cf1b0

See more details on using hashes here.

File details

Details for the file varcode-4.0.6-py3-none-any.whl.

File metadata

  • Download URL: varcode-4.0.6-py3-none-any.whl
  • Upload date:
  • Size: 128.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.6

File hashes

Hashes for varcode-4.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 94a3c80499705581d7988eea3f0cc668bec1b7d7fcc6cafccf15d7713e4d26db
MD5 914225dde9557d689d2574fc648bcbaa
BLAKE2b-256 551d6c74adb31c013414b5b6889cd29c26d24b96d0f4637e97d3aab88dc9f2c7

See more details on using hashes here.

Supported by

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