|
| 1 | +# LabKey Experiment Lineage API |
| 2 | + |
| 3 | +The LabKey Experiment Lineage API provides a powerful way to track and visualize relationships between |
| 4 | +different entities in your experimental data. This API allows you to: |
| 5 | + |
| 6 | +1. **Query lineage relationships** between samples, materials, data, and other experimental entities |
| 7 | +1. **Traverse lineage graphs** in both upstream (parent) and downstream (child) directions |
| 8 | + |
| 9 | +The lineage API represents relationships as a directed graph where: |
| 10 | + |
| 11 | +- **Nodes** represent individual entities (samples, data objects, etc.) |
| 12 | +- **Edges** represent parent-child relationships between entities |
| 13 | +- Each node is uniquely identified by its **LSID** (Life Science Identifier) |
| 14 | + |
| 15 | +### API Parameters |
| 16 | + |
| 17 | +The Lineage API accepts the following parameters to control the scope and content of lineage queries: |
| 18 | + |
| 19 | +#### Core Parameters |
| 20 | + |
| 21 | +| Parameter | Type | Description | |
| 22 | +|------------|-------------|------------------------------------------------------------------------------------------------------------------------------------------| |
| 23 | +| `lsids` | `List[str]` | List of Life Science Identifiers (LSIDs) for which to retrieve lineage information. These are the "seed" entities for the lineage query. | |
| 24 | +| `depth` | `int` | Maximum number of generations to traverse in the lineage graph. Default maximum is 100. | |
| 25 | +| `parents` | `bool` | Whether to include parent (upstream) relationships in the lineage query. Default is `True`. | |
| 26 | +| `children` | `bool` | Whether to include child (downstream) relationships in the lineage query. Default is `True`. | |
| 27 | + |
| 28 | +#### Filtering Parameters |
| 29 | +The following filter parameters filter nodes in graph to only match against the corresponding filter(s). NOTE: Using |
| 30 | +these filters can produce **disconnected graphs**. |
| 31 | + |
| 32 | +| Parameter | Type | Description | |
| 33 | +|---------------------|-------|-----------------------------------------------------------------------------------------------------------| |
| 34 | +| `exp_type` | `str` | Filter lineage by experiment type. Possible values: `ALL`, `Data`, `Material`, `ExperimentRun`, `Object`. | |
| 35 | +| `cpas_type` | `str` | Filter lineage by CPAS type (optional). | |
| 36 | +| `run_protocol_lsid` | `str` | Filter lineage to only include entities associated with a specific protocol (optional). | |
| 37 | + |
| 38 | +#### Data Inclusion Parameters |
| 39 | + |
| 40 | +| Parameter | Type | Description | |
| 41 | +|------------------------------|--------|-----------------------------------------------------------------------------------------------| |
| 42 | +| `include_properties` | `bool` | Whether to include entity properties in the response. Default is `False`. | |
| 43 | +| `include_inputs_and_outputs` | `bool` | Whether to include detailed input and output information for each entity. Default is `False`. | |
| 44 | +| `include_run_steps` | `bool` | Whether to include experiment run step information. Default is `False`. | |
| 45 | + |
| 46 | +## Response Structure |
| 47 | +The Lineage API response includes: |
| 48 | +- **seed**: The LSID(s) of the provided seed node(s) |
| 49 | +- **nodes**: A dictionary of all nodes in the lineage graph, keyed by LSID |
| 50 | +- Each node contains: |
| 51 | + - **name**: Display name of the entity |
| 52 | + - **parents**: Array of objects representing parent relationships |
| 53 | + - **children**: Array of objects representing child relationships |
| 54 | + - Additional properties when requested via inclusion parameters |
| 55 | + |
| 56 | +### Examples |
| 57 | + |
| 58 | +```python |
1 | 59 | from collections import defaultdict |
2 | 60 |
|
3 | 61 | from labkey.api_wrapper import APIWrapper |
|
142 | 200 | query_name = "Substances" |
143 | 201 | entity_name = "Ocean Water" |
144 | 202 |
|
145 | | -# Fetch the LSID of the "seed" for the lineage request. In this case, we'll query for the "Ocean Water" entity in Substances. |
| 203 | +# Fetch the LSID of the "seed" for the lineage request |
146 | 204 | result = api.query.select_rows( |
147 | 205 | schema_name, query_name, columns="Name, LSID", filter_array=[QueryFilter("name", entity_name)] |
148 | 206 | ) |
149 | 207 | seed_lsid = result["rows"][0]["LSID"] |
150 | 208 |
|
151 | | -# Lineage results includes the following: |
152 | | -# "seed": The LSID of all furnished seed nodes. A string if only a single seed, otherwise, an array of strings. |
153 | | -# "nodes": A dictionary of lineage node objects keyed by each node's LSID. Nodes are linked together by their "parents" and "children" edges. |
154 | | -# |
155 | | -# On each node the following properties allow for traversal of the flattened graph structure. |
156 | | -# "parents": An array of objects representing edges in the graph from nodes that refer to this node. |
157 | | -# "children": An aray of objects representing edges in the graph to nodes to which this node refers. |
158 | 209 | lineage_result = api.experiment.lineage([seed_lsid], depth=10) |
159 | 210 |
|
160 | | - |
161 | 211 | ################### |
162 | 212 | # Traverse the lineage |
163 | 213 | ################### |
@@ -231,3 +281,4 @@ def process_edges(edges, offset): |
231 | 281 | # OC-2 |
232 | 282 | # OC-3 |
233 | 283 | ################### |
| 284 | +``` |
0 commit comments