---
# System prepended metadata

title: 'GLDS-249, RR6, V4 amplicon data'
tags: [GeneLab]

---

---
tags: GeneLab
title: GLDS-249, RR6, V4 amplicon data
---

# GLDS-249, RR6, V4 amplicon data

[toc]


# Beta diversity views

## Live-animal return (LAR) Flight vs Ground


<a href="https://i.imgur.com/Smc9lFm.png"><img src="https://i.imgur.com/Smc9lFm.png"></a>

<center><a href="https://i.imgur.com/syeS8Ed.png"><img src="https://i.imgur.com/syeS8Ed.png"></a></center>

---

## ISS-terminated (ISS-T) Flight vs Ground

<a href="https://i.imgur.com/gWqJFEr.png"><img src="https://i.imgur.com/gWqJFEr.png"></a>


<a href="https://i.imgur.com/BA9Ki6s.png"><img src="https://i.imgur.com/BA9Ki6s.png"></a>

<a href=""><img src=""></a>
<a href=""><img src=""></a>

---


# R code
```r=
library("phyloseq")
library("vegan")
library("DESeq2")
library("ggplot2")
library("dendextend")
library("tidyr")
library("viridis")
library("reshape")
library("tidyverse")

## reading in data files
count_tab <- read.table("Final_Outputs/FluidAA_counts.tsv", header=TRUE, row.names=1, check.names=FALSE, sep="\t")
tax_tab <- read.table("Final_Outputs/FluidAA_taxonomy.tsv", header=TRUE, row.names=1, check.names=FALSE, sep="\t", na.strings="NA")
# samples table downloaded from the GLDS page: https://genelab-data.ndc.nasa.gov/genelab/accession/GLDS-249/
sample_info_tab <- read.table("GLDS-249_samples_export.csv", header = TRUE, check.names = FALSE, sep = ",", comment.char = "")
colnames(sample_info_tab)

sample_info_tab <- sample_info_tab %>% select(`Sample Name`, `Factor Value: Spaceflight`, `Factor Value: Euthanasia`)
colnames(sample_info_tab) <- c("Sample", "Treatment", "Experiment")
# renaming factors
sample_info_tab$Treatment <- sample_info_tab$Treatment %>% 
    str_replace("Basal Control ", "Basal") %>% 
    str_replace("Space Flight ", "Flight") %>% 
    str_replace("Ground Control ", "Ground")

sample_info_tab$Experiment <- sample_info_tab$Experiment %>% 
    str_replace("On Earth ", "LAR") %>% 
    str_replace("On ISS ", "ISS-T")

sample_info_tab <- sample_info_tab %>% column_to_rownames(var = "Sample")

### problem with metadata
# some are marked as LAR, but they have ISS-T in their sample name, I'm using what's in the sample name for now
sample_info_tab
sample_info_tab$Experiment <- row.names(sample_info_tab) %>% str_replace("Mmus_C57-6T_FCS_[A-Z]*_", "") %>% 
    str_replace("_Rep?_", "") %>% str_replace("_.*", "")

# adding colors for treatment
basal_col <- "lightsalmon"
flight_col <- "grey12"
ground_col <- "blue3"

sample_info_tab$treatment_color <- sample_info_tab$Treatment %>% 
    str_replace("Basal", basal_col) %>% 
    str_replace("Ground", ground_col) %>% 
    str_replace("Flight", flight_col)


## shortening sample names to remove any redundant info and so they match
names(count_tab) <- names(count_tab) %>% str_replace("Mmus_C57-6T_FCS_", "") %>% str_replace("_Rep.?", "") %>% str_replace("_FluidAA", "")
row.names(sample_info_tab) <- row.names(sample_info_tab) %>% str_replace("Mmus_C57-6T_FCS_", "") %>% str_replace("_Rep.?", "")

## LAR Flight/Ground only
LAR_Flight_Ground_samples <- sample_info_tab %>% filter(Experiment == "LAR", Treatment %in% c("Flight", "Ground")) %>% row.names()
LAR_Flight_Ground_count_tab <- count_tab %>% select(all_of(LAR_Flight_Ground_samples))
LAR_Flight_Ground_sample_info_tab <- sample_info_tab[row.names(sample_info_tab) %in% LAR_Flight_Ground_samples, ]

 # vst transforming
LAR_Flight_Ground_deseq_counts <- DESeqDataSetFromMatrix(LAR_Flight_Ground_count_tab, colData = LAR_Flight_Ground_sample_info_tab, design = ~Treatment)
LAR_Flight_Ground_deseq_counts_vst <- varianceStabilizingTransformation(LAR_Flight_Ground_deseq_counts)

LAR_Flight_Ground_vst_trans_count_tab <- assay(LAR_Flight_Ground_deseq_counts_vst)
LAR_Flight_Ground_euc_dist <- dist(t(LAR_Flight_Ground_vst_trans_count_tab))

# hclust
LAR_Flight_Ground_euc_clust <- hclust(LAR_Flight_Ground_euc_dist, method="ward.D2")
LAR_Flight_Ground_euc_dend <- as.dendrogram(LAR_Flight_Ground_euc_clust, hang=0.1)

# color by treatment
LAR_Flight_Ground_dend_cols <- as.character(LAR_Flight_Ground_sample_info_tab$treatment_color[order.dendrogram(LAR_Flight_Ground_euc_dend)])
labels_colors(LAR_Flight_Ground_euc_dend) <- LAR_Flight_Ground_dend_cols

plot(LAR_Flight_Ground_euc_dend, ylab="VST Euc. dist.", main="V4 amplicons (LAR F/G only; N=16)")
legend("topright", legend=c("Flight", "Ground"), fill=c(flight_col, ground_col), title="Treatment", inset=0.05)

# ordination
## making physeq object of vs-transformed tab
LAR_Flight_Ground_vst_count_phy <- otu_table(LAR_Flight_Ground_vst_trans_count_tab, taxa_are_rows=T)
LAR_Flight_Ground_sample_info_tab_phy <- sample_data(LAR_Flight_Ground_sample_info_tab)
LAR_Flight_Ground_vst_physeq <- phyloseq(LAR_Flight_Ground_vst_count_phy, LAR_Flight_Ground_sample_info_tab_phy)

# generating and visualizing the PCoA with phyloseq
LAR_Flight_Ground_vst_pcoa <- ordinate(LAR_Flight_Ground_vst_physeq, method="MDS", distance="euclidean")
LAR_Flight_Ground_eigen_vals <- LAR_Flight_Ground_vst_pcoa$values$Eigenvalues # allows us to scale the axes according to their magnitude of separating apart the samples

# colored by treatment, shape by experiment
plot_ordination(LAR_Flight_Ground_vst_physeq, LAR_Flight_Ground_vst_pcoa) + geom_point(size=3, aes(color = Treatment), shape=17) +
    scale_color_manual(values = rev(unique(as.vector(LAR_Flight_Ground_sample_info_tab$treatment_color)))) +
    coord_fixed(sqrt(LAR_Flight_Ground_eigen_vals[2]/LAR_Flight_Ground_eigen_vals[1])) + ggtitle("PCoA (VST Euc. dist.; LAR only; N=16)") +
    theme_bw() + theme(legend.position="bottom") + labs(color = "Treatment")

## whole-community diff test (anova)
anova(betadisper(LAR_Flight_Ground_euc_dist, LAR_Flight_Ground_sample_info_tab$Treatment)) # 0.66, ok for permanova
adonis(LAR_Flight_Ground_euc_dist~LAR_Flight_Ground_sample_info_tab$Treatment) # 0.001, at least one group is diff from the others at 0.001

plot_ordination(LAR_Flight_Ground_vst_physeq, LAR_Flight_Ground_vst_pcoa) + geom_point(size=3, aes(color = Treatment), shape=17) +
    scale_color_manual(values = rev(unique(as.vector(LAR_Flight_Ground_sample_info_tab$treatment_color)))) +
    coord_fixed(sqrt(LAR_Flight_Ground_eigen_vals[2]/LAR_Flight_Ground_eigen_vals[1])) + ggtitle("PCoA (VST Euc. dist.; LAR only; N=16)", subtitle = "Perm. ANOVA = 0.001") +
    theme_bw() + theme(legend.position="bottom", plot.title = element_text(face = "bold")) + labs(color = "Treatment")



## ISS_T Flight/Ground only
ISS_T_Flight_Ground_samples <- sample_info_tab %>% filter(Experiment == "ISS-T", Treatment %in% c("Flight", "Ground")) %>% row.names()
ISS_T_Flight_Ground_count_tab <- count_tab %>% select(all_of(ISS_T_Flight_Ground_samples))
ISS_T_Flight_Ground_sample_info_tab <- sample_info_tab[row.names(sample_info_tab) %in% ISS_T_Flight_Ground_samples, ]

 # vst transforming
ISS_T_Flight_Ground_deseq_counts <- DESeqDataSetFromMatrix(ISS_T_Flight_Ground_count_tab, colData = ISS_T_Flight_Ground_sample_info_tab, design = ~Treatment)
ISS_T_Flight_Ground_deseq_counts_vst <- varianceStabilizingTransformation(ISS_T_Flight_Ground_deseq_counts)

ISS_T_Flight_Ground_vst_trans_count_tab <- assay(ISS_T_Flight_Ground_deseq_counts_vst)
ISS_T_Flight_Ground_euc_dist <- dist(t(ISS_T_Flight_Ground_vst_trans_count_tab))

# hclust
ISS_T_Flight_Ground_euc_clust <- hclust(ISS_T_Flight_Ground_euc_dist, method="ward.D2")
ISS_T_Flight_Ground_euc_dend <- as.dendrogram(ISS_T_Flight_Ground_euc_clust, hang=0.1)

# color by treatment
ISS_T_Flight_Ground_dend_cols <- as.character(ISS_T_Flight_Ground_sample_info_tab$treatment_color[order.dendrogram(ISS_T_Flight_Ground_euc_dend)])
labels_colors(ISS_T_Flight_Ground_euc_dend) <- ISS_T_Flight_Ground_dend_cols

plot(ISS_T_Flight_Ground_euc_dend, ylab="VST Euc. dist.", main="V4 amplicons (ISS-T F/G only; N=16)")
legend("topright", legend=c("Flight", "Ground"), fill=c(flight_col, ground_col), title="Treatment", inset=0.05)

# ordination
## making physeq object of vs-transformed tab
ISS_T_Flight_Ground_vst_count_phy <- otu_table(ISS_T_Flight_Ground_vst_trans_count_tab, taxa_are_rows=T)
ISS_T_Flight_Ground_sample_info_tab_phy <- sample_data(ISS_T_Flight_Ground_sample_info_tab)
ISS_T_Flight_Ground_vst_physeq <- phyloseq(ISS_T_Flight_Ground_vst_count_phy, ISS_T_Flight_Ground_sample_info_tab_phy)

# generating and visualizing the PCoA with phyloseq
ISS_T_Flight_Ground_vst_pcoa <- ordinate(ISS_T_Flight_Ground_vst_physeq, method="MDS", distance="euclidean")
ISS_T_Flight_Ground_eigen_vals <- ISS_T_Flight_Ground_vst_pcoa$values$Eigenvalues # allows us to scale the axes according to their magnitude of separating apart the samples

# colored by treatment, shape by experiment
plot_ordination(ISS_T_Flight_Ground_vst_physeq, ISS_T_Flight_Ground_vst_pcoa) + geom_point(size=3, aes(color = Treatment), shape=17) +
    scale_color_manual(values=rev(unique(as.vector(ISS_T_Flight_Ground_sample_info_tab$treatment_color)))) +
    coord_fixed(sqrt(ISS_T_Flight_Ground_eigen_vals[2]/ISS_T_Flight_Ground_eigen_vals[1])) + ggtitle("PCoA (VST Euc. dist.; ISS_T only; N=16)") +
    theme_bw() + theme(legend.position="bottom") + labs(color = "Treatment")

## whole-community diff test (anova)
anova(betadisper(ISS_T_Flight_Ground_euc_dist, ISS_T_Flight_Ground_sample_info_tab$Treatment)) # 0.65, ok for permanova
adonis(ISS_T_Flight_Ground_euc_dist~ISS_T_Flight_Ground_sample_info_tab$Treatment) # 0.001, at least one group is diff from the others at 0.001

plot_ordination(ISS_T_Flight_Ground_vst_physeq, ISS_T_Flight_Ground_vst_pcoa) + geom_point(size=3, aes(color = Treatment), shape=17) +
    scale_color_manual(values=rev(unique(as.vector(ISS_T_Flight_Ground_sample_info_tab$treatment_color)))) +
    coord_fixed(sqrt(ISS_T_Flight_Ground_eigen_vals[2]/ISS_T_Flight_Ground_eigen_vals[1])) + ggtitle("PCoA (VST Euc. dist.; ISS-T only; N=16)", subtitle = "Perm. ANOVA = 0.001") +
    theme_bw() + theme(legend.position="bottom", plot.title = element_text(face = "bold")) + labs(color = "Treatment")
```



<a href=""><img src=""></a>
<a href=""><img src=""></a>
<a href=""><img src=""></a>
<a href=""><img src=""></a>
<a href=""><img src=""></a>
<a href=""><img src=""></a>
<a href=""><img src=""></a>
<a href=""><img src=""></a>
<a href=""><img src=""></a>