Skip to content

Commit

Permalink
!feat: remove combineSpatialCellFeatureInfo()
Browse files Browse the repository at this point in the history
- function does not work and is not used anywhere
  • Loading branch information
jiajic committed Oct 15, 2024
1 parent 4e12bc0 commit e0624c2
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 161 deletions.
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ export(combineCellData)
export(combineFeatureData)
export(combineFeatureOverlapData)
export(combineMetadata)
export(combineSpatialCellFeatureInfo)
export(combineSpatialCellMetadataInfo)
export(combineToMultiPolygon)
export(compatible_spatial_network)
Expand Down
120 changes: 0 additions & 120 deletions R/combine_metadata.R
Original file line number Diff line number Diff line change
Expand Up @@ -90,86 +90,6 @@ combineMetadata <- function(



#' @title combineSpatialCellFeatureInfo
#' @name combineSpatialCellFeatureInfo
#' @description Combine spatial cell information (e.g. polygon)
#' and spatial feature information (e.g. transcript locations)
#' @param gobject Giotto object
#' @param spat_unit spatial unit
#' @param feat_type feature type(s)
#' @param selected_features select set of features
#' @returns list of data.table(s)
#' @details
#' The returned data.table has the following columns: \cr
#' \itemize{
#' \item{sdimx: spatial feature location on the x-axis}
#' \item{sdimy: spatial feature location on the y-axis}
#' \item{feat_ID: unique feature ID}
#' \item{cell_ID: unique cell ID}
#' \item{used: how often was the feature used/assigned to a cell}
#' \item{feat: selected feature(s)}
#' }
#'
#' @export
combineSpatialCellFeatureInfo <- function(
gobject,
spat_unit = NULL,
feat_type = NULL,
selected_features = NULL) {
# define for data.table
feat_ID <- NULL

# combine
# 1. spatial morphology information ( = polygon)
# 2. spatial transcript location information

# Set feat_type and spat_unit
spat_unit <- set_default_spat_unit(
gobject = gobject,
spat_unit = spat_unit
)
feat_type <- set_default_feat_type(
gobject = gobject,
spat_unit = spat_unit,
feat_type = feat_type
)

spatial_cell_info <- gobject@spatial_info

if (is.null(spatial_cell_info)) {
stop("There is no available spatial segmentation/location information")
}


res_list <- list()
for (feat in unique(feat_type)) {
spatial_feat_locs <- gobject@feat_info[[feat]]

if (!is.null(selected_features)) {
spatial_feat_locs <- spatial_feat_locs[
feat_ID %in% selected_features
]
}

if (is.null(spatial_feat_locs)) {
stop("There is no available spatial feature location information
for ", feat, "\n")
}

output <- .merge_spatial_locs_feat_info(
spatial_info = spatial_cell_info,
feature_info = spatial_feat_locs
)
output[, "feat" := feat]

res_list[[feat]] <- output
}

return(res_list)
}



#' @title combineSpatialCellMetadataInfo
#' @name combineSpatialCellMetadataInfo
#' @description Combine cell metadata with spatial cell
Expand Down Expand Up @@ -738,46 +658,6 @@ calculateSpatCellMetadataProportions <- function(

# internals ####

#' @title .merge_spatial_locs_feat_info
#' @name .merge_spatial_locs_feat_info
#' @returns data.table
#' @description merge spatial cell and feature location information
#' @keywords internal
#' @noRd
.merge_spatial_locs_feat_info <- function(
spatial_info,
feature_info) {
# data.table variables
cell_ID <- used <- NULL

reslist <- list()
for (i in seq_len(length(unique(spatial_info$cell_ID)))) {
cell_i <- unique(spatial_info$cell_ID)[i]

temp <- sp::point.in.polygon(
point.x = feature_info$sdimx,
point.y = feature_info$sdimy,
pol.x = spatial_info[cell_ID == cell_i]$sdimx,
pol.y = spatial_info[cell_ID == cell_i]$sdimy
)

detected_feats <- feature_info[temp == 1]
detected_feats[, cell_ID := cell_i]

reslist[[i]] <- detected_feats
}

reslistfinal <- do.call("rbind", reslist)

# calculate how often a single transcript is used
# > 1 means that a transcript was assigned to more than 1 cell
reslistfinal[, used := .N, by = c("sdimx", "sdimy", "feat_ID")]

return(reslistfinal)
}





#' @title .merge_spatial_enrich_info
Expand Down
40 changes: 0 additions & 40 deletions man/combineSpatialCellFeatureInfo.Rd

This file was deleted.

0 comments on commit e0624c2

Please sign in to comment.