DnaFeaturesViewer

DnaFeaturesViewer

功能强大的DNA序列特征可视化Python库

DnaFeaturesViewer是一款功能强大的DNA序列特征可视化Python库。它能自动生成清晰简洁的图表,即使是复杂的重叠特征和长标签序列也能完美展示。该库兼容Matplotlib和Biopython,支持多种图像输出格式。DnaFeaturesViewer可从GenBank或GFF文件读取特征,绘制核苷酸序列和氨基酸翻译,并支持多行多页绘图。它为DNA序列分析和生物学研究提供了直观高效的可视化工具。

DNA Features Viewer生物信息学可视化工具基因组Python库Github开源项目

.. raw:: html

<p align="center">
<img alt="DNA Features Viewer 标志" title="DNA Features Viewer 标志" src="https://yellow-cdn.veclightyear.com/835a84d5/a20ca9dc-9878-43ab-bd32-c5f2980cb594.png" width="350">
</p>

DNA 特征查看器

.. image:: https://github.com/Edinburgh-Genome-Foundry/DnaFeaturesViewer/actions/workflows/build.yml/badge.svg :target: https://github.com/Edinburgh-Genome-Foundry/DnaFeaturesViewer/actions/workflows/build.yml :alt: GitHub CI 构建状态

.. image:: https://coveralls.io/repos/github/Edinburgh-Genome-Foundry/DnaFeaturesViewer/badge.svg?branch=master :target: https://coveralls.io/github/Edinburgh-Genome-Foundry/DnaFeaturesViewer?branch=master

DNA Features Viewer(完整文档在 这里 <https://edinburgh-genome-foundry.github.io/DnaFeaturesViewer/>_)是一个用于可视化 DNA 特征的 Python 库,例如来自 GenBank 或 GFF 文件,或 Biopython SeqRecords:

.. raw:: html

<p align="center">
<img src="https://yellow-cdn.veclightyear.com/835a84d5/d94861c7-b5ed-4c40-82ad-d62c15ee7185.png" width="500">
</p>

DNA Features Viewer 能够自动生成简洁清晰的图像,即使是对于具有许多重叠特征和长标签的序列。该库与 Matplotlib 和 Biopython 配合良好,可以输出多种不同格式的图像(PNG、JPEG、SVG、PDF),例如用于报告生成、文章图表或 LIMS 界面。

安装

如果您已安装 PIP,只需在终端中输入:

.. code:: bash

pip install dna_features_viewer

DNA Features Viewer 也可以通过解压源代码到一个目录中,然后使用以下命令安装:

.. code:: bash

python setup.py install

如果您打算使用 bokeh 功能,还需要安装 Bokeh 和 Pandas:

.. code:: bash

pip install bokeh pandas

要解析 GFF 文件,请安装 bcbio-gff 库:

.. code:: bash

pip install bcbio-gff

使用示例

基本绘图


在这个第一个示例中,我们"手动"定义特征:

.. code:: python

    from dna_features_viewer import GraphicFeature, GraphicRecord
    features=[
        GraphicFeature(start=0, end=20, strand=+1, color="#ffd700",
                       label="小特征"),
        GraphicFeature(start=20, end=500, strand=+1, color="#ffcccc",
                       label="基因1,名称很长"),
        GraphicFeature(start=400, end=700, strand=-1, color="#cffccc",
                       label="基因2"),
        GraphicFeature(start=600, end=900, strand=+1, color="#ccccff",
                       label="基因3")
    ]
    record = GraphicRecord(sequence_length=1000, features=features)
    record.plot(figure_width=5)

.. raw:: html

    <p align="center">
    <img src="https://yellow-cdn.veclightyear.com/835a84d5/d94861c7-b5ed-4c40-82ad-d62c15ee7185.png" width="500">
    </p>


如果我们在上面的代码中将 `GraphicRecord` 替换为 `CircularGraphicRecord`,我们就可以得到构造的环形图:

.. raw:: html

    <p align="center">
    <img src="https://yellow-cdn.veclightyear.com/835a84d5/8923fb28-e654-48e0-a0f4-e324904309da.png" width="443">
    </p>

也可以通过使用 ``plot_with_bokeh`` 而不是 ``plot`` 来生成交互式(基于浏览器)的图表:

.. raw:: html

    <p align="center">
    <img src="https://yellow-cdn.veclightyear.com/835a84d5/a0d4a08b-aa98-4822-8c53-d8ffc639fa57.png" width="800">
    </p>

核苷酸序列、翻译和裁剪

DNA Features Viewer 允许在记录图下方绘制核苷酸或氨基酸序列:

.. code:: python

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')

.. raw:: html

<p align="center">
<img src="https://yellow-cdn.veclightyear.com/835a84d5/7f83d279-e69f-4a10-926c-a9f1b9f20669.png" width="415">
</p>

这使得可以绘制序列的概览以及序列子段的详细视图(完整代码 <https://github.com/Edinburgh-Genome-Foundry/DnaFeaturesViewer/blob/master/examples/overview_and_detail.py>_)

.. code:: python

...
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))

.. raw:: html

<p align="center">
<img src="https://yellow-cdn.veclightyear.com/835a84d5/13458ba2-8c74-4429-ae61-2bffa929783f.png" width="900">
</p>

从 GenBank 或 GFF 文件读取特征


DnaFeaturesViewer 与 BioPython 配合良好。因此,绘制 Biopython 记录的内容,或直接绘制 GenBank(或 GFF)文件非常简单:

.. code:: python

    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)

.. raw:: html

    <p align="center">
    <img src="https://yellow-cdn.veclightyear.com/835a84d5/c8bd53ba-051d-44e7-81d1-2838dc4967f6.png" width="900">
    </p>

注1:脚本使用 ``strand_in_label_threshold=7`` 来在注释文本中为每个宽度小于约7像素的特征用箭头指示链方向。

注2:``BiopythonTranslator`` 类决定了如何将 genbank 信息转换为图形特征。它允许选择要绘制的特征类别以及不同特征的颜色。

注3:解析 GFF 文件需要 BCBio 库(``pip install bcbio-gff``)。这个库还能够从包含多个记录的 GFF 文件中提取 Biopython 记录(使用 ``GFF.parse("records.gff")``)。

与其他图表一起显示特征
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

由于它使用 Matplotlib,DNA Features Viewer 可以将特征与其他序列统计信息一起显示,例如局部 GC 含量:

.. code:: python

    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]}
    )

    # 绘制记录图
    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)
# 绘制局部GC含量(我们使用50bp窗口)
    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(%)")

多行和多页图表
~~~~~~~~~~~~~~~

从v3.0版本开始,可以在多行(使用``record.plot_on_multiple_lines()``)甚至多页(PDF)上绘制序列:

.. code:: python

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

自定义Biopython转换器
----------------------------

DNA Features Viewer允许通过使用自定义记录转换器而不是默认的``BiopythonTranslator``来定义"主题"。以下是一个示例:

.. code:: python

    from dna_features_viewer import BiopythonTranslator

    class MyCustomTranslator(BiopythonTranslator):
        """自定义转换器实现以下主题:

        - 将终止子着色为绿色,CDS为蓝色,所有其他特征为金色。
        - 不显示限制性位点特征,除非是BamHI
        - 不显示限制性位点的标签
        - 对于CDS标签,只写"CDS here"而不是基因名称。

        """

        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):
            """不显示启动子。仅仅是因为。"""
            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")

其他包中的示例:
---------------------------

DNA Chisel
~~~~~~~~~~~

这个GIF使用DNA Features Viewer来绘制使用`DNA Chisel <https://github.com/Edinburgh-Genome-Foundry/DnaChisel>`_优化DNA序列的进度。它还使用`Proglog <https://github.com/Edinburgh-Genome-Foundry/Proglog>`_在不同时间点自动生成图片。这个示例不太好的Python代码可以在`Gist <https://gist.github.com/Zulko/f9aa781aaaab2c4d66ccd968ca85ca1d>`_上找到。

GeneBlocks
~~~~~~~~~~
`GeneBlocks <https://github.com/Edinburgh-Genome-Foundry/Geneblocks>`_是一个Python库,用于计算两个序列构建的"差异",指示所有的变化(添加、删除、突变)。它使用DNA Features Viewer来显示这些变化以及其他序列的特征。

许可证 = MIT
-------------

DNA Features Viewer是一个开源软件,最初由`Zulko <https://github.com/Zulko>`_在`爱丁堡基因组铸造厂<http://genomefoundry.org>`_编写,并在MIT许可下`在Github上发布<https://github.com/Edinburgh-Genome-Foundry/DnaFeaturesViewer>`_。欢迎每个人做出贡献!

更多生物学软件
---------------------

DNA Features Viewer是`EGF Codons <https://edinburgh-genome-foundry.github.io/>`_合成生物学软件套件的一部分,用于DNA设计、制造和验证。

编辑推荐精选

博思AIPPT

博思AIPPT

AI一键生成PPT,就用博思AIPPT!

博思AIPPT,新一代的AI生成PPT平台,支持智能生成PPT、AI美化PPT、文本&链接生成PPT、导入Word/PDF/Markdown文档生成PPT等,内置海量精美PPT模板,涵盖商务、教育、科技等不同风格,同时针对每个页面提供多种版式,一键自适应切换,完美适配各种办公场景。

AI办公办公工具AI工具博思AIPPTAI生成PPT智能排版海量精品模板AI创作热门
潮际好麦

潮际好麦

AI赋能电商视觉革命,一站式智能商拍平台

潮际好麦深耕服装行业,是国内AI试衣效果最好的软件。使用先进AIGC能力为电商卖家批量提供优质的、低成本的商拍图。合作品牌有Shein、Lazada、安踏、百丽等65个国内外头部品牌,以及国内10万+淘宝、天猫、京东等主流平台的品牌商家,为卖家节省将近85%的出图成本,提升约3倍出图效率,让品牌能够快速上架。

iTerms

iTerms

企业专属的AI法律顾问

iTerms是法大大集团旗下法律子品牌,基于最先进的大语言模型(LLM)、专业的法律知识库和强大的智能体架构,帮助企业扫清合规障碍,筑牢风控防线,成为您企业专属的AI法律顾问。

SimilarWeb流量提升

SimilarWeb流量提升

稳定高效的流量提升解决方案,助力品牌曝光

稳定高效的流量提升解决方案,助力品牌曝光

Sora2视频免费生成

Sora2视频免费生成

最新版Sora2模型免费使用,一键生成无水印视频

最新版Sora2模型免费使用,一键生成无水印视频

Transly

Transly

实时语音翻译/同声传译工具

Transly是一个多场景的AI大语言模型驱动的同声传译、专业翻译助手,它拥有超精准的音频识别翻译能力,几乎零延迟的使用体验和支持多国语言可以让你带它走遍全球,无论你是留学生、商务人士、韩剧美剧爱好者,还是出国游玩、多国会议、跨国追星等等,都可以满足你所有需要同传的场景需求,线上线下通用,扫除语言障碍,让全世界的语言交流不再有国界。

讯飞绘文

讯飞绘文

选题、配图、成文,一站式创作,让内容运营更高效

讯飞绘文,一个AI集成平台,支持写作、选题、配图、排版和发布。高效生成适用于各类媒体的定制内容,加速品牌传播,提升内容营销效果。

热门AI辅助写作AI工具讯飞绘文内容运营AI创作个性化文章多平台分发AI助手
TRAE编程

TRAE编程

AI辅助编程,代码自动修复

Trae是一种自适应的集成开发环境(IDE),通过自动化和多元协作改变开发流程。利用Trae,团队能够更快速、精确地编写和部署代码,从而提高编程效率和项目交付速度。Trae具备上下文感知和代码自动完成功能,是提升开发效率的理想工具。

AI工具TraeAI IDE协作生产力转型热门
商汤小浣熊

商汤小浣熊

最强AI数据分析助手

小浣熊家族Raccoon,您的AI智能助手,致力于通过先进的人工智能技术,为用户提供高效、便捷的智能服务。无论是日常咨询还是专业问题解答,小浣熊都能以快速、准确的响应满足您的需求,让您的生活更加智能便捷。

imini AI

imini AI

像人一样思考的AI智能体

imini 是一款超级AI智能体,能根据人类指令,自主思考、自主完成、并且交付结果的AI智能体。

下拉加载更多