-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #89 from AllenNeuralDynamics/release-v0.15.0
Release v0.15.0
- Loading branch information
Showing
7 changed files
with
228 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
Examples - DocDB REST API | ||
================================== | ||
|
||
This page provides examples for interact with the Document Database (DocDB) | ||
REST API using the provided Python client. | ||
|
||
|
||
Querying Metadata | ||
~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
Count Example 1: Get # of records with a certain subject_id | ||
----------------------------------------------------------- | ||
|
||
.. code:: python | ||
import json | ||
from aind_data_access_api.document_db import MetadataDbClient | ||
API_GATEWAY_HOST = "api.allenneuraldynamics.org" | ||
DATABASE = "metadata_index" | ||
COLLECTION = "data_assets" | ||
docdb_api_client = MetadataDbClient( | ||
host=API_GATEWAY_HOST, | ||
database=DATABASE, | ||
collection=COLLECTION, | ||
) | ||
filter = {"subject.subject_id": "689418"} | ||
count = docdb_api_client._count_records( | ||
filter_query=filter, | ||
) | ||
print(count) | ||
Filter Example 1: Get records with a certain subject_id | ||
------------------------------------------------------- | ||
|
||
.. code:: python | ||
filter = {"subject.subject_id": "689418"} | ||
records = docdb_api_client.retrieve_docdb_records( | ||
filter_query=filter, | ||
) | ||
print(json.dumps(records, indent=3)) | ||
With projection (recommended): | ||
|
||
.. code:: python | ||
filter = {"subject.subject_id": "689418"} | ||
projection = { | ||
"name": 1, | ||
"created": 1, | ||
"location": 1, | ||
"subject.subject_id": 1, | ||
"subject.date_of_birth": 1, | ||
} | ||
records = docdb_api_client.retrieve_docdb_records( | ||
filter_query=filter, | ||
projection=projection, | ||
) | ||
print(json.dumps(records, indent=3)) | ||
Filter Example 2: Get records with a certain breeding group | ||
----------------------------------------------------------- | ||
|
||
.. code:: python | ||
filter = { | ||
"subject.breeding_info.breeding_group": "Chat-IRES-Cre_Jax006410" | ||
} | ||
records = docdb_api_client.retrieve_docdb_records( | ||
filter_query=filter | ||
) | ||
print(json.dumps(records, indent=3)) | ||
With projection (recommended): | ||
|
||
.. code:: python | ||
filter = { | ||
"subject.breeding_info.breeding_group": "Chat-IRES-Cre_Jax006410" | ||
} | ||
projection = { | ||
"name": 1, | ||
"created": 1, | ||
"location": 1, | ||
"subject.subject_id": 1, | ||
"subject.breeding_info.breeding_group": 1, | ||
} | ||
records = docdb_api_client.retrieve_docdb_records( | ||
filter_query=filter, | ||
projection=projection, | ||
) | ||
print(json.dumps(records, indent=3)) | ||
Aggregation Example 1: Get all subjects per breeding group | ||
---------------------------------------------------------- | ||
|
||
.. code:: python | ||
agg_pipeline = [ | ||
{ | ||
"$group": { | ||
"_id": "$subject.breeding_info.breeding_group", | ||
"subject_ids": {"$addToSet": "$subject.subject_id"}, | ||
"count": {"$sum": 1}, | ||
} | ||
} | ||
] | ||
result = docdb_api_client.aggregate_docdb_records( | ||
pipeline=agg_pipeline | ||
) | ||
print(f"Total breeding groups: {len(result)}") | ||
print(f"First 3 breeding groups and corresponding subjects:") | ||
print(json.dumps(result[:3], indent=3)) | ||
For more info about aggregations, please see MongoDB documentation: | ||
https://www.mongodb.com/docs/manual/aggregation/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
"""Init package""" | ||
|
||
__version__ = "0.14.0" | ||
__version__ = "0.15.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters