Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 28 additions & 24 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,48 @@ name: run act workflow

on:
push:
branches: [ "main" ]
branches: [ "main", "dev" ]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup R
uses: r-lib/actions/setup-r@v2
with:
r-version: '4.2.0' # Specify the R version

- name: Install R packages
run: |
Rscript -e 'install.packages(c("ggplot2", "plyr", "optparse", "tidyr", "GGIR"), repos="https://cloud.r-project.org")'

- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: "3.10"
- name: Install python dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pytest
if [ -f code/requirements.txt ]; then pip install -r code/requirements.txt; fi
- name: Run Python script
run: |
python code/main.py
- name: Commit and push changes to main
run: |
git config --global user.name "GitHub Actions Bot"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git checkout main
git add .
git commit -m "Automated changes from GitHub Actions"
git push origin main
Rscript -e 'install.packages(c("ggplot2","plyr","optparse","tidyr","remotes"), repos="https://cloud.r-project.org", dependencies=TRUE)'
Rscript -e 'remotes::install_version("GGIR", version = "3.2.6", repos = "https://cloud.r-project.org")'

- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: "3.10"

- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pytest
if [ -f code/requirements.txt ]; then pip install -r code/requirements.txt; fi

- name: Run Python script
env:
RC_TOKEN: ${{ secrets.RC_TOKEN }}
run: |
python code/main.py 1 "$RC_TOKEN"

- name: Commit and push changes to main
run: |
git config --global user.name "GitHub Actions Bot"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git checkout main
git add .
git commit -m "Automated changes from GitHub Actions"
git push origin main
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,12 @@
- [ ] add study rule ->
- if sub already in obs -> move to int
- all need to be after start date

### adding sleep logs
- [x] need to return the sleep files from `/sleep` inside the accel folder in RDSS
- [x] modify `code/utils/comparison_utils` to also add the sleep logs to the linkage, storing the correct study inside
- [ ] need to split running by session and split sleep logs by session



- [ ] create a new util that transforms the current logs into the GGIR available one
Empty file added app/.gitkeeper
Empty file.
152 changes: 152 additions & 0 deletions code/core/acc.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
#!/usr/bin/env Rscript

library(tidyr)
library(plyr)
library(optparse)
library(GGIR)

main <- function() {
# Define the option list
option_list <- list(
make_option(c("-p", "--project_dir"), type="character",
default="/mnt/nfs/lss/vosslabhpc/Projects/BOOST/InterventionStudy/3-Experiment/data/act-int-test/",
help="Path to the project directory", metavar="character"),
make_option(c("-d", "--deriv_dir"), type="character",
default="/derivatives/GGIR-2.8.2-test2/",
help="Path to the derivatives directory", metavar="character")
)

# Parse the options
opt_parser <- OptionParser(option_list=option_list)
opt <- parse_args(opt_parser)

# Assign variables
ProjectDir <- opt$project_dir
ProjectDerivDir <- opt$deriv_dir

# Print values to verify
print(paste("Project Directory:", ProjectDir))
print(paste("Derivatives Directory:", ProjectDerivDir))

# Helper functions
SubjectGGIRDeriv <- function(x) {
a <- dirname(x)
paste0(ProjectDir, ProjectDerivDir, a)
}

datadirname <- function(x) {
b <- dirname(x)
paste0(ProjectDir, b)
}

# Gather subject directories
directories <- list.dirs(ProjectDir, recursive = FALSE)
subdirs <- directories[grepl("sub-*", directories)]
print(paste("subdirs: ", subdirs))

# Create project-specific derivatives GGIR folder if it doesn't already exist
if (!dir.exists(paste0(ProjectDir, ProjectDerivDir))) {
dir.create(paste0(ProjectDir, ProjectDerivDir))
}

# List accel.csv files within subject-specific folders
filepattern <- "*accel.csv"
GGIRfiles <- list.files(subdirs, pattern = filepattern, recursive = TRUE,
include.dirs = TRUE, full.names = TRUE, no.. = TRUE)
print(paste("GGIR Files before splitting: ", GGIRfiles))

# Split files at the "//" so we only have paths from sub-XXX/ses-.....
GGIRfiles <- sapply(strsplit(GGIRfiles, "//", fixed = TRUE), function(x) paste(x[2]))

print(paste("GGIR Files after splitting: ", GGIRfiles))


# Ensure directory structure exists for GGIR processing
for (i in GGIRfiles) {
if (!dir.exists(SubjectGGIRDeriv(i))) {
dir.create(SubjectGGIRDeriv(i), recursive = TRUE)
}
}


# Run GGIR loop
for (r in GGIRfiles) {
if (dir.exists(paste0(SubjectGGIRDeriv(r), "/output_beh"))) {
next
} else {
datadir <- paste0(normalize(path(datadirname(r)))
outputdir <- paste0(SubjectGGIRDeriv(r))
print(paste("datadir: ", datadir))
print(paste("outputdir: ", outputdir))
if (!dir.exists(datadir)) {
stop(paste("Error: datadir does not exist ->", datadir))
}
# Force evaluation before calling GGIR
assign("datadir", datadir, envir = .GlobalEnv)
assign("outputdir", outputdir, envir = .GlobalEnv)

try(g.shell.GGIR(
mode = 1:5,
datadir = get("datadir", envir = .GlobalEnv),
outputdir = get("outputdir", envir = .GlobalEnv),
overwrite = FALSE,
print.filename = TRUE,
storefolderstructure = FALSE,
windowsizes = c(5, 900, 3600),
desiredtz = "America/Chicago",
do.enmo = TRUE, do.anglez = TRUE,
dayborder = 0,
strategy = 1, hrs.del.start = 0, hrs.del.end = 0,
maxdur = 0, includedaycrit = 0,
idloc = 1,
dynrange = 8,
chunksize = 1,
do.cal = TRUE,
use.temp = FALSE,
spherecrit = 0.3,
minloadcrit = 72,
printsummary = TRUE,
do.imp = TRUE,
epochvalues2csv = TRUE,
L5M5window = c(0,24),
M5L5res = 10,
winhr = c(5,10),
qlevels = c(960/1440, 1320/1440, 1380/1440, 1410/1440, 1430/1440, 1435/1440, 1438/1440),
ilevels = seq(0,600, by = 25),
iglevels = c(seq(0,4000, by = 25), 8000),
bout.metric = 4,
do.visual = TRUE,
excludefirstlast = FALSE,
includenightcrit = 0,
anglethreshold = 5,
timethreshold = 5,
ignorenonwear = TRUE,
acc.metric = "ENMO",
do.part3.pdf = TRUE,
outliers.only = FALSE,
def.noc.sleep = 1,
excludefirstlast.part5 = FALSE,
maxdur = 0,
threshold.lig = c(45),
threshold.mod = c(100),
threshold.vig = c(430),
boutdur.mvpa = c(1,5,10),
boutdur.in = c(10,20,30),
boutdur.lig = c(1,5,10),
boutcriter.mvpa = 0.8,
boutcriter.in = 0.9,
boutcriter.lig = 0.8,
timewindow = c("MM", "WW"),
acc.metric = "ENMO",
do.report = c(2,4,5),
visualreport = TRUE,
do.parallel = TRUE
))
}
}
}

# Run main if executed as a script
if (!interactive()) {
main()
}
131 changes: 131 additions & 0 deletions code/core/acc_new.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@

#!/usr/bin/env Rscript

# Usage: Rscript new_gg.R --project_dir "/Shared/vosslabhpc/Projects/BOOST/InterventionStudy/3-experiment/data/act-int-test/" --deriv_dir "derivatives/GGIR-3.2.6-test/"
library(tidyr)
library(plyr)
library(optparse)
if (!requireNamespace("remotes", quietly = TRUE)) {
install.packages("remotes")
}
if (!requireNamespace("GGIR", quietly = TRUE) || packageVersion("GGIR") != "3.2.6") {
remotes::install_version("GGIR", version = "3.2.6", repos = "https://cloud.r-project.org")
}

library(GGIR)

main <- function() {
# Define the option list
option_list <- list(
make_option(c("-p", "--project_dir"), type = "character",
default = "/mnt/nfs/lss/vosslabhpc/Projects/BOOST/InterventionStudy/3-Experiment/data/act-int-test/",
help = "Path to the project directory", metavar = "character"),
make_option(c("-d", "--deriv_dir"), type = "character",
default = "/derivatives/GGIR-3.2.6-test/",
help = "Path to the derivatives directory", metavar = "character")
)

# Parse the options
opt_parser <- OptionParser(option_list = option_list)
opt <- parse_args(opt_parser)

# Assign variables
ProjectDir <- opt$project_dir
ProjectDerivDir <- opt$deriv_dir

# Print values to verify
print(paste("Project Directory:", ProjectDir))
print(paste("Derivatives Directory:", ProjectDerivDir))

# Helper functions
SubjectGGIRDeriv <- function(x) {
a <- dirname(x)
paste0(ProjectDir, ProjectDerivDir, a)
}

datadirname <- function(x) {
b <- dirname(x)
paste0(ProjectDir, b)
}

# Gather subject directories
directories <- list.dirs(ProjectDir, recursive = FALSE)
subdirs <- directories[grepl("sub-*", directories)]
print(paste("subdirs: ", subdirs))

# Create project-specific derivatives GGIR folder if it doesn't exist
if (!dir.exists(paste0(ProjectDir, ProjectDerivDir))) {
dir.create(paste0(ProjectDir, ProjectDerivDir))
}

# List accel.csv files
filepattern <- "*accel.csv"
GGIRfiles <- list.files(subdirs, pattern = filepattern, recursive = TRUE,
include.dirs = TRUE, full.names = TRUE, no.. = TRUE)
print(paste("GGIR Files before splitting: ", GGIRfiles))

# Adjust path formatting
GGIRfiles <- sapply(strsplit(GGIRfiles, "//", fixed = TRUE), function(x) paste(x[2]))
print(paste("GGIR Files after splitting: ", GGIRfiles))

# Ensure directory structure exists
for (i in GGIRfiles) {
if (!dir.exists(SubjectGGIRDeriv(i))) {
dir.create(SubjectGGIRDeriv(i), recursive = TRUE)
}
}

# Run GGIR loop
for (r in GGIRfiles) {
if (dir.exists(paste0(SubjectGGIRDeriv(r), "/output_beh"))) {
next
} else {
datadir <- normalizePath(datadirname(r), mustWork = FALSE)
outputdir <- SubjectGGIRDeriv(r)
print(paste("datadir: ", datadir))
print(paste("outputdir: ", outputdir))
if (!dir.exists(datadir)) {
stop(paste("Error: datadir does not exist ->", datadir))
}

assign("datadir", datadir, envir = .GlobalEnv)
assign("outputdir", outputdir, envir = .GlobalEnv)

try({
GGIR(
mode = 1:6,
datadir = datadir,
outputdir = outputdir,
studyname = "boost",
overwrite = FALSE,
do.report = c(2, 4, 5, 6),
visualreport = TRUE,
old_visualreport = FALSE,
windowsizes = c(5, 900, 3600),
desiredtz = "America/Chicago",
print.filename = TRUE,
dayborder = 0,
idloc = 2,
epochvalues2csv = TRUE,
ignorenonwear = TRUE,
do.ENMO = TRUE,
acc.metric = "ENMO",
hrs.del.start = 4,
hrs.del.end = 3,
maxdur = 9,
loglocation = "/Shared/vosslabhpc/Projects/BOOST/InterventionStudy/3-experiment/data/act-int-test/sleep.csv",
colid = 1,
coln1 = 2,
sleepwindowType = "SPT",
timewindow = c("WW", "MM", "OO"),
part6CR = TRUE
)
})
}
}
}

# Run main if executed as script
if (!interactive()) {
main()
}
Loading
Loading