biocomputelab / parasbolv Goto Github PK
View Code? Open in Web Editor NEWA lightweight Python library designed to simplify the development of tools that render SBOL Visual diagrams.
License: MIT License
A lightweight Python library designed to simplify the development of tools that render SBOL Visual diagrams.
License: MIT License
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
while the upper figure should look like
.
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()
The current parametric SVG files included in the package are not final and should be updated once a complete final released set is available.
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.
We need a new function to return all the parameters for a glyph. This should be possible by looking at the defaults, and returning the keys.
We should be more generic in our use of terms in the parametric SVG files.
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.
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))
For consistency, interactions should also be passed as named tuples.
(leaving this as a reminder to fix)
At present the GlyphRenderer object is created by the render_part_list function (and the reverse version). This should be removed and the renderer sent as an argument.
In the sbolv-cli the symbol for recombination sites should be consistent with others and not use the > and < symbols. I'd suggest using 'x'.
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.