-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_dataverse_client.py
More file actions
51 lines (39 loc) · 1.46 KB
/
example_dataverse_client.py
File metadata and controls
51 lines (39 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
"""Examples for using the Dataverse client"""
import logging
from random import randint
from dataverse_client import DataverseConfig, DataverseRestClient
logging.basicConfig(level=logging.INFO)
def example_using_dataverse_client():
"""Example usage of the DataverseRestClient with mice table"""
client = DataverseRestClient(DataverseConfig())
mouse_table = "aibs_dim_mices"
mouse = client.get_entry(mouse_table, {"aibs_mouse_id": "TestMouse_111111"})
# Add mouse (fails if mouse already exists)
try:
mouse = client.add_entry(mouse_table, {"aibs_mouse_id": "614174"})
print(mouse)
except Exception as e:
print(f"Failed to add mouse: {e}")
mouse_id = "614174"
mouse = client.get_entry(mouse_table, {"aibs_mouse_id": mouse_id})
print(mouse)
mouse_guid = mouse["aibs_dim_miceid"]
mouse = client.get_entry(mouse_table, mouse_guid)
print(mouse)
mice = client.query(
mouse_table,
filter="aibs_mouse_id ne '614174'",
order_by="aibs_mouse_id",
top=5,
select=["aibs_mouse_id", "aibs_date_of_birth"],
)
print(mice)
updated_mouse = client.update_entry(
mouse_table,
{"aibs_mouse_id": mouse_id},
{"aibs_genotype": "UpdatedGenotype_" + str(randint(1, 100))},
)
print(updated_mouse)
if __name__ == "__main__":
print("Loading configuration from " + str(DataverseConfig.model_config["yaml_file"]))
example_using_dataverse_client()