Skip to content

Commit

Permalink
Version 0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Jinyao Tian committed Sep 6, 2024
1 parent fde908f commit fdf9c03
Show file tree
Hide file tree
Showing 33 changed files with 1,339 additions and 521 deletions.
Binary file modified .DS_Store
Binary file not shown.
4 changes: 4 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
^.*\.Rproj$
^\.Rproj\.user$
^_pkgdown\.yml$
^docs$
^pkgdown$
^\.github$
2 changes: 1 addition & 1 deletion .Rproj.user/6A9A55E1/pcs/files-pane.pper
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
"ascending": true
}
],
"path": "~/Desktop/WHIMs/R"
"path": "~/Desktop/WHIMs"
}
2 changes: 1 addition & 1 deletion .Rproj.user/6A9A55E1/pcs/source-pane.pper
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"activeTab": 1
"activeTab": 3
}
12 changes: 6 additions & 6 deletions .Rproj.user/6A9A55E1/pcs/windowlayoutstate.pper
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"left": {
"splitterpos": 125,
"splitterpos": 176,
"topwindowstate": "NORMAL",
"panelheight": 663,
"windowheight": 701
"panelheight": 682,
"windowheight": 720
},
"right": {
"splitterpos": 272,
"splitterpos": 204,
"topwindowstate": "NORMAL",
"panelheight": 663,
"windowheight": 701
"panelheight": 682,
"windowheight": 720
}
}
2 changes: 1 addition & 1 deletion .Rproj.user/6A9A55E1/pcs/workbench-pane.pper
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"TabSet1": 0,
"TabSet1": 4,
"TabSet2": 0,
"TabZoom": {}
}
1 change: 1 addition & 0 deletions .github/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.html
50 changes: 50 additions & 0 deletions .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]
release:
types: [published]
workflow_dispatch:

name: pkgdown.yaml

permissions: read-all

jobs:
pkgdown:
runs-on: ubuntu-latest
# Only restrict concurrency for non-PR jobs
concurrency:
group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }}
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
permissions:
contents: write
steps:
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::pkgdown, local::.
needs: website

- name: Build site
run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE)
shell: Rscript {0}

- name: Deploy to GitHub pages 🚀
if: github.event_name != 'pull_request'
uses: JamesIves/[email protected]
with:
clean: false
branch: gh-pages
folder: docs
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
.Rhistory
.RData
.Ruserdata
inst/doc
docs
38 changes: 28 additions & 10 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,19 +1,37 @@
Package: whims
Type: Package
Title: What the Package Does (Title Case)
Title: NeuroPartitioner: An R Package for ROI-Based Transformation of Neuroimages into High-Dimensional Data Frames
Version: 0.1.0
Authors@R: c(
person("Jinyao", "Tian", , "[email protected]", role = "aut")
person("Joshua", "Milstein", email = "[email protected]", role = c("aut")),
person("Jinyao", "Tian", email = "[email protected]", role = c("aut", "cre"))
)
Maintainer: Jinyao Tian <[email protected]>
Description: More about what it does (maybe more than one line)
Use four spaces when indenting paragraphs within the Description.
Maintainer: Jinyao Tian <[email protected]>, Joshua Milstein <[email protected]>
Description: NeuroPartitioner is an advanced R package designed to convert NIfTI format T1/FL neuroimages into structured, high-dimensional 2D data frames, focusing on region of interest (ROI) based processing. This package incorporates a key algorithm called ‘partition’, which offers a fast, flexible framework for agglomerative partitioning based on the Direct-Measure-Reduce approach. This method ensures that each reduced variable maintains a user-specified minimum level of information while being interpretable, as each maps uniquely to one variable in the reduced dataset. The ‘partition’ algorithm, detailed in Millstein et al. (2020), allows for customization in variable selection, measurement of information loss, and data reduction methods. NeuroPartitioner is indispensable for researchers requiring efficient, accurate preparation of neuroimaging data for detailed statistical analysis and machine learning applications, enhancing the interpretability and utility of neuroimaging studies.
License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true

Imports:
Partition (>= version_number)

Rcpp,
devtools,
partition,
dplyr,
ggplot2,
neurobase,
purrr,
tibble,
reshape2,
parallel,
roxygen2,
DT
SystemRequirements: FSL (FMRIB Software Library, available at https://fsl.fmrib.ox.ac.uk/fsl/docs/#/install/index)
LinkingTo:
Rcpp
Encoding: UTF-8
Language: en-US
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.2
Suggests:
knitr,
rmarkdown
VignetteBuilder: knitr
URL: https://jtian123.github.io/WHIMs/
23 changes: 22 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
@@ -1 +1,22 @@
exportPattern("^[[:alpha:]]+")
# Generated by roxygen2: do not edit by hand

export(eve_Fl)
export(eve_T1)
export(run_partition_pipeline)
export(suppar)
import(R6)
importFrom(EveTemplate,getEvePath)
importFrom(Rcpp,sourceCpp)
importFrom(dplyr,"%>%")
importFrom(extrantsr,bias_correct)
importFrom(extrantsr,fslbet_robust)
importFrom(fslr,fast)
importFrom(fslr,fsl_biascorrect)
importFrom(fslr,fslbet)
importFrom(fslr,fslreorient2std)
importFrom(fslr,fslstats)
importFrom(neurobase,readnii)
importFrom(neurobase,writenii)
importFrom(oro.nifti,img_data)
importFrom(oro.nifti,voxres)
useDynLib(whims, .registration = TRUE)
Binary file modified R/.DS_Store
Binary file not shown.
71 changes: 0 additions & 71 deletions R/OSCA_singleValue.R

This file was deleted.

125 changes: 125 additions & 0 deletions R/PartitionPipeline.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
#Purpose: Make an object for this pipeline, to streamline them
#' @import R6
PartitionPipeline <- R6Class("PartitionPipeline",
public = list(
tind = NULL,
nfl = NULL,
main_dir = NULL,
tissue_type = NULL,
outp_volume = TRUE,
ICC_thresh_vec = NULL,
suppar_thresh_vec = seq(0.7, 1, 0.01),
B = 2000,
roi = NULL,
num_cores = NULL,
# Constructor
initialize = function(tind = NULL, nfl = NULL, main_dir = NULL, tissue_type = NULL,
outp_volume = TRUE, ICC_thresh_vec = NULL, suppar_thresh_vec = seq(0.7, 1, 0.01), B = 2000, roi = NULL, num_cores = NULL) {
self$tind <- tind
self$nfl <- nfl
self$main_dir <- main_dir
self$tissue_type <- tissue_type
self$outp_volume <- outp_volume
self$ICC_thresh_vec <- ICC_thresh_vec
self$suppar_thresh_vec <- suppar_thresh_vec
self$B <- B
self$roi <- roi
self$num_cores = num_cores
},

# Step1: Process images and extract intensities and tissues
iproc = function() {
cat("Starting image processing for ROI:", self$tind, "\n")
result = iproc(tind = self$tind, nfl = self$nfl, main_dir = self$main_dir, outp_volume = self$outp_volume)
self$roi = result
},

# Step2: Apply super partition analysis
supparfun = function() {
cat("Starting applying Super Partition to ROI:", self$roi, "\n")
supparfun(
tind = self$tind,
roi = self$roi,
thresh_vec = self$suppar_thresh_vec,
B = self$B,
main_dir = self$main_dir)
},

# Step3: Map super partitions to ROI
map_suppar_roi = function() {
map_suppar_roi(roi = self$roi, main_dir = self$main_dir)
},

# Step4: Partition intensities based on super partitions using lapply
parfun = function() {
dep_list_path = file.path(self$main_dir, "dep_list", paste0(self$roi,'.rds'))
listes <- readRDS(dep_list_path)
cat("Partitioning intensities for all sublists based on super partitions.\n")
cl <- makeCluster(self$num_cores)
parLapply(cl, listes, function(sub_list) {
parfun(liste = sub_list,tind = self$tind, thresh_vec = self$ICC_thresh_vec, main_dir = self$main_dir)
})
# Stop the cluster after use
on.exit(stopCluster(cl))
},

# Step5: Segment tissue types
tissue_segment = function() {
dep_list_path = file.path(self$main_dir, "dep_list", paste0(self$roi,'.rds'))
listes <- readRDS(dep_list_path)
cat("tissue segmentation for all sublists based on super partitions.\n")
lapply(listes, function(sub_list) {
tissue_segment(liste = sub_list,thresh_vec = self$ICC_thresh_vec,tind = self$tind, tissue_type =self$tissue_type,
brain_volume_path = NULL, main_dir = self$main_dir)
})
},

# Step6: Combine by tissue type for each threshold and roi
Cmb_tissue_type = function(){
lapply(as.list(self$ICC_thresh_vec), function(x){
Cmb_tissue_type(thresh = x, roi = self$roi, tissue_type = self$tissue_type, main_dir = self$main_dir)
})
},

# Step7: Process independent variables from Super-Partition
process_indep_variables = function(){
indep_list_path = file.path(self$main_dir, "indep_list", paste0(self$roi,'.rds'))
indep_list <- readRDS(indep_list_path)
process_indep_variables(indep_list = indep_list, tissue_type = self$tissue_type, tind = self$tind,
roi = self$roi, main_dir = self$main_dir)
},

# Step8: Combine independent variables with reduced variables by tissue type by roi
Cmb_indep_with_dep = function(){
lapply(as.list(self$ICC_thresh_vec), function(x){
Cmb_indep_with_dep(thresh = x, roi = self$roi, tissue_type = self$tissue_type, main_dir = self$main_dir)
})
}
)
)

#test
# pipeline <- PartitionPipeline$new(tind = 5, nfl = list.files('/Users/jinyaotian/Downloads/pipeline_test/eve_t1', full.names = TRUE),
# main_dir = "/Users/jinyaotian/Downloads/pipeline_test",
# tissue_type = 2,
# ICC_thresh_vec = c(0.8, 0.9),
# roi = "inferior_frontal_gyrus_left",
# num_cores = 5)
#
# # Step 1
# pipeline$iproc()
# # Step 2
# pipeline$supparfun()
# # Step 3
# pipeline$map_suppar_roi()
# # Step 4
# pipeline$parfun()
# # Step 5
# pipeline$tissue_segment()
# # Step 6
# pipeline$Cmb_tissue_type()
# # Step 7
# pipeline$process_indep_variables()
# # Step 8
# pipeline$Cmb_indep_with_dep()

Loading

0 comments on commit fdf9c03

Please sign in to comment.