@@ -4,7 +4,7 @@ library(zoo)
4
4
library(foreign )
5
5
library(tiff )
6
6
library(data.table )
7
- source(' /users /jaywarrick/GoogleDrive/SingleCell/AndreaMatlabFiles/JayRFiles /preprocessingHelperFunctions.R' )
7
+ source(' /Users /jaywarrick/Public/Dropbox/GitHub/R-SingleCell /preprocessingHelperFunctions.R' )
8
8
9
9
# Generate Master data files based on arff files from JEX
10
10
# masterData <- getData()
@@ -24,91 +24,13 @@ rm(savedData)
24
24
# Remove ROIS with errors (bubbles etc.)
25
25
data <- data [! (data $ ID %in% errors $ ID ),]
26
26
27
- # Focus on M51R Data
28
- data <- subset(data , Virus == ' M51R' )
27
+ # preprocess and write the preprocessed data to files
28
+ temp <- preprocessVirusData(data , virusType = ' M51R' )
29
+ write.table(temp $ single , ' /Users/jaywarrick/Google Drive/SingleCellLatest/Processed Data/M51R_Data_1Cell.txt' , row.names = FALSE )
30
+ write.table(temp $ zero , ' /Users/jaywarrick/Google Drive/SingleCellLatest/Processed Data/M51R_Data_0Cell.txt' , row.names = FALSE )
31
+ write.table(temp $ thresholds , ' /Users/jaywarrick/Google Drive/SingleCellLatest/Processed Data/M51R_Thresholds.txt' , row.names = FALSE )
32
+ temp <- preprocessVirusData(data , virusType = ' N1' )
33
+ write.table(temp $ single , ' /Users/jaywarrick/Google Drive/SingleCellLatest/Processed Data/N1_Data_1Cell.txt' , row.names = FALSE )
34
+ write.table(temp $ zero , ' /Users/jaywarrick/Google Drive/SingleCellLatest/Processed Data/N1_Data_0Cell.txt' , row.names = FALSE )
35
+ write.table(temp $ thresholds , ' /Users/jaywarrick/Google Drive/SingleCellLatest/Processed Data/N1_Thresholds.txt' , row.names = FALSE )
29
36
30
- # Read in the times at which each frame was acquired and fill in the time column with the image frame number (starting at 1)
31
- timedata <- read.csv(' /Users/jaywarrick/Desktop/Octave/timeData.dat' )
32
- data [, time : = timedata $ Time [1 : length(Time )], by = ID ]
33
-
34
- # Calculate background corrected values for each color
35
- data $ R.BC <- data $ R0_CellMax - data $ R0_Mode
36
- data $ G.BC <- data $ G0_CellMax - data $ G0_Mode
37
- data $ B.BC <- data $ B0_CellMax - data $ B0_Mode
38
-
39
- # Isolate data with 0 cell in the wells
40
- null <- subset(data , Cell.Count == 0 )
41
-
42
- # Remove wells with more than 1 cell
43
- data <- subset(data , ! is.na(Cell.Count ))
44
-
45
- # Get the mean null signals over time for each ROI and take the median for each
46
- nullSummary <- null [, list (R.BC.Mean = mean(R.BC ),G.BC.Mean = mean(G.BC ),B.BC.Mean = mean(B.BC )), by = list (Device ,Image ,ID )] # Time-averaged mean of R, G, and B signals for each ROI with 0-cells in them
47
- nullSummary <- nullSummary [, list (R.BC.Mean.Median = median(R.BC.Mean ), G.BC.Mean.Median = median(G.BC.Mean ), B.BC.Mean.Median = median(B.BC.Mean )), by = list (Device ,Image )] # Median of 0-cell well R, G, and B signals for each image and device
48
-
49
- # Subtract the median signal of null wells obtained for image from data in the corresponding images
50
- nullSummary <- data.frame (nullSummary )
51
- data [, R.NULL : = nullSummary [nullSummary $ Image == Image [1 ] & nullSummary $ Device == Device [1 ],]$ R.BC.Mean.Median , by = list (Device ,Image )]
52
- data [, G.NULL : = nullSummary [nullSummary $ Image == Image [1 ] & nullSummary $ Device == Device [1 ],]$ G.BC.Mean.Median , by = list (Device ,Image )]
53
- data [, B.NULL : = nullSummary [nullSummary $ Image == Image [1 ] & nullSummary $ Device == Device [1 ],]$ B.BC.Mean.Median , by = list (Device ,Image )]
54
- data [, R.BC.NULL : = R.BC - R.NULL ]
55
- data [, G.BC.NULL : = G.BC - G.NULL ]
56
- data [, B.BC.NULL : = B.BC - B.NULL ]
57
-
58
- # Apply illumination correction
59
- countData <- data.frame (countData )
60
- data [, IF.Factor : = countData [countData $ ID == ID [1 ],]$ IF.Factor , by = ID ]
61
- data [, R.Final : = R.BC.NULL / IF.Factor ]
62
- data [, G.Final : = G.BC.NULL / IF.Factor ]
63
- data [, B.Final : = B.BC.NULL / IF.Factor ]
64
-
65
- # Separate the data into data for 0-cell wells and 1-cell wells
66
- single <- subset(data , Cell.Count == 1 )
67
- zero <- subset(data , Cell.Count == 0 )
68
-
69
- # Create a quick plot for a sense check
70
- plot(c(),c(),xlim = c(0 ,47 ),ylim = c(0 ,max(single $ R.Final )))
71
- single [, lines(Time ,R.Final , col = ' red' ), by = ID ]
72
- zero [, lines(Time ,R.Final , col = ' black' ), by = ID ]
73
-
74
- plot(c(),c(),xlim = c(0 ,47 ),ylim = c(0 ,max(single $ G.Final )))
75
- single [, lines(Time ,G.Final , col = ' green' ), by = ID ]
76
- zero [, lines(Time ,G.Final , col = ' black' ), by = ID ]
77
-
78
- plot(c(),c(),xlim = c(0 ,47 ),ylim = c(0 ,max(single $ B.Final )))
79
- single [, lines(Time ,B.Final , col = ' blue' ), by = ID ]
80
- zero [, lines(Time ,B.Final , col = ' black' ), by = ID ]
81
-
82
- # Determine the threshold based on 0-cell data
83
- zeroSummary <- zero [, list (R.Mean = mean(R.Final ),G.Mean = mean(G.Final ),B.Mean = mean(B.Final )), by = list (Device ,Image ,ID )]
84
- zeroSummary <- zeroSummary [, list (R.Mean.Median = median(R.Mean ), G.Mean.Median = median(G.Mean ), B.Mean.Median = median(B.Mean ), R.Mean.StdDev = sd(R.Mean ), G.Mean.StdDev = sd(G.Mean ), B.Mean.StdDev = sd(B.Mean )), by = list (Device ,Image )]
85
- zeroSummary [, R.Thresh : = R.Mean.Median + 3 * R.Mean.StdDev ]
86
- zeroSummary [, G.Thresh : = G.Mean.Median + 3 * G.Mean.StdDev ]
87
- zeroSummary [, B.Thresh : = B.Mean.Median + 3 * B.Mean.StdDev ]
88
- thresholds <- zeroSummary [, list (R = max(R.Thresh ), G = max(G.Thresh ), B = max(B.Thresh ))]
89
-
90
- # Zero points below threshold and spurrious points above threshold (i.e. less than 4 points in a row above 0)
91
- single [,R : = rollmin(R.Final , thresh = thresholds $ R ),by = ID ]
92
- single [,G : = rollmin(G.Final , thresh = thresholds $ G ),by = ID ]
93
- single [,B : = rollmin(B.Final , thresh = thresholds $ B ),by = ID ]
94
-
95
- # For each color, mark trajectories that have a signal
96
- hasSignal <- function (piece ){if (max(piece )> 0 ){return (TRUE )}else {return (FALSE )}}
97
- single [,Flag.R : = hasSignal(R ),by = ID ]
98
- single [,Flag.G : = hasSignal(G ),by = ID ]
99
- single [,Flag.B : = hasSignal(B ),by = ID ]
100
-
101
- # Create a quick plot for a sense check
102
- plot(c(),c(),xlim = c(0 ,47 ),ylim = c(1 ,max(single $ R )), log = ' y' )
103
- single [, lines(Time ,R , col = rgb(1 ,0 ,0 ,0.2 )), by = ID ]
104
-
105
- plot(c(),c(),xlim = c(0 ,47 ),ylim = c(1 ,max(single $ G )), log = ' y' )
106
- single [, lines(Time ,G , col = rgb(0 ,1 ,0 ,0.2 )), by = ID ]
107
-
108
- plot(c(),c(),xlim = c(0 ,47 ),ylim = c(1 ,max(single $ B )), log = ' y' )
109
- single [, lines(Time ,B , col = rgb(0 ,0 ,1 ,0.2 )), by = ID ]
110
-
111
- # Write the preprocessed data to a file
112
- write.table(single , ' /Users/jaywarrick/GoogleDrive/SingleCell/AndreaMatlabFiles/JayRFiles/M51R_Data_1Cell.txt' , row.names = FALSE )
113
- write.table(zero , ' /Users/jaywarrick/GoogleDrive/SingleCell/AndreaMatlabFiles/JayRFiles/M51R_Data_0Cell.txt' , row.names = FALSE )
114
- write.table(thresholds , ' /Users/jaywarrick/GoogleDrive/SingleCell/AndreaMatlabFiles/JayRFiles/M51R_Thresholds.txt' , row.names = FALSE )
0 commit comments