I am the PCAtools [main] developer and it's my view that the package should be used as one of many lines of evidence in the realm of feature selection, i.e., for choosing a broad range of features (here, genes) that are later further tested via differential expression, clustering, model prediction, regression, etc.<
I agree with you and that's what I am also trying to do but I wanted to know if those 138 are due to noise that might arise since the samples have not been sequenced at the same time. I uploaded the plots. let me know if you can see it for some reason I have problem with that!
#Tidy the dataset
allSE2bis2 <- shared_7770 %>% drop_na() #remove rows with NA from the merged filed
rnames <- allSE2bis2$gene #select name
allSE2bis2 <- allSE2bis2 [-c(1)] # remove gene symbol column
SE.matrix <-(as.matrix(allSE2bis2))
rownames(SE.matrix) <- rnames # assign row names
idx <- colnames(SE.matrix)
#cpmpute pca
library(PCAtools)
p <- pca(SE.matrix, scale=F)
#horn law
horn <- parallelPCA(SE.matrix)
horn$n #retain 7 PC
#plot loadings
plotloadings(p,components = getComponents(p, seq_len(7)), title = 'Loadings plot', subtitle = 'PC1 - PC7 (not all genes are shown)', shape = 21, labSize = 4, absolute = T, shapeSizeRange = c(1, 12), drawConnectors = F)
in case not visible those are the variable retained for the first 7 PCs:
-- variables retained:
SCO2, HIST1H1C, AGR3, APP, EEF1A1, FTH1, RPL7, RPLP1, TECTA, TECTB, HES7, SCN1A, ANXA1, NT5E, PHF11, ABLIM2, ACBD7, ADI1, AK8, ALDH1A2, ALS2CL, AP2A2, ATP11A, BEGAIN, BICC1, BIK, BRD2, CARS, CASC4, CCDC13, CDO1, CGNL1, CHRDL1, CHST9, COG7, COL14A1, COL1A2, COL9A1, COLEC12, CPZ, CRLF3, CTTNBP2, DLK2, DNAJC7, DUSP19, EGF, EHD3, ENKUR, ENPP2, ENTPD1, EXOC4, FA2H, FABP5, FAIM2, FAM149A, FANCA, FGD3, FNDC7, GDAP1L1, GGH, HDAC11, HS3ST5, HVCN1, IL1RAP, ITM2A, ITPKB, JAM2, KDM2B, KIT, KLF13, LOXHD1, LRP2, LSM14A, MAOB, MATN4, MCTS1, METRNL, MGST3, MLXIP, MME, MMP2, MPRIP, MRPL45, MSRA, MYBPC1, MYLK3, NAP1L4, NDST1, NSG1, PAPSS2, PBX1, PCMTD2, PCYT1B, PDE10A, PDGFD, PDGFRL, PENK, PIAS2, PIP4K2A, PIP5K1B, PITPNM3, PRKG1, PROM1, PRRG1, PUF60, RAD17, RUNDC3B, SBNO2, SCRG1, SDC1, SFRP2, SH3GL3, SIK1, SLC17A8, SMOC2, SMTNL2, STARD5, STXBP6, SULT4A1, SUSD4, SYNE2, SYNRG, TBC1D9, TCF20, TEKT1, THSD4, TJP1, TMEM52, TNFAIP8, TNKS, TSPAN12, TYMS, U2AF1, VAPA, VAV3, VWA3B, WNT5A
then I create a new dataframe selecting the "variable retained":
#select vriable retained
variableRet <- shared_7770[shared_7770$gene %in% c("SCO2", "HIST1H1C", "AGR3", "APP", "EEF1A1", "FTH1", "RPL7", "RPLP1", "TECTA", "TECTB", "HES7", "SCN1A", "ANXA1", "NT5E", "PHF11", "ABLIM2", "ACBD7", "ADI1", "AK8", "ALDH1A2", "ALS2CL", "AP2A2", "ATP11A", "BEGAIN", "BICC1", "BIK", "BRD2", "CARS", "CASC4", "CCDC13", "CDO1", "CGNL1", "CHRDL1", "CHST9", "COG7", "COL14A1", "COL1A2", "COL9A1", "COLEC12", "CPZ", "CRLF3", "CTTNBP2", "DLK2", "DNAJC7", "DUSP19", "EGF", "EHD3", "ENKUR", "ENPP2", "ENTPD1", "EXOC4", "FA2H", "FABP5", "FAIM2", "FAM149A", "FANCA", "FGD3", "FNDC7", "GDAP1L1", "GGH", "HDAC11", "HS3ST5", "HVCN1", "IL1RAP", "ITM2A", "ITPKB", "JAM2", "KDM2B", "KIT", "KLF13", "LOXHD1", "LRP2", "LSM14A", "MAOB", "MATN4", "MCTS1", "METRNL", "MGST3", "MLXIP", "MME", "MMP2", "MPRIP", "MRPL45", "MSRA", "MYBPC1", "MYLK3", "NAP1L4", "NDST1", "NSG1", "PAPSS2", "PBX1", "PCMTD2", "PCYT1B", "PDE10A", "PDGFD", "PDGFRL", "PENK", "PIAS2", "PIP4K2A", "PIP5K1B", "PITPNM3", "PRKG1", "PROM1", "PRRG1", "PUF60", "RAD17", "RUNDC3B", "SBNO2", "SCRG1", "SDC1", "SFRP2", "SH3GL3", "SIK1", "SLC17A8", "SMOC2", "SMTNL2", "STARD5", "STXBP6", "SULT4A1", "SUSD4", "SYNE2", "SYNRG", "TBC1D9", "TCF20", "TEKT1", "THSD4", "TJP1", "TMEM52", "TNFAIP8", "TNKS", "TSPAN12", "TYMS", "U2AF1", "VAPA", "VAV3", "VWA3B", "WNT5A"), ]
#remove genes from"variable retained" from the original dataset
library(dplyr)
library(tidyverse)
shared <- anti_join (shared_7770, variableRet, by ="gene") #7633
#compute PCA again
allS2 <- shared %>% drop_na() #remove rows with NA from the merged filed
rnames <- allS2$gene#select name
allS2 <- allS2[-c(1)] # remove gene symbol
allS2matrix <-(as.matrix(allS2))
rownames(allS2matrix) <- rnames # assign row names
idx <- colnames(allS2matrix)
#PCA
pRET <- pca(allS2matrix, scale=F)
#plot
biplot(pRET, lab = idx)
The package you suggested seems to work on untransformed count data so not in my case.I got negative values on FPKM expression but also with
limmaandComBat. I compute the PCA on normlised reads so it makes sense to me do the batch correction and re-run the PCA on the normalised reads to be able to compare them and see if there is a batch effect and if it has been corrected with eitherlimma/ComBat.the dataset (I have 37 samples):
here is the code:
and that's the data after the batch correction (just the first few samples and the first few rows, gene names are missing):
Is my code wrong to batch correct the dataset?
thank you!
Camilla
Hey again,
You mean
limma::removeBatchEffect()? - it cannot be used on FPKM or any other normalised count data. The manual page states that the input object should be logged:So, if we have RNA-seq data, we could only apply
limma::removeBatchEffect()to the logCPM values (EdgeR / limma-voom) or VST or rlog values (DESeq2).----------------------
The fundamental issue here is [I think] that you only have FPKM expression units, correct? I think that we had a discussion in another thread about this, relating also to zFPKM. If you must batch correct the FPKM data, then I would at least log it and add a pseudo-count prior to batch correction. For example: