예제 #1
0
Run this script by specifying the CSV file as an argument:
python add_subjects_from_csv.py subjects.csv

NOTE: this script assumes you have already added the required strains.

CSV FORMAT (example):
subject_id,sex,date_of_birth,strain_name,species
testcsv001,U,2020-02-01,C57BL/6J,Mus musculus
testcsv002,U,2020-02-01,C57BL/6J,Mus musculus
"""

import sys
import csv
import uobrainflex.utils.djconnect
from uobrainflex.pipeline import subject as subjectSchema


if len(sys.argv) < 2:
    raise ValueError('You need to specify a CSV file with subject information.')

filename = sys.argv[1]

subjectTable = subjectSchema.Subject()

with open(filename) as csvfile:
    reader = csv.DictReader(csvfile)
    for oneSubject in reader:
        subjectTable.insert1(oneSubject, skip_duplicates=True)
        print(oneSubject)
        
예제 #2
0
"""
Provides an interface to add or delete items from a DataJoint database.
"""

from uobrainflex.utils import djtools
from uobrainflex.pipeline import subject as subjectSchema
from uobrainflex.pipeline import acquisition as acquisitionSchema
from uobrainflex.pipeline import experimenter as experimenterSchema

specialFormat = {'date_of_birth': 'YYYY-MM-DD', 'sex': 'M/F/U'}

subject = subjectSchema.Subject()
strain = subjectSchema.Strain()
species = subjectSchema.Species()
behaviorSession = acquisitionSchema.BehaviorSession()
lab = experimenterSchema.Lab()
experimenter = experimenterSchema.Experimenter()

tablesDict = {
    'subject': subject,
    'strain': strain,
    'species': species,
    'behavior_session': behaviorSession,
    'lab': lab,
    'experimenter': experimenter
}
tableNames = list(tablesDict)

# -- Get primary keys --
primaryKeys = []
for tableName, tableDB in tablesDict.items():
예제 #3
0
def submit_behavior_session(nwbFullpath):
    """
    Add behavior session metadata to DataJoint database.

    Args:
        nwbFullpath (str): full path to NWB data file to register with the DJ.

    Returns:
        djBehaviorSession: DataJoint object pointing to the table of behavior sessions.
    """

    # -- Load metadata from the NWB file --
    ioObj = pynwb.NWBHDF5IO(nwbFullpath, 'r', load_namespaces=True)
    nwbFileObj = ioObj.read()
    #nwbFileObj = load.load_nwb_file(nwbFullpath)

    sessionID = nwbFileObj.identifier
    subject = nwbFileObj.subject.subject_id
    experimenter = nwbFileObj.experimenter[0]  # Use only first experimenter
    startTime = nwbFileObj.session_start_time
    sessionType = nwbFileObj.lab_meta_data['metadata'].session_type
    trainingStage = nwbFileObj.lab_meta_data['metadata'].training_stage
    behaviorVersion = nwbFileObj.lab_meta_data['metadata'].behavior_version
    performance_dict = performance.get_summary(nwbFileObj)
    licks_total = performance_dict['licks_total']
    licks_left_ratio = performance_dict['licks_left_ratio']
    choices_total = performance_dict['choices_total']
    choices_left_stim_ratio = performance_dict['choices_left_stim_ratio']
    hits_total = performance_dict['hits_total']
    hits_left_ratio = performance_dict['hits_left_ratio']
    hit_rate_left = performance_dict['hit_rate_left']
    hit_rate_right = performance_dict['hit_rate_right']

    ioObj.close()
    filename = os.path.basename(nwbFullpath)

    # -- Get access to the database tables --
    djSubject = subjectSchema.Subject()
    djExperimenter = experimenterSchema.Experimenter()
    #djSessionType = acquisitionSchema.BehaviorSessionType()
    #djTrainingStage = acquisitionSchema.BehaviorTrainingStage()
    djBehaviorSession = acquisitionSchema.BehaviorSession()

    if subject not in djSubject.fetch('subject_id'):
        errMsg = 'You need to add new subjects manually before adding sessions.'
        raise Exception(errMsg)

    if experimenter not in djExperimenter.fetch('experimenter_id'):
        errMsg = 'You need to add new experimenters manually before adding sessions.'
        raise Exception(errMsg)

    #djSessionType.insert1([sessionType], skip_duplicates=True)
    #djTrainingStage.insert1([trainingStage], skip_duplicates=True)

    # See pipeline.acquisition for order of attributes
    newSession = (sessionID, subject, startTime, sessionType, trainingStage,
                  experimenter, filename, behaviorVersion, licks_total,
                  licks_left_ratio, choices_total, choices_left_stim_ratio,
                  hits_total, hits_left_ratio, hit_rate_left, hit_rate_right,
                  None)

    # FIXME: currently it defaults to replace
    djBehaviorSession.insert1(newSession, replace=True)
    print("Submitted session '{}' to DataJoint.".format(sessionID))

    return djBehaviorSession