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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
.RData
.Ruserdata
inst/doc
docs
docs/
27 changes: 0 additions & 27 deletions R/decide_ReSegment_Operations.R
Original file line number Diff line number Diff line change
Expand Up @@ -434,30 +434,3 @@ check_config_leiden <- function(config){

return(config)
}

#' @title run_igraph_leiden
#' @description Run Leiden clustering with version-compatible resolution argument.
#' @param graph An igraph object representing the graph to cluster.
#' @param ... Additional arguments passed to `cluster_leiden()`, such as
#' `objective_function`, `resolution_parameter`, `beta`, `initial_membership`,
#' and `n_iterations`.
#' @return A clustering object returned by `cluster_leiden()`.
#' @details This function wraps `igraph::cluster_leiden()` and ensures compatibility
#' with both older (<2.1.0) and newer versions of the `igraph` package by renaming
#' the `resolution_parameter` argument to `resolution` if needed.
#' @importFrom igraph cluster_leiden
run_igraph_leiden <- function(graph, ...) {
args <- list(...)

# Rename resolution_parameter to resolution if igraph >= 2.1.0
if (packageVersion("igraph") >= "2.1.0") {
if ("resolution_parameter" %in% names(args)) {
args$resolution <- args$resolution_parameter
args$resolution_parameter <- NULL
}
}

# Call cluster_leiden with modified arguments
do.call(igraph::cluster_leiden, c(list(graph), args))
}

7 changes: 2 additions & 5 deletions R/file_utilities.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ myFun_fov_load <- function(path_to_fov) {
} else if (grepl("\\.csv$", base_path, ignore.case = TRUE)) {
con <- if (is_gz) gzfile(path_to_fov) else path_to_fov
each_transDF <- read.csv(con, sep = ',', header = TRUE)
} else if (grepl("\\.txt$", base_path, ignore.case = TRUE)) {
con <- if (is_gz) gzfile(path_to_fov) else path_to_fov
each_transDF <- read.csv(con, sep = '\t', header = TRUE)
} else if (grepl("\\.tsv$", base_path, ignore.case = TRUE)) {
} else if (grepl("\\.txt$|\\.tsv$", base_path, ignore.case = TRUE)) {
con <- if (is_gz) gzfile(path_to_fov) else path_to_fov
each_transDF <- read.csv(con, sep = '\t', header = TRUE)
} else {
Expand Down Expand Up @@ -138,7 +135,7 @@ prepare_perFOV_transDF <- function(each_transDF,
raw_locs <- each_transDF[, orig_spatLocs_colns]

# flip y coordinates (2nd) to have images shown from top to bottom
if(invert_y){
if(invert_y==TRUE){
raw_locs[[orig_spatLocs_colns[2]]] <- 0-raw_locs[[orig_spatLocs_colns[2]]]
}

Expand Down
16 changes: 0 additions & 16 deletions R/group_transcripts_in_space.R
Original file line number Diff line number Diff line change
Expand Up @@ -493,19 +493,3 @@ myFun_3point_singleCell <- function(dfCoord_subset,
}


#' @title igraph_delete_edges
#' @description Delete edges from an igraph object with version compatibility
#' @param graph An igraph object from which edges will be deleted.
#' @param edges A vector of edge IDs or an edge selector to delete.
#'
#' @return An igraph object with the specified edges removed.
#' @details This function wraps `igraph::delete_edges()` and ensures compatibility
#' with older versions (<2.0.0) of `igraph` that used `delete.edges()`.
igraph_delete_edges <- function(graph, edges) {
if (packageVersion("igraph") >= "2.0.0") {
igraph::delete_edges(graph, edges)
} else {
igraph::delete.edges(graph, edges)
}
}

43 changes: 43 additions & 0 deletions R/other_utilities.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#' @title run_igraph_leiden
#' @description Run Leiden clustering with version-compatible resolution argument.
#' @param graph An igraph object representing the graph to cluster.
#' @param ... Additional arguments passed to `cluster_leiden()`, such as
#' `objective_function`, `resolution_parameter`, `beta`, `initial_membership`,
#' and `n_iterations`.
#' @return A clustering object returned by `cluster_leiden()`.
#' @details This function wraps `igraph::cluster_leiden()` and ensures compatibility
#' with both older (<2.1.0) and newer versions of the `igraph` package by renaming
#' the `resolution_parameter` argument to `resolution` if needed.
#' @importFrom igraph cluster_leiden
run_igraph_leiden <- function(graph, ...) {
args <- list(...)

# Rename resolution_parameter to resolution if igraph >= 2.1.0
if (packageVersion("igraph") >= "2.1.0") {
if ("resolution_parameter" %in% names(args)) {
args$resolution <- args$resolution_parameter
args$resolution_parameter <- NULL
}
}

# Call cluster_leiden with modified arguments
do.call(igraph::cluster_leiden, c(list(graph), args))
}


#' @title igraph_delete_edges
#' @description Delete edges from an igraph object with version compatibility
#' @param graph An igraph object from which edges will be deleted.
#' @param edges A vector of edge IDs or an edge selector to delete.
#'
#' @return An igraph object with the specified edges removed.
#' @details This function wraps `igraph::delete_edges()` and ensures compatibility
#' with older versions (<2.0.0) of `igraph` that used `delete.edges()`.
igraph_delete_edges <- function(graph, edges) {
if (packageVersion("igraph") >= "2.0.0") {
igraph::delete_edges(graph, edges)
} else {
igraph::delete.edges(graph, edges)
}
}

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# FastReseg
An R package for detection and correction of cell segmentation error based on spatial profile of transcripts

#### [Manuscript](https://www.biorxiv.org/content/10.1101/2024.12.05.627051v1.abstract):
#### [Manuscript](https://www.nature.com/articles/s41598-025-08733-5):

Wu L, Beechem JM, Danaher P. FastReseg: using transcript locations to refine image-based cell segmentation results in spatial transcriptomics. *bioRxiv* 2024.12.05.627051; doi: https://doi.org/10.1101/2024.12.05.627051
Wu, L., Beechem, J.M. & Danaher, P. Using transcripts to refine image based cell segmentation with FastReseg. Sci Rep 15, 30508 (2025). https://doi.org/10.1038/s41598-025-08733-5

### Dev notes
`FastReseg` package processes spatial transcriptome data through 5 different modules:
Expand Down
2 changes: 1 addition & 1 deletion _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ external-articles:
title: Working principles and Manuscript
description: Manuscript for FastReseg describing working principles, performance
characterization and parameter impacts.
href: https://www.biorxiv.org/content/10.1101/2024.12.05.627051v1.abstract
href: https://www.nature.com/articles/s41598-025-08733-5

articles:
- title: Manuscript
Expand Down
2 changes: 1 addition & 1 deletion man/igraph_delete_edges.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/run_igraph_leiden.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.