Skip to content

image

Rendering of SBGN documents as images.

The rendering is performed by the web service of Frank Bergmann at https://sbml.bioquant.uni-heidelberg.de/layout, i.e., it requires an internet connection. For the documentation of the service see http://sysbioapps.spdns.org/Layout.

from pathlib import Path

from libsbgnpy import read_sbgn_from_file, render_sbgn

sbgn = read_sbgn_from_file(Path("map.sbgn"))
render_sbgn(sbgn, Path("map.png"))

RenderError

Bases: RequestException

The rendering web service answered, but not with an image.

render_sbgn

render_sbgn(sbgn, image_file, file_format='png')

Render an SBGN document to an image.

The document is sent to the rendering web service, which lays the map out and returns the image. The request is equivalent to

curl -X POST -F file=@"map.sbgn"         https://sbml.bioquant.uni-heidelberg.de/layout -o map.png

The image is only written if the service returns an image, and it is written atomically: an existing file is replaced as a whole or left as it is. The service currently returns a JPEG although it declares a PNG; the JPEG is written as it is and a warning is logged.

Parameters:

Name Type Description Default
sbgn Sbgn

SBGN document

required
image_file Path

path of the image to create, ending in .<file_format> (in any case)

required
file_format str

image format, only png is supported

'png'

Raises:

Type Description
ValueError

if the format is not supported or the file has another suffix

RenderError

if the web service answers with something else than an image, or with an image larger than RENDER_MAX_BYTES

RequestException

if the web service cannot be reached or fails; RenderError is a subclass