Giter Site home page Giter Site logo

spisakt / ptfce Goto Github PK

View Code? Open in Web Editor NEW
38.0 6.0 6.0 43.14 MB

Probabilistic Threshold-Free Cluster Enhancement of Neuroimages

Home Page: https://spisakt.github.io/pTFCE/

License: BSD 3-Clause "New" or "Revised" License

R 88.89% Dockerfile 1.26% Shell 9.85%
neuroimaging tfce fsl statistical-inference cluster-enhancement

ptfce's Introduction

pTFCE: probabilistic Threshold-free Cluster Enhancement

Open Source Love svg1 Maintenance GitHub license GitHub release GitHub issues GitHub issues-closed

For more information, check out the project pages!

For a detailed description and theory, please refer to (and please cite):

Tamás Spisák, Zsófia Spisák, Matthias Zunhammer, Ulrike Bingel, Stephen Smith, Thomas Nichols, Tamás Kincses, Probabilistic TFCE: a generalised combination of cluster size and voxel intensity to increase statistical power. Neuroimage, 185:12-26. DOI: 10.1016/j.neuroimage.2018.09.078

image

ptfce's People

Contributors

hsx1 avatar spisakt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

ptfce's Issues

run ptfce in matlab without .mat file?

Hi Tamás,

First off, thanks for creating a wonderful application! I've used the R code & found it works well. The only issue I have is the length of time pTFCE takes to execute in R. Is there a way to speed it up? Alternatively, if we could simply supply a Z-stat image & mask to MATLAB, instead of the .mat file this might also help speed things up.

Thanks again,

John

infinite t-stat/z-stat

Hi,
Sometimes I get infinite t-stat and/or z-stat values in my pTFCE-enhanced images. I guess this is somehow related to what Mark Jenkinson and Mark Woolrich describe in their tech report? I know Stephen Fromm has turned their workaround into a Matlab function, but is there a way to work around this already in pTFCE?
Many thanks,
Gina

Warning message: In ptfce(Z, MASK) : NAs detected and replaced with zero! [1] "pTFCE_Z.nii.gz"

Hello,

I am trying to run ptfce on a skeletonized DTI z-stat image.

In the future, I will use residuals in my call. Currently, my script looks like this

library(oro.nifti)
library(pTFCE)

Z=readNIfTI("/gpfs52/data/h_vmac/hudson/dti/data/outZ.nii.gz")
MASK=readNIfTI("/gpfs52/data/h_vmac/sam/oef/main/pop/mean_FA_images/mean_FA_skeleton_mask.nii")

pTFCE=ptfce(Z, MASK)
writeNIfTI(pTFCE$Z, "pTFCE_Z")

The output is:

(base) [robbwh@badger scripts]$ Rscript doPTFCE.R 
oro.nifti 0.11.0
* Estimating smoothness based on the data...
  |======================================================================| 100%
* Performing pTFCE...
  |======================================================================| 100%
Warning message:
In ptfce(Z, MASK) : NAs detected and replaced with zero!
[1] "pTFCE_Z.nii.gz"

Although my mask excludes all nan values in the z-stat image, I get this warning message.

Further, when looking at the output pTFCE_Z.nii.gz image, areas which should be masked out have a value of -8.2...

Screen Shot 2022-03-14 at 10 54 59 AM

Is the masking not functioning as expected?

R installation failed

OS: ubuntu 16.04LTS
R: v3.6.1
Rstudio: 1.2.1335
issue:

install_github("spisakt/pTFCE")
Downloading GitHub repo spisakt/pTFCE@master
✔ checking for file ‘/tmp/RtmpqsNp2W/remotes19347326a571/spisakt-pTFCE-309a772/DESCRIPTION’ ...
─ preparing ‘pTFCE’:
✔ checking DESCRIPTION meta-information ...
─ checking for LF line-endings in source and make files and shell scripts
─ checking for empty or unneeded directories
─ building ‘pTFCE_0.2.0.0.tar.gz’

Installing package into ‘/home/shengwei/R/x86_64-pc-linux-gnu-library/3.6’
(as ‘lib’ is unspecified)

  • installing source package ‘pTFCE’ ...
    ** using staged installation
    ** R
    ** inst
    ** byte-compile and prepare package for lazy loading
    Error : 'use_package' is not an exported object from 'namespace:devtools'
    Error: unable to load R code in package ‘pTFCE’
    Execution halted
    ERROR: lazy loading failed for package ‘pTFCE’
  • removing ‘/home/shengwei/R/x86_64-pc-linux-gnu-library/3.6/pTFCE’
    Error: Failed to install 'pTFCE' from GitHub:
    (converted from warning) installation of package ‘/tmp/RtmpqsNp2W/file193471772f20/pTFCE_0.2.0.0.tar.gz’ had non-zero exit status

NaN's produced.

Bstand2-int-death-negative.nii.gz
mask.nii.gz

The files above, which are of Zmaps produce NaNs for 307 voxels. Here is what I do:


Z <- readNIfTI(fname = "Bstand2-int-death-negative")
MASK <- readNIfTI(fname = "mask.nii.gz")
pTFCE <- ptfce(Z, MASK)

I get:

* Estimating smoothness based on the data...
  |======================================================================| 100%
* Performing pTFCE...
  |======================================================================| 100%
There were 50 or more warnings (use warnings() to see the first 50)

And:

warnings()
Warning messages:
1: In sqrt(d * (8 * s + d)) : NaNs produced
2: In sqrt(d * (8 * s + d)) : NaNs produced
3: In sqrt(d * (8 * s + d)) : NaNs produced
4: In sqrt(d * (8 * s + d)) : NaNs produced
5: In sqrt(d * (8 * s + d)) : NaNs produced
6: In sqrt(d * (8 * s + d)) : NaNs produced
7: In sqrt(d * (8 * s + d)) : NaNs produced
....


What is wrong? How do I get out of these NaNs?

pTFCE for analyses in R

Hi,

Thank you for creating this tool! I'm thinking about how to integrate this into some analyses/tools that we are currently using and I want to make sure I'm thinking about using pTFCE the correct way. If performing a voxel-based analysis (e.g. 2-sample t-test or regression) in R, for example, it seems like the workflow would be to create the t-stat map for the contrast of interest, convert this to a Z map and then apply the pTFCE as described in the usage instructions (similar to SPM). Is this correct? It also seems like pTFCE could be used beyond voxel-based analyses, for example surface or tract based analyses or even analyses of multiple regions of interest? (keeping in mind to use multiple comparison corrected results). Has there been any work done using pTFCE in these areas? Given pTFCE can directly output the p-values without permutation testing, are there disadvantages of pTFCE compared TFCE and permutation testing?

Thanks in advance! Much appreciated!
Doug

Z-scores change after pTFCE

Hi,

I have been trying to use the pTFCE tool but I'm very new to this kind of analysis. I'm having some issues so I might be doing something wrong.

I generated z-maps of FDG-PET images of lesioned rat brains by calculating (x-µ)/SD, where x is a voxel value in an image post-lesion and µ and SD are the voxel mean and standard deviation derived from a baseline average template of control animals. My images contain some very high z-scores but the pTFCE tool runs smoothly after truncating those values and setting them to 30. However, after pTFCE, the actual voxel z-scores are changed. E.g. after the analysis, there will be z-scores of over 30 again. If I input an image with only positive z-scores, after pTFCE some voxels will have a negative value. I don't think this should be happening since this might probably generate incorrect results when performing fwer thresholding?

Maybe I'm not using this tool correctly. I'm also not sure if truncating the high values might have a significant influence on my results...

Here are some example images.

Zmaps.zip

Thanks a lot in advance!

Special handling for two-sided Z maps?

Hi and thank you for the great software.

I ran this on a test Z map that has both positive and negative Z values, and it seems to have discarded the voxels with negative values. It appears that the user should manipulate the Z-map to be "one sided" and then reintegrate sign info if necessary. Is that correct?

Error in seq.default(logpmin, logpmax, length.out = Nh) : 'to' must be a finite number

I'm struggling with what looks like a numerical issue. Running this stat file and mask seem to get me in trouble:

library(oro.nifti) 
library(pTFCE) 
Z=readNIfTI('stat.nii.gz') 
MASK=readNIfTI('mask.nii.gz') 
pTFCE=ptfce(Z, MASK) 

Estimating smoothness based on the data...
|=============================================================| 100%
Error in seq.default(logpmin, logpmax, length.out = Nh) :
'to' must be a finite number

here are the files I'm working with. I checked to ensure all values are above board, the statistic is positive across the whole mask.

mask.nii.gz
stat.nii.gz

(Also, thanks for the great software! the download / install / test example all went beautifully)

pTFCE with or without FDR/FWE multiple-comparison correction?

Hi,

This is a naive series of clarification questions, but I'd just like to confirm that I understand a few practical things about pTFCE, seeing as there is also a bit of variation in published articles that have used (p)TFCE with some articles reporting along the lines of, "p < 0.005 pTFCE corrected" while others, "p < 0.05, FWER corrected, pTFCE".

1a). Would it be a reasonable way to think about pTFCE as addressing the problem of over-inflated p's due to multiple comparisons (without applying FDR or FWE) -- and therefore, we can very well say "p < 0.005 pTFCE corrected"? I thought TFCE was actually an alternative to cluster-extent based approach to deal with multiple comparisons -- with AFNI's AlphaSim, we would usually report along the lines of "p<0.001 uncorr. voxelwise, corrected at p<0.05 on cluster size" -- so wouldn't applying FDR and FWER on top of pTFCE be overkill? When would you do pTFCE and FDR or FWE?

1b). Any rules of thumb/things to keep in mind/pitfalls to avoid for choosing the threshold level of pTFCE-enhanced images when not using FWE/FDER as well?

According to the Wiki on ptfce.r, "In general, it is valid to threshold your enhanced Z-score image with the same Z-score threshold you would have applied for the original (unenhanced) Z-score image. E.g. you can threshold the enhanced Z-score image for an uncorrected p<0.001 with the corresponding Z-score value of Z>3.1." -- what I read in this snippet is that not applying FDR/FWE on top of pTFCE is methodologically okay as long as we choose a threshold that is low enough. (In my case, it seems like a threshold of p<0.001 in the "p_uncorr" column in the "peak" section of the SPM results table may still not be low enough -- I have quite a few 1-vx activations in my pTFCE-enhanced image, which does not instill much confidence in me. However, looking at FDR/FWE (if I were to just read it straight off the SPM results table of the pTFCE-enhanced stat map) seems overly conservative.

2). To apply FDR or FWER, is it just a matter of reading off p_FWE-corr and q_FDR-corr in the "peak-level" section of the SPM results table of the pTFCE-enhanced contrasts?

In the 2019 NeuroImage paper, "pTFCE_vox" is decribed as "T-score maps...converted to Z-score maps, fed into the pTFCE algorithm and thresholded based on GRF theory, with a corrected threshold of p < 0.05" -- would this correspond to p<0.05 in the "p_FWE_corr" column in the SPM results table of the pTFCE-enhanced stat image?

On the Wiki for the SPM-toolbox version of pTFCE, it does say that the stats in the "peak-level" section of the SPM results table is correct (and just to ignore the "cluster-level" section). Is this because the FDR/FWE q/p values are based on the original stat map? Because otherwise it would seem to contradict the ptfce.r Wiki which says:
"Never use the enhanced Z-score map as an input for GRF-based multiple correction techniques. Instead, use the original Z-score map to compute the Z-score threshold and then use this threshold on the enhanced image."

3). On the Wiki for ptfce.r, should the following passage:

"Never use voxel-level thresholding on the pTFCE-enhanced image. It already incorporates the cluster information, thus thresholding it based on cluster-extent (of the original image) would be double-dipping."

actually say "Never use cluster-level thresholding on the pTFCE-enhanced image" ?

Thank you very much for your help (and for the toolbox!)!
Gina

error in pTFCE installation

Hello,
I am trying to install pTFCE as described in the WIKI (https://github.com/spisakt/pTFCE/wiki/3.-R-package)
Since I didn't have R, I started by installing R in /usr/lib/R.
Then, from the R console I typed: install.packages("devtools")
and then library(devtools) which gave the following error:
> library(devtools)
Error in library(devtools) : there is no package called ‘devtools’

I tried to install devtools separately from another bash shell and after completing the devtools installation, I returned to the R console to continue with the installation of pTFCE. Unfortunately this was not successful. These errors came up:
> library(devtools)
Error in library(devtools) : there is no package called ‘devtools’
> install_github("spisakt/[email protected]")
Error in install_github("spisakt/[email protected]") : could not find function "install_github"

Any ideas how can get over these errors and finally use pTFCE?
Thank you!

What is the thresholded map?

Hi @spisakt

I testing pTFCE on some simulated data of the LESYMAP package. I am a bit unsure what to do with the output. Looks like the $Z output is an unthresholded map, I though I need to use $fwer0.05.Z to threshold $Z. This is not producing good results. I noticed that the zscores in $Z are all higher than the input map. I tried applying $fwer0.05.Z to threshold my original z-map, and that seems to work a bit better. Wanted to double check with you what is the right way to do this. The area of simulation in LESYMAP is the inferior temporal cortex.

Here is more or less the code I used for tests.

library(LESYMAP)

lesydata = file.path(find.package('LESYMAP'),'extdata')
filenames = Sys.glob(file.path(lesydata, 'lesions', 'Subject*.nii.gz'))
behavior = Sys.glob(file.path(lesydata, 'behavior', 'behavior.txt'))
template = antsImageRead(
  Sys.glob(file.path(lesydata, 'template', 'ch2.nii.gz')))
lsm = lesymap(filenames, behavior, method = 'ttest',
              multipleComparison = 'none', checkAssumptions=F)

save.lesymap(lsm, '~/pTFCEtest')
templatefile = Sys.glob(file.path(lesydata, 'template', 'ch2.nii.gz'))

file.copy(templatefile, '~/pTFCEtest/ch2.nii.gz')

# plot(template, lsm$stat.img, window.overlay = range(lsm$stat.img))
#
# plot(template, lsm$zmap.img, window.overlay = range(lsm$zmap.img))

zfilename = paste0(tempfile('zmap'), '.nii')
maskfilename = paste0(tempfile('mask'), '.nii')

antsImageWrite(lsm$zmap.img, zfilename)
antsImageWrite(lsm$mask.img, maskfilename)


library(pTFCE)
library(oro.nifti)

Z=readNIfTI(zfilename);

MASK=readNIfTI(maskfilename);

pTFCE=ptfce(Z, MASK);

pTFCE$number_of_resels
pTFCE$fwer0.05.Z
pTFCE$Z


writeNIfTI(pTFCE$Z, '~/pTFCEtest/pTFCE_Z.nii')

newZ = pTFCE$Z
newZ[newZ < pTFCE$fwer0.05.Z] = 0

writeNIfTI(newZ, '~/pTFCEtest/pTFCE_Zthresholded.nii')
writeNIfTI(pTFCE$p, '~/pTFCEtest/pTFCE_P.nii')


alternativeZ = antsImageClone(lsm$zmap.img)
range(alternativeZ)
alternativeZ[alternativeZ < pTFCE$fwer0.05.Z] = 0

antsImageWrite(alternativeZ, '~/pTFCEtest/zmap_img_PTFCEthresholded.nii.gz')

2-sample t-test error

Hello,

I am trying to use pTFCE in order to enhance the result of a 2-sample t-test analysis in SPM and I get this error:
Image to be enhanced: spmT_0001.nii
Index exceeds matrix dimensions.

Error in spm_write_vol (line 22)
dt = V.dim(4); if dt>256, dt = dt/256; end;

Error in gui_pTFCE (line 200)
spm_write_vol(V_ptfce,ptfce_p);

Error in spm (line 946)
evalin('base',xTB(i).prog);

Error while evaluating UIControl Callback

I have also tried pTFCE with a 1-sample t-test analysis and it worked fine...

Any help would be very valuable!
Thank you!

R package installation issue: cannot remove prior installation of package

R version 3.6.2
R studio version 1.0.153
These packages have more recent versions available.
It is recommended to update all of them.
Which would you like to update?

1: All
2: CRAN packages only
3: None
4: glue (1.4.1 -> 1.4.2) [CRAN]
5: mime (0.8 -> 0.9 ) [CRAN]
6: htmltools (0.4.0 -> 0.5.0) [CRAN]
7: xfun (0.12 -> 0.16 ) [CRAN]
8: tinytex (0.19 -> 0.25 ) [CRAN]
9: yaml (2.2.0 -> 2.2.1) [CRAN]
10: knitr (1.27 -> 1.29 ) [CRAN]
11: rmarkdown (2.1 -> 2.3 ) [CRAN]
12: Rcpp (1.0.3 -> 1.0.5) [CRAN]

Enter one or more numbers, or an empty line to skip updates:
I have tried to input either 1 or 2 or 3

But I got the error below:
Error: Failed to install 'pTFCE' from GitHub:
(converted from warning) cannot remove prior installation of package ‘Rcpp’

I tried to open R studio again but still got the same error.
I'm wondering if you can give me some advice?
Thank you!

NaNs produced

You have addressed the underflow issue before and made the updated using version 0.2.2.1. I'm currently using pTFCE version 0.2.2.1 but I'm still getting NaNs. The files (at the bottom), which are of Zmaps and the mask, produce NaNs for 1470 voxels.

I did as follows,

library("oro.nifti")
library("pTFCE")
Z <- readNIfTI(fname="Pseudo-Zmap.nii.gz")
mask <- readNIfTI(fname="Pseudo-mask.nii.gz")
pp <- ptfce(-Z,mask)
* Estimating smoothness based on the data...
  |======================================================================| 100%
* Performing pTFCE...
  |======================================================================| 100%
There were 50 or more warnings (use warnings() to see the first 50)
> warnings()
1: In sqrt(d * (8 * s + d)) : NaNs produced
2: In sqrt(d * (8 * s + d)) : NaNs produced
3: In sqrt(d * (8 * s + d)) : NaNs produced
4: In sqrt(d * (8 * s + d)) : NaNs produced
5: In sqrt(d * (8 * s + d)) : NaNs produced
...

I was hoping you could help me with this?

Many thanks,

Israel

Pseudo-Zmap.nii.gz
Pseudo-mask.nii.gz

Error while estimating smoothness

Hi!

I'm trying to run the pTFCE function on R but I'm getting this error. Any idea what could be the problem?

pTFCE=ptfce(Z, MASK)

  • Estimating smoothness based on the data...

    |
    | | 0%Error in aperm.default(apply(R, c(1, 2, 3), scale), c(2, 3, 4, 1)) :
    'perm' is of wrong length 4 (!= 3)

I'm new to R, so apologies if this is an ignorant question.
Thanks!
Alex

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.