Learn R Programming

nandb (version 0.2.1)

KmersFromImage: Calculate numbers of kmers based on an image time-series

Description

Given an image (as a file path or an array), KmersFromImage does the brightness calculation via Brightness() and then counts the numbers of each kmer via KmersFromBrightnesses(). KmersFromImagesFolder does this for an entire folder (directory) of images and outputs a csv file of the results.

Usage

KmersFromImage(arr3d, monomer, tau = NA, mst = NULL, filt = NULL,
  verbose = TRUE)

KmersFromImages(arrs3d, monomer, tau = NA, mst = NULL, filt = NULL, verbose = TRUE, mcc = parallel::detectCores(), seed = NULL)

KmersFromImagesFolder(folder.path = ".", monomer, tau = NA, mst = NULL, filt = NULL, out.name = "results", ext = "\\.tif$", mcc = parallel::detectCores(), seed = NULL, verbose = TRUE)

Arguments

arr3d

A 3-dimensional array that one would might input to Brightness() or the path to an image file on disk.

monomer

The median brightness of a monomer. You must know what this is to use this function correctly. This must be greater than 1 (this is the 'apparent brightness' of a monomer). If you're reading the Digman et al. (2008) paper, this is \(1 + \epsilon\).

tau

The time constant for the exponential filtering (see Brightness()).

mst

Do you want to apply an intensity threshold prior to calculating brightness (via autothresholdr::mean_stack_thresh())? If so, set your thresholding method here.

filt

Do you want to smooth (filt = 'smooth') or median (filt = 'median') filter the brightness image using SmoothFilterB() or MedianFilterB() respectively? If selected, these are invoked here with a filter radius of 1 and with the option na_count = TRUE. If you want to smooth/median filter the brightness image in a different way, first calculate the brightnesses without filtering (filt = NULL) using this function and then perform your desired filtering routine on the result.

verbose

If arr3d is specified as a file name, print a message to tell the user that that file is now being processed (useful for BrightnessFolder, does not work with multiple cores) and to tell when KmersFromImagesFolder is done.

arrs3d

A list of 3d arrays. To perform this on files that have not yet been read in, set this argument to the path to these files (a character vector).

mcc

The number of cores to use for the parallel processing.

seed

A seed for the random number generation for BestTau. Don't use set.seed, it won't work.

folder.path

The path (relative or absolute) to the folder you wish to process.

out.name

The name of the results csv file.

ext

the file extension of the images in the folder that you wish to process (can be rooted in regular expression for extra-safety, as in the default). You must wish to process all files with this extension; if there are files that you don't want to process, take them out of the folder.

Value

A named vector (named '1mers' '2mers' '3mers' and so on) with each element detailing the number of that kmer found, or for KmersFromImagesFolder, a csv file is written to disk detailing one of these vectors for each image. This vector also has an attribute 'mean.intensity' giving the mean intensity of the input image.

Examples

Run this code
# NOT RUN {
img <- system.file('extdata', '50.tif', package = 'nandb')
KmersFromImage(img, 1.1, tau = NA, mst = "huang")

KmersFromImages(c(img, img), 1.1, tau = NA, mst = "huang")

setwd(tempdir())
file.copy(img, ".")
KmersFromImagesFolder(monomer = 1.11)
file.remove(list.files())  # cleanup

# }

Run the code above in your browser using DataLab