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 `Design.plate_maps` parameter `well_marker` to be function of well position #222

Closed dave-doty closed 2 years ago

dave-doty commented 2 years ago

Currently well_marker is a constant string. Allow it also to be a function taking the well position as input as a string (e.g., "A1" or "C7"), and returning a string to put in that position. For example giving the identity function would put the well position itself:

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, 30).move(10).with_name('strand 1').with_idt(plate='plate 1', well='B3')

plate_maps = design.plate_maps_markdown(well_marker=lambda well: well, strands=[design.strands[0], design.strands[3]])
plate_map = plate_maps['plate 1']
print(plate_map)

would print

## plate 1
|     | 1   | 2   | 3   | 4   | 5   | 6   | 7   | 8   | 9   | 10   | 11   | 12   |
|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|------|------|------|
| A   | A1  |     |     |     |     |     |     |     |     |      |      |      |
| B   |     |     | B3  |     |     |     |     |     |     |      |      |      |
| C   |     |     |     |     |     |     |     |     |     |      |      |      |
| D   |     |     |     |     |     |     |     |     |     |      |      |      |
| E   |     |     |     |     |     |     |     |     |     |      |      |      |
| F   |     |     |     |     |     |     |     |     |     |      |      |      |
| G   |     |     |     |     |     |     |     |     |     |      |      |      |
| H   |     |     |     |     |     |     |     |     |     |      |      |      |
dave-doty commented 2 years ago

Release notes

allow Design.plate_maps parameter well_marker to be function of well position

This code (note that strands do not require a name if using well_marker)

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_idt(plate='plate 1', well='A1')
design.draw_strand(0, 10).move(10).with_idt(plate='plate 1', well='A2')
design.draw_strand(0, 20).move(10).with_idt(plate='plate 1', well='B2')
design.draw_strand(0, 30).move(10).with_idt(plate='plate 1', well='B3')
design.draw_strand(0, 40).move(10).with_idt(plate='plate 1', well='D7')

plate_map = design.plate_maps()[0]
print(plate_map.to_table(well_marker=lambda x:x))

prints


### plate "plate 1"
|     | 1   | 2   | 3   | 4   | 5   | 6   | 7   | 8   | 9   | 10   | 11   | 12   |
|:----|:----|:----|:----|:----|:----|:----|:----|:----|:----|:-----|:-----|:-----|
| A   | A1  | A2  |     |     |     |     |     |     |     |      |      |      |
| B   |     | B2  | B3  |     |     |     |     |     |     |      |      |      |
| C   |     |     |     |     |     |     |     |     |     |      |      |      |
| D   |     |     |     |     |     |     | D7  |     |     |      |      |      |
| E   |     |     |     |     |     |     |     |     |     |      |      |      |
| F   |     |     |     |     |     |     |     |     |     |      |      |      |
| G   |     |     |     |     |     |     |     |     |     |      |      |      |
| H   |     |     |     |     |     |     |     |     |     |      |      |      |