Skip to content

Commit

Permalink
add strain optional arg to Subject (#1241)
Browse files Browse the repository at this point in the history
* remove validate_core_schema.

You can check the core schema with e.g.

* Update Subject unit test

* Fix Subject unit test, add check for date_of_birth

Co-authored-by: Ryan Ly <[email protected]>
  • Loading branch information
bendichter and rly committed May 18, 2021
1 parent 130665a commit 36a46b3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
7 changes: 5 additions & 2 deletions src/pynwb/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ class Subject(NWBContainer):
'species',
'subject_id',
'weight',
'date_of_birth'
'date_of_birth',
'strain'
)

@docval({'name': 'age', 'type': str, 'doc': 'the age of the subject', 'default': None},
Expand All @@ -55,7 +56,8 @@ class Subject(NWBContainer):
{'name': 'subject_id', 'type': str, 'doc': 'a unique identifier for the subject', 'default': None},
{'name': 'weight', 'type': str, 'doc': 'the weight of the subject', 'default': None},
{'name': 'date_of_birth', 'type': datetime, 'default': None,
'doc': 'datetime of date of birth. May be supplied instead of age.'})
'doc': 'datetime of date of birth. May be supplied instead of age.'},
{'name': 'strain', 'type': str, 'doc': 'the strain of the subject', 'default': None})
def __init__(self, **kwargs):
kwargs['name'] = 'subject'
call_docval_func(super(Subject, self).__init__, kwargs)
Expand All @@ -66,6 +68,7 @@ def __init__(self, **kwargs):
self.species = getargs('species', kwargs)
self.subject_id = getargs('subject_id', kwargs)
self.weight = getargs('weight', kwargs)
self.strain = getargs('strain', kwargs)
date_of_birth = getargs('date_of_birth', kwargs)
if date_of_birth and date_of_birth.tzinfo is None:
self.date_of_birth = _add_missing_timezone(date_of_birth)
Expand Down
5 changes: 3 additions & 2 deletions tests/integration/hdf5/test_nwbfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,14 +203,15 @@ class TestSubjectIO(NWBH5IOMixin, TestCase):

def setUpContainer(self):
""" Return the test Subject """
return Subject(age='12 mo',
return Subject(age='P90D',
description='An unfortunate rat',
genotype='WT',
sex='M',
species='Rattus norvegicus',
subject_id='RAT123',
weight='2 lbs',
date_of_birth=datetime(1970, 1, 1, 12, tzinfo=tzutc()))
date_of_birth=datetime(1970, 1, 1, 12, tzinfo=tzutc()),
strain='my_strain')

def addContainer(self, nwbfile):
""" Add the test Subject to the given NWBFile """
Expand Down
9 changes: 6 additions & 3 deletions tests/unit/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,14 +417,15 @@ def test_multi_publications(self):

class SubjectTest(TestCase):
def setUp(self):
self.subject = Subject(age='12 mo',
self.subject = Subject(age='P90D',
description='An unfortunate rat',
genotype='WT',
sex='M',
species='Rattus norvegicus',
subject_id='RAT123',
weight='2 lbs',
date_of_birth=datetime(2017, 5, 1, 12, tzinfo=tzlocal()))
date_of_birth=datetime(2017, 5, 1, 12, tzinfo=tzlocal()),
strain='my_strain')
self.start = datetime(2017, 5, 1, 12, tzinfo=tzlocal())
self.path = 'nwbfile_test.h5'
self.nwbfile = NWBFile('a test session description for a test NWBFile',
Expand All @@ -438,13 +439,15 @@ def setUp(self):
subject=self.subject)

def test_constructor(self):
self.assertEqual(self.subject.age, '12 mo')
self.assertEqual(self.subject.age, 'P90D')
self.assertEqual(self.subject.description, 'An unfortunate rat')
self.assertEqual(self.subject.genotype, 'WT')
self.assertEqual(self.subject.sex, 'M')
self.assertEqual(self.subject.species, 'Rattus norvegicus')
self.assertEqual(self.subject.subject_id, 'RAT123')
self.assertEqual(self.subject.weight, '2 lbs')
self.assertEqual(self.subject.date_of_birth, datetime(2017, 5, 1, 12, tzinfo=tzlocal()))
self.assertEqual(self.subject.strain, 'my_strain')

def test_nwbfile_constructor(self):
self.assertIs(self.nwbfile.subject, self.subject)
Expand Down

0 comments on commit 36a46b3

Please sign in to comment.