Data Application

The data module describes the conditions and collection of data regarding experimental animals.

Data (or Measurement) can be stored for any type of Experiment. Conceptually, several pieces of data belong to an experiment (for example several Animal are measured at some time) and several Experiment belong to a Study.

Measurements can be stored independent of experiments and experiments can be performed outside of the context of a study. It is however, perfered that measurements are stored within an experiment and experiments are stored within studies as this will greatly facilitate the organization of the data.

Studies

In general studies are a collection of experiments. This is a large class which can contain several Experiment objects. Within a study two classes control how data is stored, Treatment and Cohort.

Treatments

A Treatment is a group of Animal that are grouped together based on some manipulation, which could be a Pharmaceutical, Diet, Implantation or some other manipulation. Generally a Study will have two or more Treatment groups.

Cohorts

For the same Treatment groups, within a Study, there may be several independent replicates of those treatment. A replicate are called Cohort. For example, there could be a Treatment in which some mice get a particular Diet, while other mice get a diffferent Diet. These two Treatment groups are designated within a cohort. Later on, using different Animal sets, this Study will be repeated. While the Treatment groupings are the same, the different series’ of Experiment will be separated by being part of a different Cohort.

Experiments

An experiment is a collection of measurements for a given set of animals. In general, an experiment is defined as a number of measurements take in a given day.

Measurements

A measurement is an animal, an assay and a measurement value. It can be associated with an experiment, or can stand alone as an individual value. Measurements can be viewed in the context of a study, an experiment, a treatment group or an animal by going to the appropriate page.

Data API Access

This package controls API access to the data app.

Overview

The API for the data application provides data on measurements and their associated data types. A list of all endpoints and links to their schemas are available at http://yourserver.org/api/v1/ where yourserver is specific to your installation. There are four access points, each of which is available using GET requests only:

  • measurements are available at the endpoint http://yourserver.org/api/v1/data/
  • assays are available at the endpoint http://yourserver.org/api/v1/assay/
  • experiments are available at the endpoint http://yourserver.org/api/v1/experiment/
  • studies are available at the endpoint http://yourserver.org/api/v1/study/

The data can be provided as either a group of objects or as a single object. Currently for all requests, no authentication is required.

The entire API schema is available from each endpoint at:

/schema/?format=xml
/schema/?format=json

For example http://yourserver.org/api/v1/study/schema/?format=json.

Sample Code

Either group requests or single object requests can be served depending on if the primary key is provided. The request URI has several parts including the servername, the api version (currently v1) then the item type (data, assay, experiment or study). There must be a trailing slash before the request parameters (which are after a ? sign and separated by a & sign).

For a collection of objects

For a collection of measurements you can request:

http://yourserver.org/api/v1/data/?format=json 

This would return all measurements in the database. This would return the response with two JSON objects, meta and objects. The format=json parameter is default for curl and not required but is necessary for browser requests. The meta object contains fields for the limit, next, offset, previous and total_count for the series of objects requested. The objects portion is an array of the returned object fields (see the details below for each API). Note the id field of an object. This is used for retrieving a single object. Collections can also be filtered based on several request parameters (see below for details for each API):

http://yourserver.org/api/v1/data/ #returns all data in JSON format 
http://yourserver.org/api/v1/experiment/set/1;3/?format=json #returns the experiments with id numbers 1 and 3 in XML format.                    

For a single object

To retrieve a single item you need to know the primary key of the object. This can be found from the id parameter of a collection (see above) or from the actual object page. You can retrieve details about a single assay with a call such as:

http://yourserver.org/api/v1/assay/2/?format=json  

In this case 2 is the primary key (or id field) of the assay in question.

Reference for Measurement API

The measurement API is available at the endpoint /api/v1/data/

Request Parameters

The following are the potential request variables, all of which are optional. The default format is JSON, but this can be set as XML if required. If viewing by web browser ?format=json must be specified By default 20 items are returned but you can increase this to all by setting limit=0.

Parameter Potential Values
format json or xml
limit 0 for all, any other number

Response Values

The response (in either JSON or XML) provides the following fields for each object (or for the only object in the case of a single object request).

Field Explanation Sample Value
id the id of the measurement 1
resource_uri the URI to request details about a measurement /api/v1/data/1/
values the measurement, or measurement(s) 423

Reference for the Assay API

The assay API is available at the endpoint /api/v1/assay/

Request Parameters

The following are the potential request variables, all of which are optional. The default format is JSON, but this can be set as XML if required. If viewing by web browser ?format=json must be specified By default 20 items are returned but you can increase this to all by setting limit=0.

Parameter Potential Values
format json or xml
limit 0 for all, any other number

Response Values

The response (in either JSON or XML) provides the following fields for each object (or for the only object in the case of a single object request).

Field Explanation Sample Value
id the id of the measurement 3
resource_uri the URI to request details about a measurement /api/v1/assay/3/
assay the name of the assay Body Weight
assay_slug the slugified name of the assay (can be used for filtering) body_weight
measurement_units the units for the measurment mg/dL
notes notes regarding this assay Some text values

Reference for the Experiment API

The experiment API is available at the endpoint /api/v1/experiment/

Request Parameters

The following are the potential request variables, all of which are optional. The default format is JSON, but this can be set as XML if required. If viewing by web browser ?format=json must be specified By default 20 items are returned but you can increase this to all by setting limit=0.

Parameter Potential Values
format json or xml
limit 0 for all, any other number

Response Values

The response (in either JSON or XML) provides the following fields for each object (or for the only object in the case of a single object request).

Field Explanation Sample Value
id the id of the measurement 5
resource_uri the URI to request details about a measurement /api/v1/experiment/5/
concentration the concentration of the injection (if done) 1mU/kg
date the date of the experiment 2012-09-28
experimentID the optional experimentID number DB-2012-09-28
fasting_time the duration of the animal fast (if done) in hours 16
feeding_state whether the animals were fed or fasted fed OR fasted
injection the injection (if done) Insulin, Glucose, Pyruvate or Glucagon
notes notes regarding this experiment Some text values
time the time of day the assay was done (24h format) 16:00

Reference for the Study API

The study API is available at the endpoint /api/v1/study/

Request Parameters

The following are the potential request variables, all of which are optional. The default format is JSON but this can be set as XML if required. If viewing by web browser ?format=json must be specified By default 20 items are returned but you can increase this to all by setting limit=0.

Parameter Potential Values
format json or xml
limit 0 for all, any other number

Response Values

The response (in either JSON or XML) provides the following fields for each object (or for the only object in the case of a single object request).

Field Explanation Sample Value
id the id of the measurement 6
resource_uri the URI to request details about a measurement /api/v1/study/6/
description the description of the study some text
notes some notes about the study some text
start_date the optional starting date of the study 2012-07-23
stop _date the optional end date of the study 2012-09-27
class mousedb.data.api.AssayResource(api_name=None)

This generates the API resource for Assay objects.

It returns all assays in the database.

class Meta

The API serves all Assay objects in the database..

object_class

alias of Assay

class mousedb.data.api.ExperimentResource(api_name=None)

This generates the API resource for Experiment objects.

It returns all experiments in the database.

class Meta

The API serves all Experiment objects in the database..

object_class

alias of Experiment

class mousedb.data.api.MeasurementAssayResource(api_name=None)

This generates serves Assay objects.

This is a limited dataset for use in MeasurementResource calls.

class Meta

The API serves all Assay objects in the database..

class mousedb.data.api.MeasurementResource(api_name=None)

This generates the API resource for Measurement objects.

It returns all measurements in the database.

class Meta

The API serves all Measurement objects in the database..

object_class

alias of Measurement

class mousedb.data.api.StudyResource(api_name=None)

This generates the API resource for Study objects.

It returns all studies in the database.

class Meta

The API serves all Study objects in the database..

object_class

alias of Study

Data Models

class mousedb.data.models.Assay(*args, **kwargs)

Assay(id, assay, assay_slug, notes, measurement_units)

class mousedb.data.models.Cohort(*args, **kwargs)

A Cohort is a group of Animals.

Generally a cohort is an experimental replicate of a Treatment as part of a Study. Cohorts are also generally defined by starting and ending dates. A cohort would generally comprise both Treatment groups being compared. The required fields are name (which must be unique to this cohort) and animals.

get_absolute_url(*moreargs, **morekwargs)

The url for a treatment-detail is /cohort/<id>.

save(*args, **kwargs)

The slug field is auto-populated during the save from the name field.

class mousedb.data.models.Diet(*args, **kwargs)

Diet(id, vendor_id, description, product_id, fat_content, protein_content, carb_content, irradiated, notes)

class mousedb.data.models.Environment(*args, **kwargs)

Environment(id, building, room, temperature, humidity, notes)

class mousedb.data.models.Experiment(*args, **kwargs)

This class describes Experiment objects.

This object describes the aspects of an experiment done on several Animal objects. This object describes the conditions under which the experiment ws done. The results of the experiment are contained in Measurement objects and grouped together in Treatment objects. Experiments may or may not be part of a Study. The required fields for this object are date, Researchers and feeding state. The optional fields are notes, time, experimentID, fasting_time, injection and concentration and the Study.

get_absolute_url(*moreargs, **morekwargs)

The absolute url of an experiment is /mousedb/experiment/id </mousedb/experiment/id>.

class mousedb.data.models.Implantation(*args, **kwargs)

Implantation(id, implant, vendor_id, product_id, notes)

class mousedb.data.models.Measurement(*args, **kwargs)

Measurement(id, animal_id, experiment_id, assay_id, values)

class mousedb.data.models.Pharmaceutical(*args, **kwargs)

This class defines a drug treatment.

Each object is specific to a particular vendor, dose and mode of delivery. For other doses, generate additional Pharmaceutical objects. The required fields are drug, dose, recurrance, mode and vendor.

get_absolute_url(*moreargs, **morekwargs)

The absolute url of a Pharmaceutical is /parameter/pharmaceutical/<id>.

class mousedb.data.models.Researcher(*args, **kwargs)

Researcher(id, first_name, last_name, name_slug, email, active)

class mousedb.data.models.Study(*args, **kwargs)

Study(id, description, start_date, stop_date, notes)

class mousedb.data.models.Transplantation(*args, **kwargs)

Transplantation(id, tissue, transplant_date, notes)

class mousedb.data.models.Treatment(*args, **kwargs)

This model defines the groupings of mice for an experiment.

The purpose of treatment groups is to associate together animals which are treated similarly in a study. A treatment group is generally defined by its specific conditions, including:

The required fields are the associated Study, the name (treatment), the Animal objects in this group and the Researcher objects in the group. There is also an optional notes field.

get_absolute_url(*moreargs, **morekwargs)

The url for a treatment-detail is /treatment/<id>.

class mousedb.data.models.Vendor(*args, **kwargs)

Vendor(id, vendor, website, email, ordering, notes)

Data Views and URLs

Cohort URLS

Url redirections for Cohort objects.

This includes generic create, update, delete, list and detail views. The views for these urls are defined in the module.

Experiment URLS

Parameter URLS

Study URLS

This URLconf defines the routing of pages for study objects.

This includes generic views for study list, study details and create, change and delete studies.

Treatment URLS

Url redirections for treatment objects.

This includes gneeric create, update, delete, list and detail views. These are restricted by login required (for detail and list) and appropriate permissions for forms.

Views

class mousedb.data.views.CohortCreate(**kwargs)

This view generates a form for creating a Cohort object.

This view is restricted to logged in users with the create-cohort permission. It is generated when the url /cohort/new is requested.

model

alias of Cohort

class mousedb.data.views.CohortDelete(**kwargs)

This view generates a view for deleting Cohort objects.

This view is restricted to logged in users with the delete-cohort permision. It passes an object cohort when the url /cohort/<slug>/delete is requested.

model

alias of Cohort

class mousedb.data.views.CohortDetail(**kwargs)

This view generates details about a Cohort object.

This view is restricted to logged in users. It passes an object cohort when the url /cohort/<slug> is requested.

model

alias of Cohort

class mousedb.data.views.CohortList(**kwargs)

This view generates list of Cohort objects.

This view is restricted to logged in users. It passes an object cohort_list when the url /cohort is requested.

model

alias of Cohort

class mousedb.data.views.CohortMeasurementCreate(**kwargs)

This view is for adding measurements for each animal in a cohort.

This view is restricted to logged in users with the add-measurement permision. It passes two objects, cohort and form when the url /cohort/<slug>/measurements is requested.

form_class

alias of MeasurementForm

model

alias of Measurement

class mousedb.data.views.CohortUpdate(**kwargs)

This view generates a form for updating Cohort objects.

This view is restricted to logged in users with the update-cohort permision. It passes an object object when the url /cohort/<slug>/edit is requested.

model

alias of Cohort

class mousedb.data.views.PharmaceuticalCreate(**kwargs)

This view generates a form for creating a Pharmaceutical object.

This view is restricted to logged in users with the create-pharmaceutical permission. It is generated when the url /parameter/pharmaceutical/new is requested.

model

alias of Pharmaceutical

class mousedb.data.views.PharmaceuticalDelete(**kwargs)

This view generates a view for deleting Pharmaceutical objects.

This view is restricted to logged in users with the delete-pharmaceutical permision. It passes an object pharmaceutical when the url /parameter/pharmaceutical/<id>/delete is requested.

model

alias of Pharmaceutical

class mousedb.data.views.PharmaceuticalDetail(**kwargs)

This view generates details about a Pharmaceutical object.

This view is restricted to logged in users. It passes an object pharmaceutical when the url /parameter/pharmaceutical/<id> is requested.

model

alias of Pharmaceutical

class mousedb.data.views.PharmaceuticalList(**kwargs)

This view generates list of Pharmaceutical objects.

This view is restricted to logged in users. It passes an object pharmaceutical when the url /parameter/pharmaceutical is requested.

model

alias of Pharmaceutical

class mousedb.data.views.PharmaceuticalUpdate(**kwargs)

This view generates a form for updating Pharmaceutical objects.

This view is restricted to logged in users with the update-pharmaceutical permision. It passes an object pharmaceutical when the url /parameter/pharmaceutical/<id>/edit is requested.

model

alias of Pharmaceutical

class mousedb.data.views.TreatmentDetail(**kwargs)

This view generates details about a Treatment object.

This view is restricted to logged in users. It passes an object treatment when the url /treatment/<pk#> is requested.

model

alias of Treatment

class mousedb.data.views.TreatmentList(**kwargs)

This view generatea list of a Treatment objects.

This view is restricted to logged in users. It passes an object treatment_list when the url /treatment is requested.

model

alias of Treatment

mousedb.data.views.add_measurement(request, *args, **kwargs)

This is a view to display a form to add single measurements to an experiment.

It calls the object MeasurementForm, which has an autocomplete field for animal.

mousedb.data.views.aging_csv(request)

This view generates a csv output file of all animal data for use in aging analysis.

The view writes to a csv table the animal, strain, genotype, age (in days), and cause of death.

mousedb.data.views.all_data_csv(request)

This view generates a csv output of all data for a strain.

mousedb.data.views.experiment_details_csv(request, experiment_id)

This view generates a csv output file of an experiment.

The view writes to a csv table the animal, genotype, age (in days), assay and values.

mousedb.data.views.litters_csv(request)

This view generates a csv output file of all animal data for use in litter analysis.

The view writes to a csv table the birthdate, breeding cage and strain.

Administrative Interface

Data Unit Tests

This file contains tests for the data application.

These tests will verify generation of new experiment, measurement, assay, researcher, study, treatment, vendor, diet, environment, implantation, transplantation and pharnaceutical objects.

class mousedb.data.tests.BasicTestCase(methodName='runTest')

This class factors out the TestcCase setup and Teardown code.

setUp()

Instantiate the test client.

tearDown()

Depopulate created model instances from test database.

class mousedb.data.tests.CohortModelTests(methodName='runTest')

These tests test the functionality of Cohort objects.

test_cohort_absolute_url()

This tests the absolute_url generation of a Cohort.

test_cohort_unicode()

This tests the unicode representation of a Cohort.

test_create_cohort_all()

This test creates a Cohort with all information entered.

test_create_cohort_minimum()

This test creates a Cohort with the required information only.

class mousedb.data.tests.CohortViewTests(methodName='runTest')

This class tests the views for Cohort objects.

test_cohort_list()

This tests the cohort-list view, ensuring that templates are loaded correctly.

This view uses a user with superuser permissions so does not test the permission levels for this view.

test_cohort_view()

This tests the cohort-view view, ensuring that templates are loaded correctly.

This view uses a user with superuser permissions so does not test the permission levels for this view.

test_cohort_view_create()

This tests the cohort-new view, ensuring that templates are loaded correctly.

This view uses a user with superuser permissions so does not test the permission levels for this view.

test_cohort_view_delete()

This tests the cohort-delete view, ensuring that templates are loaded correctly.

This view uses a user with superuser permissions so does not test the permission levels for this view.

test_cohort_view_edit()

This tests the cohort-edit view, ensuring that templates are loaded correctly.

This view uses a user with superuser permissions so does not test the permission levels for this view.

class mousedb.data.tests.PharmaceuticalModelTests(methodName='runTest')

These tests test the functionality of Pharmaceutical objects.

test_create_pharmaceutical_all()

This test creates a Pharmaceutical with all information entered.

test_create_pharmaceutical_minimum()

This test creates a Pharmaceutical with the required information only.

test_pharmaceutical_absolute_url()

This tests the absolute_url generation of a Pharmaceutical.

test_pharmaceutical_unicode()

This tests the unicode representation of a Pharmaceutical.

class mousedb.data.tests.PharmaceuticalViewTests(methodName='runTest')

This class tests the views for Pharmaceutical objects.

test_pharmaceutical_list()

This tests the pharmaceutical-list view, ensuring that templates are loaded correctly.

This view uses a user with superuser permissions so does not test the permission levels for this view.

test_pharmaceutical_view()

This tests the pharmaceutical-view view, ensuring that templates are loaded correctly.

This view uses a user with superuser permissions so does not test the permission levels for this view.

test_pharmaceutical_view_create()

This tests the pharmaceutical-new view, ensuring that templates are loaded correctly.

This view uses a user with superuser permissions so does not test the permission levels for this view.

test_pharmaceutical_view_delete()

This tests the pharmaceutical-delete view, ensuring that templates are loaded correctly.

This view uses a user with superuser permissions so does not test the permission levels for this view.

test_pharmaceutical_view_edit()

This tests the pharmaceutical-edit view, ensuring that templates are loaded correctly.

This view uses a user with superuser permissions so does not test the permission levels for this view.

class mousedb.data.tests.StudyModelTests(methodName='runTest')

Test the creation and modification of Study objects.

test_create_studey_detailed()

This is a test for creating a new study object, with all fields being entered. It also verifies that unicode is set correctly. This test is dependent on the ability to create a new Strain object (see animal.tests.StrainModelTests.test_create_minimal_strain).

test_create_study_minimal()

This is a test for creating a new study object, with only the minimum being entered. It also verifies that unicode is set correctly.

test_study_absolute_url()

This test verifies that the absolute url of a study object is set correctly. This study is dependend on a positive result on test_create_study_minimal.

class mousedb.data.tests.StudyViewTests(methodName='runTest')

These tests test the views associated with Study objects.

test_study_delete()

This test checks the view which displays a study detail page. It checks for the correct templates and status code.

test_study_detail()

This test checks the view which displays a study detail page. It checks for the correct templates and status code.

test_study_edit()

This test checks the view which displays a study edit page. It checks for the correct templates and status code.

test_study_list()

This test checks the status code, and templates for study lists.

test_study_new()

This test checks the view which displays a study creation page. It checks for the correct templates and status code.

class mousedb.data.tests.TreatmentModelTests(methodName='runTest')

These tests test the functionality of Treatment objects.

test_create_treatment_all()

This test creates a Treatment with all information entered.

test_create_treatment_minimum()

This test creates a Treatment with the required information only.

test_treatment_absolute_url()

This tests the absolute_url generation of a Treatment.

test_treatment_unicode()

This tests the unicode representation of a Treatment.

class mousedb.data.tests.TreatmentViewTests(methodName='runTest')

These tests test the views associated with Treatment objects.

test_treatment_detail()

This test checks the view which displays a treatment-detail page.

It checks for the correct templates and status code.

test_treatment_list()

This tests the treatment-list view, ensuring that templates are loaded correctly.

This view uses a user with superuser permissions so does not test the permission levels for this view.

Data Utilities

class mousedb.data.forms.ExperimentForm(data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=<class 'django.forms.util.ErrorList'>, label_suffix=':', empty_permitted=False, instance=None)

This is the configuration for the experiment form.

This form is used to set up and modify an experiment. It uses a datepicker widget for the date.

class mousedb.data.forms.MeasurementForm(data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=<class 'django.forms.util.ErrorList'>, label_suffix=':', empty_permitted=False, instance=None)

Form definition for adding and editing measurements.

This form is used for adding or modifying single measurements from within an experiment. It has an autocomplete field for animal.

class mousedb.data.forms.StudyExperimentForm(data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=<class 'django.forms.util.ErrorList'>, label_suffix=':', empty_permitted=False, instance=None)

This is the configuration for a study form (From an experiment).

This hides the study field which will be automatically set upon save.

class mousedb.data.forms.StudyForm(data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=<class 'django.forms.util.ErrorList'>, label_suffix=':', empty_permitted=False, instance=None)

This is the configuration for the study form.

This form is used to create and modify studies. It uses an autocomplete widget for the animals.

class mousedb.data.forms.TreatmentForm(data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=<class 'django.forms.util.ErrorList'>, label_suffix=':', empty_permitted=False, instance=None)

Form class for study treatment groups.

In the case of studies, animals are defined in the treatment group rather than in the study group. A treatment consists of a study, a set of animals and the conditions which define that treatment. This includes related fields for environment, diet, implants and transplants.