#nimare v.0.0.10 problem with new #neurosynth import

Hi,

I am trying to convert the Neurosynth database into Nimare following the updated example for version 0.0.10. I’m running Mac10.15.7, the latest version of Nimare on Github, and the updated Neurosynth data format (version-7). The following command fails because it’s looking for a “database” it can’t find:

neurosynth_dset = nimare.io.convert_neurosynth_to_dataset(
… database_file=neurosynth_db[“database”],
… annotations_files=neurosynth_db[“features”],
… )
Traceback (most recent call last):
File “”, line 2, in
KeyError: ‘database’

Any help would be appreciated!

I haven’t released 0.0.10 yet, but there is a release candidate out (0.0.10rc2) for which that example should work. What version are you using?

Hi – I’m Jennifer, it’s nice to meet you.

I downloaded NiMare using this link: pip install git+https://github.com/neurostuff/NiMARE.git

Hello Jennifer.

It sounds like the code should work… can you share the full script (including the fetch_neurosynth call)?

Additionally, can you do print(neurosynth_db) to see what the actual contents of the dictionary are?

Best,
Taylor

Hi Taylor,
I didn’t use the fetch call, I downloaded from the Neurosynth repo – it said it was updated 6 days ago the day I downloaded. The output from print(neurosynth_db):

Traceback (most recent call last):
File “”, line 1, in
NameError: name ‘neurosynth_db’ is not defined

The script (I’m banned from attachments as a new user):

Start with the necessary imports

--------------------------------

import os
from pprint import pprint

import nimare

###############################################################################

Download Neurosynth

-------------------

Neurosynth’s data files are stored at GitHub - neurosynth/neurosynth-data.

out_dir = os.path.abspath("/Users/jenniferbarredo/neurosynth-data-master/")
os.makedirs(out_dir, exist_ok=True)

files = nimare.extract.fetch_neurosynth(
path=out_dir,
version=“7”,
overwrite=False,
source=“abstract”,
vocab=“terms”,
)
pprint(files)
neurosynth_db = files[0]

###############################################################################

Convert Neurosynth database to NiMARE dataset file

--------------------------------------------------

neurosynth_dset = nimare.io.convert_neurosynth_to_dataset(
database_file=neurosynth_db[“database”],
annotations_files=neurosynth_db[“features”],
)
neurosynth_dset.save(os.path.join(out_dir, “neurosynth_dataset.pkl.gz”))
print(neurosynth_dset)

###############################################################################

Add article abstracts to dataset

--------------------------------

This is only possible because Neurosynth uses PMIDs as study IDs.

Make sure you replace the example email address with your own.

neurosynth_dset = nimare.extract.download_abstracts(neurosynth_dset, “jennifer_barredo@brown.edu”)
neurosynth_dset.save(os.path.join(out_dir, “neurosynth_dataset_with_abstracts.pkl.gz”))

I just wiped the old Neurosynth files and pulled down with fetch:
nimare.extract.fetch_neurosynth(
url=(
https://github.com/neurosynth/neurosynth-data/blob/
“e8f27c4a9a44dbfbc0750366166ad2ba34ac72d6/current_data.tar.gz?raw=true”
),
)

Now I get this from print(neurosynth_db):
{‘coordinates’: ‘/Users/jenniferbarredo/neurosynth-data-master/data-neurosynth_version-7_coordinates.tsv.gz’, ‘metadata’: ‘/Users/jenniferbarredo/neurosynth-data-master/data-neurosynth_version-7_metadata.tsv.gz’, ‘features’: [{‘features’: ‘/Users/jenniferbarredo/neurosynth-data-master/data-neurosynth_version-7_vocab-terms_source-abstract_type-tfidf_features.npz’, ‘vocabulary’: ‘/Users/jenniferbarredo/neurosynth-data-master/data-neurosynth_version-7_vocab-terms_vocabulary.txt’}]}

But now this line of code:
neurosynth_dset = nimare.io.convert_neurosynth_to_dataset(
database_file=neurosynth_db[“database”],
annotations_files=neurosynth_db[“features”],
)

Produces this error:
Traceback (most recent call last):
File “”, line 2, in
KeyError: ‘database’

Thanks! That last part really cleared things up. The example is incorrect, and I’ll try to fix it soon. You just need to correct the convert_neurosynth_to_dataset call, because I replaced the “database” file with two files- “coordinates” and “metadata”. The following should work:

neurosynth_dset = nimare.io.convert_neurosynth_to_dataset(
    coordinates_file=neurosynth_db["coordinates"],
    metadata_file=neurosynth_db["metadata"],
    annotations_files=neurosynth_db["features"],
)

EDIT: I’ve opened Neurosynth/NeuroQuery example uses old "database"/"features" structure · Issue #553 · neurostuff/NiMARE · GitHub for the bug and will fix it before the official 0.0.10 release.

Thanks! I was almost there, but not quite getting the annotations - features relationship. I just tried and got this error:

Traceback (most recent call last):
File “”, line 1, in
NameError: name ‘convert_neurosynth_to_dataset’ is not defined

Is this something I need to load?

Wait, never mind,… my mistake! I think I’m fine, thanks for your help!

1 Like

Hi Jennifer,

I just wanted to make you aware of a bug I noticed recently with the reorganized Neurosynth files. The features (aka Dataset.annotations) have rows in the wrong order, so that the weights do not match the associated studies. This wouldn’t affect something like a MACM, but anything that uses those features would be wrong :grimacing:. I’m sorry about that!

The good news is that it will be fixed once [FIX, DOC] Use appropriate structure in Neurosynth download example by tsalo · Pull Request #554 · neurostuff/Ni is merged later today.

Best,
Taylor

Thanks for keeping in touch, duly noted!

MANAGED BY INCF