{"id":21466720,"url":"https://github.com/edinburgh-genome-foundry/dnafeaturesviewer","last_synced_at":"2025-05-14T14:07:27.530Z","repository":{"id":37664225,"uuid":"68733876","full_name":"Edinburgh-Genome-Foundry/DnaFeaturesViewer","owner":"Edinburgh-Genome-Foundry","description":":eye: Python library to plot DNA sequence features (e.g. from Genbank files)","archived":false,"fork":false,"pushed_at":"2025-05-09T11:50:34.000Z","size":16288,"stargazers_count":625,"open_issues_count":35,"forks_count":96,"subscribers_count":18,"default_branch":"master","last_synced_at":"2025-05-09T12:17:22.616Z","etag":null,"topics":["bioinformatics","dna-visualization","genbank","molecular-biology","synthetic-biology","visualization"],"latest_commit_sha":null,"homepage":"https://edinburgh-genome-foundry.github.io/DnaFeaturesViewer/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Edinburgh-Genome-Foundry.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2016-09-20T16:57:39.000Z","updated_at":"2025-05-09T11:50:05.000Z","dependencies_parsed_at":"2022-08-08T21:15:34.040Z","dependency_job_id":"ac359e63-e162-4de6-b60a-d7d558ba9a95","html_url":"https://github.com/Edinburgh-Genome-Foundry/DnaFeaturesViewer","commit_stats":{"total_commits":163,"total_committers":10,"mean_commits":16.3,"dds":0.2883435582822086,"last_synced_commit":"ca4d739846188520dc43d2f04a9097c4cc84503a"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Edinburgh-Genome-Foundry%2FDnaFeaturesViewer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Edinburgh-Genome-Foundry%2FDnaFeaturesViewer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Edinburgh-Genome-Foundry%2FDnaFeaturesViewer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Edinburgh-Genome-Foundry%2FDnaFeaturesViewer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Edinburgh-Genome-Foundry","download_url":"https://codeload.github.com/Edinburgh-Genome-Foundry/DnaFeaturesViewer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254159935,"owners_count":22024566,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bioinformatics","dna-visualization","genbank","molecular-biology","synthetic-biology","visualization"],"created_at":"2024-11-23T08:15:03.186Z","updated_at":"2025-05-14T14:07:27.509Z","avatar_url":"https://github.com/Edinburgh-Genome-Foundry.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":".. raw:: html\n\n    \u003cp align=\"center\"\u003e\n    \u003cimg alt=\"DNA Features Viewer Logo\" title=\"DNA Features Viewer Logo\" src=\"https://raw.githubusercontent.com/Edinburgh-Genome-Foundry/DnaFeaturesViewer/master/docs/_static/images/title.png\" width=\"350\"\u003e\n    \u003c/p\u003e\n\nDNA Features Viewer\n===================\n\n.. image:: https://github.com/Edinburgh-Genome-Foundry/DnaFeaturesViewer/actions/workflows/build.yml/badge.svg\n    :target: https://github.com/Edinburgh-Genome-Foundry/DnaFeaturesViewer/actions/workflows/build.yml\n    :alt: GitHub CI build status\n\n.. image:: https://coveralls.io/repos/github/Edinburgh-Genome-Foundry/DnaFeaturesViewer/badge.svg?branch=master\n    :target: https://coveralls.io/github/Edinburgh-Genome-Foundry/DnaFeaturesViewer?branch=master\n\n\nDNA Features Viewer (full documentation `here \u003chttps://edinburgh-genome-foundry.github.io/DnaFeaturesViewer/\u003e`_) is a Python library to visualize DNA features, e.g. from GenBank or GFF files, or Biopython SeqRecords:\n\n.. raw:: html\n\n    \u003cp align=\"center\"\u003e\n    \u003cimg src=\"https://raw.githubusercontent.com/Edinburgh-Genome-Foundry/DnaFeaturesViewer/master/examples/graphic_record_defined_by_hand.png\" width=\"500\"\u003e\n    \u003c/p\u003e\n\nDNA 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.\n\nInstallation\n--------------\n\nIf you have PIP installed, just type in a terminal:\n\n.. code:: bash\n\n    pip install dna_features_viewer\n\nDNA Features Viewer can be installed by unzipping the source code in one directory and using this command:\n\n.. code:: bash\n\n    python setup.py install\n\nIf you intend to use the bokeh features, you need to also install Bokeh and Pandas:\n\n.. code:: bash\n\n    pip install bokeh pandas\n\nTo parse GFF files, install the ``bcbio-gff`` library:\n\n.. code:: bash\n\n    pip install bcbio-gff\n\n\nExamples of use\n---------------\n\n\nBasic plots\n~~~~~~~~~~~~\n\nIn this first example we define features \"by hand\":\n\n.. code:: python\n\n    from dna_features_viewer import GraphicFeature, GraphicRecord\n    features=[\n        GraphicFeature(start=0, end=20, strand=+1, color=\"#ffd700\",\n                       label=\"Small feature\"),\n        GraphicFeature(start=20, end=500, strand=+1, color=\"#ffcccc\",\n                       label=\"Gene 1 with a very long name\"),\n        GraphicFeature(start=400, end=700, strand=-1, color=\"#cffccc\",\n                       label=\"Gene 2\"),\n        GraphicFeature(start=600, end=900, strand=+1, color=\"#ccccff\",\n                       label=\"Gene 3\")\n    ]\n    record = GraphicRecord(sequence_length=1000, features=features)\n    record.plot(figure_width=5)\n\n.. raw:: html\n\n    \u003cp align=\"center\"\u003e\n    \u003cimg src=\"https://raw.githubusercontent.com/Edinburgh-Genome-Foundry/DnaFeaturesViewer/master/examples/graphic_record_defined_by_hand.png\" width=\"500\"\u003e\n    \u003c/p\u003e\n\n\nIf we replace `GraphicRecord` by `CircularGraphicRecord` in the code above we obtain\na circular plot of the construct:\n\n.. raw:: html\n\n    \u003cp align=\"center\"\u003e\n    \u003cimg src=\"https://raw.githubusercontent.com/Edinburgh-Genome-Foundry/DnaFeaturesViewer/master/examples/graphic_record_defined_by_hand_circular.png\" width=\"443\"\u003e\n    \u003c/p\u003e\n\nIt is also possible to generate interactive (browser-based) plots by using ``plot_with_bokeh`` instead of ``plot``:\n\n.. raw:: html\n\n    \u003cp align=\"center\"\u003e\n    \u003cimg src=\"https://raw.githubusercontent.com/Edinburgh-Genome-Foundry/DnaFeaturesViewer/master/examples/plot_with_bokeh.png\" width=\"800\"\u003e\n    \u003c/p\u003e\n\nNucleotide sequences, translations, and cropping\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nDNA Features Viewer allows to plot nucleotide or amino acid sequences under\nthe record plot:\n\n.. code:: python\n\n    from dna_features_viewer import GraphicFeature, GraphicRecord\n\n    sequence = \"ATGCATGCATGCATGCATGCATGCATGC\"\n    record = GraphicRecord(sequence=sequence, features=[\n        GraphicFeature(start=5, end=10, strand=+1, color='#ffcccc'),\n        GraphicFeature(start=8, end=15, strand=+1, color='#ccccff')\n    ])\n\n    ax, _ = record.plot(figure_width=5)\n    record.plot_sequence(ax)\n    record.plot_translation(ax, (8, 23), fontdict={'weight': 'bold'})\n    ax.figure.savefig('sequence_and_translation.png', bbox_inches='tight')\n\n.. raw:: html\n\n    \u003cp align=\"center\"\u003e\n    \u003cimg src=\"https://raw.githubusercontent.com/Edinburgh-Genome-Foundry/DnaFeaturesViewer/master/examples/sequence_and_translation.png\" width=\"415\"\u003e\n    \u003c/p\u003e\n\nThis enables for instance to plot an overview of a sequence along with a detailed detail of a sequence subsegment (`full code \u003chttps://github.com/Edinburgh-Genome-Foundry/DnaFeaturesViewer/blob/master/examples/overview_and_detail.py\u003e`_)\n\n.. code:: python\n\n    ...\n    record.plot(ax=ax1)\n    cropped_record = record.crop((zoom_start, zoom_end))\n    cropped_record.plot(ax=ax2)\n    cropped_record.plot_sequence(ax=ax2)\n    cropped_record.plot_translation(ax=ax2, location=(408, 423))\n\n.. raw:: html\n\n    \u003cp align=\"center\"\u003e\n    \u003cimg src=\"https://raw.githubusercontent.com/Edinburgh-Genome-Foundry/DnaFeaturesViewer/master/examples/overview_and_detail.png\" width=\"900\"\u003e\n    \u003c/p\u003e\n\n\nReading the features from a GenBank or GFF file\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nDnaFeaturesViewer 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:\n\n.. code:: python\n\n    from dna_features_viewer import BiopythonTranslator\n    graphic_record = BiopythonTranslator().translate_record(\"my_sequence.gb\")\n    ax, _ = graphic_record.plot(figure_width=10, strand_in_label_threshold=7)\n\n.. raw:: html\n\n    \u003cp align=\"center\"\u003e\n    \u003cimg src=\"https://raw.githubusercontent.com/Edinburgh-Genome-Foundry/DnaFeaturesViewer/master/examples/from_genbank.png\" width=\"900\"\u003e\n    \u003c/p\u003e\n\nNote 1: the script uses ``strand_in_label_threshold=7`` to indicate the strand with\nan arrow in the annotation text for every feature less than ~7 pixels in width.\n\nNote 2: the ``BiopythonTranslator`` class determines how the genbank information is\ntransformed into graphical features. It enables to chose which categories of\nfeatures to plot, the color of the different features.\n\nNote 3: parsing GFF files requires the BCBio library\n(``pip install bcbio-gff``). This library also enables to extract Biopython\nrecords from GFF files containing several records (using ``GFF.parse(\"records.gff\")``).\n\n\n\nDisplaying the features along with other plots\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nAs it uses Matplotlib, DNA Features Viewer can display the features on top of\nother sequences statistics, such as the local GC content:\n\n.. code:: python\n\n    import matplotlib.pyplot as plt\n    from dna_features_viewer import BiopythonTranslator\n    from Bio import SeqIO\n    import numpy as np\n\n    fig, (ax1, ax2) = plt.subplots(\n        2, 1, figsize=(12, 3), sharex=True, gridspec_kw={\"height_ratios\": [4, 1]}\n    )\n\n    # PLOT THE RECORD MAP\n    record = SeqIO.read(\"example_sequence.gb\", \"genbank\")\n    graphic_record = BiopythonTranslator().translate_record(record)\n    graphic_record.plot(ax=ax1, with_ruler=False, strand_in_label_threshold=4)\n\n    # PLOT THE LOCAL GC CONTENT (we use 50bp windows)\n    gc = lambda s: 100.0 * len([c for c in s if c in \"GC\"]) / 50\n    xx = np.arange(len(record.seq) - 50)\n    yy = [gc(record.seq[x : x + 50]) for x in xx]\n    ax2.fill_between(xx + 25, yy, alpha=0.3)\n    ax2.set_ylim(bottom=0)\n    ax2.set_ylabel(\"GC(%)\")\n\n.. raw:: html\n\n    \u003cp align=\"center\"\u003e\n    \u003cimg src=\"https://raw.githubusercontent.com/Edinburgh-Genome-Foundry/DnaFeaturesViewer/master/examples/with_gc_plot.png\" width=\"800\"\u003e\n    \u003c/p\u003e\n\nMulti-line and multi-page plots\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nSince 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):\n\n.. code:: python\n\n    graphic_record.plot_on_multiple_pages(\n        \"multipage_plot.pdf\",\n        nucl_per_line=70,\n        lines_per_page=7,\n        plot_sequence=True\n    )\n\n    \n.. raw:: html\n\n    \u003cp align=\"center\"\u003e\n    \u003cimg alt=\"DNA Features Viewer Logo\" title=\"DNA Features Viewer Logo\" src=\"https://raw.githubusercontent.com/Edinburgh-Genome-Foundry/DnaFeaturesViewer/master/docs/_static/images/multiline_example.png\" width=\"900\"\u003e\n    \u003c/p\u003e\n\nCustom Biopython translators\n----------------------------\n\nDNA Features Viewer allows to define \"themes\" by using custom record translators\ninstead of the default ``BiopythonTranslator``. Here is an example:\n\n.. code:: python\n\n    from dna_features_viewer import BiopythonTranslator\n\n    class MyCustomTranslator(BiopythonTranslator):\n        \"\"\"Custom translator implementing the following theme:\n\n        - Color terminators in green, CDS in blue, all other features in gold.\n        - Do not display features that are restriction sites unless they are BamHI\n        - Do not display labels for restriction sites\n        - For CDS labels just write \"CDS here\" instead of the name of the gene.\n\n        \"\"\"\n\n        def compute_feature_color(self, feature):\n            if feature.type == \"CDS\":\n                return \"blue\"\n            elif feature.type == \"terminator\":\n                return \"green\"\n            else:\n                return \"gold\"\n\n        def compute_feature_label(self, feature):\n            if feature.type == 'restriction_site':\n                return None\n            elif feature.type == \"CDS\":\n                return \"CDS here\"\n            else:\n                return BiopythonTranslator.compute_feature_label(self, feature)\n\n        def compute_filtered_features(self, features):\n            \"\"\"Do not display promoters. Just because.\"\"\"\n            return [\n                feature for feature in features\n                if (feature.type != \"restriction_site\")\n                or (\"BamHI\" in str(feature.qualifiers.get(\"label\", '')))\n            ]\n\n\n    graphic_record = MyCustomTranslator().translate_record(\"example_sequence.gb\")\n    ax, _ = graphic_record.plot(figure_width=10)\n    ax.figure.tight_layout()\n    ax.figure.savefig(\"custom_bopython_translator.png\")\n\n.. figure:: https://raw.githubusercontent.com/Edinburgh-Genome-Foundry/DnaFeaturesViewer/master/examples/custom_biopython_translator.png\n    :align: center\n\nExamples in other packages:\n---------------------------\n\nDNA Chisel\n~~~~~~~~~~~\n\nThis GIF uses DNA Features Viewer to plot the progress in the optimization of a DNA sequence with `DNA Chisel \u003chttps://github.com/Edinburgh-Genome-Foundry/DnaChisel\u003e`_. It also uses `Proglog \u003chttps://github.com/Edinburgh-Genome-Foundry/Proglog\u003e`_ to automatically generate a picture at different time points. See the not-so-great python code for this example `on Gist \u003chttps://gist.github.com/Zulko/f9aa781aaaab2c4d66ccd968ca85ca1d\u003e`_.\n\n.. raw:: html\n\n    \u003cp align=\"center\"\u003e\n    \u003cimg alt=\"DNA Chisel algorithm\" title=\"DNA Chisel\" src=\"https://raw.githubusercontent.com/Edinburgh-Genome-Foundry/DnaChisel/master/docs/_static/images/dnachisel_algorithm.gif\" width=\"800\"\u003e\n    \u003cbr /\u003e\n    \u003c/p\u003e\n\nGeneBlocks\n~~~~~~~~~~\n`GeneBlocks \u003chttps://github.com/Edinburgh-Genome-Foundry/Geneblocks\u003e`_ 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.\n\n.. raw:: html\n\n    \u003cp align=\"center\"\u003e\n    \u003cimg alt=\"DNA Chisel algorithm\" title=\"DNA Chisel\" src=\"https://raw.githubusercontent.com/Edinburgh-Genome-Foundry/GeneBlocks/master/examples/diff_blocks.png\" width=\"800\"\u003e\n    \u003cbr /\u003e\n    \u003c/p\u003e\n\n\n\nLicense = MIT\n-------------\n\nDNA Features Viewer is an open-source software originally written at the `Edinburgh Genome Foundry\n\u003chttp://genomefoundry.org\u003e`_ by `Zulko \u003chttps://github.com/Zulko\u003e`_\nand `released on Github \u003chttps://github.com/Edinburgh-Genome-Foundry/DnaFeaturesViewer\u003e`_ under the MIT licence.\nEveryone is welcome to contribute !\n\nMore biology software\n---------------------\n\n.. image:: https://raw.githubusercontent.com/Edinburgh-Genome-Foundry/Edinburgh-Genome-Foundry.github.io/master/static/imgs/logos/egf-codon-horizontal.png\n  :target: https://edinburgh-genome-foundry.github.io/\n\nDNA Features Viewer is part of the `EGF Codons \u003chttps://edinburgh-genome-foundry.github.io/\u003e`_ synthetic biology software suite for DNA design, manufacturing and validation.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fedinburgh-genome-foundry%2Fdnafeaturesviewer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fedinburgh-genome-foundry%2Fdnafeaturesviewer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fedinburgh-genome-foundry%2Fdnafeaturesviewer/lists"}