{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Datajoint Introductory Tutorial\n", "In this tutorial we will use datajoint to create a simple psychometric behavior plot.\n", "\n", "This tutorial assumes that you have setup the unified ibl environment [IBL python environment](../../02_installation.md) and set up your [Datajoint credentials](../../dj_docs/dj_credentials.md).\n", "\n", "First let's import datajoint" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import datajoint as dj\n", "# for the purposes of tutorial limit the table print output to 5\n", "dj.config['display.limit'] = 5" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can access datajoint tables by importing schemas from the IBL-pipeline. Let's import the `subject` schema" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from ibl_pipeline import subject" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Within this schema there is a datajoint table called `Subject`. This holds all the information about subjects registered on Alyx under IBL projects. Let's access this table and look at the first couple of entries" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "subjects = subject.Subject()\n", "subjects" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Next, we will find the entry in the table for the same subject that we looked at in the ONE tutorial, KS022. To do this we will restrict the `Subject` table by the `subject nickname`" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "subjects & 'subject_nickname = \"KS022\"'" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We now want to find information about the behavioural sessions. This information is stored in a table `Session` defined in the `acquisition` schema. Let's import this schema, access the table and display the first few entries" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from ibl_pipeline import acquisition\n", "sessions = acquisition.Session()\n", "sessions" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If we look at the primary keys (columns with black headings) in the `Subjects` and `Sessions` table, we will notice that both contain `subject_uuid` as a primary key. This means that these two tables can be joined using *****.\n", "\n", "We want to find information about all the sessions that KS022 did in the training phase of the IBL training pipeline. When combining the tables we will therefore restrict the `Subject` table by the `subject nickname` (as we did before) and the `Sessions` table by the `task protocol`" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "(subjects & 'subject_nickname = \"KS022\"') * (sessions & 'task_protocol LIKE \"%training%\"')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "There is a lot of information in this table and we are not interested in all of it for the purposes of our analysis. Let's just use the **proj** method to restrict the data presented. We do not want any columns from the `Subject` table (apart from the primary keys) and only want `session_uuid` from the `Sesssions table`. So we can write," ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "((subjects & 'subject_nickname = \"KS022\"').proj() *\n", " (sessions & 'task_protocol LIKE \"%training%\"')).proj('session_uuid')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "