How can I display an image from a file in Jupyter Notebook?

前端 未结 11 1143
被撕碎了的回忆
被撕碎了的回忆 2020-11-28 01:03

I would like to use an IPython notebook as a way to interactively analyze some genome charts I am making with Biopython\'s GenomeDiagram module. While there is extensive doc

11条回答
  •  醉梦人生
    2020-11-28 01:44

    When using GenomeDiagram with Jupyter (iPython), the easiest way to display images is by converting the GenomeDiagram to a PNG image. This can be wrapped using an IPython.display.Image object to make it display in the notebook.

    from Bio.Graphics import GenomeDiagram
    from Bio.SeqFeature import SeqFeature, FeatureLocation
    from IPython.display import display, Image
    gd_diagram = GenomeDiagram.Diagram("Test diagram")
    gd_track_for_features = gd_diagram.new_track(1, name="Annotated Features")
    gd_feature_set = gd_track_for_features.new_set()
    gd_feature_set.add_feature(SeqFeature(FeatureLocation(25, 75), strand=+1))
    gd_diagram.draw(format="linear", orientation="landscape", pagesize='A4',
                    fragments=1, start=0, end=100)
    Image(gd_diagram.write_to_string("PNG"))
    

    [See Notebook]

提交回复
热议问题