dfsp-spirit / regfusionr

R implementation of registration fusion method for MNI152 - 305 mapping.
Other
5 stars 1 forks source link

Feature request: provide fsaverage sphere files when downloading optdata #3

Open ykoush opened 2 years ago

ykoush commented 2 years ago

Hi, I'm trying to set fsaverage_to_vol() to convert mgz files from HCP project, from fsaverage to MNI, the data samples are under this project (https://osf.io/bw9ec/), precisely inside the archive (https://osf.io/tqprz). I'm using these lines of code in RStudio console (Win 10): lh <- 'lh.fit1_ang.mgz' rh <- 'rh.fit1_ang.mgz' lv = read.fs.mgh(lh, with_header = FALSE, flatten = TRUE); rv = read.fs.mgh(rh, with_header = FALSE, flatten = TRUE); fsaverage_to_vol(lv,rv, target_space = "FSL_MNI152", rf_type = "RF_ANTs", interp = "linear", out_type = "nii", out_dir = NULL, fsaverage_path = NULL, silent = TRUE)

I also had to use these options ("with_header = FALSE, flatten = TRUE"), as seemingly your function does not acknowledge the input with headers?..

AND, then I get this error: Error in subject.surface(subjects_dir, subject_id, surface, "lh") : Surface file 'C:\Users\Test\AppData\Local/fsbrain/fsbrain/subjects_dir/fsaverage/surf/lh.sphere' for subject 'fsaverage' surface 'sphere' hemi 'lh' cannot be accessed.

The folder 'surf' exists, however there is no file lh.sphere there. I guess, it is trying to read the template, e.g. in these lines: template_meshes_surface = fsbrain::subject.surface(fsaverage_path, template_subject, surface = "sphere")

So I tried to check the repositories under freesurfer website, and downloaded 'freesurfer-linux-ubuntu22_amd64-7.3.2.tar' There, there are no lh.sphere rh.sphere files but lh.sphere.reg rh.sphere.reg, which are not taken by subject.surface() if placed into the desired folder. Can I make it working under Win 10 somehow, and where can I get these .sphere templates? I hope to avoid running it on Ubuntu under R if this is just about templates, please let me know. Thank you and best wishes

dfsp-spirit commented 2 years ago

Hi @ykoush,

sorry for the late reply, I was on vacation.

You are right about the missing template: the function did not find your FreeSurfer installation, nor any other way to get the fsaverage meshes you are trying to use. You have 2 options, I recommend the 2nd way:

1) Download and extract FreeSurfer (several GB), and use the fsaverage_path parameter of the fsaverage_to_vol function to point it to <freesurfer_install>/subjects, which should be available as the environment variable $SUBJECTS_DIR after you run the FreeSurfer setup function for your shell. 2) A lot easier: review the FreeSurfer license, and if you agree start an R session, and type: fsbrain::download_fsaverage(accept_freesurfer_license=TRUE) to download only the fsaverage template. It will go into the directory mentioned in your error message, where regfusionr is looking for it. You may need to install::packages('fsbrain') to install fsbrain, but I think its not needed as it should be a regfusionr dependency.

I have added a new section Getting the fsaverage meshes to the Readme file that makes it clear that one needs these meshes, and explains how to get them.

Best,

Tim

ykoush commented 2 years ago

Hi Tim, fsbrain is installed, and the command works fsbrain::download_fsaverage(accept_freesurfer_license=TRUE) But it doesn't bring the .sphere files. Checking download_fsaverage shows that it doesn't contain .sphere links. I had an idea to edit it, but it is read-only. Could you please make sure that this function gets .sphere ? Thank you, Yury

dfsp-spirit commented 2 years ago

Ah, I see. I may not have them on the server. Yes, I can do that.

dfsp-spirit commented 2 years ago

Hi @ykoush,

I have put the files onto the remote server and updated the data downloaded by the fsbrain::download_fsaverage function in the fsbrain repo here on the develop branch.

You should be able to get that version by running: remotes::install_github("dfsp-spirit/fsbrain", ref="develop"). Note that you will need to start a new R session after installing it that way for R to actually use the newly installed version! So after installing, in a new R session, try:

fsbrain::download_fsaverage(T);

and it should grab the sphere files.

Note that I could not yet test that it works, since I do not have R on this computer. Let my know how it goes. Update: I tried it, and it works for me.

ykoush commented 2 years ago

Hi Tim, fsbrain is installed, and the command works fsbrain::download_fsaverage(accept_freesurfer_license=TRUE) But it doesn't bring the .sphere files. Checking download_fsaverage shows that it doesn't contain .sphere links. I had an idea to edit it, but it is read-only. Could you please make sure that this function gets .sphere ? Thank you, Yury

ykoush commented 2 years ago

Hi Tim, I was able to upload the new code and templates. So I started the original fsaverage_to_vol() transformation above. It hangs for >2h in Console - see update below >17h. Should it take so long? I wonder how can I know that it is progressing well (e.g. instead of cycling in some infinite loops somewhere) and what is typical time to expect? Thanks and best, Yury

ykoush commented 2 years ago

It was hanging overnight for > 17h, I guess something is not working, could you please see? 2 data files I used from HCP are in the \prfresultsmgz\prfresultsmgz\999999\ lh <- 'lh.fit1_ang.mgz' rh <- 'rh.fit1_ang.mgz' Thank you, Yury

ykoush commented 2 years ago

I also tried this, suggesting that it may miss directories and/or silent mode OFF, and got another error, seems the reason of hanging in silent mode: fsaverage_to_vol(lv,rv, target_space = "FSL_MNI152", rf_type = "RF_ANTs", interp = "linear", out_type = "nii", out_dir = "F:/mgzToConvert/", fsaverage_path = "C:/Users/Yury/AppData/Local/fsbrain/fsbrain/subjects_dir/", silent = FALSE) Error in sprintf("Using 'linear' interpolation, suitable for continuous per-vertex data, to interpolate %d values for left hemi.\n") : too few arguments

dfsp-spirit commented 2 years ago

Oh, I just realized you are using fsaverage_to_vol()! I just assumed you ere using vol_to_fsaverage().

The fsaverage_to_vol() function is not fully tested yet, that's why the website also mentioned it as being experimental. I would not recommend using it yet.

The vol_to_fsaverage() has unit tests and works fine, but please do not use fsaverage_to_vol()yet. I have made it clear in the function and in the docs now that it is not ready yet. I would like to finish it, but I currently have a new job in which I am quite busy, and I am no longer payed to work on this, so it may take a while I fear.