Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…xperiment into devel
  • Loading branch information
lambdamoses committed Jun 13, 2024
2 parents 02812a8 + 715146f commit 0ef9c8b
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions R/read.R
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,6 @@ read10xVisiumSFE <- function(samples = "",

# sanity on geometries to remove any self-intersection
#' @importFrom sf st_buffer st_is_valid
# TODO: this needs to be optimized, takes too long for real data ----
.check_st_valid <- function(sf_df = NULL) {
# sf_df is a single sf data frame, not a list of sf data frames
invalid_inds <- which(!st_is_valid(sf_df))
Expand All @@ -475,7 +474,9 @@ read10xVisiumSFE <- function(samples = "",
}
old_type <- st_geometry_type(sf_df, by_geometry = FALSE)
if (new_type != old_type && new_type != "GEOMETRY") {
sf_df <- st_cast(sf_df, as.character(new_type))
sf_df <- sfheaders::sf_cast(sf_df, as.character(new_type))
# sf::st_cast can take too long
#sf_df <- st_cast(sf_df, as.character(new_type))
}
st_geometry(sf_df)[invalid_inds] <- geoms_new
}
Expand Down Expand Up @@ -726,7 +727,7 @@ readVizgen <- function(data_dir,
meta_fn <- .check_vizgen_fns(data_dir, "cell_metadata")
metadata <- fread(meta_fn, colClasses = list(character = 1))
if (any(names(metadata) == "transcript_count") && filter_counts) {
message(">>> ..filtering `cell_metadata` - keep cells with `transcript_count` > 0")
message(">>> filtering `cell_metadata` - keep cells with `transcript_count` > 0")
metadata <- metadata[metadata$transcript_count > 0,]
}

Expand Down Expand Up @@ -988,8 +989,8 @@ readCosMX <- function(data_dir,
#' @note Sometimes when reading images, you will see this error the first time:
#' 'java.lang.NullPointerException: Cannot invoke
#' "loci.formats.DimensionSwapper.setMetadataFiltered(boolean)" because
#' "RBioFormats.reader" is null'. Rerun the code and it should work the second
#' time.
#' "RBioFormats.reader" is null'. See this issue https://github.com/aoles/RBioFormats/issues/42
#' Rerun the code and it should work the second time.
#' @export
#' @concept Read data into SFE
#' @importFrom sf st_area st_geometry<- st_as_sf
Expand Down Expand Up @@ -1236,8 +1237,8 @@ readXenium <- function(data_dir,
# Filtering count matrix, metadata and segmentations ----
# filtering metadata and count matrix
if (any(names(metadata) == "transcript_counts") && filter_counts) {
message(">>> ..filtering cell metadata - keep cells with `transcript_counts` > 0")
metadata <- metadata[metadata$transcript_count > 0,]
message(">>> filtering cell metadata - keep cells with `transcript_counts` > 0")
metadata <- metadata[metadata$transcript_counts > 0,]
sce <- sce[,match(metadata$cell_id, colnames(sce)) |> na.omit()]
} else {
# if metadata isn't already filtered
Expand Down

0 comments on commit 0ef9c8b

Please sign in to comment.