Giter VIP home page Giter VIP logo

parasbolv's Introduction

paraSBOLv

A lightweight Python library designed to simplify the rendering of highly-customisable SBOL Visual glyphs and diagrams. To do this, paraSBOLv uses the Parametric Scalable Vector Graphic (pSVG) format to enable the encoding of the shape geometry and allowed parametric variations for each glyph. The best way to learn how to use paraSBOLv is to dive into our gallery of examples which cover most of the capabilities present. In addition, all functions and classes are extensively documented in code to allow usage to be easily inferred.

Example image generated by paraSBOLv

Relationship to DNAplotlib

We are regularly asked about the relationship of parasbolv and another genetic design visualisation tool we have developed called dnaplotlib. The major difference between the two packages is that parasbolv is designed to be lightweight, include minimal additional functionality, and be tailored to tool developers to provide them with low level access to the rendering of SBOL Visual glyphs and interactions. In contrast, dnaplotlib is designed to provide a much fuller and wider range of functionalities to both developers and biologists.

It should be noted that dnaplotlib version 2.0, which is currently under development, will completely replace its legacy rendering pipeline with paraSBOLv. This will not only simplify maintenance, but also allow access to new glyphs ratified by the SBOL community as they become available.

Dependancies

paraSBOLv does not require any other dependancies when installed. However, internally it does make use of the svgpath2mpl package to handle the generation of matplotlib compatible paths from an SVG path string. Do check this package out if you'd like to know more about using SVG with matplotlib.

Installation

The easiest way to start playing with parasbolv is to clone this repository and place the parasbolv directory into you PYTHONPATH environment variable. Once done, it should be possible to then:

import parasbolv as psv

Documentation

Automatically generated documentation can be accessed at: https://biocomputelab.github.io/paraSBOLv/index.html

Tutorials

  • Getting started with paraSBOLv - This provides a basic introduction to the paraSBOLV library and the core data types of functions available. It is recommended that this is used together with the examples gallery.

  • Creating parametric SVG glyph files - If you are looking to create new parametric glyphs to use with this library then this provides an overview of the core elements that need to be added. If you are creating a new glyph that you think others in the synthetic biology might find useful, please consider also submitting to the SBOL Visual standard.

Tools

To inspire you to make your own tools, we created some simple plotting tools using paraSBOLv as a convenient foundation.

genbank2sbolv - visualises the coding regions within a GenBank file.

sbolv-cli - streamlined CLI version of paraSBOLv for rapid generation of designs from the command line.

Support

If you use this tool to create diagrams or as a basis for new software please cite the following paper. Without citations that demonstrate use it becomes difficult to support this tool.

Clark C.J., Scott-Brown J. & Gorochowski T.E. "paraSBOLv: a foundation for standard-compliant genetic design visualisation tools", Synthetic Biology, 2021 doi:10.1093/synbio/ysab022

parasbolv's People

Contributors

cclark1e avatar chofski avatar jamesscottbrown avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

parasbolv's Issues

Handling of zorder

It is currently not possible to set the zorder parameter of paths. This is sometimes necessary on complex designs so should be available for end users. Likely needs an update to the glyph drawing code to ensure it is able to handle this parameter.

Use namedtuple of elements of parts_list

Rather than having the parts_list argument to functions being a list, I think it would be clearer to use a namedtuple.

This can be defined with:

from collections import namedtuple

Part = namedtuple('part', ['glyph_type', 'orientation',  'user_parameters', 'style_parameters'])

Then a tuple can be created with:

part = Part('CDS', 'forward' , {'arrowbody_height':15}, None)

# or, from an array:

part_array = ['CDS', 'forward' , {'arrowbody_height':15}, None]
part = Part(*part_array)

This namedtuple has a more explicit string representation, and components can be accessed by name as well as by index:

>>> print(part)
part(glyph_type='CDS', orientation='forward', user_parameters={'arrowbody_height': 15}, style_parameters=None)
>>> part.orientation
'forward'
>>> part[1]
'forward'

Similarly, the bounds list-of-lists coule be replaced by:

Point = namedtuple('point', ['x', 'y'])
Bounds = namedtuple('bounds', ['lower_left', 'top_right'])
>>> Bounds(Point(1, 2), Point(3, 4))
bounds(lower_left=point(x=1, y=2), top_right=point(x=3, y=4))

Tutorial and user guide

It would be useful to have a tutorial on how to use the core functions of the library and also a description of how to create new pSVG files.

distinction between tools and examples

Since we seem to have two kinds of scripts in the gallery, tools and examples, it might be a good idea to separate them somehow - even if it is just numbering tools at the start or the end.

Bug in axes passing

Dear developers,

thanks a lot for providing this library! By testing around I encountered a bug in the support of providing own axes.

When having a subplots with more than one axes, the output is not as intended despite providing the correct axis. In particular the output is
errornous_visualization
while the upper figure should look like
intended_visualization.

The code leading to both figures is attached below.

I suggest the adaption of the implementations referenced in draw_interaction() as well as draw_interaction() itself as they use plt.plot(...) instead of ax.plot(...).

I thank you for fixing this issue.
Kind regards,
Erik

import parasbolv as psv
import matplotlib.pyplot as plt
from collections import namedtuple

Part = namedtuple('part', ['glyph_type', 'orientation',  'user_parameters', 'style_parameters'])
Interaction = namedtuple('interaction', ['starting_glyph', 'ending_glyph', 'interaction_type', 'interaction_parameters'])


part_list = []
part_list.append(Part('CDS',
                     'forward', 
                      None,
                      {'cds': {'facecolor': (1, 0.5, 0.5), 'edgecolor': (1,0,0), 'linewidth': 2}}
                      ) )

part_list.append(Part('Terminator', 'forward', None, None))
part_list.append(Part("Promoter", "forward", None, None))

part_list.append(Part('CDS',
                     'forward', 
                      None,
                      {'cds': {'facecolor': (1, 0.5, 0.5), 'edgecolor': (1,0,0), 'linewidth': 2}}
                      ) )

part_list.append(Part('Terminator', 'forward', None, None))
part_list.append(Part("Promoter", "forward", None, None))


# Create renderer
renderer = psv.GlyphRenderer()


# Create list of interactions to pass to render_part_list
interaction_list = []
interaction_list.append(Interaction(part_list[0], part_list[2], 'inhibition', {'color': (0.75,0,0)}))

# interaction_list.append(Interaction(part_list[0], part_list[1], 'inhibition', {'color': (0.75,0,0)}))
# interaction_list.append(Interaction(part_list[2], part_list[4], 'control', {'color': (0, 0.75, 0),
#                                                                             'direction':'reverse'}))


# Plot Construct
error_case = True

if error_case:
    fig, axes = plt.subplots(ncols=1, nrows=2)
    ax = axes[0]
    figure_name = "errornous_visualization.png"
else:
    fig, axes = plt.subplots(ncols=1, nrows=1)
    ax = axes
    figure_name = "intended_visualization.png"
construct = psv.Construct(part_list, renderer, interaction_list=interaction_list, fig=fig, ax=ax, start_position=(0, 0))
fig, ax, baseline_start, baseline_end, bounds = construct.draw()
ax.plot([baseline_start[0], baseline_end[0]], [baseline_start[1], baseline_end[1]], color=(0,0,0), linewidth=1.5, zorder=0)

# You can also manually plot interactions:
interaction_bounds = psv.draw_interaction(ax, ((120, 15), (50, 0)), ((60, 0), (60, 0)), 'process', None)


plt.savefig(figure_name)
plt.show()

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.