Skip to content

Commit d047737

Browse files
authored
Lineage API support (#76)
* Add lineage API * Format sample code * Update setup.py to be compatible with newer versions of Python * Add additional args to lineage API * setup.cfg: change description-file to description_file, remove test alias and coverage configuration
1 parent 66817fd commit d047737

11 files changed

+121
-26
lines changed

CHANGE.txt

+7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22
LabKey Python Client API News
33
+++++++++++
44

5+
What's New in the LabKey 3.2.0 package
6+
==============================
7+
8+
*Release date: 09/10/2024*
9+
- Add lineage API to experiment module
10+
- Accessible via API wrappers e.g. api.experiment.lineage()
11+
512
What's New in the LabKey 3.1.0 package
613
==============================
714

README.md

+13-10
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ from labkey.api_wrapper import APIWrapper
9393

9494
print("Create an APIWrapper")
9595
labkey_server = 'localhost:8080'
96-
container_path = 'Tutorials/HIV Study' # in this example, Tutorials is a project name and HIV study is a subfolder under it.
96+
# in this example, Tutorials is a project name and HIV study is a subfolder under it.
97+
container_path = 'Tutorials/HIV Study'
9798
contextPath = 'labkey'
9899
schema = 'core'
99100
table = 'Users'
@@ -119,22 +120,23 @@ LabKey Server v15.1 and later.
119120
This package is maintained by [LabKey](http://www.labkey.com/). If you have any questions or need support, please use
120121
the [LabKey Server developer support forum](https://www.labkey.org/home/developer/forum/project-start.view).
121122

123+
To install the necessary dependencies for local development you can run the following command:
124+
125+
```bash
126+
pip install -e .
127+
```
128+
122129
When contributing changes please use `Black` to format your code. To run Black follow these instructions:
123130
1. Install black: `pip install black`
124131
2. Run black: `black .`
125132
3. Commit the newly formatted code.
126133

127134
### Testing
128-
If you are looking to contribute please run the tests before issuing a PR. The tests can be initiated by running
129-
130-
```bash
131-
$ python setup.py test
132-
```
133-
134-
This runs the tests using [pytest](https://docs.pytest.org/en/latest/contents.html). If you'd like to run pytest directly you can install the testing dependencies in your virtual environment with:
135+
If you are looking to contribute please run the tests before issuing a PR. To run the tests you'll need to install the
136+
additional testing dependencies, to do this run:
135137

136138
```bash
137-
$ pip install -e .[test]
139+
$ pip install -e '.[test]'
138140
```
139141

140142
Then, the tests can be run with
@@ -150,4 +152,5 @@ $ pytest . -m "integration"
150152
```
151153

152154
### Maintainers
153-
Package maintainer's can reference the [Python Package Maintenance](https://docs.google.com/document/d/13nVxwyctH4YZ6gDhcrOu9Iz6qGFPAxicE1VHiVYpw9A/) document (requires permission) for updating releases.
155+
Package maintainer's can reference the [Python Package Maintenance](https://docs.google.com/document/d/13nVxwyctH4YZ6gDhcrOu9Iz6qGFPAxicE1VHiVYpw9A/) document (requires permission) for updating
156+
releases.

labkey/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@
1414
# limitations under the License.
1515
#
1616
__title__ = "labkey"
17-
__version__ = "3.1.0"
17+
__version__ = "3.2.0"
1818
__author__ = "LabKey"
1919
__license__ = "Apache License 2.0"

labkey/experiment.py

+94
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,70 @@ def save_batches(
218218
return None
219219

220220

221+
def lineage(
222+
server_context: ServerContext,
223+
lsids: List[str],
224+
children: bool = None,
225+
container_path: str = None,
226+
cpas_type: str = None,
227+
depth: int = None,
228+
exp_type: str = None,
229+
include_inputs_and_outputs: bool = None,
230+
include_properties: bool = None,
231+
include_run_steps: bool = None,
232+
parents: bool = None,
233+
run_protocol_lsid: str = None,
234+
):
235+
"""
236+
:param server_context: A LabKey server context. See utils.create_server_context.
237+
:param lsids: Array of LSIDs for the seed ExpData, ExpMaterials, or ExpRun
238+
:param children: Include children in the lineage response. Defaults to true.
239+
:param container_path: labkey container path if not already set in context
240+
:param cpas_type: Optional LSID of a SampleSet or DataClass to filter the response. Defaults to include all.
241+
:param depth: An optional depth argument. Defaults to include all.
242+
:param exp_type: Optional experiment type to filter response -- either "Data", "Material", or "ExperimentRun".
243+
Defaults to include all.
244+
:param include_inputs_and_outputs: Include inputs and outputs in the lineage response.
245+
:param include_properties: Include properties in the lineage response.
246+
:param include_run_steps: Include run steps in the lineage response.
247+
:param parents: Include parents in the lineage response. Defaults to true.
248+
:param run_protocol_lsid: Optional Exp Run Protocol Lsid to filter response. Defaults to include all.
249+
"""
250+
lineage_url = server_context.build_url(
251+
"experiment", "lineage.api", container_path=container_path
252+
)
253+
payload = {"lsids": lsids}
254+
255+
if children is not None:
256+
payload["children"] = children
257+
258+
if cpas_type is not None:
259+
payload["cpasType"] = cpas_type
260+
261+
if depth is not None:
262+
payload["depth"] = depth
263+
264+
if exp_type is not None:
265+
payload["expType"] = exp_type
266+
267+
if include_inputs_and_outputs is not None:
268+
payload["includeInputsAndOutputs"] = include_inputs_and_outputs
269+
270+
if include_properties is not None:
271+
payload["includeProperties"] = include_properties
272+
273+
if include_run_steps is not None:
274+
payload["includeRunSteps"] = include_run_steps
275+
276+
if parents is not None:
277+
payload["parents"] = parents
278+
279+
if run_protocol_lsid is not None:
280+
payload["runProtocolLsid"] = run_protocol_lsid
281+
282+
return server_context.make_request(lineage_url, payload=payload, method="POST")
283+
284+
221285
class ExperimentWrapper:
222286
"""
223287
Wrapper for all of the API methods exposed in the experiment module. Used by the APIWrapper class.
@@ -237,3 +301,33 @@ def save_batch(self, assay_id: int, batch: Batch) -> Optional[Batch]:
237301
@functools.wraps(save_batches)
238302
def save_batches(self, assay_id: int, batches: List[Batch]) -> Optional[List[Batch]]:
239303
return save_batches(self.server_context, assay_id, batches)
304+
305+
@functools.wraps(lineage)
306+
def lineage(
307+
self,
308+
lsids: List[str],
309+
children: bool = None,
310+
container_path: str = None,
311+
cpas_type: str = None,
312+
exp_type: str = None,
313+
depth: int = None,
314+
include_properties: bool = None,
315+
include_inputs_and_outputs: bool = None,
316+
include_run_steps: bool = None,
317+
parents: bool = None,
318+
run_protocol_lsid: str = None,
319+
):
320+
return lineage(
321+
self.server_context,
322+
lsids,
323+
children,
324+
container_path,
325+
cpas_type,
326+
depth,
327+
exp_type,
328+
parents,
329+
include_inputs_and_outputs,
330+
include_properties,
331+
include_run_steps,
332+
run_protocol_lsid,
333+
)

samples/domain_example.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from labkey.query import QueryFilter
1919

2020
labkey_server = "localhost:8080"
21-
container_path = 'Tutorials/HIV Study' # Full project/folder container path
21+
container_path = "Tutorials/HIV Study" # Full project/folder container path
2222
context_path = "labkey"
2323
api = APIWrapper(labkey_server, container_path, context_path, use_ssl=False)
2424

samples/experiment_example.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from labkey.experiment import Batch, Run
1818

1919
labkey_server = "localhost:8080"
20-
container_path = 'Tutorials/HIV Study' # Full project/folder container path
20+
container_path = "Tutorials/HIV Study" # Full project/folder container path
2121
context_path = "labkey"
2222
api = APIWrapper(labkey_server, container_path, context_path, use_ssl=False)
2323

samples/experiment_platemetadata_example.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from labkey.experiment import Batch, Run
1818

1919
labkey_server = "localhost:8080"
20-
container_path = 'Tutorials/assay' # Full project/folder container path
20+
container_path = "Tutorials/assay" # Full project/folder container path
2121
context_path = "labkey"
2222
api = APIWrapper(labkey_server, container_path, context_path, use_ssl=False)
2323
assay_id = 310 # provide one from your server

samples/query_examples.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
print("Create a server context")
3232
labkey_server = "localhost:8080"
33-
container_path = 'Tutorials/HIV Study' # Full project/folder container path
33+
container_path = "Tutorials/HIV Study" # Full project/folder container path
3434
context_path = "labkey"
3535
api = APIWrapper(labkey_server, container_path, context_path, use_ssl=False)
3636

samples/security_example.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from labkey.exceptions import ServerNotFoundError
1818

1919
labkey_server = "localhost:8080"
20-
container_path = 'Tutorials/HIV Study' # Full project/folder container path
20+
container_path = "Tutorials/HIV Study" # Full project/folder container path
2121
contextPath = "labkey"
2222
api = APIWrapper(labkey_server, container_path, contextPath, use_ssl=False)
2323

setup.cfg

+1-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,2 @@
11
[metadata]
2-
description-file = README.md
3-
4-
[aliases]
5-
test=pytest
6-
7-
[coverage:html]
8-
directory = build/coverage_html
9-
title = Test coverage report for labkey
2+
description_file = README.md

setup.py

-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@
4848
packages=packages,
4949
package_data={},
5050
install_requires=["requests"],
51-
tests_require=tests_require,
52-
setup_requires=["pytest-runner"],
5351
extras_require={"test": tests_require},
5452
keywords="labkey api client",
5553
classifiers=[

0 commit comments

Comments
 (0)