Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add strain optional arg to Subject #1241

Merged
merged 6 commits into from
Jun 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/pynwb/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,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 @@ -56,7 +57,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 @@ -67,6 +69,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 @@ -366,14 +366,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 @@ -387,13 +388,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