AllenInstitute / AllenSDK

code for reading and processing Allen Institute for Brain Science data
https://allensdk.readthedocs.io/en/latest/
Other
346 stars 151 forks source link

Encapsulate well known file queries in LIMS API #1851

Open aamster opened 3 years ago

aamster commented 3 years ago

The LIMS API has many long queries to retrieve well known files which share logic. For example the following are basically the same and differ only in the filter on wkf.attachable_type and wkft.name

        query = """
                SELECT wkf.storage_directory || wkf.filename AS stim_file
                FROM ophys_experiments oe
                JOIN ophys_sessions os ON oe.ophys_session_id = os.id
                JOIN behavior_sessions bs ON bs.ophys_session_id = os.id
                LEFT JOIN well_known_files wkf ON wkf.attachable_id = bs.id
                JOIN well_known_file_types wkft
                ON wkf.well_known_file_type_id = wkft.id
                WHERE wkf.attachable_type = 'BehaviorSession'
                AND wkft.name = 'StimulusPickle'
                AND oe.id = {};
                """.format(self.get_ophys_experiment_id())
        query = """
                SELECT wkf.storage_directory || wkf.filename AS nwb_file
                FROM ophys_experiments oe
                JOIN well_known_files wkf ON wkf.attachable_id = oe.id
                JOIN well_known_file_types wkft
                ON wkf.well_known_file_type_id = wkft.id
                WHERE wkft.name ='BehaviorOphysNwb'
                AND oe.id = {};
                """.format(self.get_ophys_experiment_id())

Reducing redundancy in the queries will help with readability.

Acceptance criteria

njmei commented 3 years ago

The OphysLimsExtractor, BehaviorOphysLimsExtractor, and BehaviorLimsExtractor classes have a number of methods that grab the exact same data.

Perhaps this issue can be renamed to Catalogue and encapsulate redundant queries in visual behavior LIMS APIs?

wbwakeman commented 3 years ago

Let's plan to look at this in the broader context of refactoring the entire set of Behavior APIs in the AllenSDK. e.g. as part of this work that Dan has started to plan out: http://confluence.corp.alleninstitute.org/display/IT/AllenSDK+Behavior+Refactor+Brainstorm