- Code: https://github.com/latchbio/fancy_samplesheet_workflow/tree/main
- Workflow UI: https://console.latch.bio/workflows/111268/parameters
What You Will Achieve
By the end of this tutorial, your workflow will let scientists seamlessly connect Registry tables to workflow execution. Here’s the user experience you are enabling:- In the UI, scientists click “Import from Registry”, choose a table, and select specific rows.
- A modal appears to match Registry column names with the workflow input parameters you define in code.
- Once confirmed, the selected rows are imported directly into the workflow.
- Users can launch the workflow with the imported data.
- The workflow then upserts results back into the same Registry records.
- Updated records are visible in the original Registry table, linking inputs with outputs.
Importing rows from Registry
Usage Example
Core Ideas
To import a table from Registry into your workflow, follow these steps:- Define a dataclass: Create a Python dataclass that represents a single row in the samplesheet.
- Mark it as a samplesheet: In the LatchMetadata, set samplesheet=True to indicate that this dataclass should be treated as a samplesheet.
- Match Registry columns: The fields in your dataclass should match the column names in the Registry table (or be a subset). If your dataclass fields use the exact same names as the Registry columns, the workflow UI will automatically align them in the “column matching” modal.
- Wrap rows in SamplesheetItem: Each row should be wrapped in a SamplesheetItem, which allows the workflow to detect whether the row came from Registry.
-
A
SamplesheetItem
has two fields:data
– the actual row data. For example,row.data.sample_name
will give you the value from the sample_name column.record
– the Registry Record object for that row.- If the row was imported from Registry,
record
will be populated with the corresponding Record. - If the row was created manually (not imported),
record
will beNone
.
- If the row was imported from Registry,
Upserting rows to Registry
ATable
can be modified by using the Table.update()
function. Table.update()
returns a context manager (and hence must be called using with
syntax) with an upsert_record
method. Visit the Table Object page for the API reference.
Usage Example
Core Ideas
- Retrieve the Table ID by calling
get_table_id()
on theRecord
object. - Initialize a
Table
object by callingTable(id=table_id)
. - Call
Table.update()
to get a context manager with anupsert_record
method.