README.md

readCzi

readCzi is an R package to read CZI image files (images from ZEISS microscopes), stack them if needed (projection), convert the files to tifs (also normalized and histogram equalized), and store the metadata a CSV files.

Readable image/microscopy formats

The R package readCzi has been checked with image data from * ZEISS Apotome, * ZEISS AxioImager, * ZEISS laser scanning microscopes (1 to 3 channels, 1 to 3 tracks, 1 to n z layers). Please contact Kai for further information and sample data.

Example code for using the R package

The following example (script and results) shows the capabilities of the package. The script is found in inst/testscript.R.

# Testscript for using the R package readCzi +++++++++++++++++++++++++++++++
# Author: Kai Budde-Sagert
# Created: 2021/04/08
# Last changed: 2024/01/17


# Delete everything in the environment
rm(list = ls())
# close all open plots in RStudio
graphics.off()

# Load packages ############################################################
groundhog.day <- "2023-01-01"
if(!any(grepl(pattern = "groundhog", x = installed.packages(), ignore.case = TRUE))){
  install.packages("groundhog")
}

# Load packages
library(groundhog)
pkgs <- c("BiocManager", "devtools", "reticulate", "tibble", "xml2")
groundhog.library(pkgs, groundhog.day)

if(!("EBImage" %in% utils::installed.packages())){
  print("Installing EBImage.")
  BiocManager::install("EBImage")
}

require(EBImage)

# Install Python package for reading data of CZI files
# (Users will be asked to install miniconda when starting for the first time)
if(! "czifile" %in% reticulate::py_list_packages()$package){
  reticulate::py_install("czifile")
}

# Install this R package for reading CZI images in R
if(!("readCzi" %in% installed.packages()[,"Package"])){
  devtools::install_github("SFB-ELAINE/readCzi")
}
require(readCzi)

# Please adapt the following parameters ####################################
# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

# Input file
input_file <- system.file("extdata", "LSM_threeChannels.czi",
                          package = "readCzi", mustWork = TRUE)

# <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

## 1. Read czi file and store as array -------------------------------------
image_data <- readCzi(input_file = input_file)

## 2. Read metadata of czi file and save as CSV ----------------------------
##    (in German and English format)
df_metadata <- readCziMetadata(input_file = input_file,
                               save_metadata = TRUE)

file_path_de <- file.path(dirname(input_file), "output",
                          paste0(gsub("\\.czi", "", basename(input_file)),
                          "_df_metadata_de.csv"))
file_path_en <- file.path(dirname(input_file), "output",
                          paste0(gsub("\\.czi", "", basename(input_file)),
                          "_df_metadata_en.csv"))

dir.create(path = file.path(dirname(input_file), "output"),
showWarnings = FALSE)
readr::write_csv(x = df_metadata, file = file_path_en)
readr::write_csv2(x = df_metadata, file = file_path_de)

## 3. Convert czi file to tifs ---------------------------------------------
convertCziToTif(input_file = input_file,
                convert_all_slices = TRUE)

The results are the following:

1. LSM_threeChannels.czi

(The jpgs were created with the R package 'magick'. Please see ´inst/testscript.R´ for details.)



SFB-ELAINE/readCzi documentation built on March 31, 2024, 4:50 a.m.