-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from dynverse/devel
dynfeature 1.0.0
- Loading branch information
Showing
25 changed files
with
534 additions
and
330 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,6 @@ | |
^\.Rproj\.user$ | ||
^\.travis | ||
^README\.Rmd$ | ||
^\.git$ | ||
^\.git$ | ||
^\.github$ | ||
^cran-comments\.md$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
on: | ||
push: | ||
branches: | ||
- master | ||
- devel | ||
pull_request: | ||
branches: | ||
- master | ||
schedule: | ||
- cron: "0 0 * * 1" | ||
|
||
name: R-CMD-check | ||
|
||
jobs: | ||
R-CMD-check: | ||
runs-on: ${{ matrix.config.os }} | ||
if: "!contains(github.event.head_commit.message, 'ci skip')" | ||
name: ${{ matrix.config.os }} (${{ matrix.config.r }}) | ||
|
||
strategy: | ||
fail-fast: false | ||
matrix: | ||
config: | ||
#- {os: windows-latest, r: 'release'} | ||
#- {os: macOS-latest, r: 'release'} | ||
- {os: ubuntu-20.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"} | ||
- {os: ubuntu-20.04, r: 'devel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"} | ||
|
||
env: | ||
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true | ||
RSPM: ${{ matrix.config.rspm }} | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- uses: r-lib/actions/setup-r@master | ||
with: | ||
r-version: ${{ matrix.config.r }} | ||
|
||
- uses: r-lib/actions/setup-pandoc@master | ||
|
||
- name: Query dependencies | ||
run: | | ||
install.packages('remotes') | ||
saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2) | ||
writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version") | ||
shell: Rscript {0} | ||
|
||
- name: Restore R package cache | ||
if: runner.os != 'Windows' | ||
uses: actions/cache@v2 | ||
with: | ||
path: ${{ env.R_LIBS_USER }} | ||
key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }} | ||
restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1- | ||
|
||
- name: Install system dependencies | ||
if: runner.os == 'Linux' | ||
run: | | ||
while read -r cmd | ||
do | ||
eval sudo $cmd | ||
done < <(Rscript -e 'writeLines(remotes::system_requirements("ubuntu", "20.04"))') | ||
- name: Install dependencies | ||
run: | | ||
remotes::install_deps(dependencies = TRUE) | ||
remotes::install_cran("rcmdcheck") | ||
shell: Rscript {0} | ||
|
||
- name: Check | ||
env: | ||
_R_CHECK_CRAN_INCOMING_REMOTE_: false | ||
run: rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "warning", check_dir = "check") | ||
shell: Rscript {0} | ||
|
||
- name: Upload check results | ||
if: failure() | ||
uses: actions/upload-artifact@master | ||
with: | ||
name: ${{ runner.os }}-r${{ matrix.config.r }}-results | ||
path: check | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
on: | ||
push: | ||
branches: | ||
- master | ||
- devel | ||
pull_request: | ||
branches: | ||
- master | ||
|
||
name: test-coverage | ||
|
||
jobs: | ||
test-coverage: | ||
runs-on: ubuntu-latest | ||
if: "!contains(github.event.head_commit.message, 'ci skip')" | ||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- uses: r-lib/actions/setup-r@master | ||
|
||
- uses: r-lib/actions/setup-pandoc@master | ||
|
||
- name: Query dependencies | ||
run: | | ||
install.packages('remotes') | ||
saveRDS(remotes::dev_package_deps(dependencies = TRUE), "depends.Rds", version = 2) | ||
shell: Rscript {0} | ||
|
||
- name: Cache R packages | ||
uses: actions/cache@v1 | ||
with: | ||
path: ${{ env.R_LIBS_USER }} | ||
key: ubuntu-r-release-${{ hashFiles('depends.Rds') }} | ||
restore-keys: ubuntu-r-release- | ||
|
||
- name: Install system dependencies | ||
if: runner.os == 'Linux' | ||
run: | | ||
while read -r cmd | ||
do | ||
eval sudo $cmd | ||
done < <(Rscript -e 'writeLines(remotes::system_requirements("ubuntu", "20.04"))') | ||
- name: Install dependencies | ||
run: | | ||
install.packages(c("remotes")) | ||
remotes::install_deps(dependencies = TRUE) | ||
remotes::install_cran("covr") | ||
shell: Rscript {0} | ||
|
||
- name: Test coverage | ||
run: covr::codecov() | ||
shell: Rscript {0} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,22 @@ | ||
Package: dynfeature | ||
Type: Package | ||
Title: Dynamic feature importance | ||
Version: 1.0.0.9000 | ||
Authors@R: c( | ||
person("Robrecht", "Cannoodt", email = "[email protected]", role = c("aut")), | ||
person("Wouter", "Saelens", email = "[email protected]", role = c("aut", "cre"))) | ||
Description: Calculating feature importance scores from trajectories | ||
Title: Feature Importance for Dynamic Processes | ||
Version: 1.0.0 | ||
Authors@R: | ||
c(person(given = "Robrecht", | ||
family = "Cannoodt", | ||
role = c("aut", "cre"), | ||
email = "[email protected]", | ||
comment = c(ORCID = "0000-0003-3641-729X", github = "rcannood")), | ||
person(given = "Wouter", | ||
family = "Saelens", | ||
role = "aut", | ||
email = "[email protected]", | ||
comment = c(ORCID = "0000-0002-7114-6248", github = "zouter"))) | ||
Description: Calculating feature importance scores from trajectories using the random forests algorithm and more. Saelens and Cannoodt et | ||
al. (2019) <doi:10.1038/s41587-019-0071-9>. | ||
License: GPL-3 | ||
Encoding: UTF-8 | ||
LazyData: true | ||
Imports: | ||
dplyr, | ||
dynutils (>= 1.0.2), | ||
|
@@ -22,19 +30,7 @@ Imports: | |
tidyr, | ||
tibble | ||
Suggests: | ||
caret | ||
RoxygenNote: 6.1.1 | ||
caret, | ||
covr | ||
RoxygenNote: 7.1.1 | ||
Roxygen: list(markdown = TRUE) | ||
Remotes: | ||
dynverse/dynutils@devel, | ||
dynverse/dynwrap@devel | ||
Collate: | ||
'calculate_feature_importances.R' | ||
'calculate_branch_feature_importance.R' | ||
'calculate_branching_point_feature_importance.R' | ||
'calculate_cell_feature_importance.R' | ||
'calculate_milestone_feature_importance.R' | ||
'calculate_overall_feature_importance.R' | ||
'calculate_waypoint_feature_importance.R' | ||
'fi_methods.R' | ||
'package.R' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,46 @@ | ||
#' @rdname calculate_overall_feature_importance | ||
#' | ||
#' @export | ||
#' | ||
#' @include calculate_feature_importances.R | ||
calculate_branch_feature_importance <- inherit_default_params( | ||
super_functions = list(calculate_feature_importances), | ||
fun = function( | ||
trajectory, | ||
expression_source = "expression", | ||
fi_method, | ||
verbose | ||
) { | ||
# assign name to each edge | ||
milestone_network <- | ||
trajectory$milestone_network %>% | ||
mutate(edge_id = as.character(row_number())) %>% | ||
select(from, to, edge_id) | ||
calculate_branch_feature_importance <- function( | ||
trajectory, | ||
expression_source = "expression", | ||
fi_method = fi_ranger_rf_lite(), | ||
verbose = FALSE | ||
) { | ||
# assign name to each edge | ||
milestone_network <- | ||
trajectory$milestone_network %>% | ||
mutate(edge_id = as.character(row_number())) %>% | ||
select(.data$from, .data$to, .data$edge_id) | ||
|
||
# determine which cell is part of which edge | ||
edge_membership <- | ||
trajectory$progressions %>% | ||
group_by(cell_id) %>% | ||
top_n(1, percentage) %>% | ||
ungroup() %>% | ||
left_join(milestone_network, c("from", "to")) %>% | ||
reshape2::acast(cell_id ~ edge_id, value.var = "percentage") %>% | ||
{!is.na(.)} | ||
# determine which cell is part of which edge | ||
edge_membership <- | ||
trajectory$progressions %>% | ||
group_by(.data$cell_id) %>% | ||
top_n(1, .data$percentage) %>% | ||
ungroup() %>% | ||
left_join(milestone_network, c("from", "to")) %>% | ||
mutate(contains = TRUE) %>% | ||
reshape2::acast(cell_id ~ edge_id, value.var = "contains", fill = FALSE) | ||
|
||
expression <- get_expression(trajectory, expression_source) | ||
expression <- get_expression(trajectory, expression_source) | ||
|
||
out <- calculate_feature_importances( | ||
X = expression, | ||
Y = edge_membership, | ||
fi_method = fi_method, | ||
verbose = verbose | ||
) | ||
suppressWarnings({ | ||
out <- out %>% | ||
left_join(milestone_network, c("predictor_id" = "edge_id")) | ||
}) | ||
|
||
out <- calculate_feature_importances( | ||
X = expression, | ||
Y = edge_membership, | ||
fi_method = fi_method, | ||
verbose = verbose | ||
out %>% | ||
transmute( | ||
.data$feature_id, | ||
from = factor(.data$from, trajectory$milestone_ids), | ||
to = factor(.data$to, trajectory$milestone_ids), | ||
.data$importance | ||
) | ||
suppressWarnings({ | ||
out <- out %>% | ||
left_join(milestone_network, c("predictor_id" = "edge_id")) | ||
}) | ||
|
||
out %>% | ||
transmute( | ||
feature_id, | ||
from = factor(from, trajectory$milestone_ids), | ||
to = factor(to, trajectory$milestone_ids), | ||
importance | ||
) | ||
} | ||
) | ||
} |
Oops, something went wrong.