R Tutorial: Load, create, and access single-cell datasets in R

Learn to use the SingleCellExperiment S4 class for managing single-cell RNA-seq data in R. Create SCE objects from count matrices, convert SummarizedExperiment objects, and load real datasets like the Allen visual cortex mouse data with gene and cell metadata included.
Chapters
Let's learn how to load, create and access single cell data in R. In this video we focus on the single cell experiment class. It's a S4 class developed by Aaron Lund and David Erisso and it's very useful to analyze single cell data because it allows you to easily store and retrieve the matrix of counts, but also information about the cells, the genes. You remember the three matrices, one with the row counts and the other two for gene and cell level information I showed you in the previous video. The idea here is that we are going to use only one R object to store these three matrices. So how does it work in practice? First you need to install and load the single cell experiment package you using the usual BIOC light and library functions. The next step is to create a single cell experiment object. And there are two ways to do this. The first way is to use the single cell experiment function. For that, you'll create a small matrix count with four genes and two cells where we simulate counts from a Poisson distribution using the RPWAS function. Let's use the row names and colnames functions to name the rows as the gene names and the colons as the cell names. Here you see that gene names are Lamb 5, Fam 19, A1, CNR1 and RORB. And cell names start with SRR and then a number. Using the matrix counts we just created, we create a SCE object using the single cell experiment function. The first argument is assays, which takes a list of count matrices. Here we'll only use our matrix counts with four genes and two cells. The second and third arguments are are raw data and cold data for data frames with information about genes and cells. Here we only store the gene and cell names, which are the row and column names of our matrix counts. You see that we have created a SCE object with a dimension of four by two and you can see the gene and cell names. The other way to create a single cell experiment object is by transforming an existing summarized experiment object which is commonly used when working with bulk RNA sequencing data. If you're not familiar with this class, you can look at the package documentation. We first need to create a summarized experiment object using the same count matrix as in the previous slide. And then use the AS function to transform the summarized experiment into the single cell experiment object. You see that the new object SCE is exactly the same as the SCE object we created in the previous slide. So we've created a fake data set, but now let's look at a real data set. We we can load the Allen dataset from the package SCRNSSEQ using the data function. The dataset is a subset of the data published by Tacic et al. In 2016. It contains about 400 cells from the visual cortex in male mice, where cells were extracted from different layers of neurons. The dataset Allen is a summarized experiment object. So, as in the previous slides, we can create a single cell experiment object from the object Allen using the as function and argument single cell experiment. In the SCE object, you can see the gene and cell names, and we also have access to cell quality measures, for example the total number of reads aligned for each cell in the colon n al of the cold data data frame. Let's now practice with.
More from Richie

#359 My Best Friend is AI with Valerie Tiberius, Professor of Philosophy at University of Minnesota

How AI Agents Will Work While You Sleep | Ruslan Salakhutdinov, Professor at Carnegie Mellon

#358 How AI Agents Will Work While You Sleep | Ruslan Salakhutdinov, Professor at Carnegie Mellon







