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

General-purporse key lookup tool(s) for buried primary keys #923

Closed
CBroz1 opened this issue Apr 10, 2024 · 3 comments
Closed

General-purporse key lookup tool(s) for buried primary keys #923

CBroz1 opened this issue Apr 10, 2024 · 3 comments
Assignees
Labels
enhancement New feature or request infrastructure Unix, MySQL, etc. settings/issues impacting users

Comments

@CBroz1
Copy link
Member

CBroz1 commented Apr 10, 2024

Navigating restrictions described in #630 requires burying primary keys in table definitions like...

@schema
class SpikeSortingRecordingSelection(SpyglassMixin, dj.Manual):
    definition = """
    # Raw voltage traces and parameters. Use `insert_selection` method to insert rows.
    recording_id: uuid
    ---
    -> Raw
    -> SortGroup
    -> IntervalList
    -> SpikeSortingPreprocessingParameters
    -> LabTeam
    """

A unique pairing of each secondary key is associated with a uuid so we don't have issues declaring downstream tables.

As a workaround, we've needed helper functions to be able to trace keys up or down through bury tables, as in #910

@schema
class CurationV1(SpyglassMixin, dj.Manual):
    ...
   @classmethod
    def get_sort_group_info(cls, key: dict) -> dj.Table:
        """Returns the sort group information for the curation
        (e.g. brain region, electrode placement, etc.)
        Parameters
        ----------
        key : dict
            restriction on CuratedSpikeSorting table
        Returns
        -------
        sort_group_info : Table
            Table with information about the sort groups
        """
        table = (
            (cls & key) * SpikeSortingSelection()
        ) * SpikeSortingRecordingSelection().proj(
            "recording_id", "sort_group_id"
        )

        electrode_restrict_list = []
        for x in table:
            # pull just one electrode from each sort group for info
            electrode_restrict_list.extend(
                ((SortGroup.SortGroupElectrode() & x) * Electrode).fetch(
                    limit=1
                )
            )

        sort_group_info = (
            (Electrode & electrode_restrict_list)
            * table
            * SortGroup.SortGroupElectrode()
        ) * BrainRegion()
        return (cls & key).proj() * sort_group_info

Does this need to be handled on a case-by-case basis? Could it be generalized?

@CBroz1 CBroz1 added enhancement New feature or request infrastructure Unix, MySQL, etc. settings/issues impacting users labels Apr 11, 2024
@samuelbray32 samuelbray32 self-assigned this Apr 12, 2024
@samuelbray32
Copy link
Collaborator

I think I have something close to a general solution. It seems able to replicate some of the methods I have in #910.
I'll put together a PR with it. Once I do, @CBroz1 could you help me with detecting alias projections between a parent and a child?

@CBroz1
Copy link
Member Author

CBroz1 commented Apr 14, 2024

Alias mapping is done in the graph, which each table has a copy of.

@samuelbray32
Copy link
Collaborator

addressed in #949

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request infrastructure Unix, MySQL, etc. settings/issues impacting users
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants