---
title: "Effect of Gal3 on mitochondrial pathways and mitochondrially encoded genes"
author: "Burnet Bioinformatics group"
date: "`r Sys.Date()`"
output:
  html_document:
    toc: true
    toc_float: true
    fig_width: 7
    fig_height: 7
theme: cosmo
---

# Introduction

Test whether Gal3 KO causes changes to expressionn of mitochondrial genes.

```{r,libs}

library("mitch")

```

# Read in reference data

Read in a gene table, reactome gene sets and the mitochondrially encoded gene.

```{r,readdata1}

gt <- read.table("genetable.tsv")
head(gt)
reactome <- gmt_import("m2.cp.reactome.v2024.1.Mm.symbols.gmt")
mtgenes <- readLines("mtgenes.txt")
mtgenes <- sapply(strsplit(mtgenes,"_"),"[[",2)
mt_trna <- mtgenes[grep("mt-T",mtgenes)]
mt_mrna <- mtgenes[grep("mt-T",mtgenes,invert=TRUE)]
mtgenelist <- list("mtgenes"=mtgenes,"mt tRNA"=mt_trna, "mt mRNA"=mt_mrna)

```

# Comparison 1 WILD TYPE VERSUS GAL3 KO

Gal3KO causes a subtle increase iin electron transport, but no changes to other mitochondrial pathways.

```{r,mitch1a}

wt_v_gal3ko <- read.table("WTvsGAL3KO.tsv",row.names=1,header=TRUE)
head(wt_v_gal3ko)
m_wt_v_gal3ko <- mitch_import(x=wt_v_gal3ko,DEtype="edger",geneTable=gt)
dim(m_wt_v_gal3ko)
tail(m_wt_v_gal3ko)

```

mitch with mito genes - no change.

```{r,mitch1b}

mt_wt_v_gal3ko <- mitch_calc(x=m_wt_v_gal3ko,genesets=mtgenelist,priority="effect",cores=4,minsetsize=3)
mt_wt_v_gal3ko$enrichment_result

```

Mitch with reactome. Noticed big change in electron transport but not much with other mito pathways.

```{r,mitch1c}

mr_wt_v_gal3ko <- mitch_calc(x=m_wt_v_gal3ko,genesets=reactome,priority="effect",cores=4,minsetsize=3)
head(mr_wt_v_gal3ko$enrichment_result)
#  some subtle changes in electron transport
mr2_wt_v_gal3ko <- mr_wt_v_gal3ko$enrichment_result
head(mr2_wt_v_gal3ko[grep("ELECTRON",mr2_wt_v_gal3ko$set),])

mr2_wt_v_gal3ko_mito <- mr2_wt_v_gal3ko[grep("MITOC",mr2_wt_v_gal3ko$set),]
subset(mr2_wt_v_gal3ko_mito, p.adjustANOVA < 0.05)

```


# Comparison 2 TG VERSUS TG GAL3 KO

First set up the analysis.

```{r,mitch2a}

tg_v_tggal3ko <- read.table("MST1TGvsMST1TGGAL3KO.tsv",row.names=1,header=TRUE)
head(tg_v_tggal3ko)

m_tg_v_tggal3ko <- mitch_import(x=tg_v_tggal3ko,DEtype="edger",geneTable=gt)
dim(m_tg_v_tggal3ko)
tail(m_tg_v_tggal3ko)

```

Mitch with mito genes - big increase.

```{r,mitch2b}

mt_tg_v_tggal3ko <- mitch_calc(x=m_tg_v_tggal3ko,genesets=mtgenelist,priority="effect",cores=4,minsetsize=3)
mt_tg_v_tggal3ko$enrichment_result

```

Mitch with reactome.

```{r,mitch2c}

mr_tg_v_tggal3ko <- mitch_calc(x=m_tg_v_tggal3ko,genesets=reactome,priority="effect",cores=4,minsetsize=3)
head(mr_tg_v_tggal3ko$enrichment_result)
#  some subtle changes in electron transport
mr2_tg_v_tggal3ko <- mr_tg_v_tggal3ko$enrichment_result
head(mr2_tg_v_tggal3ko[grep("MITOC",mr2_tg_v_tggal3ko$set),])
head(mr2_tg_v_tggal3ko[grep("ELECTRON",mr2_tg_v_tggal3ko$set),])

```
