suppressPackageStartupMessages({
library(SummarizedExperiment)
library(SEtools)
library(edgeR)
library(DT)
library(pheatmap)
library(plotly)
library(dplyr)
library(sva)
library(viper)
})source("Functions/EDC_Functions.R")
source("Functions/CriFormatted.R")
load("Data/AllSEcorrected.RData",verbose=T)
## Loading objects:
## SEs
## DEAs
load("Data/regulon_weighted.RData", verbose = T)
## Loading objects:
## regulon
<- SEs$chronic.fetal
se <- SEtools::log2FC(se, "corrected", controls=se$EXPO=="CNT", isLog = TRUE)
se <- readRDS("Data/psychencode_reduced.rds")
ag <- ag[which(ag[,1] %in% row.names(se) & ag[,2] %in% row.names(se)),]
ag write.table( ag, file="Data/psychencode_reduced.txt", col.names=F, row.names=F, sep="\t", quote=F)
<- TFA(se, DEAs$chronic.fetal, ~EXPO, "Data/psychencode_reduced.txt",
tf1.ch testCoef=c("EXPO1X","EXPO1000X"), assayName="corrected")
## WARNING! NOT CONVERGENT!
## number of iterations= 1000
## WARNING! NOT CONVERGENT!
## number of iterations= 1000
## WARNING! NOT CONVERGENT!
## number of iterations= 1000
<- SEtools::log2FC(tf1.ch, "viper", tf1.ch$EXPO=="CNT", isLog=TRUE)
tf1.ch plotTFA(tf1.ch)
## Warning: `line.width` does not currently support multiple values.
We restrict ourselves to transcription factors whose expression pattern is coherent with their differential activity:
<- rowData(tf1.ch)
rd <- row.names(rd)[(sign(rd$activity.max.logFC)==sign(rd$expression.logFC) & rd$activity.FDR<0.05 & rd$expression.FDR<0.1)]
sig <- se
sef <- mergeSEs(list(expression=se,activity=tf1.ch), do.scale = FALSE)
m $assay <- m$Dataset
msehm(m[,which(m$EXPO %in% c("CNT","1X","1000X"))], sig, do.scale = FALSE, assayName = "log2FC", anno_columns = c("EXPO2","assay"), breaks = 0.99, main="Expression and activity of significant TFs")
<- sig FetTF
<- SEs$chronic.org
se <- SEtools::log2FC(se, "corrected", controls=se$EXPO=="CNT", isLog = TRUE)
se <- readRDS("Data/psychencode_reduced.rds")
ag <- ag[which(ag[,1] %in% row.names(se) & ag[,2] %in% row.names(se)),]
ag write.table( ag, file="Data/psychencode_reduced.txt", col.names=F, row.names=F, sep="\t", quote=F)
<- TFA(se, DEAs$chronic.org, ~EXPO, "Data/psychencode_reduced.txt",
to1.ch testCoef=c("EXPO1X","EXPO1000X"), assayName="corrected")
## WARNING! NOT CONVERGENT!
## number of iterations= 1000
## WARNING! NOT CONVERGENT!
## number of iterations= 1000
## number of iterations= 338
<- SEtools::log2FC(to1.ch, "viper", to1.ch$EXPO=="CNT", isLog=TRUE)
to1.ch plotTFA(to1.ch)
## Warning: `line.width` does not currently support multiple values.
We restrict ourselves to transcription factors whose expression pattern is coherent with their differential activity:
<- rowData(to1.ch)
rd <- row.names(rd)[(sign(rd$activity.max.logFC)==sign(rd$expression.logFC) & rd$activity.FDR<0.05 & rd$expression.FDR<0.05)]
sig <- mergeSEs(list(expression=se,activity=to1.ch), do.scale = FALSE)
m $assay <- m$Dataset
msehm(m[,which(m$EXPO %in% c("CNT","1X","1000X"))], sig, do.scale = FALSE, assayName = "log2FC", anno_columns = c("EXPO2","assay"), breaks = 0.99, main="Expression and activity of significant TFs",show_rownames = T)
<-sig
OrgTF <- union(OrgTF,FetTF) TF
<- merge(rowData(to1.ch), rowData(tf1.ch), by="row.names", suffixes=c("organoid","fetal"))
rd <- rd$Row.names[which(
sig apply(sign(as.matrix(rd[,grep("logFC",colnames(rd))])),1,FUN=function(x) length(unique(x))==1) &
$activity.FDRorganoid < 0.1 & rd$activity.FDRfetal < 0.2 &
rd$expression.FDRorganoid < 0.25 & rd$expression.FDRfetal < 0.25
rd
)]<- mergeSEs(list(exp.org=se,activity.org=to1.ch,exp.fetal=sef, activity.fetal=tf1.ch), do.scale = FALSE)
m $assay <- c("expression","activity")[1+as.numeric(grepl("activity",m$Dataset))]
m$system <- c("fetal","organoid")[1+as.numeric(grepl("org",m$Dataset))]
msehm(m[,which(m$EXPO %in% c("CNT","1X","1000X"))], sig, do.scale = FALSE, assayName = "log2FC", anno_columns = c("EXPO2","assay","system"), breaks = 0.99, main="Expression and activity of significant TFs in both fetal and organoids", sortRowsOn = NULL)
<-sig
TFshortsave(OrgTF,FetTF,TF, TFshort, file = "Data/HormonalGenes/HormonalTFs/TF.RData")
<- to1.ch
Org <- tf1.ch
Fet save(Org, Fet, file="Data/TFA.RData")