edickie / ciftify

The tools of the Human Connectome Project (HCP) adapted for working with non-HCP datasets
https://edickie.github.io/ciftify/
MIT License
116 stars 157 forks source link

Many 0s in fMRI timeseries (using raw HCP data) #164

Open bwinsto2 opened 2 years ago

bwinsto2 commented 2 years ago

Happy holidays!!

I am hoping to use ciftify as a prerequisite for our upcoming BIDS app but am experiencing an issue.

Starting from raw HCP data, I ran fMRIprep and freesurfer and then ciftify (through docker). I then execute some commands for obtaining a matrix (n_vert x n_timepoints) of intensities (but please let me know if there is an easier way of doing this):

shell commands:

wb_command -cifti-separate {dtseries_from_ciftify} COLUMN -metric CORTEX_LEFT hem-l.func.gii
wb_command -cifti-separate {dtseries_from_ciftify} COLUMN -metric CORTEX_RIGHT hem-r.func.gii

python:

timeseries_matrix = read_functional_timeseries(hem-l.func.gii, hem-r.func.gii)

def read_functional_timeseries(lhfunc,rhfunc):
    l = nib.load(lhfunc).darrays
    r = nib.load(rhfunc).darrays
    timeseries = np.zeros((2*len(l[0].data), len(r)))
    for i in range(len(l)):
        lt = np.array(l[i].data)
        rt = np.array(r[i].data)
        tp = np.concatenate((lt, rt))
        timeseries[:, i] = tp
    return timeseries_matrix

However, in the resulting timeseries matrix, there are many vertices which have value 0 at every timepoint. For example, I looked at a working memory scan, and 14,000 of the ~65,000 vertices had a 0.

The code I provided above, when applied to dtseries files from the HCP 1200 subject release (minimally preprocessed dataset), produces a matrix without any zeroes (for the same scan). Therefore, I am not sure exactly where this problem is originating from: fMRIprep (seems unlikely), ciftify, or the above code for converting dtseries -> timeseries matrix (which works for HCP dtseries, so seems unlikely to be the problem).

I am a bit unfamiliar with this space (no pun intended), so any insight would be very appreciated! We are hoping to recommend users to run ciftify as a prerequisite to our pipeline, so I hope we can get this figured out!

Thanks.

edickie commented 2 years ago

One cause if missing data might be the medial wall mask, which gets rewritten with zeros if you convert to gifti.

p.s. nibabel can read cifti directly. Do you see zero timerseries if you load the dtseries data directly (nib.load(cifti).get_fdata())?

bwinsto2 commented 2 years ago

hi @edickie thank you for the response!! looks unlikely to be the medial wall since even when loading in the 91k dtseries directly as you described, there are over 15,000 zeroes. I loaded in an HCP one for comparison and there were no zeroes.

Here I used this code to plot the cifti data from cortex left and right to the surface. Here is a dtseries from ciftify:

Screen Shot 2021-12-29 at 1 37 53 PM Screen Shot 2021-12-29 at 1 37 58 PM

And here's one from HCP minimal preprocess download:

Screen Shot 2021-12-29 at 1 38 09 PM Screen Shot 2021-12-29 at 1 38 03 PM

So it looks like it's not just random vertices missing data. Any idea why the whole dorsal areas seem to be missing values?

fMRIprep output looks fine. is it possible there's something weird going on with the MNI transform? not sure if it matters, but the MNI transformed image shown below almost looks cut off in the top two non-axial views:

Screen Shot 2021-12-28 at 11 50 03 PM

Thank you very much,

Brian

edickie commented 2 years ago

Yeah the registration looks completely off! That would be the problem..

On Wed, Dec 29, 2021, 13:45 Brian Winston @.***> wrote:

hi @edickie https://github.com/edickie thank you for the response!! looks unlikely to be the medial wall since even when loading in the 91k dtseries directly as you described, there are over 15,000 zeroes. I loaded in an HCP one for comparison and there were no zeroes.

Here I used this code https://neurostars.org/t/separate-cifti-by-structure-in-python/17301/2?u=bwinsto2 to plot the cifti data from cortex left and right to the surface. Here is a dtseries from ciftify: [image: Screen Shot 2021-12-29 at 1 37 53 PM] https://user-images.githubusercontent.com/61159065/147693368-e0908666-4f2a-4dff-9998-02dae20ee112.png [image: Screen Shot 2021-12-29 at 1 37 58 PM] https://user-images.githubusercontent.com/61159065/147693367-fcc826a1-f384-4209-9a10-8d888b418262.png

And here's one from HCP minimal preprocess download: [image: Screen Shot 2021-12-29 at 1 38 09 PM] https://user-images.githubusercontent.com/61159065/147693440-e521f669-83cd-4d4a-b4f7-c669dc1607c5.png [image: Screen Shot 2021-12-29 at 1 38 03 PM] https://user-images.githubusercontent.com/61159065/147693441-fd4a10ab-b048-45d0-9b51-775ea3a13c16.png

So it looks like it's not just random vertices missing data. Any idea why the whole dorsal areas seem to be missing values?

fMRIprep output looks fine. is it possible there's something weird going on with the MNI transform? not sure if it matters, but the MNI transformed image shown below almost looks cut off in the top two non-axial views:

[image: Screen Shot 2021-12-28 at 11 50 03 PM] https://user-images.githubusercontent.com/61159065/147628366-c42b6cf9-4b1e-4e06-b051-34531395f633.png

Thank you very much,

Brian

— Reply to this email directly, view it on GitHub https://github.com/edickie/ciftify/issues/164#issuecomment-1002730385, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADEXT5TVCYIBYYSEWNHHUKLUTNJLPANCNFSM5K5FVUYA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you were mentioned.Message ID: @.***>

bwinsto2 commented 2 years ago

Thanks @edickie. I'm not sure how exactly to proceed since MNI transform is a part of ciftify. Ultimately I am using the --resample-to-T1w option on the anatomical side, so I am hoping for ciftis that can be projected on a 32k T1w surface. I have ciftify installed locally too so I can try out some of the options. I tried skipping MNI transform, but got an error that "label volume has a different space than data volume".

fMRIprep can also output 91k ciftis. Those work pretty well, but I was hoping to keep everything in ciftify if possible. Any ideas how to resolve this registration issue? Thanks.