Package: pyanatomogram
Table of contents[TOC]What is PyAnatomogram?PyAnatomogram is a python package to annotate and highlight organs and tissues in figures.PyAnatomogram parses anatomy svg images from the EBI Gene Expression Group'sanatomogram repositoryand provides
a python interface for programmatically annotating the individual organs with colors or other style attributes.
See ebi-gene-expression-group anatomogram repository for afor a full listof animal and plant organisms that are supported.This package was inspired by thegganatogramR-package by
Jesper Maag, and was written to provide similar functionality in python and to provide full resolution figures.Example use - Gallus Gallus (chicken)Highlight individual organsLet's color-code the heart and lung in a chicken image according to some measurement of interest.importpyanatomogramanatomogram=pyanatomogram.Anatomogram('gallus_gallus')anatomogram.set_tissue_style('heart',fill='red')anatomogram.set_tissue_style('lung',fill='blue')anatomogram.to_matplotlib()A full list of organs that can be highlighted in the gallus gallus svg image can be obtained by:importpyanatomogramanatomogram=pyanatomogram.Anatomogram('gallus_gallus')anatomogram.get_tissue_names()Highlight multiple organs with measurement using a matplotlib colormapMultiple organs can be highlighted by passing a dictionary or a pandas Series tohightlight_tissues. Values will be
mapped to colors using a matplotlib colormap.importpyanatomogramanatomogram=pyanatomogram.Anatomogram('gallus_gallus')anatomogram.highlight_tissues({'heart':0,'lung':2,'brain':3,'colon':1,'liver':4},cmap='Reds')anatomogram.to_matplotlib()Style organs with CSSCustom CSS style attributes can be used to tailor the visualization.importpyanatomogramanatomogram=pyanatomogram.Anatomogram('gallus_gallus')anatomogram.set_tissue_style('heart',**{'fill':'red','stroke':'black','stroke-width':1,'fill-opacity':0.8})anatomogram.set_tissue_style('lung',**{'fill':'cornflowerblue','stroke':'darkblue','stroke-width':1,'fill-opacity':0.5})anatomogram.to_matplotlib()Import into matplotlib axesThe anatomogram can be imported into a matplotlib figure with theto_matplotlib()method, and combined with
other figure elements in matplotlib.importmatplotlib.pyplotimportpandasimportpyanatomogramdata=pandas.Series({'heart':0,'lung':2,'brain':3,'colon':1,'liver':4})fig,axes=matplotlib.pyplot.subplots(nrows=1,ncols=2)data.plot(kind='barh',ax=axes[0])axes[0].set_xlabel('Relative expression')axes[0].set_ylabel('Organ')cmap=matplotlib.cm.Redsnorm=matplotlib.colors.Normalize()norm.autoscale(data)anatomogram=pyanatomogram.Anatomogram('gallus_gallus')anatomogram.highlight_tissues(data.to_dict(),cmap=cmap,norm=norm)anatomogram.to_matplotlib(ax=axes[1])matplotlib.pyplot.colorbar(matplotlib.cm.ScalarMappable(norm=norm,cmap=cmap),ax=axes[1],orientation='horizontal',label='Relative expression')helper for use in seaborn facetgridPyAnatomogram comes with a helper functionfacetgrid_helper()to be used together with the seabornFacetGridclass to generate multiple anatomogram subplots faceted by grouping variable(s).importpandasimportpyanatomogramimportseabornimportmatplotlibdata=pandas.DataFrame({'Condition1':{'heart':0,'lung':2,'brain':3,'colon':1,'liver':4},'Condition2':{'heart':3,'lung':4,'brain':2,'colon':2,'liver':3},'Condition3':{'heart':7,'lung':9,'brain':1,'colon':7,'liver':2},}).stack().rename_axis(['organ','condition']).to_frame('expression')g=seaborn.FacetGrid(data.reset_index(),col='condition')cmap=matplotlib.cm.Redsnorm=matplotlib.colors.Normalize()norm.autoscale(data)g.map(pyanatomogram.facetgrid_helper,'organ','expression',name='gallus_gallus',cmap=cmap,norm=norm)g.fig.colorbar(matplotlib.cm.ScalarMappable(norm=norm,cmap=cmap),label='Relative expression')Generate SVG fileAlternatively to importing the anatomogram into a matplotlib figure, the anatomogram can be saved directly to svg
with thesave_svg()method.importpyanatomogramanatomogram=pyanatomogram.Anatomogram('gallus_gallus')anatomogram.set_tissue_style('heart',fill='red')anatomogram.set_tissue_style('lung',fill='blue')anatomogram.save_svg('anatomogram.svg')