This function extracts PCA loadings stored in the DimReduction slot of a
geneda object and combines them with the associated metadata. It ensures
that the metadata has valid rownames and aligns the PCA loadings accordingly.
Value
A data.frame combining PCA loadings and sample metadata, where rows
correspond
to samples and columns include principal component loadings and metadata
fields.
Details
The function performs several checks:
Ensures the input object is of class
geneda.Verifies that the
DimReductionslot contains PCA loadings.Confirms that the metadata has valid rownames.
Reorders the PCA loadings to match the order of metadata rows.
If metadata rownames are missing or invalid, the function throws an error.
Examples
data(Snail1KO)
counts <- as.matrix(Snail1KO$rawCounts)
counts <- counts[rowSums(counts >= 10) >= 3, ]
meta <- Snail1KO$metadata
rownames(meta) <- meta$Sample
norm <- log2(t(t(counts) / colSums(counts)) * 1e6 + 1)
obj <- GenEDA(normalized = norm, metadata = meta, counts = counts)
obj <- FindVariableFeatures(obj, nfeatures = 1000)
obj <- RunPCA(obj)
#> Calculating principal components from top 1000 HVGs
#> Percent variations:
#> PC1: 88.56 %
#> PC2: 5.9 %
#> PC3: 2.91 %
#> PC4: 1.55 %
#> PC5: 1.08 %
#> PC6: 0 %
pca_df <- ExtractPCA(obj)
head(pca_df[, c("PC1", "PC2", "Genotype")])
#> PC1 PC2 Genotype
#> ERR1736465 -26.51610 8.8812248 WT
#> ERR1736466 -29.45724 -14.1901804 WT
#> ERR1736467 -28.65501 5.8971266 WT
#> ERR1736468 27.63783 -1.0411693 Snai1_KO
#> ERR1736469 27.39885 -0.8413095 Snai1_KO
#> ERR1736470 29.59167 1.2943077 Snai1_KO
