forked from GreshamLab/flow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflow_multi_timepoint_analysis.Rmd
226 lines (168 loc) · 6.87 KB
/
flow_multi_timepoint_analysis.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
---
title: "Gresham Lab Flow Cytometry Multi Timepoint Analysis"
date: "`r Sys.Date()`"
output: html_notebook
---
## R Markdown
This is the code to generate figures about CNV dynamics from aggregated flow cyto data.
This notebook contains the code necessary to to generate figures from flow cytometry data across timepoints in the Gresham Lab.
To analyze flow cytometry data, you MUST use the latest version of this code, available on the [Gresham Lab github](https://github.com/GreshamLab/flow).
**Experimental overview**
Write a detailed description of your experiment here including the goal of the analysis and your interpretation of the results.
If you still see this text it means that you have not described the experiment and whatever follows is meaningless.
**Requirements**
In order to run this code you need:
* have run the "Gresham Lab Floww Cytometry Single Timepoint Analysis" and saved the proportional data, the filtered individual flow data, and/or the statistical data on one or more flowcyto runs
**Output**
This script combines the data from multiple flow cyto runs and can save the combined runs in the following formats
1. As a dataframe converted from fcs with all or some of the data.
2. As a .csv with summary statistics (e.g. median FL1 per sample)
3. As a .csv with proportional data (e.g. cells flourescent in population)
**Libraries**
```{r Load libs}
#Load libraries
library(openCyto)
library(ggcyto)
library(tidyverse)
library(ggjoy)
library(ggforce)
```
```{r User Defined Variables}
#working directory
dir = '.'
#file location
path.data = "/Users/Brandt/Google Drive/MiniStatRun_10_2018/2019-01-24/"
#name of the experiment
name <- "LTEE_mCitrine_GAP1_Variants"
#date of extracted data to use
#style of input
#Reading Data in
#Read in and combine individual Proportional Data
read.prop <- "No"
#Read in and combine individual DataFrames
read.df <- "No"
#Read in and combine individual Experiment Statistics
read.stats <- "No"
#Appending Data to previous data
#use the date to identify the combined data file you wish to append a new file to
appendto.date <- "2019-02-14"
#Use the Timepoint identifier and the date to identify what file you wish to add to your old file
append.timepoint <- "T00"
append.date <- "2019-01-24"
#Read in combined Proportional data file and append a single Proportional Data timepoint
append.prop <- "Yes"
#Read in combined DataFrame file and append a single DataFrame timepoint
append.df <- "Yes"
#Read in combined Statistics data file and append a single Statistics Data timepoint
append.stats <- "Yes"
#Saving curent Files
#Save combined Proportional Data
save.prop <- "Yes"
#Save combined DataFrame - Individual data points
save.df <- "Yes"
#Save combined Experiment Statistics
save.stats <- "Yes"
#Loading
#Date of combined data files you wish to load
load.date <- ""
#Load combined Proportional Data
load.prop <- "No"
#Load combined DataFrame - Individual data points
load.df <- "No"
#Load combined Experiment Statistics
load.stats <- "No"
#filenames
file.prop <- paste(name,"_propAllData_",Sys.Date(),sep="")
file.df <- paste(name,"_dfAllData_",Sys.Date(),sep="")
file.stats <- paste(name,"_statsAllData_",Sys.Date(),sep="")
```
```{r Read or load in Data}
#Reading in Data
#Read in and Combine all Proportional Data files found in path
#Creates a list of proportional data files, identifed by have _prop_ and .csv in the file name
prop.list <- list.files(path=path.data, pattern = "_prop_[[:print:]]*.csv")
#Load each file and combine them
if(read.prop=="Yes"){
data.prop <- read_csv(paste(path.data,prop.list[1], sep=""))
for(i in 2:length(prop.list)){
data.prop_temp <- read_csv(paste(path.data,prop.list[i], sep=""))
data.prop<- bind_rows(data.prop, data.prop_temp)
}
data.prop <- select(data.prop,-c(1))
}
#Read in and Combine data frames found in path
#Creates a list of data frames in Rdata files, identifed by have _ddf_ and .Rdata in the file name
df.list <- list.files(path=path.data, pattern = "_df_[[:print:]]*.Rdata")
#Load each file and combine them
if(read.df=="Yes"){
load(paste(path.data,df.list[1], sep=""))
data.df <- filtered.data
for(i in 2:length(df.list)) {
load(paste(path.data,df.list[i], sep=""))
data.df_temp<-filtered.data
data.df <- rbind(data.df, data.df_temp)
}
}
#Read in and Combine Statistical Data in path
#Creates a list of Statistical data files, identifed by have _stats_ and .csv in the file name
stats.list <- list.files(path=path.data, pattern = "_stats_[[:print:]]*.csv" )
#Load each file and combine them
if(read.stats=="Yes"){
data.stats <- read_csv(paste(path.data,stats.list[1], sep=""))
for(i in 2:length(stats.list)){
data.stats_temp <- read_csv(paste(path.data,stats.list[i], sep=""))
data.stats<- bind_rows(data.stats, data.stats_temp)
}
data.stats <- select(data.stats,-c(1))
}
#Append Data - Requires a previously saved all data file as well as a new timepoint
#Read in and add new Proportinal timepoint
if(append.prop=="Yes"){
data.prop <- read_csv(paste(path.data,name,"_propAllData_",appendto.date,".csv",sep=""))
data.prop_temp <- read_csv(paste(path.data,list.files(path=path.data, pattern =paste(append.timepoint,"_prop_",append.date,sep="")), sep=""))
data.prop<- bind_rows(data.prop, data.prop_temp)
data.stats <- select(data.stats,-c(1))
}
#Read in and and add new data frames
if(append.df=="Yes"){
load(paste(path.data,name,"_dfAllData_",appendto.date,".Rdata",sep=""))
data.df <- filtered.data
load(paste(path.data,list.files(path=path.data, pattern =paste(append.timepoint,"_df_",append.date,sep="")), sep=""))
data.df_temp<-filtered.data
data.df <- rbind(data.df, data.df_temp)
}
#Read in and add new Statistical Data timepoint
if(append.stats=="Yes"){
data.stats <- read_csv(paste(path.data,name,"_statsAllData_",appendto.date,".csv",sep=""))
data.stats_temp <- read_csv(paste(path.data,list.files(path=path.data, pattern =paste(append.timepoint,"_stats_",append.date,sep="")), sep=""))
data.stats<- bind_rows(data.stats, data.stats_temp)
data.stats <- select(data.stats,-c(1))
}
#Saving Current Data
#Save Proportional Data
if(save.prop=="Yes"){
write.csv(data.prop, file= paste(path.data,file.prop,".csv",sep=""), row.names=TRUE, quote=F)
}
#Save dataframes
if(save.df=="Yes"){
save(data.df, file=paste(path.data,file.df,".Rdata",sep=""))
}
#Save Statistical Data
if(save.stats=="Yes"){
write.csv(data.stats, file= paste(path.data,file.stats,".csv",sep=""), row.names=TRUE, quote=F)
}
#Loading Data
#Read in and Combine Proportional Data
if(load.prop=="Yes"){
data.prop <- read_csv(paste(path.data,name,"_propAllData_",load.date,".csv",sep=""))
}
#Read in and Combine data frames
if(load.df=="Yes"){
load(paste(path.data,name,"_dfAllData_",load.date,".Rdata",sep=""))
}
#Read in and Combine Statistical Data
if(load.stats=="Yes"){
data.stats <- read_csv(paste(path.data,name,"_statsAllData_",load.date,".csv",sep=""))
}
```
##Plots