Interface
SingleCellProjections.add_columnSingleCellProjections.add_obs_columnSingleCellProjections.add_var_columnSingleCellProjections.annotate_obsSingleCellProjections.annotate_varSingleCellProjections.annotationSingleCellProjections.categorical_covariateSingleCellProjections.column_dataSingleCellProjections.create_tableSingleCellProjections.designmatrixSingleCellProjections.filter_matrixSingleCellProjections.filter_obsSingleCellProjections.filter_varSingleCellProjections.find_optimal_coord_transformSingleCellProjections.flipx2dSingleCellProjections.flipx3dSingleCellProjections.flipy2dSingleCellProjections.flipy3dSingleCellProjections.flipz3dSingleCellProjections.force_layoutSingleCellProjections.ftestSingleCellProjections.get_colnamesSingleCellProjections.get_columnsSingleCellProjections.get_id_colnameSingleCellProjections.get_matrixSingleCellProjections.get_obsSingleCellProjections.get_value_colnameSingleCellProjections.get_varSingleCellProjections.id_columnSingleCellProjections.id_column_dataSingleCellProjections.load_countsSingleCellProjections.load_csvSingleCellProjections.load_h5adSingleCellProjections.loadingsSingleCellProjections.local_outlier_factorSingleCellProjections.logtransformSingleCellProjections.mannwhitneySingleCellProjections.negative_regression_matrixSingleCellProjections.nobsSingleCellProjections.normalize_matrixSingleCellProjections.numerical_covariateSingleCellProjections.nvarSingleCellProjections.obs_counts_fractionSingleCellProjections.obs_counts_sumSingleCellProjections.pcaSingleCellProjections.population_matrixSingleCellProjections.projectSingleCellProjections.pseudobulkSingleCellProjections.relative_stdSingleCellProjections.rot2dSingleCellProjections.rotxSingleCellProjections.rotySingleCellProjections.rotzSingleCellProjections.sctransformSingleCellProjections.signatureSingleCellProjections.stdSingleCellProjections.subset_matrixSingleCellProjections.subset_obsSingleCellProjections.subset_varSingleCellProjections.svdSingleCellProjections.table_hcatSingleCellProjections.table_leftjoinSingleCellProjections.table_ncolSingleCellProjections.table_nrowSingleCellProjections.tf_idf_transformSingleCellProjections.transfer_annotationSingleCellProjections.transform_annotationSingleCellProjections.transform_coordsSingleCellProjections.transposeSingleCellProjections.tsneSingleCellProjections.ttestSingleCellProjections.twogroup_covariateSingleCellProjections.umapSingleCellProjections.value_columnSingleCellProjections.value_column_dataSingleCellProjections.var_counts_fractionSingleCellProjections.var_counts_sumSingleCellProjections.variance
SingleCellProjections.add_column — Method
SCP.add_column(table, name, column) -> JobAdd a column named name with values column to table. The length of column must match the number of rows in table.
See also table_hcat, add_var_column, add_obs_column.
SingleCellProjections.add_obs_column — Method
SCP.add_obs_column(data, name, column) -> JobAdd a single column named name with values column to the observation annotations. The length and order of column must match the rows of data.obs.
See also add_var_column, annotate_obs.
SingleCellProjections.add_var_column — Method
SCP.add_var_column(data, name, column) -> JobAdd a single column named name with values column to the variable annotations. The length and order of column must match the rows of data.var.
See also add_obs_column, annotate_var.
SingleCellProjections.annotate_obs — Method
SCP.annotate_obs(data, df; kwargs...) -> JobAdd observation annotations by left-joining df onto data.obs. The first column of df should contain IDs matching the first column in data.obs. The IDs are used as the key when joining the tables.
See also annotate_var, add_obs_column.
SingleCellProjections.annotate_var — Method
SCP.annotate_var(data, df; kwargs...) -> JobAdd variable annotations by left-joining df onto data.var. The first column of df should contain IDs matching the first column in data.var. The IDs are used as the key when joining the tables.
See also annotate_obs, add_var_column.
SingleCellProjections.annotation — Method
SCP.annotation(table, colname) -> JobExtract the ID column and the column named colname from table, returning a two-column table. Useful for passing annotations to filtering or covariate specification.
SingleCellProjections.categorical_covariate — Method
categorical_covariate()Create a categorical covariate description. Used in Pairs to specify that a column should be treated as categorical, e.g. "celltype" => categorical_covariate().
This is the default for string columns, so explicit use is rarely needed.
See also numerical_covariate, twogroup_covariate.
SingleCellProjections.column_data — Method
SCP.column_data(table, col; kwargs...) -> JobReturn the values of column col from table as a vector.
See also id_column_data, value_column_data.
SingleCellProjections.create_table — Method
SCP.create_table(col1 => values1, col2 => values2, ...) -> JobCreate a new table Job from column name/value pairs.
SingleCellProjections.designmatrix — Method
SCP.designmatrix(data, covariates...; center=true, kwargs...) -> JobConstruct a design matrix from observation covariates. Covariates can be column names (strings) or Pairs of column name and covariate description. Used internally by SCP.normalize_matrix.
See also normalize_matrix, negative_regression_matrix.
SingleCellProjections.filter_matrix — Method
SCP.filter_matrix(fvar, fobs, data; kwargs...) -> JobFilter both variables and observations simultaneously.
See also filter_var, filter_obs.
SingleCellProjections.filter_obs — Method
SCP.filter_obs(fobs, data; kwargs...) -> JobFilter observations by the predicate fobs. fobs can be:
- An integer range or vector of indices.
- A
Pairof column name and predicate (e.g."celltype" => isequal("Monocyte")). - An annotation table
Jobwith a predicate.
(TODO: Add an example with predicate. Cannot use the relative_std one.)
See also filter_var, filter_matrix, subset_obs.
SingleCellProjections.filter_var — Method
SCP.filter_var(fvar, data; kwargs...) -> JobFilter variables by the predicate fvar. fvar can be:
- An integer range or vector of indices (e.g.
1:100). - A
Pairof column name and predicate (e.g."name" => >("D")). - An annotation table
Jobwith a predicate (e.g.SCP.relative_std(data) => >=(0.1)).
See also filter_obs, filter_matrix, subset_var.
SingleCellProjections.find_optimal_coord_transform — Method
SCP.find_optimal_coord_transform(data, group_filters...; kwargs...) -> JobFind an optimal rotation matrix that aligns data coordinates so that specified cell groups are separated along the principal axes. The first group filter defines the direction of the first axis (up), the second group the second axis, and so on — each is made orthogonal to the preceding axes.
Each group_filter is a Pair of column name and predicate (e.g. "celltype" => isequal("HSC")).
Examples
Rotation of 3D plot:
julia> transform = SCP.find_optimal_coord_transform(fl,
"celltype"=>isequal("HSC"),
"celltype"=>isequal("T-cells"),
"celltype"=>isequal("B-cells"))
julia> fl_rotated = SCP.transform_coords(fl, transform; keep_var=true)Rotation of 2D plot:
julia> transform = SCP.find_optimal_coord_transform(fl_2d,
"celltype"=>isequal("HSC"),
"celltype"=>isequal("T-cells"))
julia> fl_rotated = SCP.transform_coords(fl_2d, transform; keep_var=true)See also transform_coords, force_layout.
SingleCellProjections.flipx2d — Method
flipx2d()Return a 2×2 matrix that flips the x-axis. For use with transform_coords.
SingleCellProjections.flipx3d — Method
flipx3d()Return a 3×3 matrix that flips the x-axis. For use with transform_coords.
SingleCellProjections.flipy2d — Method
flipy2d()Return a 2×2 matrix that flips the y-axis. For use with transform_coords.
SingleCellProjections.flipy3d — Method
flipy3d()Return a 3×3 matrix that flips the y-axis. For use with transform_coords.
SingleCellProjections.flipz3d — Method
flipz3d()Return a 3×3 matrix that flips the z-axis. For use with transform_coords.
SingleCellProjections.force_layout — Method
SCP.force_layout(data; ndim=3, kwargs...) -> JobCompute a force-directed layout embedding of data. Returns a DataMatrix with ndim layout dimensions as variables.
Keyword arguments:
k— number of nearest neighbors for the graph.k_fraction— alternative tok, specify neighbors as a fraction of observations.niter— number of force simulation iterations (default100).link_distance,link_strength— link force parameters (defaults40,0.05).charge,charge_min_distance,theta— repulsion parameters (defaults40,1,0.9).center_strength— centering force (default0.05).velocity_decay— velocity damping (default0.9).initialAlpha,finalAlpha— simulation temperature schedule (defaults1.0,1e-3).initialScale— initial coordinate scale (default10).seed— random seed (default1234).k_projection— neighbors used when projecting onto this layout (default10).
Examples
julia> SCP.force_layout(reduced; ndim=3, seed=4567, k=100, k_projection=25)See also transform_coords, find_optimal_coord_transform, umap, tsne.
SingleCellProjections.ftest — Method
SCP.ftest(data, h1; h0=(), center=true, kwargs...) -> JobPerform an F-test for each variable comparing the full model h1 against the null model h0. Returns a table with test statistics and p-values.
h1 and h0 are covariates specified as column name strings or Pairs of column name and covariate description. The covariate type (categorical/numerical) is normally autodetected. With a single categorical covariate, this is equivalent to a one-way ANOVA.
Keyword arguments:
statistic_col="F"/pvalue_col="pValue"- output column names (set tonothingto omit).do_sort=true- sort variables by theFstatistic (most significant first).
(TODO: Examples.)
See also ttest, normalize_matrix.
SingleCellProjections.get_colnames — Method
SCP.get_colnames(table; kwargs...) -> JobReturn the column names of table.
See also get_id_colname, get_value_colname.
SingleCellProjections.get_columns — Method
SCP.get_columns(table, colnames...) -> JobSelect specific columns from table by name or index.
See also id_column, value_column.
SingleCellProjections.get_id_colname — Method
SCP.get_id_colname(table) -> JobReturn the name of the first (ID) column of table.
See also get_colnames, get_value_colname.
SingleCellProjections.get_matrix — Method
SCP.get_matrix(data) -> JobExtract the matrix component from a DataMatrix Job.
SingleCellProjections.get_obs — Method
SCP.get_obs(data) -> JobExtract the observation annotation table from a DataMatrix Job.
See also get_matrix, get_var.
SingleCellProjections.get_value_colname — Method
SCP.get_value_colname(table) -> JobReturn the name of the second (value) column of table. Requires the table to have exactly two columns.
See also get_colnames, get_id_colname.
SingleCellProjections.get_var — Method
SCP.get_var(data) -> JobExtract the variable annotation table from a DataMatrix Job.
See also get_matrix, get_obs.
SingleCellProjections.id_column — Method
SCP.id_column(table) -> JobExtract the first (ID) column of table as a single-column table.
See also value_column, id_column_data.
SingleCellProjections.id_column_data — Method
SCP.id_column_data(table) -> JobReturn the vector of IDs (first column) from table.
See also column_data, value_column_data.
SingleCellProjections.load_counts — Method
SCP.load_counts(filenames; sample_names, feature_filenames=nothing, barcode_filenames=nothing, prefilter="feature_type"=>isequal("Gene Expression"), extra_id_cols="feature_type", kwargs...) -> JobLoad raw count matrices from one or more 10x files. Returns a Job whose result is a DataMatrix with genes as variables and cells as observations.
Each file can be a 10x HDF5 (.h5) file, or a CellRanger Matrix Market matrix (.mtx[.gz]). For a .mtx file, the matching feature and barcode files are found in the same folder (following the CellRanger naming convention), or can be given explicitly.
sample_namesis required and assigns a name to each sample.feature_filenames/barcode_filenames— explicit feature/barcode files (a single filename or a vector matchingfilenames). Whennothing(default), they are guessed from each.mtxfilename; for a.h5file the file itself is used.prefilterselects which features to keep (defaults to Gene Expression only).extra_id_colsspecifies additional columns used (together with the first column) to uniquely identify variables when merging samples. Variables with matching ID columns are combined.
Examples
Load a single sample:
julia> SCP.load_counts("SampleA.h5"; sample_names="SampleA")Load multiple samples:
julia> SCP.load_counts(["SampleA.h5", "SampleB.h5"]; sample_names=["SampleA","SampleB"])Load from a Matrix Market file (features/barcodes found in the same folder):
julia> SCP.load_counts("matrix.mtx.gz"; sample_names="SampleA")See also load_csv.
SingleCellProjections.load_csv — Function
SCP.load_csv(filepath; kwargs...) -> JobLoad a CSV or TSV file as a table Job. The file path is automatically checksummed for cache invalidation. Requires the CSV package to be loaded.
See also load_counts.
SingleCellProjections.load_h5ad — Function
SCP.load_h5ad([T], filepath; layer=nothing, obsm=nothing, obsp=nothing, varm=nothing, varp=nothing, kwargs...) -> JobLoad a .h5ad (AnnData) file as a DataMatrix Job. Requires the Muon package to be loaded.
The optional type parameter T determines the eltype of the matrix. If specified, the matrix will be converted (e.g. Int for count matrices stored as floats).
By default, the main matrix X is loaded. Use one of the following mutually exclusive kwargs to load from a different source:
layer— a named layer fromlayers(e.g."raw_counts")obsm— observation embeddings (e.g."X_umap"), var is set to synthetic dimension IDsobsp— observation pairwise matrix, both var and obs are set to obs annotationsvarm— variable embeddings, obs is set to synthetic dimension IDsvarp— variable pairwise matrix, both var and obs are set to var annotations
Examples
Load the main matrix X.
julia> SCP.load_h5ad("data.h5ad")Load raw counts. Note that we want to specify the eltype Int, because h5ad typically stores counts as Float32.
julia> SCP.load_h5ad(Int, "data.h5ad"; layer="raw_counts")Load a UMAP embedding.
julia> SCP.load_h5ad("data.h5ad"; obsm="X_umap")See also load_counts, load_csv.
SingleCellProjections.loadings — Method
SCP.loadings(data; nsv, seed=1234, kwargs...) -> JobExtract PCA loadings from data. Returns a DataMatrix where each column is a loading vector. The loadings are not affected by projection. Uses the same randomized SVD algorithm as SCP.pca and accepts the same keyword arguments (nsv, seed, subspacedims, niter).
Examples
Compute the loadings of normalized for the 100 first principal components. Useful in combination with a call to SCP.pca (with the same parameters).
julia> SCP.loadings(normalized; nsv=100)SingleCellProjections.local_outlier_factor — Method
SCP.local_outlier_factor(data, full; k=10, col="LOF") -> JobCompute the Local Outlier Factor for each observation in data relative to the full dataset full, using k nearest neighbors. Returns a table with IDs and LOF scores in a column named col.
When projecting, only neighbors in the base dataset are considered.
SingleCellProjections.logtransform — Method
SCP.logtransform([T=Float64,] counts; scale_factor=10_000, kwargs...) -> JobApply log transformation: log(1 + x * scale_factor / total_counts). Returns a DataMatrix with the transformed matrix. The element type of the resulting matrix is T.
(TODO: Add example.)
See also sctransform, normalize_matrix.
SingleCellProjections.mannwhitney — Method
SCP.mannwhitney(data, column, [group_a, group_b]; h1_missing=:skip, kwargs...) -> JobPerform a Mann-Whitney U-test (a.k.a. Wilcoxon rank-sum test) between two groups of observations, for each variable. The U statistic is corrected for ties, and p-values are computed using a normal approximation. Returns a table with variable IDs, U statistics and p-values, sorted by significance (see below).
data must contain a sparse matrix. It is recommended to first logtransform (or tf_idf_transform) the raw counts.
column selects a column in data.obs that determines group membership:
- If neither
group_anorgroup_bis given,columnmust have exactly two unique values (ignoringmissing). - If only
group_ais given, observations equal togroup_aare compared against all others (ignoringmissing). - If both are given, observations equal to
group_aare compared against those equal togroup_b.
Keyword arguments:
h1_missing=:skip-:skipexcludesmissingvalues incolumn;:errorthrows if any are present.statistic_col="U"/pvalue_col="pValue"/z_col=nothing- output column names (set tonothingto omit;zis omitted by default).do_sort=true- sort variables by|z|(most significant first).
Results are sorted by the absolute standardized statistic |z|, where z = (U - n1*n2/2)/σ. This orders variables by significance without the underflow that sorting by pValue suffers (p-values collapse to 0 for strongly-separated variables). The signed z (available via z_col) is monotone with the p-value and also indicates the direction of the effect.
The test is projectable: when projecting onto other data, the group labels resolved here are reused and the test is recomputed on the projected observations.
See also ftest, ttest, logtransform.
SingleCellProjections.negative_regression_matrix — Method
SCP.negative_regression_matrix(data, design_matrix; kwargs...) -> JobCompute the negative regression coefficient matrix for normalization. Used internally by SCP.normalize_matrix.
See also normalize_matrix, designmatrix.
SingleCellProjections.nobs — Method
SingleCellProjections.normalize_matrix — Method
SCP.normalize_matrix(data, covariates...; center=true, kwargs...) -> JobNormalize data by centering and regressing out covariates. Covariates can be column names (strings) or Pairs of column name and covariate description.
Optional keyword arguments for annotating per-variable statistics:
annotate_variance: Set to true to add a column with per-variable variance.annotate_std: Set to true to add a column with per-variable standard deviation.annotate_relative_std: Set to true to add a column with per-variable relative standard deviation.variance_col: Custom name for the variance column.std_col: Custom name for the std column.relative_std_col: Custom name for the relative standard deviation.
Examples
Center transformed data:
julia> SCP.normalize_matrix(transformed)Center transformed data and regress out the fraction_mt covariate.
julia> SCP.normalize_matrix(transformed, "fraction_mt")Annotate by relative std:
julia> SCP.normalize_matrix(transformed; annotate_relative_std=true)Annotate by variance, using a custom name:
julia> SCP.normalize_matrix(transformed; variance_col="my_variance_column")See also sctransform, logtransform, designmatrix.
SingleCellProjections.numerical_covariate — Method
numerical_covariate()Create a numerical covariate description. Used in Pairs to specify that a column should be treated as numerical, e.g. "age" => numerical_covariate().
This is the default for numeric columns, so explicit use is rarely needed.
See also categorical_covariate, twogroup_covariate.
SingleCellProjections.nvar — Method
SingleCellProjections.obs_counts_fraction — Function
SCP.obs_counts_fraction(counts, col, sub_filter, tot_filter=Returns(true); project_ids=:no) -> JobCompute the fraction of counts from a subset of observations (cells) for each variable, and add it as a new variable annotation column named col.
sub_filter and tot_filter are predicates applied to the variable annotations to select the subset and total gene sets respectively.
See also obs_counts_sum, var_counts_fraction.
SingleCellProjections.obs_counts_sum — Function
SCP.obs_counts_sum([f,] counts, col, filter=Returns(true); project_ids=:no) -> JobCompute the sum of counts (optionally transformed by f) from a filtered subset of observations for each variable, and add it as a new variable annotation column named col.
Examples
For each variable, count the number of cells with a non-zero value.
julia> SCP.obs_counts_sum(!iszero, counts, "nonzero_cell_count")See also obs_counts_fraction, var_counts_sum.
SingleCellProjections.pca — Method
SCP.pca(data; nsv, seed=1234, kwargs...) -> JobCompute PCA of data, keeping nsv principal components. Returns a DataMatrix where the variables are the principal components and the observations are unchanged. Uses a randomized SVD algorithm based on Halko, Martinsson, and Tropp (2011).
The returned principal components are scaled by the singular values, to make this an accurate nsv-dimensional approximation of the original data.
Keyword arguments controlling the iterative procedure:
seed— random seed for reproducibility.subspacedims— dimension of the random subspace (default4nsv).niter— number of power iterations (default3).
Examples
Compute a 100-dimensional PCA of normalized.
julia> SCP.pca(normalized; nsv=100)See also svd, loadings, normalize_matrix.
SingleCellProjections.population_matrix — Method
SCP.population_matrix(obs, obs_covariate1, obs_covariates...; new_var_covariates, kwargs...) -> JobCreate a matrix where each entry is the fraction of cells belonging to each combination of new_var_covariates within each group defined by the observation covariates. The observation covariates define the columns (samples/groups) and new_var_covariates define the rows (e.g. cell type proportions per sample).
(TODO: Add an example.)
See also pseudobulk.
SingleCellProjections.project — Method
SCP.project(onto, old => new, ...; kwargs...) -> JobProjects a dataset onto another, while replacing old=>new. Multiple replacement pairs can be specified. (TODO: Describe projection properly.)
Examples
Given a force layout Job fl, we here project proj_raw_counts onto that force layout, by replacing raw_counts with proj_raw_counts.
julia> SCP.project(fl, raw_counts=>proj_raw_counts)SingleCellProjections.pseudobulk — Method
SCP.pseudobulk(data, obs_covariate1, obs_covariates...; kwargs...) -> JobAggregate single-cell data into pseudobulk by grouping observations according to the specified covariates. Returns a DataMatrix where each column is a pseudobulk sample.
(TODO: Add example.)
See also population_matrix.
SingleCellProjections.relative_std — Method
SCP.relative_std(data; assume_centered, col="relative_std", project=:no) -> JobCompute the standard deviation of each variable in data relative to the maximum standard deviation, returning a table with IDs and values in [0,1].
Useful for filtering variables: SCP.filter_var(SCP.relative_std(data) => >=(f), data) keeps only variables whose std is at least a fraction f of the highest-std variable.
assume_centered(required) must be set totrueto confirm thatdatais mean-centered; the std is computed assuming a mean of zero.colis the name of the annotation column, defaults to"relative_std".projectcan be:no(default) or:yes. If:no, it will compute the std of the base data set, and if:yes, it will compute the std of the projected data set.
See also variance, std, normalize_matrix.
SingleCellProjections.rot2d — Method
rot2d(α)Return a 2×2 rotation matrix for angle α (in radians). For use with transform_coords.
SingleCellProjections.rotx — Method
rotx(α)Return a 3×3 rotation matrix around the x-axis by angle α (in radians). For use with transform_coords.
SingleCellProjections.roty — Method
roty(α)Return a 3×3 rotation matrix around the y-axis by angle α (in radians). For use with transform_coords.
SingleCellProjections.rotz — Method
rotz(α)Return a 3×3 rotation matrix around the z-axis by angle α (in radians). For use with transform_coords.
SingleCellProjections.sctransform — Method
SCP.sctransform([T=Float64,] counts; kwargs...) -> JobApply SCTransform (variance-stabilizing transformation) to raw count data. Returns a DataMatrix with the transformed matrix. The element type of the resulting matrix is T.
Keyword arguments:
var_filter— filter variables used for parameter estimation (default:).min_cells— minimum number of cells with nonzero counts for a variable to be included (default5).annotate— iftrue, add SCTransform parameters tovarannotations.
Examples
SCTransform a counts data matrix.
julia> SCP.sctransform(counts)See also logtransform, normalize_matrix.
SingleCellProjections.signature — Method
SCP.signature(data, var_filter, out_col_name; loadings=false, kwargs...) -> JobCompute a gene signature score for each observation by filtering to genes matching var_filter, normalizing, and extracting the first principal component. Returns a table with IDs and the signature scores in a column named out_col_name.
(TODO: Example.)
SingleCellProjections.std — Method
SCP.std(data; assume_centered, col="std", project=:no) -> JobCompute the standard deviation of each variable in data, returning a table with IDs and values.
assume_centered(required) must be set totrueto confirm thatdatais mean-centered; the std is computed assuming a mean of zero.colis the name of the annotation column, defaults to"std".projectcan be:no(default) or:yes. If:no, it will compute the std of the base data set, and if:yes, it will compute the std of the projected data set.
See also variance, relative_std, normalize_matrix.
SingleCellProjections.subset_matrix — Method
SCP.subset_matrix(data, var_ids, obs_ids) -> JobSubset data to keep only variables and observations with IDs present in var_ids and obs_ids.
See also subset_var, subset_obs.
SingleCellProjections.subset_obs — Method
SCP.subset_obs(data, obs_ids) -> JobSubset data to keep only observations with IDs present in obs_ids.
See also subset_var, subset_matrix, filter_obs.
SingleCellProjections.subset_var — Method
SCP.subset_var(data, var_ids) -> JobSubset data to keep only variables with IDs present in var_ids.
See also subset_obs, subset_matrix, filter_var.
SingleCellProjections.svd — Method
SCP.svd(data; nsv, seed=1234, kwargs...) -> JobCompute a truncated SVD of data, keeping nsv singular values. Returns a DataMatrix containing the SVD result. Uses a randomized algorithm based on Halko, Martinsson, and Tropp (2011).
Keyword arguments controlling the iterative procedure:
seed— random seed for reproducibility.subspacedims— dimension of the random subspace (default4nsv).niter— number of power iterations (default3).
SingleCellProjections.table_hcat — Method
SCP.table_hcat(a, tables...) -> JobHorizontally concatenate tables. All tables must have the same number of rows and matching row order.
See also table_leftjoin, add_column.
SingleCellProjections.table_leftjoin — Method
SCP.table_leftjoin(a, b) -> JobLeft-join table b onto table a by their ID columns.
See also table_hcat, annotate_var, annotate_obs.
SingleCellProjections.tf_idf_transform — Method
SCP.tf_idf_transform([T=Float64,] counts; scale_factor=10_000, annotate=false, kwargs...) -> JobApply the TF-IDF (term frequency-inverse document frequency) transform to raw count data. Returns a DataMatrix with the transformed matrix. The element type of the resulting matrix is T.
The transform is log(1 + scale_factor * tf * idf), where the term frequency is tf = counts ./ max.(1, sum(counts; dims=1)) and the inverse document frequency is idf = nobs ./ max.(1, sum(counts; dims=2)).
idf is estimated from counts and stored in the model, so that projecting onto another dataset reuses it (remapping to the projected variables by ID) rather than recomputing.
Keyword arguments:
scale_factor— term-frequency scale factor (default10_000).annotate— iftrue, add theidfvector as avarannotation.
See also logtransform, sctransform, normalize_matrix.
SingleCellProjections.transfer_annotation — Method
SCP.transfer_annotation(base, new, covariate; k, kwargs...) -> JobTransfer cell annotations from base to new using kNN-based label transfer. The covariate specifies which annotation column to transfer. k is the number of nearest neighbors used for voting.
Returns a table with the transferred labels and confidence scores.
(TODO: Add example - maybe I need to construct one? It should be about celltype transfer.)
SingleCellProjections.transform_annotation — Method
SCP.transform_annotation(f, table; kwargs...) -> JobApply function f element-wise to the value column of table, returning a new table with transformed values. The table must have exactly two columns (ID and value). Use new_name to rename the value column.
(TODO: Example.)
SingleCellProjections.transform_coords — Method
SCP.transform_coords(data, transform; kwargs...) -> JobApply a coordinate transformation matrix transform to the matrix of data.
See also find_optimal_coord_transform, force_layout.
SingleCellProjections.transpose — Method
SCP.transpose(data) -> JobTranspose a DataMatrix, swapping variables and observations.
SingleCellProjections.tsne — Function
SCP.tsne(data; ndim=3, kwargs...) -> JobCompute a t-SNE embedding of data with ndim dimensions. Returns a DataMatrix with t-SNE dimensions as variables. Requires the TSne package to be loaded.
Additional keyword arguments (max_iter, perplexity, etc.) are forwarded to TSne.tsne.
See also force_layout, umap.
SingleCellProjections.ttest — Method
SCP.ttest(data, h1; h0=(), center=true, kwargs...) -> JobPerform a t-test for each variable testing the effect of h1 while controlling for h0. Returns a table with test statistics and p-values. h1 must be a numerical covariate or a two-group covariate.
Keyword arguments:
statistic_col="t"/pvalue_col="pValue"/difference_col="difference"- output column names (set tonothingto omit).do_sort=true- sort variables by|t|(most significant first).
(TODO: Examples.)
See also ftest, normalize_matrix, twogroup_covariate.
SingleCellProjections.twogroup_covariate — Function
twogroup_covariate(group_a, group_b=nothing)Create a two-group covariate description for comparing two specific groups within a categorical column. group_a and group_b specify the two group values to compare. If group_b is nothing, all observations not in group_a are treated as the other group.
See also categorical_covariate, numerical_covariate.
SingleCellProjections.umap — Function
SCP.umap(data; ndim, seed=1234, kwargs...) -> JobCompute a UMAP embedding of data with ndim dimensions. Returns a DataMatrix with UMAP dimensions as variables. Requires the UMAP package to be loaded.
seed is used to reset the global RNG for reproducibility, but results may still vary across runs due to threading differences in the UMAP nearest neighbor search.
Additional keyword arguments are forwarded to UMAP.fit.
See also force_layout, tsne.
SingleCellProjections.value_column — Method
SCP.value_column(table) -> JobExtract the second (value) column of table as a single-column table.
See also id_column, value_column_data.
SingleCellProjections.value_column_data — Method
SCP.value_column_data(table) -> JobReturn the values (second column) from table as a vector. Requires the table to have exactly two columns.
See also column_data, id_column_data.
SingleCellProjections.var_counts_fraction — Function
SCP.var_counts_fraction(counts, col, sub_filter, tot_filter=Returns(true); project_ids=:intersect) -> JobCompute the fraction of counts from a subset of variables (genes) for each observation, and add it as a new observation annotation column named col.
sub_filter and tot_filter are predicates applied to the variable annotations to select the subset and total gene sets respectively.
Examples
Count the fraction of reads that come from Mitochondrial genes.
julia> SCP.var_counts_fraction(counts, "fraction_mt", "name"=>startswith("MT-"))See also var_counts_sum, obs_counts_fraction.
SingleCellProjections.var_counts_sum — Function
SCP.var_counts_sum([f,] counts, col, filter=Returns(true); project_ids=:intersect) -> JobCompute the sum of counts (optionally transformed by f) from a filtered subset of variables for each observation, and add it as a new observation annotation column named col.
Examples
Let counts be the raw counts.
To count the total number of reads in each cell:
julia> SCP.var_counts_sum(counts, "total_RNA_count")To count the number of genes that have a non-zero value:
julia> SCP.var_counts_sum(!iszero, counts, "nonzero_RNA_count")See also var_counts_fraction, obs_counts_sum, load_counts.
SingleCellProjections.variance — Method
SCP.variance(data; assume_centered, col="variance", project=:no) -> JobCompute the variance of each variable in data, returning a table with IDs and variances.
assume_centered(required) must be set totrueto confirm thatdatais mean-centered; the variance is computed assuming a mean of zero.colis the name of the annotation column, defaults to"variance".projectcan be:no(default) or:yes. If:no, it will compute the variance of the base data set, and if:yes, it will compute the variance of the projected data set.
See also std, relative_std, normalize_matrix.