Skip to content

Commit 28a1fbc

Browse files
jaywarrickjaywarrick
jaywarrick
authored and
jaywarrick
committed
Update functions to use GitHub files and refactor slightly
1 parent b93d3dd commit 28a1fbc

13 files changed

+745
-419
lines changed

Figure_7.R

+12-8
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11

2-
source('/Users/jaywarrick/GoogleDrive/SingleCell/FACS Data/R FACS Plotting Functions/logicle.R')
3-
source('/Users/jaywarrick/GoogleDrive/SingleCell/FACS Data/R FACS Plotting Functions/plotFACS.R')
4-
source('/Users/jaywarrick/GoogleDrive/SingleCell/FACS Data/R FACS Plotting Functions/getSingleStats.R')
5-
source('/Users/jaywarrick/GoogleDrive/SingleCell/FACS Data/R FACS Plotting Functions/getDoubleStats.R')
6-
source('/Users/jaywarrick/GoogleDrive/SingleCell/FACS Data/R FACS Plotting Functions/drawStats.R')
7-
source('/Users/jaywarrick/GoogleDrive/SingleCell/FACS Data/R FACS Plotting Functions/drawLogicleAxis.R')
2+
source('/Users/jaywarrick/Public/DropBox/GitHub/R-SingleCell/logicle.R')
3+
source('/Users/jaywarrick/Public/DropBox/GitHub/R-SingleCell/plotFACS.R')
4+
source('/Users/jaywarrick/Public/DropBox/GitHub/R-SingleCell/getSingleStats.R')
5+
source('/Users/jaywarrick/Public/DropBox/GitHub/R-SingleCell/getDoubleStats.R')
6+
source('/Users/jaywarrick/Public/DropBox/GitHub/R-SingleCell/drawStats.R')
7+
source('/Users/jaywarrick/Public/DropBox/GitHub/R-SingleCell/drawLogicleAxis.R')
8+
source('/Users/jaywarrick/Public/Dropbox/GitHub/R-SingleCell/plotHelperFunctions.R')
89
library(flowCore)
910
library(flowViz)
1011
library(MASS)
@@ -13,6 +14,9 @@ library(foreign)
1314
library(hash)
1415

1516
# Have data object prepared (i.e. use preProcessing.R & postProcessing.R) or read in the appropriate microscope data
17+
data <- read.table('/users/jaywarrick/Google Drive/SingleCellLatest/Processed Data/N1_Data_1Cell.txt', header=TRUE)
18+
thresholds <- read.table('/Users/jaywarrick/Google Drive/SingleCellLatest/Processed Data/N1_Thresholds.txt', header=TRUE)
19+
setwd('/Users/jaywarrick/Google Drive/SingleCellLatest/Figure Masters/Plots/Microwell')
1620

1721
threshR <- thresholds$R
1822
threshG <- thresholds$G
@@ -25,14 +29,14 @@ fractions <- data.frame(t=numeric(0), pp=numeric(0), pm=numeric(0), mp=numeric(0
2529
for(frame in unique(data$Time))
2630
{
2731
temp <- subset(data, Time==frame & (Flag.R | Flag.G))
28-
pdf(paste('MicrowellFACS_',temp$Time[1],'.pdf',sep=''),width=1.1*W,height=1.1*H)
32+
pdf(paste('MicrowellFACS_N1_',temp$Time[1],'.pdf',sep=''),width=1.1*W,height=1.1*H)
2933
stats <- plotFACS(title='dummy', temp, xThresh=threshG, yThresh=threshR, xTransition=threshG, yTransition=threshR, xmax=4000, ymax=13000, yCross=0.0007)
3034
fractions <- rbind(fractions, data.frame(t=temp$time[1], pp=stats$'XY % ++', pm=stats$'XY % +-', mp=stats$'XY % -+', mm=stats$'XY % --'))
3135
dev.off()
3236
# browser()
3337
}
3438

35-
pdf('Figure_7b.pdf', height=1.1*H, width=1.1*W)
39+
pdf('MicrowellSummary_N1.pdf', height=1.1*H, width=1.1*W)
3640
paperParams(1,1)
3741
par(mar = c(3.7,3.7,0.8,0.8)); # beyond plot frame [b,l,t,r]
3842
par(mgp = c(2,0.8,0)); # placement of axis labels [1], numbers [2] and symbols[3]

Histograms.R

-179
This file was deleted.

drawLogicleAxis.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ drawLogicleAxis <- function(ticks=c(-10,1,10,100,1000,10000,100000,1000000), tic
1818
{
1919
axis(axisNum, at=ticks, labels=tickLabels)
2020
}
21-
21+
2222
}

makePaperPlots.R

+15-13
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
rm(list=ls())
2-
setwd('/Users/jaywarrick/GoogleDrive/SingleCell/Figures')
3-
source('/Users/jaywarrick/GoogleDrive/SingleCell/Figures/plotHelperFunctions.R')
2+
source('/Users/jaywarrick/Public/DropBox/R-SingleCell/plotHelperFunctions.R')
43
library(Hmisc)
54

65
# Read the raw and summary data
7-
data <- read.table('/users/jaywarrick/GoogleDrive/SingleCell/AndreaMatlabFiles/JayRFiles/M51R_Data_1Cell.txt', header=TRUE)
8-
params <- read.table('/Users/jaywarrick/GoogleDrive/SingleCell/AndreaMatlabFiles/JayRFiles/TrajectoryParameters_20131027.txt', header=TRUE)
9-
thresholds <- read.table('/Users/jaywarrick/GoogleDrive/SingleCell/AndreaMatlabFiles/JayRFiles/M51R_Thresholds.txt', header=TRUE)
6+
data <- read.table('/users/jaywarrick/Google Drive/SingleCellLatest/Processed Data/M51R_Data_1Cell.txt', header=TRUE)
7+
params <- read.table('/Users/jaywarrick/Google Drive/SingleCellLatest/Processed Data/TrajectoryParameters_20131027.txt', header=TRUE)
8+
thresholds <- read.table('/Users/jaywarrick/Google Drive/SingleCellLatest/Processed Data/M51R_Thresholds.txt', header=TRUE)
109

1110
# Define all the populations that will be potted
1211
pop_MaxInt.Gp <- subset(params, Flag.R & Flag.G & (Death==1 | Death==2)) # Remove no plateau rois
@@ -47,12 +46,15 @@ R <- 'darkred'
4746
H <- 4.7
4847
W <- 4.5
4948

50-
source('/Users/jaywarrick/GoogleDrive/SingleCell/Figures/Figure_6.R')
51-
source('/Users/jaywarrick/GoogleDrive/SingleCell/Figures/Figure_7.R')
52-
source('/Users/jaywarrick/GoogleDrive/SingleCell/Figures/Figure_8.R')
53-
source('/Users/jaywarrick/GoogleDrive/SingleCell/Figures/Figure_9.R')
54-
source('/Users/jaywarrick/GoogleDrive/SingleCell/Figures/Figure_10.R')
55-
source('/Users/jaywarrick/GoogleDrive/SingleCell/Figures/Figure_11.R')
56-
source('/Users/jaywarrick/GoogleDrive/SingleCell/Figures/Figure_12.R')
57-
source('/Users/jaywarrick/GoogleDrive/SingleCell/Figures/Tables.R')
49+
source('/Users/jaywarrick/Public/DropBox/R-SingleCell/plotScriptFACS.R')
50+
source('/Users/jaywarrick/Public/DropBox/R-SingleCell/plotScriptMicroscope.R')
51+
source('/Users/jaywarrick/Public/DropBox/R-SingleCell/plotScriptMicrowell.R')
52+
source('/Users/jaywarrick/Public/DropBox/R-SingleCell/Figure_6.R')
53+
source('/Users/jaywarrick/Public/DropBox/R-SingleCell/Figure_7.R')
54+
source('/Users/jaywarrick/Public/DropBox/R-SingleCell/Figure_8.R')
55+
source('/Users/jaywarrick/Public/DropBox/R-SingleCell/Figure_9.R')
56+
source('/Users/jaywarrick/Public/DropBox/R-SingleCell/Figure_10.R')
57+
source('/Users/jaywarrick/Public/DropBox/R-SingleCell/Figure_11.R')
58+
source('/Users/jaywarrick/Public/DropBox/R-SingleCell/Figure_12.R')
59+
source('/Users/jaywarrick/Public/DropBox/R-SingleCell/Tables.R')
5860

performPreprocessing.R

+10-88
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ library(zoo)
44
library(foreign)
55
library(tiff)
66
library(data.table)
7-
source('/users/jaywarrick/GoogleDrive/SingleCell/AndreaMatlabFiles/JayRFiles/preprocessingHelperFunctions.R')
7+
source('/Users/jaywarrick/Public/Dropbox/GitHub/R-SingleCell/preprocessingHelperFunctions.R')
88

99
# Generate Master data files based on arff files from JEX
1010
# masterData <- getData()
@@ -24,91 +24,13 @@ rm(savedData)
2424
# Remove ROIS with errors (bubbles etc.)
2525
data <- data[!(data$ID %in% errors$ID),]
2626

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)
2936

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

Comments
 (0)