int-brain-lab / ONE

Open Neurophysiology Environment
MIT License
16 stars 4 forks source link

Do general users have access to the alyx REST Querries? Where are the list of available terms in each search type? #101

Closed AngCamp closed 9 months ago

AngCamp commented 9 months ago

I tried to query experiment tags using the alyx api but I could not. Also it's not clear how to find the lists of available items in each search_term.

My attempt to use the alyx restful api:

>from one.api import ONE, OneAlyx
>one = One()
>one.alyx.rest('tags', 'list')
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/home/acampbell/Stienmetz2019Reanalyzed/ExtractingSWRs/ibl_swr_data/ibl_swr_detector_testing.ipynb Cell 7 line 3
      [1](vscode-notebook-cell://ssh-remote%2Bitchy.msl.ubc.ca/home/acampbell/Stienmetz2019Reanalyzed/ExtractingSWRs/ibl_swr_data/ibl_swr_detector_testing.ipynb#X34sdnNjb2RlLXJlbW90ZQ%3D%3D?line=0) from one.api import ONE, OneAlyx
----> [3](vscode-notebook-cell://ssh-remote%2Bitchy.msl.ubc.ca/home/acampbell/Stienmetz2019Reanalyzed/ExtractingSWRs/ibl_swr_data/ibl_swr_detector_testing.ipynb#X34sdnNjb2RlLXJlbW90ZQ%3D%3D?line=2) one.alyx.rest('tags', 'list')

AttributeError: 'One' object has no attribute 'alyx'

When I was hoping to look in projects, it's not clear what the available search terms are. Is it possible to print the options for each search term in some way?

>one = One()
>print(one.search_terms())
('dataset', 'date_range', 'laboratory', 'number', 'projects', 'subject', 'task_protocol')

I ended up doing the following:

>examp, examp_dict = one.search(projects='', details=True)
>proj_list = [examp_dict[x]['projects'] for x in range(0, len(examp_dict))]
>print(set(proj_list))

{'', 'ibl_certif_neuropix_recording', 'test', 'zador_les', 'ibl_neuropixel_brainwide_01', 'carandiniharris_midbrain_ibl', 'practice'}

Is there another way to do this that's built into the api?

k1o0 commented 9 months ago

Hello,

There are two ONE classes, One and OneAlyx. The former is offline only and is used to search and load data on your local filesystem (called the dataset cache directory). This class has limited meta data (only the fields you see in the search terms list). I'm not familiar with the notebook you are running, however if it's using a specific data cache that only contains a subset of the IBL data, then you will not have access to things like release tag. If this is indeed the case then you're method of listing projects is fine. Here's another way: one._cache.sessions.projects.unique().

The second class, OneAlyx can connect to a remote meta database called OpenAlyx, which provides many more search fields including release tag, and contains all publicly available IBL data. In the first code block you are instantiating the offline class. The best way to use ONE for all IBL data is to call the ONE function, which will return you the correct object.

To setup ONE to use the OpenAlyx database you can run the following:

from one.api import ONE
ONE.setup(base_url='https://openalyx.internationalbrainlab.org', silent=True, make_default=True)

You can then instantiate ONE the following way:

one = ONE()

Now you will be able to use the one.alyx methods. NB: You may be prompted to enter an Alyx password from time to time. The password is 'international'.

When I was hoping to look in projects, it's not clear what the available search terms are. Is it possible to print the options for each search term in some way?

For one.search you can find details on the input arguments and a few examples in the API documentation. This page provides even more examples on searching with ONE, including a section about release tags.

Finally, for information on listing projects and searching using all available meta data, please consult the page on exploring Alyx REST endpoints. This shows you how to list all the available search parameters and contains many helpful examples.

In this online mode you can list projects in the following manner: [project['name'] for project in one.alyx.rest('projects', 'list')]

NB: Remember that this returns all public IBL projects, whereas your notebook may use using only a subset of IBL data. Best to ask the author of the notebook.

k1o0 commented 9 months ago

No response for a week so I'm closing this for now. Please feel free to re-open if you still have issues.