Commit 7ff3d0c0 authored by Thomas Schwarzl's avatar Thomas Schwarzl
Browse files

added short/long studies

parent 1fc65a8f
......@@ -15,7 +15,8 @@ output_dir <- file.path("out")
lookup_dir <- file.path("..", "RBPbaseBackend", "input", "Review")
input_dir <- file.path("input")
background_dir <- file.path("..", "RBPbaseBackend", "background")
script_dir <- file.path("..", "RBPbaseServer", "app")
script_dir <- file.path("..", "RBPbase", "app")
#script_dir <- file.path("..", "RBPbaseServer", "app")
```
Create directories
......@@ -42,6 +43,7 @@ suppressPackageStartupMessages({
tidyverse,
eulerr,
seqsetvis,
r6extended,
RVenn,
ggExtra,
Cairo,
......@@ -53,7 +55,7 @@ suppressPackageStartupMessages({
ReactomePA,
ggupset,
IHW,
org.Mm.eg.db,
org.Sc.sgd.db,
openxlsx)
#library(cowplot)
require(termEnrichment)
......@@ -81,6 +83,7 @@ file_table <- file.path(input_dir, "COMPILED_TABLE.Rda")
file_anno <- file.path(input_dir, "ANNO_STUDIES.Rda")
file_studies <- file.path(input_dir, "RIC_STUDIES.Rda")
file_background <- file.path(background_dir, "Sc_Ascencio2019_Background.Rds")
file_background2 <- file.path(background_dir, "Sc_Ascencio2020_short_long_Background.Rds")
file_lookup <- file.path(lookup_dir, "LOOKUP.rda")
if (!file.exists(file_table) | !file.exists(file_anno) | !file.exists(file_studies)) {
......@@ -92,6 +95,7 @@ load(file_anno)
load(file_studies)
load(file_lookup)
TRIC_Background <- readRDS(file_background)
TRICp_Background <- readRDS(file_background2)
```
......@@ -110,14 +114,12 @@ Ids
```{r}
TRIC <- "RBPBASE000000056.1"
LTRIC <- "RBPBASE000000068.1"
STRIC <- "RBPBASE000000069.1"
#selected_studies_ids <- c(TRIC, LTRIC, STRIC)
selected_studies_ids <- c(TRIC)
TRICp <- "RBPBASE000000068.1"
SRICp <- "RBPBASE000000069.1"
LRICp <- "RBPBASE000000070.1"
selected_studies_ids <- c(TRIC, TRICp, SRICp)
#selected_studies_ids <- c(TRIC)
```
Define organisms which to compare to
......@@ -178,9 +180,9 @@ RA_but_TRAPP <- new_RBPbaseAnalysis(COMPILED_TABLE,
update = TRUE)
```
Custom selection for Sc studies wanted by collaborators
```{r}
# Custom selection for Sc studies wanted by collaborators
anySc_id <- RA$add_annotation(name = "any_Sc",
values =
RA$get_studies_only_table(count_comparison_hits = T,
......@@ -189,12 +191,12 @@ anySc_id <- RA$add_annotation(name = "any_Sc",
main_organism_studies = T) %>%
mutate(property = number_hits_compare > 0) %>%
pull(property) )
# Custom selection for Sc studies wanted by collaborators
#
```
Custom selection for Sc studies wanted by collaborators
```{r}
anyScExpTRAPP_id <- RA$add_annotation(name = "any_Sc",
values =
RA_but_TRAPP$get_studies_only_table(count_comparison_hits = T,
......@@ -203,10 +205,12 @@ anyScExpTRAPP_id <- RA$add_annotation(name = "any_Sc",
main_organism_studies = T) %>%
mutate(property = number_hits_compare > 0) %>%
pull(property) )
```
Custom selection for MM or Hs studies wanted by collaborators
# Custom selection for MM or Hs studies wanted by collaborators
```{r}
anyScMmHs_id <- RA$add_annotation(name = "any_MmHs",
values =
RA$get_studies_only_table(count_comparison_hits = T,
......@@ -220,6 +224,25 @@ anyScMmHs_id <- RA$add_annotation(name = "any_MmHs",
RA$set_anyRIC_id(id = anyScMmHs_id, update = TRUE)
```
Summary of TRIC
```{r}
any_TRIC <- RA$add_annotation(name = "any_TRIC",
values =
RA$get_main_table() %>%
mutate(property = !!sym(TRIC) | !!sym(TRICp)) %>%
pull(property) )
```
Summary of STRIC
```{r}
any_STRIC <- RA$add_annotation(name = "any_STRIC",
values =
RA$get_main_table() %>%
mutate(property = !!sym(TRIC) | !!sym(TRICp) | !!sym(SRICp)) %>%
pull(property) )
```
## Add custom annotations
......@@ -673,8 +696,13 @@ p
## Comparison of
```{r}
RA$save_venn(selection_ids = c(TRIC,
TRICp,
SRICp),
names = c("TRIC", "TRICp", "SRICp"),
file_root = file.path(output_dir, "TRIC_TRICp_SRICp"),
fill = cbbPalette[c(6,7,3)])
```
......@@ -682,19 +710,13 @@ p
## Enrichment Analysis
### Define Inputs
Helpfer function to retreive IDs
```{r}
get_ids = function(x, colfilter, type = "Ensembl") {
get_ids = function(x, colfilter) {
id = "ID"
if (type == "Entrez") {
id = "RBPANNO000000066.1" # Mouse Entrez Gene IDs
}
x %>%
dplyr::filter(!!sym(colfilter)) %>%
pull(!!sym(id)) %>%
......@@ -702,80 +724,50 @@ get_ids = function(x, colfilter, type = "Ensembl") {
unlist %>%
sort %>%
unique
}
```
#### As Ensembl IDs
```{r}
#source("TermEnrichment.R")
#source("../RBPbaseAnalysisMmCelllines/TermEnrichment.R")
EHE <- EnrichmentHandler$new()
EHE$add_comparison_manually("kidney",
EH <- EnrichmentHandler$new()
EH$add_comparison_manually("TRIC",
get_ids(RA$get_main_table(), TRIC),
TRIC_Background$GENEID)
#get_ids(RA$get_main_table(), kidney_id),
#get_ids(RA$get_main_table(), wcl_kidney_id))
EHE$write_comparisons(path = output_dir)
```
#### As Entrez / NCBI Gene IDs
```{r}
source("TermEnrichment.R")
EHN <- EnrichmentHandler$new()
EHN$add_comparison_manually("kidney",
get_ids(RA$get_main_table(), kidney_id, type = "Entrez"),
get_ids(RA$get_main_table(), wcl_kidney_id, type = "Entrez"))
EH$add_comparison_manually("TRICp",
get_ids(RA$get_main_table(), TRICp),
TRICp_Background$GENEID)
EH$add_comparison_manually("SRICp",
get_ids(RA$get_main_table(), SRICp),
TRICp_Background$GENEID)
# TRICp - SRIC
EHN$add_comparison_manually("brain",
get_ids(RA$get_main_table(), brain_id, type = "Entrez"),
get_ids(RA$get_main_table(), wcl_brain_id, type = "Entrez")
)
EHN$add_comparison_manually("liver",
get_ids(RA$get_main_table(), liver_id, type = "Entrez"),
get_ids(RA$get_main_table(), wcl_liver_id, type = "Entrez")
)
EHN$add_comparison_manually("more20",
get_ids(RA$get_main_table() %>% filter(!!sym(anyMm_id)), more20_id, type = "Entrez"),
get_ids(RA$get_main_table(), TRIC, type = "Entrez")
)
#EHN$add_enrichment(ReactomePAEnrichment$new(organism = "mouse"))
#EHN$options$verbose <- T
#EHN$run()
#EHN
EH$write_comparisons(path = output_dir)
```
### KEGG enrichment
#### Tissue comparison
```{r}
kegg_cluster <- compareCluster(geneCluster = list(
Brain = EHN$get_comparison("brain")$get_foreground(),
Kidney = EHN$get_comparison("kidney")$get_foreground(),
Liver = EHN$get_comparison("liver")$get_foreground()),
Brain = EH$get_comparison("TRIC")$get_foreground(),
Kidney = EH$get_comparison("TRICp")$get_foreground(),
Liver = EH$get_comparison("SRICp")$get_foreground()),
organism = 'mmu',
# universe = c(EHN$get("brain")$get_universe() ,
# EHN$get("kidney")$get_universe(),
# EHN$get("liver")$get_universe()) %>% sort %>% unique,
keyType = 'ncbi-geneid',
# keyType = 'ncbi-geneid',
pAdjustMethod = "BH",
fun = "enrichKEGG")
p <- dotplot(kegg_cluster)
ggsave(p, filename = file.path(output_dir, "enrich_all_kegg_comparison.pdf"))
ggsave(p,
filename = file.path(output_dir,
"enrich_all_kegg_comparison.pdf"))
```
#### Individual
......@@ -783,9 +775,9 @@ kegg_cluster <- compareCluster(geneCluster = list(
Perform enrichment for all comparisons
```{r}
for (i in names(EHN$get_comparison_names())) {
for (i in names(EH$get_comparison_names())) {
RK <- KEGGClusterProfilerEnrichment$new(organism = "mmu")
RK$set_input(EHN$get_comparison(i))
RK$set_input(EH$get_comparison(i))
RK$run_enrichment()
RK$plot_enrichment()
RK$save_enrichment(path = output_dir)
......@@ -826,15 +818,12 @@ KEGGresults_translated <- lapply(files_kegg_tables, function(input_file) {
Perform enrichment for all comparisons
```{r}
for (i in names(EHN$get_comparison_names())) {
RE <- ReactomePAEnrichment$new(organism = "mouse")
RE$set_input(EHN$get_comparison(i))
for (i in EH$get_comparison_names()) {
RE <- ReactomePAEnrichment$new(organism = "yeast")
RE$set_input(EH$get_comparison(i))
RE$run_enrichment()
RE$save_enrichment(path = output_dir)
}
#RE <- ReactomePAEnrichment$new(organism = "mouse")
#RE$set_input(EHN$get_comparison(i))
```
### GO enrichment
......@@ -843,18 +832,21 @@ for (i in names(EHN$get_comparison_names())) {
```{r}
for (gotype in c("BP", "CC", "MF")) {
for (i in EHE$get_comparison_names()) {
RO <- GOProfilerEnrichment$new(org_db = org.Mm.eg.db,
ont = gotype)
RO$set_input(EHE$get_comparison(i))
for (i in EH$get_comparison_names()) {
RO <- GOProfilerEnrichment$new(org_db = org.Sc.sgd.db::org.Sc.sgd.db,
ont = gotype,
key_type = "GENENAME")
RO$set_input(EH$get_comparison(i))
RO$run_enrichment()
RO$save_enrichment(path = output_dir)
}
}
RO <- GOProfilerEnrichment$new(org_db = org.Mm.eg.db,
ont = "BP")
RO$set_input(EHE$get_comparison("brain"))
RO <- GOProfilerEnrichment$new(org_db = org.Sc.sgd.db,
ont = "BP",
key_type = "GENENAME")
RO$set_input(EH$get_comparison("TRIC"))
RO$run_enrichment()
RO$plot_enrichment()
RO$enrichment
......
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment