Create a usable Seurat object from a sample.
create_seurat_object.RdEverything needed to take a sample from a counts file to an object ready for clustering, in one call.
Usage
create_seurat_object(
path,
sample_name,
num_mads = 3,
min_genes = 500,
max_genes = NULL,
min_counts = NULL,
max_counts = NULL,
max_mt = 10,
normalization_method = "log",
num_variable_genes = 3000,
num_pcs = 50,
num_dim = 30,
log_file = NULL
)Arguments
- path
Path to a 10x directory or a flat counts file.
- sample_name
Sample/library name, used as the cell ID prefix.
- num_mads, min_genes, max_genes, min_counts, max_counts, max_mt
Quality cutoffs, passed to
filter_cells()— see there for how the outlier stage and the fixed cutoffs combine.- normalization_method
Normalization method, passed to
normalize_counts()(as its ownmethodargument): "log" or "sct".- num_variable_genes
Number of variable features.
- num_pcs
Principal components to compute. Reduced automatically when the object is too small to support that many.
- num_dim
Number of dimensions for the first-pass tSNE/UMAP, capped at
num_pcs.- log_file
Filename for the log file.
Value
A Seurat object with normalized data, variable features, scaled
data, and "pca", "tsne", and "umap" reductions — ready for
cluster_seurat_object(). Also writes the variable-feature, PCA, tSNE,
and UMAP diagnostic plots (via normalize_counts(), run_pca(),
run_tsne(), and run_umap()) and the metadata+embeddings table (via
save_metadata(), as metadata.csv.gz) to the working directory.
Details
The function runs these steps:
Read the counts (
read_counts_file()).Build the object (
initialize_seurat_object()).Attach any antibody capture data as an "ADT" assay (
add_seurat_assay()).Apply the quality cutoffs (
filter_cells()).Normalize, select variable features, and scale (
normalize_counts(), which does all three for either method).Run PCA (
run_pca()).Compute a first-pass tSNE/UMAP (
run_tsne(),run_umap()).
This function attaches the ADT assay before filtering, on purpose.
add_seurat_assay() restricts the object to the barcodes both matrices
share. Attaching ADT after filtering would apply the cutoffs to a
different set of cells.
PCA, and the tSNE/UMAP computed from it, runs on whichever assay
normalization left active. SCTransform() creates and activates "SCT".
The log path leaves "RNA" active. So dr_assay is decided directly from
normalization_method, not read back off the object. Reading it back off
DefaultAssay() would reintroduce the implicit dependency an explicit
assay argument exists to avoid.
The tSNE/UMAP computed here are a first-pass look, capped at num_dim
dimensions. cluster_seurat_object() recomputes both once a clustering
resolution's own num_dim is chosen. So this pair is not the final one
used for the actual clustering plots.