Skip to content

Commit

Permalink
new version 0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
buddekai committed Nov 30, 2023
1 parent d6e79b3 commit 747f438
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 240 deletions.
91 changes: 59 additions & 32 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,36 @@ cff-version: 1.2.0
message: 'To cite package "readCzi" in publications use:'
type: software
license: GPL-3.0-or-later
title: 'readCzi: Read czi image files, convert them to tifs, and save metadata'
version: 0.2.4
abstract: The package reads (z-stack) czi microscopy files, edits them, and stores
the results in the tif format. The metadata is also read and saved and transformed
into a tibble.
title: 'readCzi: Read CZI image files, convert them to tifs, and save metadata'
version: 0.3.0
doi: NN
abstract: The package reads (z-stack) CZI microscopy files, edits them, and stores
the results in the tif format. The metadata is also read, transformed into a tibble,
and saved as a CSV file.
authors:
- family-names: Budde
- family-names: Budde-Sagert
given-names: Kai
email: [email protected]
- name: c
- family-names: c)
given-names: comment =
orcid: https://orcid.org/0000-0001-6836-9865
preferred-citation:
type: manual
title: 'readCzi: Read CZI image files, convert them to tifs, and save metadata'
authors:
- family-names: Budde-Sagert
given-names: Kai
email: [email protected]
orcid: https://orcid.org/0000-0001-6836-9865
year: '2023'
notes: R package version 0.3.0
doi: NN
url: https://github.com/SFB-ELAINE/readCzi
repository-code: https://github.com/SFB-ELAINE/readCzi
url: https://github.com/SFB-ELAINE/readCzi
contact:
- family-names: Budde
- family-names: Budde-Sagert
given-names: Kai
email: [email protected]
orcid: https://orcid.org/0000-0001-6836-9865
references:
- type: software
title: 'R: A Language and Environment for Statistical Computing'
Expand All @@ -50,26 +62,7 @@ references:
email: [email protected]
orcid: https://orcid.org/0000-0002-5874-8148
year: '2023'
version: '>='
- type: software
title: reticulate
abstract: 'reticulate: Interface to ''Python'''
notes: Imports
url: https://rstudio.github.io/reticulate/
repository: https://CRAN.R-project.org/package=reticulate
authors:
- family-names: Ushey
given-names: Kevin
email: [email protected]
- family-names: Allaire
given-names: JJ
email: [email protected]
- family-names: Tang
given-names: Yuan
email: [email protected]
orcid: https://orcid.org/0000-0001-5243-233X
year: '2023'
version: '>='
version: '>= 1.30.19'
- type: software
title: EBImage
abstract: 'EBImage: Image processing and analysis toolbox for R'
Expand All @@ -92,7 +85,41 @@ references:
- family-names: Marais
given-names: Philip A.
year: '2023'
version: '>='
version: '>= 4.40.0'
- type: software
title: reticulate
abstract: 'reticulate: Interface to ''Python'''
notes: Imports
url: https://rstudio.github.io/reticulate/
repository: https://CRAN.R-project.org/package=reticulate
authors:
- family-names: Ushey
given-names: Kevin
email: [email protected]
- family-names: Allaire
given-names: JJ
email: [email protected]
- family-names: Tang
given-names: Yuan
email: [email protected]
orcid: https://orcid.org/0000-0001-5243-233X
year: '2023'
version: '>= 1.26'
- type: software
title: tibble
abstract: 'tibble: Simple Data Frames'
notes: Imports
url: https://tibble.tidyverse.org/
repository: https://CRAN.R-project.org/package=tibble
authors:
- family-names: Müller
given-names: Kirill
email: [email protected]
- family-names: Wickham
given-names: Hadley
email: [email protected]
year: '2023'
version: '>= 3.1.8'
- type: software
title: xml2
abstract: 'xml2: Parse XML'
Expand All @@ -108,4 +135,4 @@ references:
- family-names: Ooms
given-names: Jeroen
year: '2023'
version: '>='
version: '>= 1.3.3'
31 changes: 20 additions & 11 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
Package: readCzi
Type: Package
Title: Read czi image files, convert them to tifs, and save metadata
Version: 0.2.3
Author: c(person("Kai", "Budde", email = "[email protected]",
role = c("aut", "cre"))
Maintainer: Kai Budde <[email protected]>
Description: This package may read (z-stack) czi image data, edit them,
and store the results in the tif-format. The metadata is also read and
saved and transformed into a data frame.
License: LICENSE
Title: Read CZI image files, convert them to tifs, and save metadata
Version: 0.3.0
Authors@R: person("Kai", "Budde-Sagert", email = "[email protected]",
role = c("aut", "cre"), comment = c(ORCID = "0000-0001-6836-9865"))
Maintainer: Kai Budde-Sagert <[email protected]>
Description: The package reads (z-stack) CZI microscopy files, edits them,
and stores the results in the tif format. The metadata is also read,
transformed into a tibble, and saved as a CSV file.
URL: https://github.com/SFB-ELAINE/readCzi
BugReports: https://github.com/SFB-ELAINE/readCzi/issues
License: GPL (>= 3)
Depends:
R (>= 4.0.0)
Imports:
BiocManager (>= 1.30.19),
EBImage (>= 4.40.0),
reticulate (>= 1.26),
tibble (>= 3.1.8),
xml2 (>= 1.3.3)
Encoding: UTF-8
LazyData: true
Imports: BiocManager, reticulate, EBImage, xml2
RoxygenNote: 7.2.1
RoxygenNote: 7.2.3
43 changes: 0 additions & 43 deletions R/addScaleBar.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,6 @@ addScaleBar <- function(image = NULL,
distance_from_border = 20,
number_size_factor = 1){

# if(class(image) == "EBImage"){
# # Convert to array for faster manipulation
# image <- as.array(image)
# image_was_EBImage <- TRUE
# }else{
# image_was_EBImage <- FALSE
# }


# dim_x <- dim(image)[2]
# dim_y <- dim(image)[1]
# dim_c <- dim(image)[3]
dim_x <- dim(image)[1]
dim_y <- dim(image)[2]
dim_c <- dim(image)[3]
Expand Down Expand Up @@ -63,9 +51,6 @@ addScaleBar <- function(image = NULL,
heigth_scale_bar_pixels <- as.integer(round(dim_y/150))

# Add the scale_bar
# image[(dim_y-distance_from_border-heigth_scale_bar_pixels):(dim_y-distance_from_border),
# (dim_x-distance_from_border-length_scale_bar_pixels):(dim_x-distance_from_border),
# 1:dim_c] <- 1
if(dim_z == 1){
image[(dim_x-distance_from_border-length_scale_bar_pixels):(dim_x-distance_from_border),
(dim_y-distance_from_border-heigth_scale_bar_pixels):(dim_y-distance_from_border),
Expand All @@ -78,8 +63,6 @@ addScaleBar <- function(image = NULL,


# Add length of scale bar and unit
# number_pos_x <- dim_y-distance_from_border-heigth_scale_bar_pixels
# number_pos_y <- dim_x-distance_from_border-0.5*length_scale_bar_pixels
number_pos_x <- dim_x-distance_from_border-0.5*length_scale_bar_pixels
number_pos_y <- dim_y-distance_from_border-heigth_scale_bar_pixels

Expand All @@ -89,9 +72,6 @@ addScaleBar <- function(image = NULL,

scale_legend_image <- EBImage::readImage(files = scale_legend_path,
type = "tiff")
# scale_legend_image <- tiff::readTIFF(source = scale_legend_path,
# convert = TRUE,
# info = FALSE)

# Only keep the black layer
scale_legend_image <- scale_legend_image[,,4]
Expand All @@ -103,27 +83,10 @@ addScaleBar <- function(image = NULL,

dim_legend_x <- dim(scale_legend_image)[1]
dim_legend_y <- dim(scale_legend_image)[2]
# dim_legend_x <- dim(scale_legend_image)[1]
# dim_legend_y <- dim(scale_legend_image)[2]

# Add number images to image
start_x <- floor(dim_x-distance_from_border-0.5*length_scale_bar_pixels-0.5*dim_legend_x)
start_y <- floor(dim_y-distance_from_border-heigth_scale_bar_pixels-1.1*dim_legend_y)
# start_x <- dim_x-distance_from_border-0.5*length_scale_bar_pixels-0.5*dim_legend_x
# start_y <- dim_y-distance_from_border-heigth_scale_bar_pixels-1.1*dim_legend_y

# for(row in 1:dim_legend_y){
# for(col in 1:dim_legend_x){

# for(col in 1:dim_legend_x){
# for(row in 1:dim_legend_y){
# if(scale_legend_image[row, col] > 0){
# # if(scale_legend_image[col, row] > 0){
# # image[start_y+row, start_x+col, 1:dim_c] <- scale_legend_image[row, col]
# image[start_x+col, start_y+row, 1:dim_c] <- scale_legend_image[row, col]
# }
# }
# }

# Add \um image to original image
scale_legend_image_copy <- scale_legend_image
Expand All @@ -132,22 +95,16 @@ addScaleBar <- function(image = NULL,
if(dim_z == 1){
scale_legend_image[start_x:(start_x+dim_legend_x-1),
start_y:(start_y+dim_legend_y-1),] <-
# EBImage::transpose(scale_legend_image_copy)
scale_legend_image_copy
}else{
scale_legend_image[start_x:(start_x+dim_legend_x-1),
start_y:(start_y+dim_legend_y-1),,] <-
# EBImage::transpose(scale_legend_image_copy)
scale_legend_image_copy
}


image <- scale_legend_image + image
image[image > 1] <- 1

# if(image_was_EBImage){
# image <- EBImage::Image(data = image_data, colormode = "Color")
# }

return(image)
}
12 changes: 0 additions & 12 deletions R/convertCziToTif.R
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,6 @@ convertCziToTif <- function(input_file = NULL,

if(dim_z > 1){

# for(i in 1:3){
# if(max(Image_Stack[,,i]) > 0){
# Image_Stack_normalized[,,i] <- Image_Stack_normalized[,,i]/max(Image_Stack_normalized[,,i])
# }
# }

disregarded_layers <- c()
for(i in 1:3){
if(max(Image_Stack[,,i]) == 0){
Expand All @@ -232,12 +226,6 @@ convertCziToTif <- function(input_file = NULL,
output_file_name <- paste(output_dir, "/", image_name_wo_czi, "_zstack_histogram_equalized_normalized.tif", sep="")
}else{

# for(i in 1:3){
# if(max(Image_Data[,,i]) > 0){
# Image_Stack_normalized[,,i] <- Image_Stack_normalized[,,i]/max(Image_Stack_normalized[,,i])
# }
# }

disregarded_layers <- c()
for(i in 1:3){
if(max(Image_Data[,,i]) == 0){
Expand Down
67 changes: 0 additions & 67 deletions R/readCzi.R
Original file line number Diff line number Diff line change
Expand Up @@ -141,53 +141,6 @@ readCzi <- function(input_file = NULL) {

color_axis <- "C"

# if(number_of_channels == 3){
# wavelengths <- gsub(
# pattern = paste(".+<EmissionWavelength>(.+)</EmissionWavelength>.+",
# ".+<EmissionWavelength>(.+)</EmissionWavelength>.+",
# ".+<EmissionWavelength>(.+)</EmissionWavelength>.+",
# sep=""),
# replacement = "\\1,\\2,\\3",
# x = metadata)
# }else if(number_of_channels == 2){
# wavelengths <- gsub(
# pattern = paste(".+<EmissionWavelength>(.+)</EmissionWavelength>.+",
# ".+<EmissionWavelength>(.+)</EmissionWavelength>.+",
# sep=""),
# replacement = "\\1,\\2",
# x = metadata)
# }else if(number_of_channels == 1){
# wavelengths <- gsub(
# pattern = paste(".+<EmissionWavelength>(.+)</EmissionWavelength>.+",
# sep=""),
# replacement = "\\1",
# x = metadata)
# }

# wavelengths <- as.numeric(strsplit(wavelengths, split = ",")[[1]])

# Upper and lower limits of wavelengths to determine the colors
# red: > 600nm
# green: >= 500nm and <= 600nm
# blue: < 500nm

# upper_limit_blue <- 450#500
# lower_limit_red <- 550#600
#
# test_red <- any(wavelengths > lower_limit_red)
# red_id <- ifelse(test = test_red, yes = which(wavelengths > lower_limit_red), no = 0)
# if(length(red_id) > 1){print("More than one red channel!?")}
#
# test_green <- any( (upper_limit_blue) <= wavelengths & (wavelengths <= lower_limit_red))
# green_id <- ifelse(test = test_green, yes = which((upper_limit_blue <= wavelengths) & (wavelengths <= lower_limit_red)), no = 0)
# if(length(green_id) > 1){print("More than one green channel!?")}
#
# test_blue <- any(wavelengths < upper_limit_blue)
# blue_id <- ifelse(test = test_blue, yes = which(upper_limit_blue > wavelengths), no = 0)
# if(length(blue_id) > 1){print("More than one blue channel!?")}
#
# rgb_layers <- c(red_id, green_id, blue_id)

rgb_layers <- c(df_metadata$red_channel,
df_metadata$green_channel,
df_metadata$blue_channel)
Expand Down Expand Up @@ -275,9 +228,6 @@ readCzi <- function(input_file = NULL) {
# Reorganize the array according according to: "X","Y", "C"/"0", "Z"
new_array_order <- c("X", "Y", color_axis, "Z")
}else{
# print(paste("The image is one-dimensional in z-direction (no z-stack).",
# sep=""))

# Reorganize the array according according to: "X","Y", "C"/"0"
new_array_order <- c("X", "Y", color_axis)
}
Expand All @@ -300,10 +250,6 @@ readCzi <- function(input_file = NULL) {
copy_image_loaded <- image_loaded
image_loaded <- array(data = 0, dim = c(dim_x, dim_y, 3, dim_z))

# if(number_of_channels != 3){
# image_loaded[,,-which(rgb_layers == 0),] <- copy_image_loaded
# }

# Copy image layers in the correct order depending on which dimension
# the original image has
if(length(dim(copy_image_loaded)) == 12){
Expand Down Expand Up @@ -377,13 +323,6 @@ readCzi <- function(input_file = NULL) {
check_array_dims <- length(new_array_order)
}

# # Remove z dimension in array if it is 1
# if(!zstack){
# # Drop all arrays with dim=1
# image_loaded <- drop(image_loaded)
# }


if(length(dim(image_loaded)) != check_array_dims){
print("There is more or less information than thought in the image.")
return()
Expand Down Expand Up @@ -437,12 +376,6 @@ readCzi <- function(input_file = NULL) {
print(paste("There is no color axis.", sep=""))
}

# Check if we have a (Transmitted light detector (T-PMT)) which needs to
# be saved in a different color (to not overwrite the other ones)

# Reverse y-axis (It will go from top to bottom instead from bottom to top)
#image_loaded <- EBImage::flip(image_loaded)

rm(copy_image_loaded)

rm(list= c("czi_class"))
Expand Down
Loading

0 comments on commit 747f438

Please sign in to comment.