ONE advanced queries

While the basic command allows us to filter experimental sessions by date, lab, user, subject etc, you may quickly find that you want to apply more complex queries to restrict your search output. This can be achieved using the command. This has access to a range of tables stored in Alyx and gives us more flexibilty when forming our queries. vs

We will get started by importing ONE

from import ONE
one = ONE()
Connected to as mayo

We can list the possible tables that we have access to, by typing the following command


Let’s first look at sessions table. The information about what filters can be applied to this table are available under Query Parameters here. Let’s apply a filter based on subject and task_protocol. We can do this using the following expression,

sess_info ='sessions', 'list', subject='SWC_015', task_protocol='ephys')
{'subject': 'SWC_015',
 'start_time': '2020-01-25T18:53:42.203528',
 'number': 1,
 'lab': 'hoferlab',
 'project': 'ibl_neuropixel_brainwide_01',
 'url': '',
 'task_protocol': '_iblrig_tasks_ephysChoiceWorld6.2.5'}

Notice how this command doesn’t just return the session eID but a dictionary containing information about each session. We can extract the set of eIDs from the url key

eids = [s['url'] for s in sess_info]
eids = [e.split('/')[-1] for e in eids]

You might have noticed that this same query could be have been achieved using the method,

eids ='SWC_015', task_protocol='ephys')

Let’s add in another filter to see the benefits of the approach. We will add an atlas_acronym filter to see if any of the ephys sessions from SWC_015 were recorded from the somatomotor areas (acronym MO). This query would not be possible with the command!

sess_info ='sessions', 'list', subject='SWC_015', task_protocol='ephys',
[{'subject': 'SWC_015',
  'start_time': '2020-01-24T14:56:07.183680',
  'number': 1,
  'lab': 'hoferlab',
  'project': 'ibl_neuropixel_brainwide_01',
  'url': '',
  'task_protocol': '_iblrig_tasks_ephysChoiceWorld6.2.5'},
 {'subject': 'SWC_015',
  'start_time': '2020-01-23T16:22:24.861589',
  'number': 1,
  'lab': 'hoferlab',
  'project': 'ibl_neuropixel_brainwide_01',
  'url': '',
  'task_protocol': '_iblrig_tasks_ephysChoiceWorld6.2.5'},
 {'subject': 'SWC_015',
  'start_time': '2020-01-22T17:04:18.126507',
  'number': 1,
  'lab': 'hoferlab',
  'project': 'ibl_neuropixel_brainwide_01',
  'url': '',
  'task_protocol': '_iblrig_tasks_ephysChoiceWorld6.2.5'}]

Accessing other Alyx tables

With the command we are not only limited to the sessions table, but can formulate queries based on other tables to find session eIDs of interest. Consider the case where we want to find all sessions that have probe insertions that target a specific ML and AP coordinate. For this we can formulate our query based on the trajectories table. Let’s see if there are any probe insertions at the coordinates ML(x) = -2000, and AP(y) = -2000 from bregma.

trajs ='trajectories', 'list', x=-2000, y=-2000)
{'id': '8741d377-a3de-4d94-9ba0-1eb28787da49',
 'probe_insertion': 'dc50c3de-5d84-4408-9725-22ae55b93522',
 'x': -2000.0,
 'y': -2000.0,
 'z': -169.0,
 'depth': 4000.0,
 'theta': 15.0,
 'phi': 180.0,
 'roll': 0.0,
 'provenance': 'Micro-manipulator',
 'session': {'subject': 'SWC_023',
  'start_time': '2020-02-13T15:36:50.234590',
  'number': 1,
  'lab': 'mrsicflogellab',
  'id': '38d95489-2e82-412a-8c1a-c5377b5f1555',
  'task_protocol': '_iblrig_tasks_ephysChoiceWorld6.2.5'},
 'probe_name': 'probe01',
 'coordinate_system': 'Needles-Allen',
 'datetime': '2020-06-09T07:59:14.315700',
 'json': None}

We can find the session eID associated with this trajectory by looking at the id of the session field in the returned dictionary

eid = trajs[0]['session']['id']


It is not just sessions that have unique IDs associated with them! Every object stored in Alyx has a unique UUID, whether it is a trajectory, a subject, a user or a dataset. For example in the above example we can access the unique ID of the trajectory by typing traj_id = trajs[0]['id']

Searching with

The command is also a far superior method compared to one.list for searching the database for possible keywords that you can use to restrict your queries. For example, if we want to find the names of female subjects in the Witten lab that are alive, we can use the subjects table to write,

subj_info ='subjects', 'list', lab='wittenlab', sex='F', alive=True)
subj_nickname = [subj['nickname'] for subj in subj_info]