rmarkello / abagen

A toolbox for working with Allen Human Brain Atlas microarray expression data
https://abagen.readthedocs.io
BSD 3-Clause "New" or "Revised" License
95 stars 41 forks source link

Question about using freesurfer .annot files #223

Closed xuansean closed 9 months ago

xuansean commented 1 year ago

Hi Abagen experts,

I'm new to the field of neuroimaging/imaging transcriptomics so hopefully this question doesn't sound too dumb.

I want to use .annot file from freesurfer recon-all outputs as an input to abagen.

I have the following code:

import abagen left_annot = '/Users/xuansean/Desktop/BR2072/label/lh.aparc.annot' left_atlas = abagen.annot_to_gifti(left_annot) expression = abagen.get_expression_data(left_atlas)

but this gives me multiple errors:

Traceback (most recent call last): File "/Users/xuansean/opt/anaconda3/lib/python3.9/site-packages/abagen/images.py", line 562, in coerce_atlas_to_dict for donor, atl in atlas.items() AttributeError: 'GiftiImage' object has no attribute 'items'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/Users/xuansean/opt/anaconda3/lib/python3.9/site-packages/abagen/images.py", line 352, in check_atlas atlas = check_img(atlas) File "/Users/xuansean/opt/anaconda3/lib/python3.9/site-packages/abagen/images.py", line 218, in check_img raise TypeError('Provided image must be an existing filepath or a ' TypeError: Provided image must be an existing filepath or a pre-loaded niimg-like object

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/Users/xuansean/MRI_pediatric/abagen/abagen_test.py", line 15, in expression = abagen.get_expression_data(left_atlas) File "/Users/xuansean/opt/anaconda3/lib/python3.9/site-packages/abagen/allen.py", line 385, in get_expression_data atlas, group_atlas = images.coerce_atlas_to_dict(atlas, donors, atlas_info) File "/Users/xuansean/opt/anaconda3/lib/python3.9/site-packages/abagen/images.py", line 572, in coerce_atlas_to_dict atlas = check_atlas(atlas, atlas_info) File "/Users/xuansean/opt/anaconda3/lib/python3.9/site-packages/abagen/images.py", line 355, in check_atlas atlas, info = check_surface(atlas) File "/Users/xuansean/opt/anaconda3/lib/python3.9/site-packages/abagen/images.py", line 265, in check_surface if len(atlas) != 2: TypeError: object of type 'GiftiImage' has no len()

Initially I thought maybe it was due to the fact that my .annot files are not in fsaverage5 resolution, so I tried to down-sampled it using freesurfer commands but didn't work out as well.

What am I missing here? Thank you in advance for any help!

liuzhenqi77 commented 1 year ago

Hi, thank you for using abagen!

I would recommend checking the user guide for detailed walk-through, specifically, the page on defining a parcellation.

If you are using aparc, you can directly follow the guide where it demonstrates how to use Desikan-Killiany atlas.

Please feel free to let us know if you need more help.

xuansean commented 1 year ago

Thank you for the reply @liuzhenqi77! Right now I'm just trying to go through the guide with the default Desikan-Killiany atlas. My code is just the same in the guide: import abagen atlas = abagen.fetch_desikan_killiany() print(atlas['image']) print(atlas['info']) expression = abagen.get_expression_data(atlas['image'], atlas['info']) But I got an error message as the following: Traceback (most recent call last):

File "/Users/xuansean/MRI_pediatric/abagen/abagen_demo.py", line 15, in expression = abagen.get_expression_data(atlas['image'], atlas['info']) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/xuansean/anaconda3/lib/python3.11/site-packages/abagen/allen.py", line 444, in get_expressiondata microarray = probes.collapse_probes(flattendict(files, 'microarray'), ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/xuansean/anaconda3/lib/python3.11/site-packages/abagen/probes.py", line 757, in collapse_probes micro = micro.set_axis(symbols, axis=1, inplace=False) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TypeError: DataFrame.set_axis() got an unexpected keyword argument 'inplace'

Before the error there are just numerous of

FutureWarning: DataFrame.groupby with axis=1 is deprecated. Do frame.T.groupby(...) without axis instead.

I updated pandas and other needed packages but still got the same error. Really appreciate your help!

I'm using a macbook, OS ventura 13.5.2 with apple M1 chip. Somehow the code above will run without error on my ubuntu machine...(still gives the future warnings)

liuzhenqi77 commented 9 months ago

This should have been fixed by the latest GitHub commits. Please reopen if more help is needed.