Skip to content

Commit f8e4714

Browse files
authored
Merge pull request #1 from HBClab/dev
Dev
2 parents 348ea4a + dab14b5 commit f8e4714

23 files changed

+9087
-115
lines changed

.github/workflows/main.yml

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,48 @@ name: run act workflow
22

33
on:
44
push:
5-
branches: [ "main" ]
5+
branches: [ "main", "dev" ]
66

77
jobs:
88
build:
99
runs-on: ubuntu-latest
1010

1111
steps:
12-
- uses: actions/checkout@v4
12+
- name: Checkout repository
13+
uses: actions/checkout@v4
14+
1315
- name: Setup R
1416
uses: r-lib/actions/setup-r@v2
1517
with:
1618
r-version: '4.2.0' # Specify the R version
1719

1820
- name: Install R packages
1921
run: |
20-
Rscript -e 'install.packages(c("ggplot2", "plyr", "optparse", "tidyr", "GGIR"), repos="https://cloud.r-project.org")'
21-
22-
- name: Set up Python 3.10
23-
uses: actions/setup-python@v3
24-
with:
25-
python-version: "3.10"
26-
- name: Install python dependencies
27-
run: |
28-
python -m pip install --upgrade pip
29-
python -m pip install flake8 pytest
30-
if [ -f code/requirements.txt ]; then pip install -r code/requirements.txt; fi
31-
- name: Run Python script
32-
run: |
33-
python code/main.py
34-
- name: Commit and push changes to main
35-
run: |
36-
git config --global user.name "GitHub Actions Bot"
37-
git config --global user.email "github-actions[bot]@users.noreply.github.com"
38-
git checkout main
39-
git add .
40-
git commit -m "Automated changes from GitHub Actions"
41-
git push origin main
22+
Rscript -e 'install.packages(c("ggplot2","plyr","optparse","tidyr","remotes"), repos="https://cloud.r-project.org", dependencies=TRUE)'
23+
Rscript -e 'remotes::install_version("GGIR", version = "3.2.6", repos = "https://cloud.r-project.org")'
4224
25+
- name: Set up Python 3.10
26+
uses: actions/setup-python@v3
27+
with:
28+
python-version: "3.10"
4329

30+
- name: Install Python dependencies
31+
run: |
32+
python -m pip install --upgrade pip
33+
python -m pip install flake8 pytest
34+
if [ -f code/requirements.txt ]; then pip install -r code/requirements.txt; fi
4435
36+
- name: Run Python script
37+
env:
38+
RC_TOKEN: ${{ secrets.RC_TOKEN }}
39+
run: |
40+
python code/main.py 1 "$RC_TOKEN"
4541
42+
- name: Commit and push changes to main
43+
run: |
44+
git config --global user.name "GitHub Actions Bot"
45+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
46+
git checkout main
47+
git add .
48+
git commit -m "Automated changes from GitHub Actions"
49+
git push origin main

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,12 @@
2020
- [ ] add study rule ->
2121
- if sub already in obs -> move to int
2222
- all need to be after start date
23+
24+
### adding sleep logs
25+
- [x] need to return the sleep files from `/sleep` inside the accel folder in RDSS
26+
- [x] modify `code/utils/comparison_utils` to also add the sleep logs to the linkage, storing the correct study inside
27+
- [ ] need to split running by session and split sleep logs by session
28+
29+
30+
31+
- [ ] create a new util that transforms the current logs into the GGIR available one

app/.gitkeeper

Whitespace-only changes.

code/core/acc.R

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
#!/usr/bin/env Rscript
2+
3+
library(tidyr)
4+
library(plyr)
5+
library(optparse)
6+
library(GGIR)
7+
8+
main <- function() {
9+
# Define the option list
10+
option_list <- list(
11+
make_option(c("-p", "--project_dir"), type="character",
12+
default="/mnt/nfs/lss/vosslabhpc/Projects/BOOST/InterventionStudy/3-Experiment/data/act-int-test/",
13+
help="Path to the project directory", metavar="character"),
14+
make_option(c("-d", "--deriv_dir"), type="character",
15+
default="/derivatives/GGIR-2.8.2-test2/",
16+
help="Path to the derivatives directory", metavar="character")
17+
)
18+
19+
# Parse the options
20+
opt_parser <- OptionParser(option_list=option_list)
21+
opt <- parse_args(opt_parser)
22+
23+
# Assign variables
24+
ProjectDir <- opt$project_dir
25+
ProjectDerivDir <- opt$deriv_dir
26+
27+
# Print values to verify
28+
print(paste("Project Directory:", ProjectDir))
29+
print(paste("Derivatives Directory:", ProjectDerivDir))
30+
31+
# Helper functions
32+
SubjectGGIRDeriv <- function(x) {
33+
a <- dirname(x)
34+
paste0(ProjectDir, ProjectDerivDir, a)
35+
}
36+
37+
datadirname <- function(x) {
38+
b <- dirname(x)
39+
paste0(ProjectDir, b)
40+
}
41+
42+
# Gather subject directories
43+
directories <- list.dirs(ProjectDir, recursive = FALSE)
44+
subdirs <- directories[grepl("sub-*", directories)]
45+
print(paste("subdirs: ", subdirs))
46+
47+
# Create project-specific derivatives GGIR folder if it doesn't already exist
48+
if (!dir.exists(paste0(ProjectDir, ProjectDerivDir))) {
49+
dir.create(paste0(ProjectDir, ProjectDerivDir))
50+
}
51+
52+
# List accel.csv files within subject-specific folders
53+
filepattern <- "*accel.csv"
54+
GGIRfiles <- list.files(subdirs, pattern = filepattern, recursive = TRUE,
55+
include.dirs = TRUE, full.names = TRUE, no.. = TRUE)
56+
print(paste("GGIR Files before splitting: ", GGIRfiles))
57+
58+
# Split files at the "//" so we only have paths from sub-XXX/ses-.....
59+
GGIRfiles <- sapply(strsplit(GGIRfiles, "//", fixed = TRUE), function(x) paste(x[2]))
60+
61+
print(paste("GGIR Files after splitting: ", GGIRfiles))
62+
63+
64+
# Ensure directory structure exists for GGIR processing
65+
for (i in GGIRfiles) {
66+
if (!dir.exists(SubjectGGIRDeriv(i))) {
67+
dir.create(SubjectGGIRDeriv(i), recursive = TRUE)
68+
}
69+
}
70+
71+
72+
# Run GGIR loop
73+
for (r in GGIRfiles) {
74+
if (dir.exists(paste0(SubjectGGIRDeriv(r), "/output_beh"))) {
75+
next
76+
} else {
77+
datadir <- paste0(normalize(path(datadirname(r)))
78+
outputdir <- paste0(SubjectGGIRDeriv(r))
79+
print(paste("datadir: ", datadir))
80+
print(paste("outputdir: ", outputdir))
81+
if (!dir.exists(datadir)) {
82+
stop(paste("Error: datadir does not exist ->", datadir))
83+
}
84+
# Force evaluation before calling GGIR
85+
assign("datadir", datadir, envir = .GlobalEnv)
86+
assign("outputdir", outputdir, envir = .GlobalEnv)
87+
88+
try(g.shell.GGIR(
89+
mode = 1:5,
90+
datadir = get("datadir", envir = .GlobalEnv),
91+
outputdir = get("outputdir", envir = .GlobalEnv),
92+
overwrite = FALSE,
93+
print.filename = TRUE,
94+
storefolderstructure = FALSE,
95+
windowsizes = c(5, 900, 3600),
96+
desiredtz = "America/Chicago",
97+
do.enmo = TRUE, do.anglez = TRUE,
98+
dayborder = 0,
99+
strategy = 1, hrs.del.start = 0, hrs.del.end = 0,
100+
maxdur = 0, includedaycrit = 0,
101+
idloc = 1,
102+
dynrange = 8,
103+
chunksize = 1,
104+
do.cal = TRUE,
105+
use.temp = FALSE,
106+
spherecrit = 0.3,
107+
minloadcrit = 72,
108+
printsummary = TRUE,
109+
do.imp = TRUE,
110+
epochvalues2csv = TRUE,
111+
L5M5window = c(0,24),
112+
M5L5res = 10,
113+
winhr = c(5,10),
114+
qlevels = c(960/1440, 1320/1440, 1380/1440, 1410/1440, 1430/1440, 1435/1440, 1438/1440),
115+
ilevels = seq(0,600, by = 25),
116+
iglevels = c(seq(0,4000, by = 25), 8000),
117+
bout.metric = 4,
118+
do.visual = TRUE,
119+
excludefirstlast = FALSE,
120+
includenightcrit = 0,
121+
anglethreshold = 5,
122+
timethreshold = 5,
123+
ignorenonwear = TRUE,
124+
acc.metric = "ENMO",
125+
do.part3.pdf = TRUE,
126+
outliers.only = FALSE,
127+
def.noc.sleep = 1,
128+
excludefirstlast.part5 = FALSE,
129+
maxdur = 0,
130+
threshold.lig = c(45),
131+
threshold.mod = c(100),
132+
threshold.vig = c(430),
133+
boutdur.mvpa = c(1,5,10),
134+
boutdur.in = c(10,20,30),
135+
boutdur.lig = c(1,5,10),
136+
boutcriter.mvpa = 0.8,
137+
boutcriter.in = 0.9,
138+
boutcriter.lig = 0.8,
139+
timewindow = c("MM", "WW"),
140+
acc.metric = "ENMO",
141+
do.report = c(2,4,5),
142+
visualreport = TRUE,
143+
do.parallel = TRUE
144+
))
145+
}
146+
}
147+
}
148+
149+
# Run main if executed as a script
150+
if (!interactive()) {
151+
main()
152+
}

code/core/acc_new.R

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
2+
#!/usr/bin/env Rscript
3+
4+
# 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/"
5+
library(tidyr)
6+
library(plyr)
7+
library(optparse)
8+
if (!requireNamespace("remotes", quietly = TRUE)) {
9+
install.packages("remotes")
10+
}
11+
if (!requireNamespace("GGIR", quietly = TRUE) || packageVersion("GGIR") != "3.2.6") {
12+
remotes::install_version("GGIR", version = "3.2.6", repos = "https://cloud.r-project.org")
13+
}
14+
15+
library(GGIR)
16+
17+
main <- function() {
18+
# Define the option list
19+
option_list <- list(
20+
make_option(c("-p", "--project_dir"), type = "character",
21+
default = "/mnt/nfs/lss/vosslabhpc/Projects/BOOST/InterventionStudy/3-Experiment/data/act-int-test/",
22+
help = "Path to the project directory", metavar = "character"),
23+
make_option(c("-d", "--deriv_dir"), type = "character",
24+
default = "/derivatives/GGIR-3.2.6-test/",
25+
help = "Path to the derivatives directory", metavar = "character")
26+
)
27+
28+
# Parse the options
29+
opt_parser <- OptionParser(option_list = option_list)
30+
opt <- parse_args(opt_parser)
31+
32+
# Assign variables
33+
ProjectDir <- opt$project_dir
34+
ProjectDerivDir <- opt$deriv_dir
35+
36+
# Print values to verify
37+
print(paste("Project Directory:", ProjectDir))
38+
print(paste("Derivatives Directory:", ProjectDerivDir))
39+
40+
# Helper functions
41+
SubjectGGIRDeriv <- function(x) {
42+
a <- dirname(x)
43+
paste0(ProjectDir, ProjectDerivDir, a)
44+
}
45+
46+
datadirname <- function(x) {
47+
b <- dirname(x)
48+
paste0(ProjectDir, b)
49+
}
50+
51+
# Gather subject directories
52+
directories <- list.dirs(ProjectDir, recursive = FALSE)
53+
subdirs <- directories[grepl("sub-*", directories)]
54+
print(paste("subdirs: ", subdirs))
55+
56+
# Create project-specific derivatives GGIR folder if it doesn't exist
57+
if (!dir.exists(paste0(ProjectDir, ProjectDerivDir))) {
58+
dir.create(paste0(ProjectDir, ProjectDerivDir))
59+
}
60+
61+
# List accel.csv files
62+
filepattern <- "*accel.csv"
63+
GGIRfiles <- list.files(subdirs, pattern = filepattern, recursive = TRUE,
64+
include.dirs = TRUE, full.names = TRUE, no.. = TRUE)
65+
print(paste("GGIR Files before splitting: ", GGIRfiles))
66+
67+
# Adjust path formatting
68+
GGIRfiles <- sapply(strsplit(GGIRfiles, "//", fixed = TRUE), function(x) paste(x[2]))
69+
print(paste("GGIR Files after splitting: ", GGIRfiles))
70+
71+
# Ensure directory structure exists
72+
for (i in GGIRfiles) {
73+
if (!dir.exists(SubjectGGIRDeriv(i))) {
74+
dir.create(SubjectGGIRDeriv(i), recursive = TRUE)
75+
}
76+
}
77+
78+
# Run GGIR loop
79+
for (r in GGIRfiles) {
80+
if (dir.exists(paste0(SubjectGGIRDeriv(r), "/output_beh"))) {
81+
next
82+
} else {
83+
datadir <- normalizePath(datadirname(r), mustWork = FALSE)
84+
outputdir <- SubjectGGIRDeriv(r)
85+
print(paste("datadir: ", datadir))
86+
print(paste("outputdir: ", outputdir))
87+
if (!dir.exists(datadir)) {
88+
stop(paste("Error: datadir does not exist ->", datadir))
89+
}
90+
91+
assign("datadir", datadir, envir = .GlobalEnv)
92+
assign("outputdir", outputdir, envir = .GlobalEnv)
93+
94+
try({
95+
GGIR(
96+
mode = 1:6,
97+
datadir = datadir,
98+
outputdir = outputdir,
99+
studyname = "boost",
100+
overwrite = FALSE,
101+
do.report = c(2, 4, 5, 6),
102+
visualreport = TRUE,
103+
old_visualreport = FALSE,
104+
windowsizes = c(5, 900, 3600),
105+
desiredtz = "America/Chicago",
106+
print.filename = TRUE,
107+
dayborder = 0,
108+
idloc = 2,
109+
epochvalues2csv = TRUE,
110+
ignorenonwear = TRUE,
111+
do.ENMO = TRUE,
112+
acc.metric = "ENMO",
113+
hrs.del.start = 4,
114+
hrs.del.end = 3,
115+
maxdur = 9,
116+
loglocation = "/Shared/vosslabhpc/Projects/BOOST/InterventionStudy/3-experiment/data/act-int-test/sleep.csv",
117+
colid = 1,
118+
coln1 = 2,
119+
sleepwindowType = "SPT",
120+
timewindow = c("WW", "MM", "OO"),
121+
part6CR = TRUE
122+
)
123+
})
124+
}
125+
}
126+
}
127+
128+
# Run main if executed as script
129+
if (!interactive()) {
130+
main()
131+
}

0 commit comments

Comments
 (0)