Operations on TglowDataset
The following page shows examples of common operations that can be performed on TglowDatasets and its derived objects.
Show
Show will show some useful info on the object
You can also show tglow assays
Slicing
TglowDatasets and assays can be sliced by row
They can also be sliced by column, but this is not recommended unless using column names, as assays can have different number of columns. A warning is raised when you try to slice columns with a non-character.
Individual TglowAssays can also be sliced, in this case it is safe to use integers to select features.
Accessing assays
You can access TglowAssays from the @assays slot by using $ or by [[]]
Accessing feature data
You can access the data using slicing [] or by using $ on a TglowAssay or a TglowMatrix. If you use slicing on a TglowAssay, a new assay is returned. If you use $ a list with items data and scale.data is returned.
Setting and manipulating assays
You can set TglowAssays using the @assays slot. The assays slot is just a list, so you can put anything in it but if you want it to work properly new.assay must be a TglowAssay. Note at the moment you can only add assays using tglow@assays[["new.assay"]] <- new.assay and not the other operators.
You can manipulate specific slots in existing assays as well. For example, replacing the data slot with the scale.data slot.
Adding features to an existing assay
The function add_features_to_assay() can be used to add new features to an existing assay. This will remove the other slot unless preserve.other=TRUE is set in which case NA's will be added in the other slot.
Accessing data
To get a mix of meta data of feature information per cell object there is a convenience function getDataByObject() which grabs data from any assay, slot or metadata item as long as its colnames are uniquely findable. The function returns a object x feature data frame. The function getDataByObject() only works with one assay at the time, if you grab features from two different assays, you will need to run getDataByObject twice and call cbind on the result.
Getting and setting object IDs
Object ID's can be viewed in two ways
The method objectIds is implemented for TglowDataset, TglowAssay and TglowReduction.
To set object ID's you can use the <- operator.
NOTE: You can also do it manually through the slots, but this is not recommended, as it can lead to issues when not all slots are set properly, as it assumed all slots have the rownames set to enable easy slicing by object ID. Similarly, you could call
objectIds(tglow@assays[[1]]) <- 1:nrow(tglow)but this will likely break downstream functionality.
Aggregating datasets
TglowDatasets can be aggregated using aggregate_by_imagecol() which will take a dataset, apply the supplied aggregation function, and return a new TglowDataset with the aggregated data. Supported aggregations are mean, median and sum. Metadata (factors, characters, logicals) are aggregated as well, and kept if there is one unique value. If there are more than one unique value, the result is set to NA. Columns that have only NA's are dropped unless drop.na.col=FALSE.
The output object is a valid TglowDataset, so all functions should work as usual
Matching two TglowDatasets
Matching on nearest neighbour position
There are often cases when features have been extracted for the same set of images and cells, but perhaps using slightly different masks, or different softwares. This can make it harder to match due to rounding errors or implementation differences yielding slightly different xyz positions for cells. Tglow-r contains a function that matches two TglowDatasets based on the nearest neighbors in xy space. Note the feature map must be set for this to work.
Matching manually on ID
You can align two datasets on a matching ID. Filesets might not always be read in the same order, so the default ObjectNumber_Global id's are not guaranteed to match when using cellprofiler results from different runs. Given we use the same cellpose masks and if you have configured cellprofiler to NOT relabel cells you can use the ObjectNumber to match between datasets.