-
Notifications
You must be signed in to change notification settings - Fork 0
/
Control.Rmd
148 lines (119 loc) · 5.51 KB
/
Control.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
---
title: "From MSDial on"
author: "Katherine Heal"
date: "August 28, 2019"
output: html_document
---
Organization notes:
As of 05/14/20, Skyline files for environmental samples have been moved to within their respective folders containing the .mzxml files for ease of file location (i.e. Manual_Integrations/HILICPos); Output from Skyline integrations of environmental samples are placed into "Manual_Integrations/DataProcessing/RawOutput"
All culture Skyline data are in rawDat folders
Analysis notes:
```{r, message=FALSE, error=FALSE}
library(tidyverse)
library(cowplot)
theme_set(theme_cowplot())
library(here)
```
# Quality control and tidy up culture samples
Run the qualtiy contorl (QC) for each analytical fraction for the culture samples, combine and make tidy to compare with environmental samples
```{r, message=FALSE, error=FALSE, warning=FALSE, }
source("SourceCode/QC_HILICPos_Cultures.R")
remove(list = ls())
source("SourceCode/QC_HILICNeg_Cultures.R")
remove(list = ls())
source("SourceCode/QC_RP_Cultures.R")
remove(list = ls())
source("SourceCode/Combine_and_tidy_cultures.R")
remove(list = ls())
```
# BMIS on the HILIC output from Skyline, save output in BMISReports Folder, remove the intermediate output
```{r, error = FALSE, warning=FALSE, message=FALSE}
source('SourceCode/BMIS_QEHILIC.R')
ggsave("Intermediates/BMISReports/BMIS_IS_StandardsRep_HILIC.pdf", plot = BMISlist[[1]], device = "pdf", width = 10, height = 10, units = "in")
write_file(BMISlist[[2]], "Intermediates/BMISReports/BMIS_Summary_HILIC.txt")
ggsave("Intermediates/BMISReports/BMIS_IS_StandardsTest_HILIC.pdf", plot = BMISlist[[3]], device = "pdf", width = 10, height = 10, units = "in")
write_csv(BMISlist[[4]], "Intermediates/BMISReports/BMISd_Areas_long_HILIC.csv")
rm(BMISlist)
```
# BMIS on the CyanoAq output from Skyline, save output in BMISReports Folder, remove the intermediate output
```{r, error = FALSE, warning=FALSE, message=FALSE}
source('SourceCode/BMIS_QECyano.R')
ggsave("Intermediates/BMISReports/BMIS_IS_StandardsRep_Cyano.pdf", plot = BMISlist[[1]], device = "pdf", width = 10, height = 10, units = "in")
write_file(BMISlist[[2]], "Intermediates/BMISReports/BMIS_Summary_Cyano.txt")
ggsave("Intermediates/BMISReports/BMIS_IS_StandardsTest_Cyano.pdf", plot = BMISlist[[3]], device = "pdf", width = 10, height = 10, units = "in")
write_csv(BMISlist[[4]], "Intermediates/BMISReports/BMISd_Areas_long_Cyano.csv")
rm(BMISlist)
```
# Combine and Tidy environmental data, add in culture data
```{r, error = FALSE, warning=FALSE, message=FALSE}
source('SourceCode/Combine_Clean_nofunction.R')
#Add in the culture data
dat.file <- read_csv("Intermediates/WideArea_withIDinfo.csv")
culture.file <- read_csv("Intermediates/Culture_Intermediates/combined_wide_LogBioArea.csv")
combo.wide <- left_join(dat.file, culture.file)
write_csv(combo.wide, "Intermediates/WideArea_withIDinfo_withCultureLogBioArea.csv")
remove(list = ls())
```
# Grab MS2 data to report
This isn't working through the rmd file, but works fine as an .R script
Takes a while and isn't necessary to run unless the specific Mass Features have changed
```{r, error = FALSE, warning=FALSE, message=FALSE}
source('SourceCode/get_MS2s.R')
detach("package:xcms", unload=TRUE)
detach("package:MSnbase", unload=TRUE)
detach("package:S4Vectors", unload=TRUE)
remove(list = ls())
```
# Quantify compounds that we are able to
1. Calculate response factor (RF) and response factor ratio (RFratio) for each compound in each data set using integrated standards.
2. Apply these response factors and get the concentrations in vial, then in environment for each compound in each data set
```{r, error = FALSE, warning=FALSE, message=FALSE}
#Calculate RF and RF ratios for all our quantifiable compounds
source('SourceCode/CalculateRF_andRFratios.R')
remove(list = ls())
#Use RF and RF ratios to calculate concentrations in organisms
source('SourceCode/Quantification_Cultures.R')
remove(list = ls())
#Use RF and RF ratios to calculate concentrations in environmental samples
source('SourceCode/Quantification_EnvironSamples.R')
remove(list = ls())
```
# Cluster the mass features using a K-means approach
Assign each MF:dataset a cluster, save out cluster diagnostics for each sample set.
Bootstrap the clusters to see if there is overexpressed overlap between clusters
```{r, error = FALSE, warning=FALSE, message=FALSE}
#seeds are set so should be reproducible
source("SourceCode/clustering_all_seperate.R")
remove(list = ls())
#To reorganize the clusters, rename them within this file
source("SourceCode/cluster_cleaner.R")
remove(list = ls())
source("SourceCode/bootstrap_clusters.R")
remove(list = ls())
```
# Clean up the cluster results
```{r}
source("SourceCode/metaClusterNamer.R")
remove(list = ls())
```
# Get basic stats for results section
```{r, error = FALSE, warning=FALSE, message=FALSE}
source("SourceCode/Basiccalcs.R")
```
# Write out files for Metabolomics Workbench
```{r}
source('SourceCode/Metab_WorkBench_Prepper.R')
remove(list = ls())
```
# Write out a file for CMAP export
```{r, error = FALSE, warning=FALSE, message=FALSE}
source('SourceCode/CMAP_maker.R')
cmap.results <- CMAPPER(quan.dat.file = "Intermediates/Quantified_LongDat.csv", metaG1.file = "MetaData/SampInfo_wMetaData_withUTC.csv")
# write.csv(cmap.results[[1]], "Intermediates/G1_GradientsTargeted_forCMAP.csv")
# write.csv(cmap.results[[2]], "Intermediates/G2_GradientsTargeted_forCMAP.csv")
remove(list = ls())
```
# Make some output for Anitra to peruse
```{r, error = FALSE, warning=FALSE, message=FALSE}
source('SourceCode/Summary_forAnitra.R')
```