Subject API endpoint

An animal in a study, described by its species, strain, sex and the procedures and logs recorded for it.

Table of contents

  1. Endpoints
  2. Fields
  3. List
  4. Add
  5. Detail
  6. Change
  7. Delete
  8. JSON field schemas
    1. Additional fields
  9. Data model
  10. Usage notes

Endpoints

  • Private portal: https://www.brainstem.org/api/private/stem/subject/ (needs a token; one record: append <id>/)
  • Public portal: https://www.brainstem.org/api/public/stem/subject/ (read-only, public projects, no token)
  • Response keys: subject (detail, create, update), subjects (list)
  • Permissions: inherited through projects (from project)
  • Uniqueness: name unique across BrainSTEM
  • Deleting: also deletes the linked experimentalinterface, procedure, subjectlog records; refused (400) while breeding, procedureepisode records point to it; clears the link on specimenset records

Fields

[required] fields must be sent on create; [read-only] fields are returned but cannot be set. A nestable relation can be traversed in filters (filter{field.other}) and sideloaded with include[]=field.*; other relations can only be compared with ids (filter{field}=<id>). See the query syntax.

FieldDescription
idUUID string [read-only]
namestring [required]; max 100 characters
descriptionstring; nullable
projectslist of project ids [required]; nestable
licenseslist of license ids; nestable. Licenses covering this subject for regulatory reporting and compliance
speciesspecies id [required]; nestable
strainstrain id; nullable; nestable. The strain of the subject, when one is defined.
sexone of F, M, U [required]
statusone of planned, active, inactive, transferred, deceased, unknown [required]. Current participation status of the subject in research activities
genetic_linestring; max 100 characters. The genetic line of your subject, e.g., Wild type or local genetic line: PV-Cre x Ai32 line A
genotypestring; max 200 characters. Confirmed genotype, e.g., ‘PV-Cre/wt; Ai32/wt’. BrainSTEM also has Genotyping as a Subject log type, to describe the genotyping procedure and detailed results.
subject_identifierstring; max 100 characters
suppliersupplier id; nullable
breedingbreeding id; nullable; nestable
birth_datedate; nullable
death_datedate; nullable
extra_fieldsJSON object
procedureslist of procedure ids [read-only]; nullable; nestable
subjectlogslist of subjectlog ids [read-only]; nullable; nestable
tagslist of strings; filter with filter{tags.name}=<name>
name_used_in_storagestring; max 200 characters; nullable

List

  • Allowed portals: private, public
  • Request method: GET
  • URL: https://www.brainstem.org/api/private/stem/subject/
  • Responses: 200 OK; 401 Not authenticated; 403 Not allowed

Use example (Python API tool)

resp = client.load('subject', load_all=True)
records = resp['subjects']

Use example (MATLAB API tool)

resp = client.load('subject', 'load_all', true);
records = resp.subjects;

Response example

{
    "subjects": [
        {
            "id": "<id>",
            "name": "Subject 1",
            "description": "",
            "projects": [
                "<project-id>"
            ],
            "licenses": [
                "<license-id>"
            ],
            "species": "<species-id>",
            "strain": "<strain-id>",
            "sex": "F",
            "status": "active",
            "genetic_line": "",
            "genotype": "",
            "subject_identifier": "",
            "supplier": "<supplier-id>",
            "breeding": "<breeding-id>",
            "birth_date": "2024-03-22",
            "death_date": "2024-03-22",
            "extra_fields": {},
            "procedures": [
                "<procedure-id>"
            ],
            "subjectlogs": [
                "<subjectlog-id>"
            ],
            "tags": [],
            "name_used_in_storage": ""
        }
    ],
    "meta": {
        "page": 1,
        "per_page": 100,
        "total_results": 1,
        "total_pages": 1
    }
}

Add

  • Allowed portals: private
  • Request method: POST
  • URL: https://www.brainstem.org/api/private/stem/subject/
  • Data: JSON object with at least the required fields
  • Responses: 201 Created; 400 Bad request (validation errors per field); 403 Not allowed

Use example (Python API tool)

resp = client.save('subject', data={"name": "Subject 1", "projects": ["<project-id>"], "species": "<species-id>", "sex": "F", "status": "active"})
record = resp.json()['subject']

Use example (MATLAB API tool)

created = client.save(struct('name', 'Subject 1', 'projects', {{'<project-id>'}}, 'species', '<species-id>', 'sex', 'F', 'status', 'active'), 'subject');
record = created.subject;

Detail

  • Allowed portals: private, public
  • Request method: GET
  • URL: https://www.brainstem.org/api/private/stem/subject/<id>/
  • Responses: 200 OK; 403 Not allowed; 404 Not found

Use example (Python API tool)

resp = client.load('subject', id='<id>')
record = resp.json()['subject']

Use example (MATLAB API tool)

out = client.load('subject', 'id', '<id>');
record = out.subject;

Response example

{
    "subject": {
        "id": "<id>",
        "name": "Subject 1",
        "description": "",
        "projects": [
            "<project-id>"
        ],
        "licenses": [
            "<license-id>"
        ],
        "species": "<species-id>",
        "strain": "<strain-id>",
        "sex": "F",
        "status": "active",
        "genetic_line": "",
        "genotype": "",
        "subject_identifier": "",
        "supplier": "<supplier-id>",
        "breeding": "<breeding-id>",
        "birth_date": "2024-03-22",
        "death_date": "2024-03-22",
        "extra_fields": {},
        "procedures": [
            "<procedure-id>"
        ],
        "subjectlogs": [
            "<subjectlog-id>"
        ],
        "tags": [],
        "name_used_in_storage": ""
    }
}

Change

  • Allowed portals: private
  • Request method: PATCH
  • URL: https://www.brainstem.org/api/private/stem/subject/<id>/
  • Data: JSON object with the fields to change. Lists (projects, tags, …) and JSON payloads (details, coordinates) are replaced as a whole: read the record first and send the full list or object.
  • Responses: 200 OK; 400 Bad request; 403 Not allowed; 404 Not found

Use example (Python API tool)

resp = client.save('subject', id='<id>', data={"name": "Subject 1 (renamed)"})

Use example (MATLAB API tool)

client.save(struct('id', '<id>', 'name', 'Subject 1 (renamed)'), 'subject', 'method', 'patch');

Delete

  • Allowed portals: private
  • Request method: DELETE
  • URL: https://www.brainstem.org/api/private/stem/subject/<id>/
  • Responses: 204 Deleted; 400 Still referenced by other records; 403 Not allowed; 404 Not found

Use example (Python API tool)

resp = client.delete('subject', id='<id>')

Use example (MATLAB API tool)

client.delete('<id>', 'subject');

JSON field schemas

Schemas for the additional fields of a subject. The REST API returns these JSON fields as stored and validates writes against the schemas below. Every version is published at https://www.brainstem.org/schemas/Subject/<Type>/<version>.json and never changes; see Public schemas.

Additional fields

  • type code Array · version 1.0.1 · schema

Any extra parameters you want to add to this subject. Saved as key-value pairs. Values can be strings or numbers.

PropertyDescription
keytext
valueobject

Illustrative payload:

[
    {
        "key": "text",
        "value": {}
    }
]

Data model

The fields are described for the web forms on the Subject data model page.

Usage notes

  • extra_fields is a JSON object whose keys start with a letter and contain only letters, digits and underscores; values are strings or numbers.