Skip to content

Commit

Permalink
update to version 0.8.4
Browse files Browse the repository at this point in the history
  • Loading branch information
buddekai committed Apr 4, 2024
1 parent 45ba0a0 commit ffcf50b
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 134 deletions.
30 changes: 11 additions & 19 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type: software
license: GPL-3.0-or-later
title: 'detectCilia: Detect and measure the lengths of primary cilia in microscopy
images'
version: 0.8.3
version: 0.8.4
doi: 10.5281/zenodo.10521546
abstract: The package loads confocal fluorescence microscopy images and automatically
determines the positions and lengths of primary cilia of the cells and counts nuclei.
Expand All @@ -27,7 +27,7 @@ preferred-citation:
email: [email protected]
orcid: https://orcid.org/0000-0001-6836-9865
year: '2024'
notes: R package version 0.8.3
notes: R package version 0.8.4
doi: 10.5281/zenodo.10521546
url: https://github.com/SFB-ELAINE/detectCilia
repository-code: https://github.com/SFB-ELAINE/detectCilia
Expand Down Expand Up @@ -78,17 +78,13 @@ references:
title: BiocManager
abstract: 'BiocManager: Access the Bioconductor Project Package Repository'
notes: Imports
url: https://bioconductor.github.io/BiocManager/
url: https://github.com/Bioconductor/BiocManager
repository: https://CRAN.R-project.org/package=BiocManager
authors:
- family-names: Morgan
given-names: Martin
email: [email protected]
orcid: https://orcid.org/0000-0002-5874-8148
- family-names: Ramos
given-names: Marcel
email: [email protected]
orcid: https://orcid.org/0000-0002-3242-0582
year: '2024'
version: '>= 1.30.19'
- type: software
Expand All @@ -100,7 +96,7 @@ references:
authors:
- family-names: Wickham
given-names: Hadley
email: hadley@posit.co
email: hadley@rstudio.com
orcid: https://orcid.org/0000-0003-4757-117X
- family-names: François
given-names: Romain
Expand All @@ -110,10 +106,6 @@ references:
- family-names: Müller
given-names: Kirill
orcid: https://orcid.org/0000-0002-1416-3412
- family-names: Vaughan
given-names: Davis
email: [email protected]
orcid: https://orcid.org/0000-0003-4777-038X
year: '2024'
version: '>= 1.0.10'
- type: software
Expand All @@ -123,7 +115,7 @@ references:
url: https://github.com/aoles/EBImage
repository: https://bioconductor.org/
authors:
- family-names: Oleś
- family-names: Oles
given-names: Andrzej
- family-names: Pau
given-names: Gregoire
Expand All @@ -138,7 +130,6 @@ references:
- family-names: Marais
given-names: Philip A.
year: '2024'
doi: 10.18129/B9.bioc.EBImage
version: '>= 4.40.0'
- type: software
title: magrittr
Expand All @@ -157,7 +148,8 @@ references:
version: '>= 2.0.3'
- type: software
title: readCzi
abstract: 'readCzi: Read CZI image files, convert them to tifs, and save metadata'
abstract: 'readCzi: readCzi: R package to read CZI image files, convert them to
tifs, and save metadata'
notes: Imports
url: https://github.com/SFB-ELAINE/readCzi
authors:
Expand All @@ -176,12 +168,12 @@ references:
authors:
- family-names: Wickham
given-names: Hadley
email: hadley@posit.co
email: hadley@rstudio.com
- family-names: Hester
given-names: Jim
- family-names: Bryan
given-names: Jennifer
email: jenny@posit.co
email: jenny@rstudio.com
orcid: https://orcid.org/0000-0002-6983-2759
year: '2024'
version: '>= 2.1.3'
Expand All @@ -194,9 +186,9 @@ references:
authors:
- family-names: Henry
given-names: Lionel
email: lionel@posit.co
email: lionel@rstudio.com
- family-names: Wickham
given-names: Hadley
email: hadley@posit.co
email: hadley@rstudio.com
year: '2024'
version: '>= 1.0.6'
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: detectCilia
Title: Detect and measure the lengths of primary cilia in microscopy images
Version: 0.8.3
Version: 0.8.4
Authors@R:
person("Kai", "Budde-Sagert", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0001-6836-9865"))
Expand Down
168 changes: 55 additions & 113 deletions R/detectCilia.R
Original file line number Diff line number Diff line change
Expand Up @@ -1313,8 +1313,8 @@ detectCilia <- function(
}
}
rm(list = c("jx", "jy", "df_cilium_points_connect_shifted"))


df_cilium_points_connect <- df_cilium_points_connect[
df_cilium_points_connect$possibleCilium,]

Expand Down Expand Up @@ -1386,7 +1386,7 @@ detectCilia <- function(

# Mark all structures that are too small and therefore may not be a cilium
for(k in unique(df_cilium_points_connect$ciliumNumber)){
if(sum(df_cilium_points_connect$ciliumNumber == k) < min_cilium_area_in_pixels){
if(sum(df_cilium_points_connect$ciliumNumber == k) < floor(min_cilium_area_in_pixels/2)){
df_cilium_points_connect$possibleCilium[
df_cilium_points_connect$ciliumNumber == k] <- FALSE
}
Expand Down Expand Up @@ -1609,72 +1609,30 @@ detectCilia <- function(
!df_cilium_information$ciliumNumber %in% cilium_numbers_to_be_removed,]
}

###new from here

# Delete all cilia that are disconnected
# In every found cilium (cluster), delete separated cilium parts that
# are not directly connected (being vicinity_connect apart) to the
# brightest part of that cilium

df_cilium_all$disconnectedCilia <- FALSE
df_cilium_all$ClusterNumber <- 0

for(i in unique(df_cilium_all$ciliumNumber)){
# print(i)
df_dummy <- df_cilium_all[df_cilium_all$ciliumNumber == i,]

# # Create a data frame with (x, y) coordinates
# coordinates <- data.frame(x = df_dummy$pos_x, y = df_dummy$pos_y)
#
# # Calculate pairwise distances
# distances <- as.matrix(dist(coordinates, method = "manhattan"))
# distances[!lower.tri(distances)] <- NA
#
# # Set the threshold distance (e.g., 2 units)
# threshold_distance <- 1
#
# # Initialize labels
# labels <- rep(NA, length(df_dummy$pos_x))
# current_label <- 1
#
# # Assign labels based on connectivity
# for (k in 1:(length(x_coords) - 1)) {
# if(is.na(labels[k])) {
# neighbors <- which(distances[,k] <= threshold_distance)
# labels[neighbors] <- current_label
# current_label <- current_label + 1
# }
# }
#
#
#
#
#
#
# distances <- as.matrix(dist(cbind(df_dummy$pos_x, df_dummy$pos_y), upper = FALSE, method = "manhattan"))
# distances[!lower.tri(distances)] <- NA
#
# threshold_distance <- 1
#
# connected_pairs <- which(distances <= threshold_distance, arr.ind = TRUE)
#
# for (k in 1:nrow(connected_pairs)) {
# point1 <- connected_pairs[k, "row"]
# point2 <- connected_pairs[k, "col"]
#
# df_dummy
# }


j <- 1

rows_gone_through <- j
rows_to_go_through <- 1:length(df_dummy$pos_x)
rows_to_go_through <- rows_to_go_through[rows_to_go_through != j]

threshold_distance <- 1
df_dummy$ClusterNumber[j] <- 1

if(length(df_dummy$ClusterNumber) > 1){

next_point <- rows_to_go_through[
rows_to_go_through %in%
which(df_dummy$pos_x %in% (df_dummy$pos_x[j] - threshold_distance) : (df_dummy$pos_x[j] + threshold_distance) &
Expand All @@ -1684,112 +1642,96 @@ detectCilia <- function(
}else{
j <- next_point
}

while(0 %in% df_dummy$ClusterNumber){

.pos_x_distance <- df_dummy$pos_x[j] -
df_dummy$pos_x

.pos_y_distance <- df_dummy$pos_y[j] -
df_dummy$pos_y

.pos_x_distance[abs(.pos_x_distance) <= threshold_distance] <- 0
.pos_y_distance[abs(.pos_y_distance) <= threshold_distance] <- 0

.distance <- abs(.pos_x_distance) + abs(.pos_y_distance)

# Get the cluster number (close cilium that has been detected)
ClusterNumber_dummy <-
unique(df_dummy$ClusterNumber[.distance == 0])

if(length(ClusterNumber_dummy) == 1 && ClusterNumber_dummy == 0){
# Advance cluster number number because there is no cluster close by
ClusterNumber <- max(df_dummy$ClusterNumber) + 1
}else{
# Points belong to already existing cluster
ClusterNumber <- ClusterNumber_dummy[!(ClusterNumber_dummy == 0)]
}

# if(length(ClusterNumber) > 1){
# print(paste0("The following clusters of cilium ", i,
# " are now one: ", paste0(ClusterNumber, collapse = ", ")))
# for(k in 2:length(ClusterNumber)){
# df_dummy$ClusterNumber[
# df_dummy$ClusterNumber == ClusterNumber[k]] <-
# ClusterNumber[1]
# }
# rm(k)
#
# }else{

df_dummy$ClusterNumber[
df_dummy$ClusterNumber == 0 & .distance == 0] <- ClusterNumber
# }
#

rows_to_go_through <- rows_to_go_through[rows_to_go_through != j]
next_point <- rows_to_go_through[
rows_to_go_through %in%
which(df_dummy$pos_x %in% (df_dummy$pos_x[j] - threshold_distance) : (df_dummy$pos_x[j] + threshold_distance) &
df_dummy$pos_y %in% (df_dummy$pos_y[j] - threshold_distance) : (df_dummy$pos_y[j] + threshold_distance))][1]
if(is.na(next_point)){
j <- rows_to_go_through[1]
point_connected_to_others <- FALSE
l <- 1
while(!point_connected_to_others && l <= length(rows_to_go_through)){
.pos_x_distance <- df_dummy$pos_x[rows_to_go_through[l]] -
df_dummy$pos_x

.pos_y_distance <- df_dummy$pos_y[rows_to_go_through[l]] -
df_dummy$pos_y

.pos_x_distance[abs(.pos_x_distance) <= threshold_distance] <- 0
.pos_y_distance[abs(.pos_y_distance) <= threshold_distance] <- 0

.distance <- abs(.pos_x_distance) + abs(.pos_y_distance)

if(0 %in% .distance[rows_gone_through]){
j <- rows_to_go_through[l]
point_connected_to_others <- TRUE
}else{
l <- l+1
}
}
if(!point_connected_to_others){
j <- rows_to_go_through[1]
}
rows_gone_through <- c(rows_gone_through, j)
}else{
j <- next_point
rows_gone_through <- c(rows_gone_through, j)
}

}
rm(list = c("j", "ClusterNumber"))

# df_test <- df_dummy %>%
# dplyr::group_by(ClusterNumber) %>%
# dplyr::summarise(meanIntensity = mean(.data$fluorescence_intensity),
# clusterSize = length(.data$fluorescence_intensity))
#
# # Remove all clusters that are too small
# df_test <- df_test[!(df_test$clusterSize < min_cilium_area_in_pixels),]
#
# cluster_number_with_heighest_mean_intensity <- df_test$ClusterNumber[
# df_test$meanIntensity == max(df_test$meanIntensity)]
#
# if(length(cluster_number_with_heighest_mean_intensity)>1){
# print("Please check the determination of the cluster number.")
# }
#
# df_dummy$disconnectedPart[
# df_dummy$ClusterNumber != cluster_number_with_heighest_mean_intensity] <- TRUE
#
# df_dummy <- df_dummy[!df_dummy$disconnectedPart,]
# df_dummy <- df_dummy[,!names(df_dummy)=="ClusterNumber"]

# # Keep only rows that have been found
# if(i == unique(df_cilium_points$ciliumNumber)[1]){
# df_cilium_points2 <- df_dummy
# }else{
# df_cilium_points2 <- rbind(df_cilium_points2, df_dummy)
# }

rm(list = c("j", "l", "ClusterNumber"))

if(max(df_dummy$ClusterNumber) > 1){
df_cilium_all$disconnectedCilia[df_cilium_all$ciliumNumber == i] <- TRUE
}

}

}
rm(list = c("i", "df_dummy"))

# Remove cilia with disconnected cilia
disconnectedCilia <- unique(df_cilium_all$ciliumNumber[df_cilium_all$disconnectedCilia])

df_cilium_information <- df_cilium_information[!df_cilium_information$ciliumNumber %in% disconnectedCilia, ]
df_cilium_all <- df_cilium_all[!df_cilium_all$ciliumNumber %in% disconnectedCilia,]

# Drop extra columns
df_cilium_all <-
df_cilium_all[,!names(df_cilium_all)=="disconnectedCilia"]
df_cilium_all <-
df_cilium_all[,!names(df_cilium_all)=="ClusterNumber"]

###new up to here


# Renumber cilia
.number <- 1
df_cilium_information$ciliumNumber_NEW <- NA
Expand Down
2 changes: 1 addition & 1 deletion inst/CITATION
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ bibentry(bibtype = "Manual",
title = "{detectCilia}: R package for detecting the lengths of primary cilia",
author = person("Kai", "Budde-Sagert"),
year = 2024,
note = "R package version 0.8.3",
note = "R package version 0.8.4",
doi = "10.5281/zenodo.10521546",
url = "https://github.com/SFB-ELAINE/detectCilia"
)
Expand Down

0 comments on commit ffcf50b

Please sign in to comment.