UC-Davis-molecular-computing / scadnano-python-package

Python scripting library for generating designs readable by scadnano.
https://scadnano.org
MIT License
13 stars 7 forks source link

allow other table formats besides Markdown in `Design.plate_maps` #224

Closed dave-doty closed 2 years ago

dave-doty commented 2 years ago

Port the code from alhambra (https://github.com/DNA-and-Natural-Algorithms-Group/alhambra) that allows more flexible table formats for plate map tables.

This and issue #222 can be closed at the same time, since alhambra also supports the more sophisticated well_marker parameter.

dave-doty commented 2 years ago

Release notes

allow other table formats besides Markdown in Design.plate_maps

In a jupyter notebook cell, put this code:

import scadnano as sc

helices = [sc.Helix(max_offset=100)]
design = sc.Design(helices=helices, strands=[], grid=sc.square)
design.draw_strand(0, 0).move(10).with_name('strand 0').with_idt(plate='plate 1', well='A1')
design.draw_strand(0, 10).move(10).with_name('strand 1').with_idt(plate='plate 1', well='A2')
design.draw_strand(0, 20).move(10).with_name('strand 2').with_idt(plate='plate 1', well='B2')
design.draw_strand(0, 30).move(10).with_name('strand 3').with_idt(plate='plate 1', well='B3')
design.draw_strand(0, 40).move(10).with_name('strand 4').with_idt(plate='plate 1', well='D7')

from IPython.display import display, Markdown
def dm(o):
    display(Markdown(o))

plate_map = design.plate_maps()[0]
dm(plate_map.to_table(tablefmt='html', vertical_borders=True))

It should render

The returned HTML uses inline styles to ensure there are vertical borders between columns of the table. The vertical borders make it easier to see which column a well is in. This is useful when rendering in a Jupyter notebook, since the inline styles will be preserved when saving the Jupyter notebook using the nbconvert tool: https://nbconvert.readthedocs.io/en/latest/

Any format supported by the tabular package is supported as tablefmt for the method PlateMap.to_table(). See API for more details: https://scadnano-python-package.readthedocs.io/en/latest/#scadnano.PlateMap.to_table