Пример #1
0
    def __init__(self, pathDict):
        # Parse L_modified file
        self.pathLmod = os.path.join(pathDict['Preferences'], 'L_modified.mat')
        prepcommon._testfile(self.pathLmod)
        self.allen = pymatreader.read_mat(self.pathLmod)['L']

        # Parse sessions file
        pathSessions = os.path.join(pathDict['Preferences'],
                                    'sessions_aud.csv')
        self.dfSession = pd.read_csv(pathSessions, sep='\t')

        # Find parse TGT files
        self.dataPaths = pd.DataFrame(columns=[
            'mouse',
            'day',
            'session',
            'sessionPath',  #'trialIndPath',
            'trialStructPath',
            'pathActivePassive',
            'pathMovementVectors'
        ])

        self.pathT1 = defaultdict(dict)
        self.find_parse_data_paths(pathDict['AUD'])

        # Find parse Overlay
        # self.pathRef = {}
        self.pathT2 = {}
        self.find_parse_overlay(pathDict['Overlay'])
    def __init__(self, pathDict):
        # Parse L_modified file
        self.pathLmod = os.path.join(pathDict['Preferences'], 'L_modified.mat')
        prepcommon._testfile(self.pathLmod)
        self.allen = pymatreader.read_mat(self.pathLmod)['L']

        # Parse sessions file
        pathSessions = os.path.join(pathDict['Preferences'], 'sessions_tex.csv')
        self.dfSession = pd.read_csv(pathSessions, sep='\t')

        # with open(pathSessions, 'r') as json_file:
        #     self.sessions = json.load(json_file)

        # Find parse TGT files
        self.dataPaths = pd.DataFrame(
            columns=['mouse', 'day', 'session', 'sessionPath',
                     'trialIndPath', 'trialStructPathMat', 'trialStructPathLabview',
                     'pathActivePassive', 'pathMovementVectors'])
        self.pathT1 = defaultdict(dict)

        if 'TDT' in pathDict:
            self.find_parse_tdt(pathDict['TDT'])

        # Find parse Overlay
        self.pathRef = {}
        self.pathT2 = {}
        if 'Overlay' in pathDict:
            self.find_parse_overlay(pathDict['Overlay'])
Пример #3
0
    def find_parse_overlay(self, pathOverlay):
        for mouseName, dfMouse in self.dfSession.groupby(['mousename']):
            pathMouse = os.path.join(pathOverlay, mouseName)
            # pathRef = os.path.join(pathMouse, 'refImg_ROIs.mat')
            pathT2 = os.path.join(pathMouse, 't2str.mat')

            prepcommon._testdir(pathMouse)
            # self._testfile(pathRef)
            prepcommon._testfile(pathT2)

            # self.pathRef[mouseName] = pathRef
            self.pathT2[mouseName] = pathT2
Пример #4
0
    def find_parse_data_paths(self, pathAUD):
        for mouseName, dfMouse in self.dfSession.groupby(['mousename']):
            pathMouse = os.path.join(pathAUD, mouseName)
            prepcommon._testdir(pathMouse)

            for dayName, dfDay in dfMouse.groupby(['dateKey']):
                print(mouseName, dayName)
                pathDay = os.path.join(pathMouse, dayName, 'widefield_labview')
                pathAllen = os.path.join(pathDay, 'ROI_Allen',
                                         'registration_transform_1510.mat')
                haveDir = prepcommon._testdir(pathDay, critical=False)
                haveFile = prepcommon._testfile(pathAllen, critical=False)

                if haveDir and haveFile:
                    self.pathT1[mouseName][dayName] = pathAllen
                    for idx, row in dfDay.iterrows():
                        sessionSuffix = row['sessionKey']

                        pathSession = os.path.join(pathDay, sessionSuffix)
                        pathMat = os.path.join(pathSession, 'Matt_files')
                        # pathTrialInd = os.path.join(pathMat, 'trials_ind.mat')

                        matFiles = [
                            f for f in os.listdir(pathMat)
                            if os.path.splitext(f)[1] == '.mat'
                            and f[:9] == 'Behavior_'
                        ]
                        assert len(matFiles) == 1
                        pathTrialStruct = os.path.join(pathMat, matFiles[0])

                        pathActivePassive = os.path.join(
                            pathMat,
                            'trials_with_and_wo_initial_moves_OCIA_from_movie.mat'
                        )

                        pathMovementVectors = os.path.join(
                            pathMat, 'move_vectors_from_movie.mat')

                        prepcommon._testdir(pathSession)
                        prepcommon._testdir(pathMat)
                        # prepcommon._testfile(pathTrialInd)
                        prepcommon._testfile(pathTrialStruct)
                        prepcommon._testfile(pathActivePassive)
                        prepcommon._testfile(pathMovementVectors,
                                             critical=False)

                        self.dataPaths = pd_append_row(
                            self.dataPaths,
                            [
                                mouseName,
                                dayName,
                                sessionSuffix,
                                pathSession,  #pathTrialInd,
                                pathTrialStruct,
                                pathActivePassive,
                                pathMovementVectors
                            ])
    def find_parse_tdt(self, pathTDT):
        print('Parsing TDT:')

        for mouseName, dfMouse in self.dfSession.groupby(['mousename']):
            pathMouse = os.path.join(pathTDT, mouseName)
            prepcommon._testdir(pathMouse)

            for dayName, dfDay in dfMouse.groupby(['dateKey']):
                print('--', mouseName, dayName)

                pathDay = os.path.join(pathMouse, 'TDT', dayName, 'widefield_labview')
                pathAllen = os.path.join(pathDay, 'ROI_Allen', 'registration_transform_1510.mat')
                prepcommon._testdir(pathDay)
                prepcommon._testfile(pathAllen)

                self.pathT1[mouseName][dayName] = pathAllen

                for idx, row in dfDay.iterrows():
                    sessionSuffix = row['sessionKey']

                    pathSession = os.path.join(pathDay, sessionSuffix)
                    pathMat = os.path.join(pathSession, 'Matt_files')
                    pathTrialInd = os.path.join(pathMat, 'trials_ind.mat')

                    if mouseName == 'mou_5':
                        matFiles = [f for f in os.listdir(pathMat) if os.path.isfile(os.path.join(pathMat, f))]
                        matFiles = [f for f in matFiles if '.mat' in f]
                        matFiles = [f for f in matFiles if dayName[:4] in f]

                        assert len(matFiles) == 1
                        pathTrialStructMat = os.path.join(pathMat, matFiles[0])
                    else:
                        pathTrialStructMat = os.path.join(pathMat, dayName + sessionSuffix + '.mat')


                    if mouseName == 'mou_5':
                        sessionKeyLabview = '_s' + sessionSuffix[-1]
                    elif mouseName == 'mou_6':
                        sessionKeyLabview = '_s' + str(self._letters_to_sessions(sessionSuffix))
                    else:
                        sessionKeyLabview = '_' + sessionSuffix

                    pathTrialStructLabview = os.path.join(pathSession, mouseName + sessionKeyLabview + ''.join(dayName.split('_')) + '.txt')

                    pathActivePassive = os.path.join(pathMat, 'trials_with_and_wo_initial_moves_OCIA_from_movie.mat')

                    pathMovementVectors = os.path.join(pathMat, 'move_vectors_from_movie.mat')

                    prepcommon._testdir(pathSession)
                    prepcommon._testdir(pathMat)
                    prepcommon._testfile(pathTrialInd)
                    prepcommon._testfile(pathTrialStructMat)
                    prepcommon._testfile(pathTrialStructLabview, critical=False)
                    prepcommon._testfile(pathActivePassive, critical=False)
                    prepcommon._testfile(pathMovementVectors, critical=False)

                    self.dataPaths = pd_append_row(self.dataPaths, [
                        mouseName, dayName, sessionSuffix, pathSession,
                        pathTrialInd, pathTrialStructMat, pathTrialStructLabview,
                        pathActivePassive, pathMovementVectors
                    ])