Skip to content

Commit

Permalink
Merge branch 'suite_dev' of https://github.com/drieslab/Giotto into s…
Browse files Browse the repository at this point in the history
…uite_dev
  • Loading branch information
jiajic committed May 21, 2024
2 parents b54fe7b + f20d581 commit 88536f0
Show file tree
Hide file tree
Showing 17 changed files with 173 additions and 156 deletions.
4 changes: 2 additions & 2 deletions R/cell_segmentation.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ doCellSegmentation <- function(raster_img,
# sliding window
start_x <- 0
end_x <- start_x + tile_dim
for (i in 1:nxwindow) {
for (i in seq_len(nxwindow)) {
start_y <- 0
end_y <- start_y + tile_dim
for (j in 1:nywindow) {
for (j in seq_len(nywindow)) {
ext_crop <- terra::ext(c(start_x, end_x, start_y, end_y))
img_crop <- terra::crop(raster_img, ext_crop, snap = "in")
img_crop_rescaled <- terra::aggregate(img_crop, reduce_resolution)
Expand Down
25 changes: 13 additions & 12 deletions R/clustering.R
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ doLeidenCluster <- function(gobject,
if (isTRUE(set_seed)) {
seed_number <- as.integer(seed_number)
} else {
seed_number <- as.integer(sample(x = 1:10000, size = 1))
seed_number <- as.integer(sample(x = seq_len(10000), size = 1))
}

## extract NN network
Expand Down Expand Up @@ -551,7 +551,7 @@ doGiottoClustree <- function(gobject,
if (isTRUE(set_seed)) {
seed_number <- as.integer(seed_number)
} else {
seed_number <- as.integer(sample(x = 1:10000, size = 1))
seed_number <- as.integer(sample(x = seq_len(10000), size = 1))
}

network_edge_dt <- data.table::as.data.table(igraph::as_data_frame(
Expand Down Expand Up @@ -1102,9 +1102,9 @@ doSNNCluster <- function(gobject,
cell_id_numeric <- unique(x = c(igraph_DT$from, igraph_DT$to))
names(cell_id_numeric) <- seq_along(cell_id_numeric)
igraph_DT[, from_T := as.numeric(names(cell_id_numeric[
cell_id_numeric == from])), by = 1:nrow(igraph_DT)]
cell_id_numeric == from])), by = seq_len(nrow(igraph_DT))]
igraph_DT[, to_T := as.numeric(names(cell_id_numeric[
cell_id_numeric == to])), by = 1:nrow(igraph_DT)]
cell_id_numeric == to])), by = seq_len(nrow(igraph_DT))]
temp_igraph_DT <- igraph_DT[, .(from_T, to_T, weight, distance)]
data.table::setnames(
temp_igraph_DT, old = c("from_T", "to_T"), new = c("from", "to"))
Expand All @@ -1116,7 +1116,7 @@ doSNNCluster <- function(gobject,
)

ident_clusters_DT <- data.table::data.table(
"cell_ID" = cell_id_numeric[1:nrow(kNN_object$dist)],
"cell_ID" = cell_id_numeric[seq_len(nrow(kNN_object$dist))],
"name" = sNN_clusters$cluster)
data.table::setnames(ident_clusters_DT, "name", name)

Expand Down Expand Up @@ -1247,7 +1247,7 @@ doKmeans <- function(gobject,
)

dimensions_to_use <- dimensions_to_use[
dimensions_to_use %in% 1:ncol(dim_coord[])]
dimensions_to_use %in% seq_len(ncol(dim_coord[]))]
matrix_to_use <- dim_coord[][, dimensions_to_use]
} else {
values <- match.arg(
Expand Down Expand Up @@ -1470,7 +1470,7 @@ doHclust <- function(gobject,
)

dimensions_to_use <- dimensions_to_use[
dimensions_to_use %in% 1:ncol(dim_coord)]
dimensions_to_use %in% seq_len(ncol(dim_coord))]
matrix_to_use <- dim_coord[, dimensions_to_use]
} else {
## using original matrix ##
Expand Down Expand Up @@ -2813,7 +2813,8 @@ getClusterSimilarity <- function(gobject,
cor_table[, c("group1", "group2") := list(
as.character(group1), as.character(group2))]
cor_table[, unified_group := paste(
sort(c(group1, group2)), collapse = "--"), by = 1:nrow(cor_table)]
sort(c(group1, group2)), collapse = "--"),
by = seq_len(nrow(cor_table))]
cor_table <- cor_table[!duplicated(cor_table[, .(value, unified_group)])]

cor_table <- merge(
Expand Down Expand Up @@ -2933,7 +2934,7 @@ mergeClusters <- function(gobject,
## get list of correlated groups
finallist <- list()
start_i <- 1
for (row in 1:nrow(filter_set)) {
for (row in seq_len(nrow(filter_set))) {
first_clus <- filter_set[row][["group1"]]
second_clus <- filter_set[row][["group2"]]

Expand Down Expand Up @@ -2971,7 +2972,7 @@ mergeClusters <- function(gobject,
as.character(get(cluster_column)) %in% finalvec,
names(finalvec[finalvec == as.character(get(cluster_column))]),
as.character(get(cluster_column))
), by = 1:nrow(metadata)]
), by = seq_len(nrow(metadata))]



Expand Down Expand Up @@ -3205,7 +3206,7 @@ getDendrogramSplits <- function(gobject,
splitDT <- data.table::as.data.table(t_flex(
data.table::as.data.table(splitList[[2]])))
colnames(splitDT) <- c("node_h", "tree_1", "tree_2")
splitDT[, nodeID := paste0("node_", 1:.N)]
splitDT[, nodeID := paste0("node_", seq_len(.N))]

return(splitDT)
}
Expand Down Expand Up @@ -3317,7 +3318,7 @@ doClusterProjection <- function(target_gobject,

dim_coord <- dim_obj[]
dimensions_to_use <- dimensions_to_use[
dimensions_to_use %in% 1:ncol(dim_coord)]
dimensions_to_use %in% seq_len(ncol(dim_coord))]
matrix_to_use <- dim_coord[, dimensions_to_use]

## create the training and testset from the matrix
Expand Down
12 changes: 6 additions & 6 deletions R/cross_section.R
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ createCrossSection <- function(gobject,

spatial_locations <- as.matrix(spatial_locations)
rownames(spatial_locations) <- cell_IDs
cell_ID_vec <- c(1:nrow(spatial_locations))
cell_ID_vec <- seq_len(nrow(spatial_locations))
names(cell_ID_vec) <- rownames(spatial_locations)

# generate section plane equation
Expand All @@ -542,7 +542,7 @@ createCrossSection <- function(gobject,
message("either point or norm vector was not provided.")
} else {
plane_equation <- c()
plane_equation[1:3] <- normVector
plane_equation[seq_len(3)] <- normVector
plane_equation[4] <- -point1 %*% normVector
}
} else if (method == "point and two plane vectors") {
Expand All @@ -551,7 +551,7 @@ createCrossSection <- function(gobject,
provided.")
} else {
normVector <- crossprod(planeVector1, planeVector2)
plane_equation[1:3] <- normVector
plane_equation[seq_len(3)] <- normVector
plane_equation[4] <- -point1 %*% normVector
}
} else if (method == "3 points") {
Expand All @@ -561,7 +561,7 @@ createCrossSection <- function(gobject,
planeVector1 <- point2 - point1
planeVector2 <- point3 - point1
normVector <- crossprod(planeVector1, planeVector2)
plane_equation[1:3] <- normVector
plane_equation[seq_len(3)] <- normVector
plane_equation[4] <- -point1 %*% normVector
}
}
Expand All @@ -584,7 +584,7 @@ createCrossSection <- function(gobject,
spatial_locations, as.matrix(rep(1, dim(spatial_locations)[1])))
norm_vec <- function(x) sqrt(sum(x^2))
distance_to_plane_vector <- abs(spatial_locations_mat %*% as.matrix(
plane_equation) / norm_vec(plane_equation[1:3]))
plane_equation) / norm_vec(plane_equation[seq_len(3)]))

# select cells within section ###
cell_subset <- distance_to_plane_vector <= max_distance_to_section_plane
Expand All @@ -604,7 +604,7 @@ createCrossSection <- function(gobject,
cell_subset_projection_locations <- t(apply(
cell_subset_spatial_locations, 1,
function(x) projection_fun(x, plane_point = plane_point,
plane_norm = plane_equation[1:3])))
plane_norm = plane_equation[seq_len(3)])))

# get the local coordinates of selected cells on the section plane
cell_subset_projection_PCA <- stats::prcomp(
Expand Down
2 changes: 1 addition & 1 deletion R/differential_expression.R
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ findGiniMarkers <- function(gobject,
aggr_sc[, comb_score := (expression_gini * expression_rank) * (
detection_gini * detection_rank)]
setorder(aggr_sc, cluster, -comb_score)
aggr_sc[, comb_rank := 1:.N, by = cluster]
aggr_sc[, comb_rank := seq_len(.N), by = cluster]

top_feats_scores <- aggr_sc[comb_rank <= min_feats | (
expression_rank <= rank_score & detection_rank <= rank_score)]
Expand Down
Loading

0 comments on commit 88536f0

Please sign in to comment.