# ==================== subject ==================== fnames = np.hstack( glob.glob(os.path.join(dir_files[0], '*.mat')) for dir_files in os.walk(path) if len(dir_files[1]) == 0) for fname in fnames: mat = sio.loadmat(fname, struct_as_record=False, squeeze_me=True) mat_units = mat['unit'] mat_trial_info = mat.get('trial_info') this_sess = meta_data.loc[re.sub('_units.mat|_JRC_units', '', os.path.split(fname)[-1])] print(f'\nReading: {this_sess.name}') subject_info = dict( subject_id=this_sess.subject_id.lower(), date_of_birth=utilities.parse_date(str(this_sess.date_of_birth)), sex=this_sess.sex[0].upper(), species='Mus musculus', # not available, hard-coded here animal_source='N/A') # animal source not available from data allele_dict = { alias.lower(): allele for alias, allele in subject.AlleleAlias.fetch() } regex_str = '|'.join([re.escape(alias) for alias in allele_dict.keys()]) alleles = [ allele_dict[s.lower()] for s in re.findall(regex_str, this_sess.genotype, re.I) ] with subject.Subject.connection.transaction:
path = os.path.join('.', 'data', 'data', 'L4FS_loose_seal_ION_cut') fname = 'JY1589AAAA.nwb' nwb = h5.File(os.path.join(path, fname), 'r') subject_info = { c: nwb['general']['subject'][c].value.decode('UTF-8') for c in ('subject_id', 'description', 'sex', 'species', 'weight', 'age', 'genotype') } # force subject_id to be lower-case for consistency subject_info['subject_id'] = subject_info['subject_id'].lower() # dob and sex subject_info['sex'] = subject_info['sex'][0].upper() dob_str = re.search('(?<=Date of birth:\s)(.*)', subject_info['description']) if utilities.parse_date(dob_str.group()) is not None: subject_info['date_of_birth'] = utilities.parse_date(dob_str.group()) # allele allele_str = re.search('(?<=Animal Strain:\s)(.*)', subject_info['description']).group( ) # extract the information related to animal allele allele_dict = { alias.lower(): allele for alias, allele in subject.AlleleAlias.fetch() } regex_str = '|'.join([re.escape(alias) for alias in allele_dict.keys()]) alleles = [ allele_dict[s.lower()] for s in re.findall(regex_str, allele_str, re.I) ] # source
for fname in fnames: print(f'Reading {fname}...') nwb = h5.File(fname, 'r') subject_info = { c: nwb['general']['subject'][c].value.decode('UTF-8') for c in ('description', 'sex', 'species', 'weight', 'age', 'genotype') } # force subject_id to be lower-case for consistency subject_info['subject_id'] = os.path.split(fname)[-1].split('_')[0].lower() # dob and sex subject_info['sex'] = subject_info['sex'][0].upper() dob_str = re.search('(?<=Date of birth:\s)(.*)', subject_info['description']) if utilities.parse_date(dob_str.group()) is not None: subject_info['date_of_birth'] = utilities.parse_date(dob_str.group()) # allele allele_str = re.search( '(?<=Animal Strain:\s)(.*)', subject_info['description']).group( ) # extract the information related to animal allele allele_dict = { alias.lower(): allele for alias, allele in subject.AlleleAlias.fetch() } regex_str = '|'.join([re.escape(alias) for alias in allele_dict.keys()]) alleles = [ allele_dict[s.lower()] for s in re.findall(regex_str, allele_str, re.I) ] # source
subject_id, session_time = sess_meta.filename.replace( '.mat', '').split('_')[-2:] # --- Subject - No info on: animal sex, dob, source, strains subject_info = dict( subject_id=subject_id.lower(), species='Mus musculus', # not available, hard-coded here animal_source='N/A' ) # animal source not available from data, nor 'sex' subject.Subject.insert1(subject_info, skip_duplicates=True) # --- Session - no session types session_info = dict(subject_id=subject_info['subject_id'], session_id=sess_idx, session_time=utilities.parse_date(session_time)) experimenters = ['Mike Economo'] # hard-coded here with acquisition.Session.connection.transaction: if session_info not in acquisition.Session.proj(): acquisition.Session.insert1(session_info, ignore_extra_fields=True) acquisition.Session.Experimenter.insert( (dict(session_info, experimenter=k) for k in experimenters), ignore_extra_fields=True) print( f'\nCreating Session - Subject: {subject_info["subject_id"]} - Date: {session_info["session_time"]}' )
for fname in fnames: print(f'Reading {fname}...') nwb = h5.File(fname, 'r') subject_info = { c: nwb['general']['subject'][c].value.decode('UTF-8') for c in ('subject_id', 'description', 'sex', 'species', 'weight', 'age', 'genotype') } # force subject_id to be lower-case for consistency subject_info['subject_id'] = subject_info['subject_id'].lower() # dob and sex subject_info['sex'] = subject_info['sex'][0].upper() dob_str = re.search('(?<=Date of birth:\s)(.*)', subject_info['description']) if utilities.parse_date(dob_str.group()) is not None: subject_info['date_of_birth'] = utilities.parse_date(dob_str.group()) # allele allele_str = re.search( '(?<=Animal Strain:\s)(.*)', subject_info['description']).group( ) # extract the information related to animal allele allele_dict = { alias.lower(): allele for alias, allele in subject.AlleleAlias.fetch() } regex_str = '|'.join([re.escape(alias) for alias in allele_dict.keys()]) alleles = [ allele_dict[s.lower()] for s in re.findall(regex_str, allele_str, re.I) ] # source