Giter Club home page Giter Club logo

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

Watchers

 avatar  avatar  avatar  avatar

parasbolv's Issues

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()

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.

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.

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))

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.

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.