Skip to content

Commit b217cd1

Browse files
bendichterrly
andcommitted
add strain optional arg to Subject (#1241)
* 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]>
1 parent 91e11ae commit b217cd1

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

src/pynwb/file.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ class Subject(NWBContainer):
4444
'species',
4545
'subject_id',
4646
'weight',
47-
'date_of_birth'
47+
'date_of_birth',
48+
'strain'
4849
)
4950

5051
@docval({'name': 'age', 'type': str, 'doc': 'the age of the subject', 'default': None},
@@ -55,7 +56,8 @@ class Subject(NWBContainer):
5556
{'name': 'subject_id', 'type': str, 'doc': 'a unique identifier for the subject', 'default': None},
5657
{'name': 'weight', 'type': str, 'doc': 'the weight of the subject', 'default': None},
5758
{'name': 'date_of_birth', 'type': datetime, 'default': None,
58-
'doc': 'datetime of date of birth. May be supplied instead of age.'})
59+
'doc': 'datetime of date of birth. May be supplied instead of age.'},
60+
{'name': 'strain', 'type': str, 'doc': 'the strain of the subject', 'default': None})
5961
def __init__(self, **kwargs):
6062
kwargs['name'] = 'subject'
6163
call_docval_func(super(Subject, self).__init__, kwargs)
@@ -66,6 +68,7 @@ def __init__(self, **kwargs):
6668
self.species = getargs('species', kwargs)
6769
self.subject_id = getargs('subject_id', kwargs)
6870
self.weight = getargs('weight', kwargs)
71+
self.strain = getargs('strain', kwargs)
6972
date_of_birth = getargs('date_of_birth', kwargs)
7073
if date_of_birth and date_of_birth.tzinfo is None:
7174
self.date_of_birth = _add_missing_timezone(date_of_birth)

tests/integration/hdf5/test_nwbfile.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -203,14 +203,15 @@ class TestSubjectIO(NWBH5IOMixin, TestCase):
203203

204204
def setUpContainer(self):
205205
""" Return the test Subject """
206-
return Subject(age='12 mo',
206+
return Subject(age='P90D',
207207
description='An unfortunate rat',
208208
genotype='WT',
209209
sex='M',
210210
species='Rattus norvegicus',
211211
subject_id='RAT123',
212212
weight='2 lbs',
213-
date_of_birth=datetime(1970, 1, 1, 12, tzinfo=tzutc()))
213+
date_of_birth=datetime(1970, 1, 1, 12, tzinfo=tzutc()),
214+
strain='my_strain')
214215

215216
def addContainer(self, nwbfile):
216217
""" Add the test Subject to the given NWBFile """

tests/unit/test_file.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -417,14 +417,15 @@ def test_multi_publications(self):
417417

418418
class SubjectTest(TestCase):
419419
def setUp(self):
420-
self.subject = Subject(age='12 mo',
420+
self.subject = Subject(age='P90D',
421421
description='An unfortunate rat',
422422
genotype='WT',
423423
sex='M',
424424
species='Rattus norvegicus',
425425
subject_id='RAT123',
426426
weight='2 lbs',
427-
date_of_birth=datetime(2017, 5, 1, 12, tzinfo=tzlocal()))
427+
date_of_birth=datetime(2017, 5, 1, 12, tzinfo=tzlocal()),
428+
strain='my_strain')
428429
self.start = datetime(2017, 5, 1, 12, tzinfo=tzlocal())
429430
self.path = 'nwbfile_test.h5'
430431
self.nwbfile = NWBFile('a test session description for a test NWBFile',
@@ -438,13 +439,15 @@ def setUp(self):
438439
subject=self.subject)
439440

440441
def test_constructor(self):
441-
self.assertEqual(self.subject.age, '12 mo')
442+
self.assertEqual(self.subject.age, 'P90D')
442443
self.assertEqual(self.subject.description, 'An unfortunate rat')
443444
self.assertEqual(self.subject.genotype, 'WT')
444445
self.assertEqual(self.subject.sex, 'M')
445446
self.assertEqual(self.subject.species, 'Rattus norvegicus')
446447
self.assertEqual(self.subject.subject_id, 'RAT123')
447448
self.assertEqual(self.subject.weight, '2 lbs')
449+
self.assertEqual(self.subject.date_of_birth, datetime(2017, 5, 1, 12, tzinfo=tzlocal()))
450+
self.assertEqual(self.subject.strain, 'my_strain')
448451

449452
def test_nwbfile_constructor(self):
450453
self.assertIs(self.nwbfile.subject, self.subject)

0 commit comments

Comments
 (0)