Skip to content

Commit

Permalink
Merge pull request #7 from dynverse/devel
Browse files Browse the repository at this point in the history
dynfeature 1.0.0
  • Loading branch information
rcannood authored Jun 14, 2021
2 parents 822c05d + ab72f40 commit cd2703a
Show file tree
Hide file tree
Showing 25 changed files with 534 additions and 330 deletions.
4 changes: 3 additions & 1 deletion .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
^\.Rproj\.user$
^\.travis
^README\.Rmd$
^\.git$
^\.git$
^\.github$
^cran-comments\.md$
1 change: 1 addition & 0 deletions .github/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.html
83 changes: 83 additions & 0 deletions .github/workflows/R-CMD-check.yml
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

54 changes: 54 additions & 0 deletions .github/workflows/test_coverage.yml
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}

40 changes: 18 additions & 22 deletions DESCRIPTION
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 = "rcannood@gmail.com", role = c("aut")),
person("Wouter", "Saelens", email = "wouter.saelens@ugent.be", 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 = "rcannood@gmail.com",
comment = c(ORCID = "0000-0003-3641-729X", github = "rcannood")),
person(given = "Wouter",
family = "Saelens",
role = "aut",
email = "wouter.saelens@gmail.com",
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),
Expand All @@ -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'
5 changes: 4 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ export(calculate_waypoint_feature_importance)
export(fi_caret)
export(fi_ranger_rf)
export(fi_ranger_rf_lite)
export(fi_ranger_rf_tiny)
import(dplyr)
import(dynutils)
import(dynwrap)
import(methods)
import(tibble)
import(tidyr)
importFrom(purrr,"%>%")
importFrom(purrr,invoke)
Expand All @@ -28,3 +28,6 @@ importFrom(purrr,map_lgl)
importFrom(purrr,set_names)
importFrom(ranger,ranger)
importFrom(reshape2,acast)
importFrom(tibble,as_tibble)
importFrom(tibble,tibble)
importFrom(tibble,tribble)
8 changes: 6 additions & 2 deletions inst/NEWS.md → NEWS.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# dynfeature 1.0.0 (28-03-2019)
# dynfeature 1.0.0

Initial release of dynfeature on CRAN.

* MINOR CHANGE: Use only one core by default.

* MINOR CHANGE: Support sparse matrices
* MINOR CHANGE: Support sparse matrices.

* DOCUMENTATION: Add examples and returns.

# dynfeature 0.2.0 (25-10-2018)

Expand Down
82 changes: 38 additions & 44 deletions R/calculate_branch_feature_importance.R
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
)
}
)
}
Loading

0 comments on commit cd2703a

Please sign in to comment.