• Stars
    star
    491
  • Rank 89,636 (Top 2 %)
  • Language
    Python
  • License
    MIT License
  • Created about 8 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

๐Ÿ‘๏ธ Python library to plot DNA sequence features (e.g. from Genbank files)

DNA Features Viewer

DNA Features Viewer Logo

Travis CI build status https://coveralls.io/repos/github/Edinburgh-Genome-Foundry/DnaFeaturesViewer/badge.svg?branch=master

DNA Features Viewer (full documentation here) is a Python library to visualize DNA features, e.g. from GenBank or GFF files, or Biopython SeqRecords:

DNA Features Viewer automatically produce simple and clear plots even for sequences with many overlapping features and long labels. The libray plays well with Matplotlib and Biopython, and the plots can be output to many different formats (PNG, JPEG, SVG, PDF), e.g. for report generation, article figures, or LIMS interfaces.

Installation

If you have PIP installed, just type in a terminal:

pip install dna_features_viewer

DNA Features Viewer can be installed by unzipping the source code in one directory and using this command:

python setup.py install

If you intend to use the bokeh features, you need to also install Bokeh and Pandas:

pip install bokeh pandas

To parse GFF files, install the bcbio-gff library:

pip install bcbio-gff

Examples of use

Basic plots

In this first example we define features "by hand":

from dna_features_viewer import GraphicFeature, GraphicRecord
features=[
    GraphicFeature(start=0, end=20, strand=+1, color="#ffd700",
                   label="Small feature"),
    GraphicFeature(start=20, end=500, strand=+1, color="#ffcccc",
                   label="Gene 1 with a very long name"),
    GraphicFeature(start=400, end=700, strand=-1, color="#cffccc",
                   label="Gene 2"),
    GraphicFeature(start=600, end=900, strand=+1, color="#ccccff",
                   label="Gene 3")
]
record = GraphicRecord(sequence_length=1000, features=features)
record.plot(figure_width=5)

If we replace GraphicRecord by CircularGraphicRecord in the code above we obtain a circular plot of the construct:

It is also possible to generate interactive (browser-based) plots by using plot_with_bokeh instead of plot:

Nucleotide sequences, translations, and cropping

DNA Features Viewer allows to plot nucleotide or amino acid sequences under the record plot:

from dna_features_viewer import GraphicFeature, GraphicRecord

sequence = "ATGCATGCATGCATGCATGCATGCATGC"
record = GraphicRecord(sequence=sequence, features=[
    GraphicFeature(start=5, end=10, strand=+1, color='#ffcccc'),
    GraphicFeature(start=8, end=15, strand=+1, color='#ccccff')
])

ax, _ = record.plot(figure_width=5)
record.plot_sequence(ax)
record.plot_translation(ax, (8, 23), fontdict={'weight': 'bold'})
ax.figure.savefig('sequence_and_translation.png', bbox_inches='tight')

This enables for instance to plot an overview of a sequence along with a detailed detail of a sequence subsegment (full code)

...
record.plot(ax=ax1)
cropped_record = record.crop((zoom_start, zoom_end))
cropped_record.plot(ax=ax2)
cropped_record.plot_sequence(ax=ax2)
cropped_record.plot_translation(ax=ax2, location=(408, 423))

Reading the features from a GenBank or GFF file

DnaFeaturesViewer plays nice with BioPython. As a result it is super easy to plot the content of a Biopython record, or directly a GenBank (or GFF) file:

from dna_features_viewer import BiopythonTranslator
graphic_record = BiopythonTranslator().translate_record("my_sequence.gb")
ax, _ = graphic_record.plot(figure_width=10, strand_in_label_threshold=7)

Note 1: the script uses strand_in_label_threshold=7 to indicate the strand with an arrow in the annotation text for every feature less than ~7 pixels in width.

Note 2: the BiopythonTranslator class determines how the genbank information is transformed into graphical features. It enables to chose which categories of features to plot, the color of the different features.

Note 3: parsing GFF files requires the BCBio library (pip install bcbio-gff). This library also enables to extract Biopython records from GFF files containing several records (using GFF.parse("records.gff")).

Displaying the features along with other plots

As it uses Matplotlib, DNA Features Viewer can display the features on top of other sequences statistics, such as the local GC content:

import matplotlib.pyplot as plt
from dna_features_viewer import BiopythonTranslator
from Bio import SeqIO
import numpy as np

fig, (ax1, ax2) = plt.subplots(
    2, 1, figsize=(12, 3), sharex=True, gridspec_kw={"height_ratios": [4, 1]}
)

# PLOT THE RECORD MAP
record = SeqIO.read("example_sequence.gb", "genbank")
graphic_record = BiopythonTranslator().translate_record(record)
graphic_record.plot(ax=ax1, with_ruler=False, strand_in_label_threshold=4)

# PLOT THE LOCAL GC CONTENT (we use 50bp windows)
gc = lambda s: 100.0 * len([c for c in s if c in "GC"]) / 50
xx = np.arange(len(record.seq) - 50)
yy = [gc(record.seq[x : x + 50]) for x in xx]
ax2.fill_between(xx + 25, yy, alpha=0.3)
ax2.set_ylim(bottom=0)
ax2.set_ylabel("GC(%)")

Multi-line and multi-page plots

Since v3.0 it is possible to plot a sequence over multiple lines (using record.plot_on_multiple_lines()) or even on multiple pages (of a PDF):

graphic_record.plot_on_multiple_pages(
    "multipage_plot.pdf",
    nucl_per_line=70,
    lines_per_page=7,
    plot_sequence=True
)

DNA Features Viewer Logo

Custom Biopython translators

DNA Features Viewer allows to define "themes" by using custom record translators instead of the default BiopythonTranslator. Here is an example:

from dna_features_viewer import BiopythonTranslator

class MyCustomTranslator(BiopythonTranslator):
    """Custom translator implementing the following theme:

    - Color terminators in green, CDS in blue, all other features in gold.
    - Do not display features that are restriction sites unless they are BamHI
    - Do not display labels for restriction sites
    - For CDS labels just write "CDS here" instead of the name of the gene.

    """

    def compute_feature_color(self, feature):
        if feature.type == "CDS":
            return "blue"
        elif feature.type == "terminator":
            return "green"
        else:
            return "gold"

    def compute_feature_label(self, feature):
        if feature.type == 'restriction_site':
            return None
        elif feature.type == "CDS":
            return "CDS here"
        else:
            return BiopythonTranslator.compute_feature_label(self, feature)

    def compute_filtered_features(self, features):
        """Do not display promoters. Just because."""
        return [
            feature for feature in features
            if (feature.type != "restriction_site")
            or ("BamHI" in str(feature.qualifiers.get("label", '')))
        ]


graphic_record = MyCustomTranslator().translate_record("example_sequence.gb")
ax, _ = graphic_record.plot(figure_width=10)
ax.figure.tight_layout()
ax.figure.savefig("custom_bopython_translator.png")
https://raw.githubusercontent.com/Edinburgh-Genome-Foundry/DnaFeaturesViewer/master/examples/custom_biopython_translator.png

Examples in other packages:

DNA Chisel

This GIF uses DNA Features Viewer to plot the progress in the optimization of a DNA sequence with DNA Chisel. It also uses Proglog to automatically generate a picture at different time points. See the not-so-great python code for this example on Gist.

DNA Chisel algorithm

GeneBlocks

GeneBlocks is a Python library which computes "diffs" of constructs two sequences, indicating all the changes (additions, deletions, mutations). It uses DNA Features Viewer to display these changesx along with the other sequence's features.

DNA Chisel algorithm

License = MIT

DNA Features Viewer is an open-source software originally written at the Edinburgh Genome Foundry by Zulko and released on Github under the MIT licence. Everyone is welcome to contribute !

More biology software

https://raw.githubusercontent.com/Edinburgh-Genome-Foundry/Edinburgh-Genome-Foundry.github.io/master/static/imgs/logos/egf-codon-horizontal.png

DNA Features Viewer is part of the EGF Codons synthetic biology software suite for DNA design, manufacturing and validation.

More Repositories

1

pdf_reports

๐Ÿ“• Python library and CSS theme to generate PDF reports from HTML/Pug
Python
190
star
2

DnaChisel

โœ๏ธ A versatile DNA sequence optimizer
Python
176
star
3

Flametree

๐Ÿ”ฅ Python file and zip operations made easy
Python
147
star
4

Taskpacker

๐ŸŽ’ Simple schedule optimization library for Python
Python
135
star
5

blabel

๐Ÿท๏ธ Python label/sticker PDF generation. HTML templates, built-in barcodes, qr codes, and other goodies
Python
135
star
6

Proglog

๐Ÿ“ Logs and progress bars manager for Python
Python
93
star
7

lala

๐ŸŒŽ Analyze and generate reports of web logs (NGINX)
Python
60
star
8

DnaCauldron

โš—๏ธ Simple cloning simulator (Golden Gate etc.) for single and combinatorial assemblies
Python
44
star
9

sequenticon

๐Ÿ‘พ Generate identicons for DNA sequences with Python
Python
36
star
10

Plateo

๐Ÿค– Python biolab automation library: parsers, reports generators, picklists simulators, and more
Python
35
star
11

Primavera

๐ŸŒธ Python library for primer-based verification of DNA assemblies: primer selection, data analyis, etc.
Python
32
star
12

codon-usage-tables

๐Ÿ“Š Codon usage tables in code-friendly format + Python bindings
Python
31
star
13

Geneblocks

๐Ÿ’  Find common blocks and differences between DNA sequences
Python
28
star
14

crazydoc

Read DNA sequences from colourful Microsoft Word documents
Python
24
star
15

DnaWeaver

A route planner for DNA assembly
Python
22
star
16

Caravagene

๐ŸŽจ Python library to plot multi-part genetic constructs
Python
21
star
17

genome_collector

๐ŸŒ  Easily download genomes and build BLAST/Bowtie indexes in Python
Python
20
star
18

CAB

๐Ÿš– The friendly Computational App Boilerplate. Django + Vue.JS + Redis queues + NginX
Vue
20
star
19

CUBA

๐Ÿ–๏ธ The EGF Collection of Useful Bio Apps - Web demos of EGF software
Vue
19
star
20

BandWagon

๐ŸŽบ Plot DNA digestion band patterns with Python
Python
17
star
21

BandWitch

๐Ÿ’ซ Computer-aided DNA assembly validation and identification from restriction digests.
Python
15
star
22

SBOL-Visual-CSS

โžฐ Draw genetic elements with HTML & CSS
HTML
15
star
23

genedom

Batch domestication of genetic parts with Python
Python
13
star
24

Sequeduct

Sequencing analysis pipeline
Nextflow
12
star
25

bioprinter

๐Ÿ–จ๏ธ Print pictures with living micro-organisms !
Python
12
star
26

Minotaor

An amino acid sequence annotator
Python
11
star
27

tatapov

๐Ÿพ DNA overhang misannealing data for Python
Python
9
star
28

GoldenHinges

๐Ÿ”— Short overhangs design for DNA assembly
Python
9
star
29

zymp

โœ‚๏ธ Design compact restriction sites arrays (python utility)
Python
8
star
30

kappagate

๐Ÿ”ฎ Predict DNA assembly clone validity rates - powered by Kappa
Python
8
star
31

dab

๐Ÿ‘‰ EGF Design and Build, the Foundry's DNA design ordering portal
Vue
8
star
32

egf-shared-documents

๐Ÿ“š Shared slideshows, courses, etc. from the EGF
HTML
7
star
33

easy_dna

๐ŸŽ’ Python library to read, write, edit DNA sequences
Python
6
star
34

icebreaker

โ„๏ธ Python API for the JBEI-ICE sample manager
Python
6
star
35

Examples

Collection of Python modules and Jupyter notebook examples
HTML
5
star
36

topkappy

๐ŸŒ” Pythonic bindings for the Kappa model simulation language
Python
5
star
37

crecombio

A simple Cre, Flp and other site-specific recombination simulator
Python
4
star
38

HowTo

๐Ÿ“’ Short opinionated recipes, mostly for us.
Python
4
star
39

genedeals

Data on different commercial offers for gene-sized DNA
4
star
40

igem-registry-downloader

Download the full iGEM database of parts
Python
3
star
41

saboteurs

๐Ÿ’ฃ Identify elements impairing success accross group experiments.
Python
3
star
42

Ediacara

Python package for interpreting sequencing data of assembled DNA constructs (plasmids)
Python
3
star
43

DnaWeaver-online

A web app for DNA Weaver
Vue
2
star
44

trellab

Thin layer on top of pytrello for automating Trello organization-based tasks
Python
2
star
45

Polymera

Polymera is a Python package for representing ambiguous sequences written with complement alphabets.
Python
2
star
46

OT2Metclo

MSc project
Python
2
star
47

GeneAlloy

Python
2
star
48

Edinburgh-Genome-Foundry.github.io

๐Ÿ“š The EGF Software Website
HTML
1
star
49

tatapov_data

Data for the EGF Tatapov package
1
star
50

egf-codons-website

๐Ÿ“š Sources of the EGF Codons website, written with Vue.js
Vue
1
star
51

Overhang

Compendium of overhangs
Python
1
star
52

Plasmid_assessor

Plasmid assessment for Golden Gate cloning
Python
1
star
53

ImagesAnnotator

Simple web app to annotate images by hand - built with Vue.js
JavaScript
1
star
54

EGF_Docker_Jupyter

Docker Jupyter images with (almost) all EGF packages
Dockerfile
1
star