---
title: "Untitled"
author: "Shelly Trigg"
date: "7/3/2020"
output: html_document
editor_options: 
  chunk_output_type: console
---

load libraries
```{r}
library(data.table)
library(ggplot2)
library(dplyr)
library(ggpubr)

```


read in data from Qualimap MultiBamQC summary tables
```{r}
pact_summary <- fread("https://gannet.fish.washington.edu/metacarcinus/FROGER_meth_compare/20200416/Pact/multibamQC/raw_data_multisampleBamQcReport/Pact_MultiBamQC_Summary.txt")

mcap_summary <- fread("https://gannet.fish.washington.edu/metacarcinus/FROGER_meth_compare/20200416/Mcap/multibamQC/raw_data_multisampleBamQcReport/Mcap_MultiBamQC_Summary.txt")

```

convert MBD to MBDBS
```{r}
mcap_summary$Group <- gsub("MBD", "MBDBS", mcap_summary$Group)

pact_summary$Group <- gsub("MBD", "MBDBS", pact_summary$Group)
```

Add new sample names to match corr plots
```{r}
#mcap_summary$new_sample_name <- rep(c(1,2,3),3)

```

PCA of data

```{r}
set.seed(101)
mcap_pca <- prcomp(mcap_summary[,-c(1,2)])
mcap_pca_meta <- cbind(mcap_summary[,c(1:2)],mcap_pca$x)


a <- ggplot(mcap_pca_meta, aes(PC1, PC2)) + geom_point(aes(color = Group), size = 3) + scale_color_manual(values = c("#FD8D3C","#9E9AC8","#74C476")) + theme_bw() + ylab("PC2") + xlab("PC1") + ggtitle(expression(italic("M.capitata")))


#adds sample names to plot
#ggplot(mcap_pca_meta, aes(PC1, PC2, label = Sample)) + geom_point(aes(color = Group)) + geom_text(size = 1.5,hjust=1,vjust=-1) + scale_color_manual(values = c("#E6550D", "#756BB1","#31A354" )) + theme_bw() + ylab("PC2") + xlab("PC1")

pact_pca <- prcomp(pact_summary[,-c(1,2)])
pact_pca_meta <- cbind(pact_summary[,c(1:2)],pact_pca$x)


b <- ggplot(pact_pca_meta, aes(PC1, PC2)) + geom_point(aes(color = Group), size = 3) + scale_color_manual(values = c("#FD8D3C","#9E9AC8","#74C476")) + theme_bw() + ylab("PC2") + xlab("PC1") + ggtitle(expression(italic("P.acuta")))

jpeg("../../Output/PCA_AlignmentFeatures.jpg", height = 4, width = 10, units = "in", res = 300 )
ggarrange(a,b, ncol = 2)
dev.off()

#adds sample names to plot
#ggplot(pact_pca_meta, aes(PC1, PC2, label = Sample)) + geom_point(aes(color = Group)) + geom_text(size = 1.5,hjust=1,vjust=-1) + scale_color_manual(values = c("#E6550D", "#756BB1","#31A354" )) + theme_bw() + ylab("PC2") + xlab("PC1")
```
