Skip to content

Commit

Permalink
Added an option to return a list object with all the keywords of the …
Browse files Browse the repository at this point in the history
…neurosynth database to decode_surf_data().
  • Loading branch information
chabld committed May 21, 2024
1 parent f9ebd73 commit 710a41e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
20 changes: 16 additions & 4 deletions R/otherfunc.R
Original file line number Diff line number Diff line change
Expand Up @@ -683,20 +683,21 @@ surf_to_vol=function(surf_data, filename)
#'
#' @description Correlates the significant clusters of an earlier vertex-wise analysis with a database of task-based fMRI and voxel-based morphometric statistical maps and associate them with relevant key words
#'
#' @details The \href{https://nimare.readthedocs.io/en/stable/index.html}{NiMARE} python module is used for the imaging decoding and is imported via the reticulate package. The function also downloads the \href{https://github.com/neurosynth/neurosynth-data}{neurosynth} database in the package's inst/extdata direcotry (~8 Mb) for the analysis.
#' @details The \href{https://nimare.readthedocs.io/en/stable/index.html}{NiMARE} python module is used for the imaging decoding and is imported via the reticulate package. The function needs the \href{https://github.com/neurosynth/neurosynth-data}{neurosynth} database in the package's inst/extdata directory to be downloaded (~8 Mb) for the analysis. To maximise the speed of processing, keywords were excluded from the original database if they were: the name of an anatomical brain region, protocol-specific descriptive words that are not meaningful out of context (e.g., “studied”, “clips”, “engaged”), and broad categories that do not specifically point to a content (“disorder”, “psychological”, “cognitive”). A full list can be obtained with the keyword_list argument.
#'
#' @param surf_data a numeric vector with a length of 20484
#' @param contrast A string object indicating whether to decode the positive or negative mask ('positive' or 'negative')
#' @param keywords_list A boolean stating whether to return the full list of keywords in the imported neurosynth database
#'
#' @returns A data.frame object listing the keywords and their Pearson's R values
#' @returns A data.frame object listing the keywords and their Pearson's R values. If keywords_list is TRUE, a list containing the same data.frame object and the list of all the database keywords.
#' @examples
#' CTv = rbinom(20484, 1, 0.001)
#' decode_surf_data(CTv, 'positive')
#' @importFrom reticulate import r_to_py
#' @export

##CT image decoding
decode_surf_data=function(surf_data,contrast="positive")
decode_surf_data=function(surf_data,contrast="positive", keywords_list=F)
{
#Check if required python dependencies and neurosynth are present, nothing will happen if absent
VWRfirstrun("neurosynth")
Expand Down Expand Up @@ -751,7 +752,18 @@ decode_surf_data=function(surf_data,contrast="positive")
colnames(result)=c("keyword","r")
result=result[order(-result$r),]

return(result)
if (keywords_list==T) {
neurosynth_dset = nimare.dataset$Dataset$load(system.file("extdata/neurosynth_dataset.pkl.gz", package='VertexWiseR'))
keywords=colnames(neurosynth_dset$annotations)
keywords=sapply(strsplit(keywords, '__'),"[", 2)[-c(1:3)]
result=list(result,keywords)
}
else
{
return(result)
}


}
}

Expand Down
6 changes: 4 additions & 2 deletions man/decode_surf_data.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 710a41e

Please sign in to comment.