Main stages
# get data
san_mic <- gnp.mic$san_mic
exp_mic_vsn <- gnp.mic$exp_mic_vsn # non imputed counts
exp_mic_lg2 <- gnp.mic$exp_mic_lg2 # non imputed counts
# format: fid2rownames
exp_mic_vsn <- as.data.frame(t(exp_mic_vsn))
exp_mic_lg2 <- as.data.frame(t(exp_mic_lg2))
# match san order
identical(colnames(exp_mic_vsn), colnames(exp_mic_lg2)) # samples
san_mic <- san_mic[match(colnames(exp_mic_vsn), san_mic$id),]
identical(san_mic$id, colnames(exp_mic_lg2))
# dex design
design_stage_mic <- model.matrix(
~0 + stage,
data = san_mic)
contrast_mic_stages <- makeContrasts(
## progression
MBtoMC = stageMC - stageMB, # progression main 1
#PMtoMC = stageMC - stagePM, # progression main 2
MCtoMM = stageMM - stageMC, # progression main 3
MMtoB = stageB - stageMM, # progression main 4
BtoS = stageS - stageB, # progression main 5
StoPMN = stagePMN - stageS, # progression main 6
BtoPMN = stagePMN - stageB, # progression to match pro
# stage jumps: MB
#MBtoMC = stageMC - stageMB, # jump MB
MBtoMM = stageMM - stageMB, # jump MB
MBtoB = stageB - stageMB, # jump MB
MBtoS = stageS - stageMB,
MBtoPMN = stagePMN - stageMB, # jump MB
# stage jumps: PM
#PMtoMM = stageMM - stagePM, # jump PM
#PMtoB = stageB - stagePM, # jump PM
#PMtoS = stageS - stagePM,
#PMtoPMN = stagePMN - stagePM, # jump PM
# stage jumps MC
MCtoB = stageB - stageMC, # jump MC
MCtoS = stageS - stageMC,
MCtoPMN = stagePMN - stageMC, # jump MC
# stage jumps MM
MMtoS = stageS - stageMM,
MMtoPMN = stagePMN - stageMM, # jump MM
## vs PMN (to match vs Healthy in SCN. Do this both ways so no need for x(-1) later on)
MBvsPMN = stageMB - stagePMN, #vsPMN 1.1
#PMvsPMN = stagePM - stagePMN, #vsPMN 1.2
MCvsPMN = stageMC - stagePMN, #vsPMN 1.3
MMvsPMN = stageMM - stagePMN, #vsPMN 1.4
SvsPMN = stageS - stagePMN,
BvsPMN = stageB - stagePMN, #vsPMN 1.5
PMNvsMB = stagePMN - stageMB, #vsPMN 2.1
#PMNvsPM = stagePMN - stagePM, #vsPMN 2.2
PMNvsMC = stagePMN - stageMC, #vsPMN 2.3
PMNvsMM = stagePMN - stageMM, #vsPMN 2.4
PMNvsB = stagePMN - stageB, #vsPMN 2.5
PMNvsS = stagePMN - stageS,
# vs B (because PMN localizes a bit strange in PCA so B may represent the most mature stage)
MBvsB = stageMB - stageB, #vsB 1.1
#PMvsB = stagePM - stageB, #vsB 1.2
MCvsB = stageMC - stageB, #vsB 1.3
MMvsB = stageMM - stageB, #vsB 1.4
SvsB = stageS - stageB,
PMNvsB = stagePMN - stageB, #vsB 1.5
BvsMB = stageB - stageMB, #vsB 2.1
#BvsPM = stageB - stagePM, #vsB 2.2
BvsMC = stageB - stageMC, #vsB 2.3
BvsMM = stageB - stageMM, #vsB 2.4
BvsS = stageB - stageS,
BvsPMN = stageB - stagePMN, #vsB 2.5
# progression
levels = design_stage_mic)
# execute limma_getRes fct
FITs_stages_mic_vsn <- limma_getRes(exp_mic_vsn, design_stage_mic, contrast_mic_stages)
FITs_stages_mic_lg2 <- limma_getRes(exp_mic_lg2, design_stage_mic, contrast_mic_stages)
#export diffEx tables from limmas fit3 objects
#export diffEx tables from limmas FITs objects (use fit3)
extract_stages_mic <- function(fit3){
# progression
MBtoMC <- topTable(fit3, number = nrow(fit3), coef = 'MBtoMC') #
#PMtoMC <- topTable(fit3, number = nrow(fit3), coef = 'PMtoMC') #
MCtoMM <- topTable(fit3, number = nrow(fit3), coef = 'MCtoMM') #
MMtoB <- topTable(fit3, number = nrow(fit3), coef = 'MMtoB') #
BtoS <- topTable(fit3, number = nrow(fit3), coef = 'BtoS') #
BtoPMN <- topTable(fit3, number = nrow(fit3), coef = 'BtoPMN') #
StoPMN <- topTable(fit3, number = nrow(fit3), coef = 'StoPMN') #
# stage jumps: MB
MBtoMC <- topTable(fit3, number = nrow(fit3), coef = 'MBtoMC') #
MBtoMM <- topTable(fit3, number = nrow(fit3), coef = 'MBtoMM') #
MBtoB <- topTable(fit3, number = nrow(fit3), coef = 'MBtoB') #
MBtoS <- topTable(fit3, number = nrow(fit3), coef = 'MBtoS') #
MBtoPMN <- topTable(fit3, number = nrow(fit3), coef = 'MBtoPMN') #
# stage jumps: MC
MCtoB <- topTable(fit3, number = nrow(fit3), coef = 'MCtoB') #
MCtoS <- topTable(fit3, number = nrow(fit3), coef = 'MCtoS') #
MCtoPMN <- topTable(fit3, number = nrow(fit3), coef = 'MCtoPMN') #
# stage jumps: MM
MMtoPMN <- topTable(fit3, number = nrow(fit3), coef = 'MMtoPMN') #
MMtoS <- topTable(fit3, number = nrow(fit3), coef = 'MMtoS') #
# vs PMN and viceVersa
MBvsPMN <- topTable(fit3, number = nrow(fit3), coef = "MBvsPMN") #
#PMvsPMN <- topTable(fit3, number = nrow(fit3), coef = "PMvsPMN") #
MCvsPMN <- topTable(fit3, number = nrow(fit3), coef = "MCvsPMN") #
MMvsPMN <- topTable(fit3, number = nrow(fit3), coef = "MMvsPMN") #
BvsPMN <- topTable(fit3, number = nrow(fit3), coef = "BvsPMN") #
SvsPMN <- topTable(fit3, number = nrow(fit3), coef = "SvsPMN") #
PMNvsMB <- topTable(fit3, number = nrow(fit3), coef = "PMNvsMB") #
#PMNvsPM <- topTable(fit3, number = nrow(fit3), coef = "PMNvsPM") #
PMNvsMC <- topTable(fit3, number = nrow(fit3), coef = "PMNvsMC") #
PMNvsMM <- topTable(fit3, number = nrow(fit3), coef = "PMNvsMM") #
PMNvsB <- topTable(fit3, number = nrow(fit3), coef = "PMNvsB") #
PMNvsS <- topTable(fit3, number = nrow(fit3), coef = "PMNvsS") #
# vs B and viceVersa
MBvsB <- topTable(fit3, number = nrow(fit3), coef = "MBvsB") #
#PMvsB <- topTable(fit3, number = nrow(fit3), coef = "PMvsB") #
MCvsB <- topTable(fit3, number = nrow(fit3), coef = "MCvsB") #
MMvsB <- topTable(fit3, number = nrow(fit3), coef = "MMvsB") #
SvsB <- topTable(fit3, number = nrow(fit3), coef = "SvsB") #
PMNvsB <- topTable(fit3, number = nrow(fit3), coef = "PMNvsB") #
BvsMB <- topTable(fit3, number = nrow(fit3), coef = "BvsMB") #
#BvsPM <- topTable(fit3, number = nrow(fit3), coef = "BvsPM") #
BvsMC <- topTable(fit3, number = nrow(fit3), coef = "BvsMC") #
BvsMM <- topTable(fit3, number = nrow(fit3), coef = "BvsMM") #
BvsS <- topTable(fit3, number = nrow(fit3), coef = "BvsS") #
BvsPMN <- topTable(fit3, number = nrow(fit3), coef = "BvsPMN") #
# result list
result <- list(
MBtoMC = MBtoMC ,
#PMtoMC = PMtoMC,
MCtoMM =MCtoMM,
MMtoB = MMtoB,
BtoS = BtoS,
BtoPMN= BtoPMN,
StoPMN = StoPMN,
MBtoMC= MBtoMC,
MBtoMM= MBtoMM,
MBtoB=MBtoB,
MBtoS=MBtoS,
MBtoPMN=MBtoPMN,
MCtoB =MCtoB ,
MCtoS =MCtoS ,
MCtoPMN= MCtoPMN ,
MMtoS=MMtoS,
MMtoPMN= MMtoPMN ,
MBvsPMN =MBvsPMN,
#PMvsPMN =PMvsPMN ,
MCvsPMN =MCvsPMN,
MMvsPMN= MMvsPMN,
BvsPMN =BvsPMN,
SvsPMN=SvsPMN,
PMNvsMB= PMNvsMB,
#PMNvsPM= PMNvsPM,
PMNvsMC =PMNvsMC ,
PMNvsMM= PMNvsMM,
PMNvsB =PMNvsB,
PMNvsS=PMNvsS,
MBvsB= MBvsB ,
#PMvsB =PMvsB,
MCvsB =MCvsB,
MMvsB= MMvsB,
SvsB=SvsB,
PMNvsB =PMNvsB,
BvsMB =BvsMB,
#BvsPM= BvsPM,
BvsMC =BvsMC,
BvsMM= BvsMM,
BvsS=BvsS,
BvsPMN =BvsPMN
)
return(result)
}
## extract results
dex_stage_mic_vsn <- extract_stages_mic(FITs_stages_mic_vsn$fit3)
dex_stage_mic_lg2 <- extract_stages_mic(FITs_stages_mic_lg2$fit3)
# make rownames fid
dex_stage_mic_vsn <- map(dex_stage_mic_vsn, rownames_to_column, var = "fid")
dex_stage_mic_lg2 <- map(dex_stage_mic_lg2, rownames_to_column, var = "fid")
# as df
dex_stage_mic_vsn <- bind_rows(dex_stage_mic_vsn, .id = "comparison")
dex_stage_mic_lg2 <- bind_rows(dex_stage_mic_lg2, .id = "comparison")
### get ANOVA
# vsn
anova_mic_vsn <- topTable(FITs_stages_mic_vsn$fit3, coef=1:5, number = nrow(FITs_stages_mic_vsn$fit3))
anova_mic_vsn %>% filter(adj.P.Val < 0.05) %>% nrow() # 203
anova_mic_vsn$fid <- rownames(anova_mic_vsn)
# non
anova_mic_lg2 <- topTable(FITs_stages_mic_lg2$fit3, coef=1:5, number = nrow(FITs_stages_mic_lg2$fit3))
anova_mic_lg2 %>% filter(adj.P.Val < 0.05) %>% nrow() # 180
anova_mic_lg2$fid <- rownames(anova_mic_lg2)
check
# pop_gen
comp_progression_mic <- c('MBtoMC','MCtoMM', 'MMtoB', 'BtoS', 'StoPMN')
# prep
res_mic_vsn <- dex_stage_mic_vsn %>%
filter(comparison %in% comp_progression_mic) %>%
group_by(comparison) %>%
dplyr::summarize(
n_up = sum(adj.P.Val < 0.05 & logFC >= 1),
n_down = -sum(adj.P.Val < 0.05 & logFC <= -1) # checked
) %>%
pivot_longer(-comparison, names_to = "direction", values_to = "n")
res_mic_vsn$type = "vsn"
res_mic_lg2 <- dex_stage_mic_lg2 %>%
filter(comparison %in% comp_progression_mic) %>%
group_by(comparison) %>%
dplyr::summarize(
n_up = sum(adj.P.Val < 0.05 & logFC >= 1),
n_down = -sum(adj.P.Val < 0.05 & logFC <= -1) # checked
) %>%
pivot_longer(-comparison, names_to = "direction", values_to = "n")
res_mic_lg2$type = "lg2"
res_dex_mic <- rbind(res_mic_vsn, res_mic_lg2)
# plot
res_dex_mic %>%
ggplot(aes(x = factor(comparison, level = comp_progression_mic), y = n, fill = type)) +
geom_bar(stat="identity", position = "dodge") +
geom_text(aes(y = n + 5 * sign(n), label=n), position = position_dodge(width = .9)) +
ggtitle("Dex in microRNA: normalisation dependecy \n [abs(FC)>=1, adj.p<0.05]") +
ylab("Number of dex") +
geom_hline(yintercept = 0)
