The iRfcb
package is an open-source R package designed to streamline the analysis of Imaging FlowCytobot (IFCB) data, with a focus on supporting marine ecological research and monitoring. By integrating R and Python functionalities, the package facilitates efficient handling and sharing of IFCB image data, extraction of key metadata, and preparation of outputs for further taxonomic, ecological, or spatial analyses.
This tutorial serves as an introduction to the core functionalities of iRfcb
, providing step-by-step instructions for data preprocessing, taxonomic analysis, and SHARK-compliant data export. For additional guides—such as quality control of IFCB data, data sharing, and integration with MATLAB—please refer to the other tutorials available on the project's webpage.
You can install the package from CRAN using:
install.packages("iRfcb")
Load the iRfcb
and dplyr
libraries:
library(iRfcb) library(dplyr) # For data wrangling
library(iRfcb) library(dplyr) # For data wrangling
To get started, download sample data from the SMHI IFCB Plankton Image Reference Library (Torstensson et al. 2024) with the following function:
# Define data directory data_dir <- "data" # Download and extract test data in the data folder ifcb_download_test_data(dest_dir = data_dir, max_retries = 10, sleep_time = 30)
This section demonstrates a selection of general data extraction tools available in iRfcb
.
Extract timestamps from sample names or filenames:
# Example sample names filenames <- list.files("data/data/2023/D20230314", recursive = TRUE) # Print filenames print(filenames) # Convert filenames to timestamps timestamps <- ifcb_convert_filenames(filenames) # Print result print(timestamps)
If the filename includes ROI numbers (e.g., in an extracted .png
image), a separate column, roi
, will be added to the output.
# Example sample names filenames <- list.files("data/png/Alexandrium_pseudogonyaulax_050") # Print filenames print(filenames) # Convert filenames to timestamps timestamps <- ifcb_convert_filenames(filenames) # Print result print(timestamps)
The analyzed volume of a sample can be calculated using data from .hdr
and .adc
files.
# Path to HDR file hdr_file <- "data/data/2023/D20230314/D20230314T001205_IFCB134.hdr" # Calculate volume analyzed (in ml) volume_analyzed <- ifcb_volume_analyzed(hdr_file) # Print result print(volume_analyzed)
Get the runtime from a .hdr
file:
# Get runtime from HDR-file run_time <- ifcb_get_runtime(hdr_file) # Print result print(run_time)
Read all feature files (.csv
) from a folder:
# Read feature files from a folder features <- ifcb_read_features("data/features/2023/", verbose = FALSE) # Do not print progress bar # Print output of first 10 columns from the first sample in the list head(features[[1]])[,1:10] # Read only multiblob feature files multiblob_features <- ifcb_read_features("data/features/2023", multiblob = TRUE, verbose = FALSE) # Print output of first 10 columns from the first sample in the list head(multiblob_features[[1]])[,1:10]
IFCB images stored in .roi
files can be extracted as .png
files using the iRfcb
package, as demonstrated below.
Extract all images from a sample using the ifcb_extract_pngs()
function. You can specify the out_folder
, but by default, images will be saved in a subdirectory within the same directory as the ROI file. The gamma
can be adjusted to enhance image contrast, and an optional scale bar can be added by specifying scale_bar_um
.
# All ROIs in sample ifcb_extract_pngs( "data/data/2023/D20230314/D20230314T001205_IFCB134.roi", gamma = 1, # Default gamma value scale_bar_um = 5 # Add a 5 micrometer scale bar )
Extract specific ROIs:
# Only ROI number 2 and 5 ifcb_extract_pngs("data/data/2023/D20230314/D20230314T003836_IFCB134.roi", ROInumbers = c(2, 5))
To extract annotated images or classified results from MATLAB files, please see the vignette("image-export-tutorial")
and vignette("matlab-tutorial")
tutorials.
Maintaining up-to-date taxonomic data is essential for ensuring accurate species names and classifications, which directly impact calculations like carbon concentrations in iRfcb
.
Up-to-date taxonomy also ensures data harmonization by preventing issues like misspellings, outdated synonyms, or inconsistent classifications. This consistency is crucial for integrating and comparing datasets across studies, regions, and time periods, improving the reliability of scientific outcomes.
Taxonomic names can be matched against the World Register of Marine Species (WoRMS), ensuring accuracy and consistency. The iRfcb
package includes a built-in function for taxon matching via the WoRMS API, featuring a retry mechanism to handle server errors, making it particularly useful for automated data pipelines. For additional tools and functionality, the R package worrms
provides a comprehensive suite of options for interacting with the WoRMS database.
# Example taxa names taxa_names <- c("Alexandrium_pseudogonyaulax", "Guinardia_delicatula") # Retrieve WoRMS records worms_records <- ifcb_match_taxa_names(taxa_names, verbose = FALSE) # Do not print progress bar # Print result tibble(worms_records)
This function takes a list of taxa names, cleans them, retrieves their corresponding classification records from WoRMS, and checks if they belong to the specified diatom class. The function only uses the first name (genus name) of each taxa for classification. This function can be useful for converting biovolumes to carbon according to Menden-Deuer and Lessard (2000). See vol2C_nondiatom()
and vol2C_lgdiatom()
for carbon calculations (not included in NAMESPACE).
# Read class2use file and select five taxa class2use <- ifcb_get_mat_variable("data/config/class2use.mat")[10:15] # Create a dataframe with class name and result from `ifcb_is_diatom` class_list <- data.frame(class2use, is_diatom = ifcb_is_diatom(class2use, verbose = FALSE)) # Print rows 10-15 of result class_list
The default class for diatoms is defined as Bacillariophyceae, but may be adjusted using the diatom_class
argument.
This function takes a list of taxa names and matches them with the SMHI Trophic Type list used in SHARK.
# Example taxa names taxa_list <- c( "Acanthoceras zachariasii", "Nodularia spumigena", "Acanthoica quattrospina", "Noctiluca", "Gymnodiniales" ) # Get trophic type for taxa trophic_type <- ifcb_get_trophic_type(taxa_list) # Print result print(trophic_type)
This function is used by SMHI to map IFCB data into the SHARK standard data delivery format. An example submission is also provided in iRfcb
.
# Get column names from example shark_colnames <- ifcb_get_shark_colnames() # Print column names print(shark_colnames) # Load example stored from `iRfcb` shark_example <- ifcb_get_shark_example() # Print first ten columns of the SHARK data submission example head(shark_example)[1:10]
This concludes this tutorial for the iRfcb
package. For additional guides—such as quality control of IFCB data, data sharing, and integration with MATLAB—please refer to the other tutorials available on the project's webpage. See how data pipelines can be constructed using iRfcb
in the following Example Project. Happy analyzing!
# Print citation citation("iRfcb")
# Clean up unlink(file.path(data_dir, "data/2023/D20230314/D20230314T001205_IFCB134"), recursive = TRUE) unlink(file.path(data_dir, "data/2023/D20230314/D20230314T003836_IFCB134"), recursive = TRUE)
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.