-
Notifications
You must be signed in to change notification settings - Fork 0
/
Analysis_Hdf5_tracking_CD_v3_5.Rmd
2329 lines (1722 loc) · 98.3 KB
/
Analysis_Hdf5_tracking_CD_v3_5.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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
author: Steven Wink, Gerhard Burger
changelog
version 2_3: tracking data reorganization (unique parents and linking broken tracks complete)
reformat script h5 file CellProfiler
version 3_3: ?
version 3_4: ?
version 3_5: GB: start splitting up code into managable parts (see also H5CellProfiler.R)
-----------
For a ~1 GB hdf5 file you will require ~1 GB of free RAM: in practice you might want to have 8 GB of RAM to run this script
When multiple objects per parent object exist computation time will take several factors longer ( computation time of this matching part is around 30 - 60 seconds), this cannot be helped (although maybe optimized some) since the algorithm has to look in each image if multiple parents exist for each non-parent object.
install latest version of R
install RStudio
install knitr
set RStudio to use knitr
install packages:
source("http://bioconductor.org/biocLite.R")
biocLite(c("knitr", "rhdf5", "bit64", "stringr")
create csv file: see example f/media/Image Data/POC/2012_10_04/TIFs/output/Bipile "2012-12-06 Pipette sheet cyc1 srxn1 actn1 prpf40a.csv" - create this file using original spreadsheet layout, copy formulas to other experiment layout files.
set working directory to location of csv file and h5 files
First run r-script (wellFolders2013__05_01.Rmd) to place all ND2 exported Tiffs in to well-named folders (A01_1, A01_2, A02_1, A02_2, ...)
Then run CellProfiler (trunk build with hdf5 implementation) using the folder names as metadata
format for csv file: anything but include the same date identifier as for your h5 file: yyyy_mm_dd this is so you can't by accident switch layouts/ data
format for hdf5 file: anythinghere_yyyy_mm_dd.h5
If you split your data in 2 sets make sure to append _set1.h5 and _set2.h5
CellProfiler setting requirements
1) include metadata in LoadImages module and define the location as a single parameter as group
2) include metadata location as well_# ( from well script )
3) Always include relateobjects if you have multiple objects: larger object is parent, smaller object inside parent is the secondary object (it 's child). Each object must have a parent child relationship, there is always 1 parent - there can be multiple children.
eenmalig packages installeren die je niet hebt ( library( blah) werkt dan niet)
source("http://bioconductor.org/biocLite.R")
biocLite("packageHier")
Run each block seperately
BLOCK 1: extracting Hdf5 data
BLOCK 2: plotting single cell population based data
BLOCK 3: Organizes single cell tracking analysis
BLOCK 4: plotting single cell tracking data + measurement
All data is organized via the tracked object, so multiple objects per tracked object will be summarized by the mean or by a chosen quantile (will reuire a small code change since the quantile is very slow to perform in certain cases)
TODO
1) integrate plateID in script using time course data
- duplicate plot scripts and modify 1 with plateID (plotting changes)
- duplicate summary statistic scripts and modify 1 with plateID
2) modify script for single time point data (generate a fake time vector with 1's)
3) Nfkb translocatie parameters
# TODO: single time points, also for siRNA screens: different graphs etc. Maybe just add siRNA script into block-1, and run some of those plots and some of block-2 plots based on the single time point image data.
BLOCK 1: Extracting Hdf5 data
# TODO: many matched controls, negative and positive. e.g. compound1+mock is matched control of compound1+siRNA1, or different solvents
```{r generateCSVfiles}
getwd()
#"D:/DILI screen/2013-12-11"
#run fixTrackingFun
#modify myDFo met output
#fix alle plotjes
#distribueer
#analyzeer sylvia data
options(stringsAsFactors = FALSE)
#setwd("G:/Endpoint assay/2014-10-30_R002/Output XBP1")
dir()
#load library with methods for reading xls files
rm(list=ls())
cp.pipeline.location <- 'D:/h5Cellprofiler/H5CellProfiler'
source(file.path(cp.pipeline.location, "mainFunction.R"), chdir = TRUE)
source(file.path(cp.pipeline.location, "fixTrackingFun.R"))
library(rhdf5)
library(stringr)
library(plyr)
library(data.table)
library(doParallel)
library(ggplot2)
library(reshape2)
library(grid)
library(shiny)
library(ggvis)
source(file.path(cp.pipeline.location, "theme_sharp.R"))
source(file.path(cp.pipeline.location, "countCellFun.R"))
#=================user defined variables=================================================================
#========================================================================================================
#========================================================================================================
#========================================================================================================
#========================================================================================================
#========================================================================================================
#====================================,====================================================================
#global variables:
dir()
# Each hdf5 file contains 1 or multiple plate-based data (i.e. do not divide data from 1 plate in multiple h5 files unless different time points)
hdf5FileNameL <- c("2014_05_23_Hs578T RCM.h5") # mainFunction will loop through this vector, at the end rbinding the individual outputs.
# each hdf5 gets it's own metadata info. Either a path WITH the "Image/" character or a manualy defined string WITHOUT the "/" character
# If each h5 file has identical metadata 1 entry is sufficient. Else provide entry for each h5 file
# these metadata variables should be defined in metadata layout file if they vary within the h5 file, if not needed in the metadata file (so metadata is provided in these variables) - then put NA's in the metadata file
locationID <- c("Image/Metadata_Loc") # well/ location metadata
plateID <- c( "20140523Hs578T_RCM") # PlateID must always be provided (either manual or h5 paths)- here AND in layout file: becuase plateID is used to couple metadata plate layout file.
imageID <- c("Image/Metadata_xy") # Image/Metadata_ ... image number (obtained from image file name )
timeID <- c("Image/Metadata_tp") # timeID, either hdf5 path, or vector of numbers according to hdf5 files (each hdf5 is then a time point) So capture time point in h5 file if needed. Or defined in metadata layout file
replID <- c("") # replicate ID (are the plate replicates of each other? (just easy for plotting options))
exposureDelay <- c("00:00") # hh:mm
timeBetweenFrames <- c("00:06:00") # hh:mm:ss
#define the paths of the measurements you are interested in, leave empty if you dont need so many: full full full empty empty empty..... NOT: full empty full.....
# this is for measurements: tracking will be handled automatically
# only object related data or image related data( e.g. not implemented yet for Relationship/ Experiment related data )
# only add the object/feature part for example: "myObject/Inensity_MeanIntensity_img"
myFeaturePathsA <- list( #do not define displacement and parent object - these are automatically included
firstFeature = "Filteredcell/AreaShape_MedianRadius", # enter a objectpath inside .h5 file to measurement ( there will be one / meaning--> object/measurement)
secondFeature = "Image/Count_Filteredcell",
thirdFeature = "Filteredcell/TrackObjects_Displacement_20",
fourthFeature = "Filteredcell/AreaShape_Area",
fifthFeature = "",
sixthFeature = "",
seventhFeature= "",
eighthFeature = "",
ninethFeature = "",
thenthFeature = "" )
# tab delimted text file with metadata headers: well treatment dose_uM control cell_line
#the control is 1 or `1 where `1 is a control (just used for some extra coloring in plots)
plateMDFileName <- "2014_05_23_Hs578T RCM.txt"
dir()
parentObject <- "Filteredcell" # the name in hdf5 file of the parent ( as defined in relate objects module in CellProfiler ) if no parent (only 1 object defined in CP for example: then enter the object here)
childObject1 <- "" # First child of parentObject (if a child object was tracked - define this as your tracked object)
childObject2 <- ""
childObject3 <- ""
childObject4 <- ""
childObject5 <- ""
tertiaryObject <- "" # child of parentObject and childObject1 object. Defined (in CP) by substraction of larger object minus smaller object
# what summary statistic do you prefer to display the multiple objects per parent object with? This is NOT performed for nuclei, but for children objects like foci this can be usefull
multiplePerParentFunction <- function(x) { mean(x, na.rm = TRUE) } # or function(x) { quantile(x, 0.8, na.rm = TRUE) }
oscillation <- FALSE # TRUE / FALSE - will extract oscillation related parameters of divisionOne (TRUE is not implemented yet)
writeSingleCellDataPerWell <- FALSE # write all single cell data in seperate file per well, takes time
writeAllSingleCellData<- FALSE # Only needed of you need the txt file yourselfl writes all single cell data in single txt file.
numberCores <- min(4, detectCores())
dir()
#do the same for set2 if exists, then rbind the results with myDF
outputList= list()
# run main function: this could be made parralel but so far speed has not been an issue for this function
if(length(hdf5FileNameL) > 1) {
registerDoParallel(min(numberCores, length(hdf5FileNameL)))
outputList<- foreach( h5loop = seq_along(hdf5FileNameL ),
.packages = c("rhdf5", "stringr", "data.table", "plyr")) %dopar%
{
mainFunction( h5loop=h5loop,
hdf5FileNameL=hdf5FileNameL,locationID=locationID, timeID=timeID, plateID=plateID,
imageID=imageID, replID = replID,
myFeaturePathsA=myFeaturePathsA, plateMDFileName=plateMDFileName,
parentObject=parentObject, childObject1=childObject1, childObject2=childObject2,
childObject3=childObject3, childObject4=childObject4, childObject5=childObject5,
tertiaryObject=tertiaryObject, multiplePerParentFunction=multiplePerParentFunction,
oscillation=oscillation,
writeSingleCellDataPerWell=writeSingleCellDataPerWell,
writeAllSingleCellData=writeAllSingleCellData,
timeBetweenFrames=timeBetweenFrames, exposureDelay=exposureDelay,
numberCores = numberCores
)
}
} else {
h5loop <- 1
outputList <- mainFunction( h5loop=h5loop,
hdf5FileNameL=hdf5FileNameL,locationID=locationID, timeID=timeID, plateID=plateID,
imageID=imageID, replID = replID,
myFeaturePathsA=myFeaturePathsA, plateMDFileName=plateMDFileName,
parentObject=parentObject, childObject1=childObject1, childObject2=childObject2,
childObject3=childObject3, childObject4=childObject4, childObject5=childObject5,
tertiaryObject=tertiaryObject, multiplePerParentFunction=multiplePerParentFunction,
oscillation=oscillation,
writeSingleCellDataPerWell=writeSingleCellDataPerWell,
writeAllSingleCellData=writeAllSingleCellData,
timeBetweenFrames=timeBetweenFrames, exposureDelay =exposureDelay,
numberCores = numberCores
)
}
save(outputList, file = 'outputList.Rdata')
#load("outputList.Rdata")
if(length(unlist(lapply( lapply(outputList, names),str_match_all, "myDT") )) > 1) {
outputListmyDT<- lapply(outputList, "[[", "myDT")
testColN<- lapply(outputListmyDT, function(x) {( (names(x)))} )
all.identical <- function(x) all(mapply(identical, x[1], x[-1]))
if(!all.identical(testColN))
{
myDFo <- do.call('rbind', outputListmyDT)
} else{
myDFo <- rbindlist(outputListmyDT)
}
outputListsumData <- lapply(outputList, "[[", "sumData")
sumData <- rbindlist(outputListsumData)
kMyVars <- outputList[length(outputList)][[1]]
kMyVars$myDT <- NULL
} else {
outputListmyDT <- outputList$myDT
myDFo <- outputListmyDT
kMyVars <- outputList[-1]
sumData<- outputList$sumData
}
kColNames <- kMyVars$kColNames
dataFileName <- gsub(".txt", "",kMyVars$plateMDFileName)
myFeatures <- gsub("/", "_",
gsub("^(Measurements/[0-9]{4}(-[0-9]{2}){5}/)", "", kMyVars$myFeaturePathsA)
)
numberCores <- kMyVars$numberCores
runApp(file.path(cp.pipeline.location, 'time plots'), launch.browser = TRUE )
```
BLOCK 2
summary statistics
=============
# ff summary data bar plot
```{r }
piDataL <- melt(piData, measure.vars = c("binaryOne_pi_obj_maskedAreaShape_Area.DIV.NucleiAreaShape_Area", "imageCountParentObj"))
piDataL <- piDataL[ order( piDataL[ , "treatment"], piDataL[ , "dose_uM"]), ]
counts.d <- by(data = piDataL, INDICES = piDataL[, "treatment"], function(x) d.levels = unique(x[, "dose_uM"]))
if(sum(lapply(counts.d, length ) >1 ) > 0 ) { # if any compound has more than 1 dose level:
counts.d.l <- sapply(counts.d, as.list)
counts.d.l <- melt(counts.d.l, length)
old.nrow <- nrow(piDataL)
piDataL <- merge(piDataL, counts.d.l, by.x = c( "treatment", "dose_uM"), by.y = c( "L1", "value"), sort = FALSE)
if(nrow(piDataL) != old.nrow){
stop("setting dose levels for density plots failed")
}
piDataL$L2 <- factor(piDataL$L2)
colnames(piDataL)[ colnames(piDataL) == "L2"] <- "doseLevel"
}
head(piDataL)
toOrder <- piDataL[ piDataL$variable == "binaryOne_pi_obj_maskedAreaShape_Area.DIV.NucleiAreaShape_Area",]
indO <- ddply(toOrder, .(treatment), summarize, meanV = mean(value))
head(indO)
indOrder <- order(indO$meanV)
compOrder <- indO$treatment[indOrder]
piDataL$treatment <- factor(piDataL$treatment, levels = compOrder, order = TRUE)
p <- ggplot(data = piDataL, aes(x = treatment , y = value, fill = doseLevel, group = plateID, color=plateID)) + geom_bar(stat = "identity", position = "dodge")
p <- p + theme( axis.text.x = element_text(angle = 90, hjust = 1, vjust =0.4, size = 12 + round(400/ nrow(piDataL), 0),
colour = "grey50") ) + theme( strip.text.x = element_text( )) +
ggtitle("MV_AUC") +
theme(plot.title = element_text(lineheight=.8, size = 14 ))
dodge <- position_dodge(width=0.9)
p <- p + facet_wrap( ~variable , ncol=1, scales = "free_y" )
p
lapply(piDataL, class)
piDataL <- piDataL[!indr,]
indr<-(piDataL$value>7000)
```
Run Block1 first.
BLOCK 2: summary statistics & plotting
```{r summaryStatistics}
rm(list=ls()[ls() != "cp.pipeline.location"])
options(StringsAsFactors = FALSE)
library(rhdf5)
library(ggplot2)
library(reshape2)
library(stringr)
library(plyr)
library(pracma)
library(grid)
library(doParallel)
library(data.table)
library(shiny)
library(ggvis)
source(file.path(cp.pipeline.location, "theme_sharp.R"))
source(file.path(cp.pipeline.location, "countCellFun.R"))
# use as p + theme_sharp()
# setwd()
dir()
##========================== user defined variables=================
skip.locations <- c( ) # c("plate_1_B02_1", "plate_2_B02_1" )
summaryStatFunction <- function(x) { mean(x, na.rm = TRUE) } # function(x) { mean(x, na.rm = TRUE) } or function(x) { quantile(x, 0.8, na.rm = TRUE) } (you can choose which quantile - here it is set to 0.8)
errorType <- "sd" #"sd" or "cl95" the cl95 is two sided 95% confidence interval. sd is standard error, half above and half under the average
makeQuantilePlots <-TRUE # takes very long, do you need these ?
writePDFs <- TRUE # write plots as pdf? Takes time - choose false to only write RData files (plots are generated with ggplot2)
densityPlots <- TRUE
whichQuantiles <-c(0.05, 0.25, 0.5, 0.75, 0.95) # for large datasets; > 1GB hfd5 file, choose max 4 quantiles. Choose any quantiles. extra plots per feature are created displaying these quantiles of single cell data
##########=========================================##############
## ========================== end user defined variables============
##########=========================================##############
##########=========================================##############
dir()
# make seperate functions which are run in this rmd file depending on what user wants
# define global variables here (environment in which functions are called)
load("outputList.Rdata")
if(!exists("outputList"))
{
stop("No outputList.Rdata file found")
}
outputListmyDT<- lapply(outputList, "[[", "myDT")
testColN<- lapply(outputListmyDT, function(x) {( (names(x)))} )
all.identical <- function(x) all(mapply(identical, x[1], x[-1]))
if(!all.identical(testColN))
{
stop("outputlist does have tables with identical column names/
object names, manually rbind the outputlist")
}
myDFo <- rbindlist(outputListmyDT)
kMyVars <- outputList[length(outputList)][[1]]
kMyVars$myDT <- NULL
kColNames <- kMyVars$kColNames
dataFileName <- gsub(".txt", "",kMyVars$plateMDFileName)
print(paste("Plot processing ",dataFileName))
Sys.sleep(1)
myFeatures <- gsub("/", "_",
gsub("^(Measurements/[0-9]{4}(-[0-9]{2}){5}/)", "", kMyVars$myFeaturePathsA)
)
numberCores <- kMyVars$numberCores
setkey(myDFo, plateWellID)
if(!is.null(skip.locations))
{
myDFo<-myDFo[!skip.locations] # by assignment (memmove in c) is not possible by row in data.table (yet)
}
uniqueLocations <- unique(myDFo [ , plateWellID])
# write count parent cell file & return split data.tables for par. comp.
print("Counting parent objects and splitting data for MC processing")
splitDataL <- countCellFun( kColNames )
summaryStatsDir <- paste(dataFileName, "summaryStats", sep = "_")
if ( !file.exists( summaryStatsDir ))
{
dir.create( summaryStatsDir )
}
#
# time series plot of average of cell population
runApp(file.path(cp.pipeline.location, 'time plots'), launch.browser = TRUE )
# TODO : 11 aug 2014: bouw alles van plotten block 2 in in shiny applicatie
# zorg dat het wel met meer checks komt zodat de app niet zomaar kan vastlopen.
hieronder oude code nog niet met data.table/ goed memory gebruik van parallen & ook niet in app geintegreerd
?dataTableOutput
print(object.size(x=myDFo),units = "Mb")
nrow(myDFo)
?object.size
if (divisionOne[[1]] != FALSE & divisionTwo[[2]] != FALSE & binaryOne == FALSE & binaryTwo == FALSE){ # both division are not false and both binary are false
myDataL <- melt(myDFo, measure.vars=c(myFeatures,"Displacement", "imageCountTracked",
paste(divisionOne[[1]], divisionOne[[2]], sep ="_"),
paste(divisionTwo[[1]], divisionTwo[[2]], sep ="_")))
myData_ss <- ddply( myDataL, c("treatment", "dose_uM", locationID, "timeAfterExposure", "control", "cell_line", "variable"),
summarize, summaryStat = summaryStatFunction(value))
} else if (divisionOne[[1]] != FALSE & divisionTwo[[2]] == FALSE & binaryOne == FALSE ) # only first division is not false and it's binary is false
{
myDataL <- melt(myData, measure.vars=c(myFeatures,"Displacement", "imageCountTracked",
paste(divisionOne[[1]], divisionOne[[2]], sep ="_")
))
myData_ss <- ddply( myDataL, c("treatment", "dose_uM", locationID , "timeAfterExposure", "control", "cell_line", "variable"),
summarize, summaryStat = summaryStatFunction(value))
} else if (divisionOne[[1]] != FALSE & divisionTwo[[1]] == FALSE & binaryOne !=FALSE ) # only first division is not false and it's binary is not FALSE
{
myDataL <- melt(myData, measure.vars=c(myFeatures,"Displacement", "imageCountTracked",
paste("binaryOne",divisionOne[[1]], divisionOne[[2]], sep ="_")
))
myData_ss <- ddply( myDataL, c("treatment", "dose_uM", locationID , "timeAfterExposure", "control", "cell_line", "variable"),
summarize, summaryStat = summaryStatFunction(value), sum = sum(value, na.rm= TRUE))
myData_ss[ myData_ss$variable == paste("binaryOne",divisionOne[[1]], divisionOne[[2]], sep ="_"), "summaryStat" ] <-
myData_ss[ myData_ss$variable == paste("binaryOne",divisionOne[[1]], divisionOne[[2]], sep ="_"), "sum" ]
myData_ss$sum <- NULL
} else if ( divisionOne[[1]] != FALSE & divisionTwo[[1]] != FALSE & binaryOne == FALSE & binaryTwo != FALSE ) # both division are not false and only first binary is false
{
myDataL <- melt(myData, measure.vars=c(myFeatures,"Displacement", "imageCountTracked",
paste(divisionOne[[1]], divisionOne[[2]], sep ="_"),
paste("binaryTwo",divisionTwo[[1]], divisionTwo[[2]], sep ="_")
))
myData_ss <- ddply( myDataL, c("treatment", "dose_uM", locationID , "timeAfterExposure", "control", "cell_line", "variable"),
summarize, summaryStat = summaryStatFunction(value), sum = sum(value, na.rm= TRUE))
myData_ss[ myData_ss$variable == paste("binaryTwo",divisionTwo[[1]], divisionTwo[[2]], sep ="_"), "summaryStat" ] <-
myData_ss[ myData_ss$variable == paste("binaryTwo",divisionTwo[[1]], divisionTwo[[2]], sep ="_"), "sum" ]
myData_ss$sum <- NULL
} else if ( divisionOne[[1]] != FALSE & divisionTwo[[2]] != FALSE & binaryOne != FALSE & binaryTwo == FALSE ) # both division are not false and only second binary is false
{
myDataL <- melt(myData, measure.vars=c(myFeatures,"Displacement", "imageCountTracked",
paste(divisionTwo[[1]], divisionTwo[[2]], sep ="_"),
paste("binaryOne",divisionOne[[1]], divisionOne[[2]], sep ="_")
))
myData_ss <- ddply( myDataL, c("treatment", "dose_uM", locationID , "timeAfterExposure", "control", "cell_line", "variable"),
summarize, summaryStat = summaryStatFunction(value), sum = sum(value, na.rm= TRUE))
myData_ss[ myData_ss$variable == paste("binaryOne",divisionOne[[1]], divisionOne[[2]], sep ="_"), "summaryStat" ] <-
myData_ss[ myData_ss$variable == paste("binaryOne",divisionOne[[1]], divisionOne[[2]], sep ="_"), "sum" ]
myData_ss$sum <- NULL
} else if ( divisionOne[[1]] == FALSE & divisionTwo[[2]] == FALSE) # no column divisions defined
{
myDataL <- melt(myData, measure.vars=c(myFeatures,"Displacement", "imageCountTracked"))
myData_ss <- ddply( myDataL, c("treatment", "dose_uM", locationID , "timeAfterExposure", "control", "cell_line", "variable"),
summarize, summaryStat = summaryStatFunction(value))
} else if (divisionOne[[1]] != FALSE & divisionTwo[[2]] != FALSE & binaryOne != FALSE & binaryTwo != FALSE) # both division columns used for cell death data
{
myDataL <- melt(myData, measure.vars=c(myFeatures,"Displacement", "imageCountTracked",paste("binaryOne",divisionOne[[1]], divisionOne[[2]], sep ="_"),
paste("binaryTwo",divisionTwo[[1]], divisionTwo[[2]], sep ="_")))
myData_ss <- ddply( myDataL, c("treatment", "dose_uM", locationID , "timeAfterExposure", "control", "cell_line", "variable"),
summarize, summaryStat = summaryStatFunction(value), sum = sum(value, na.rm= TRUE))
myData_ss[ myData_ss$variable == paste("binaryOne",divisionOne[[1]], divisionOne[[2]], sep ="_") |
myData_ss$variable == paste("binaryTwo",divisionTwo[[1]], divisionTwo[[2]], sep ="_"), "summaryStat" ] <-
myData_ss[ myData_ss$variable == paste("binaryOne",divisionOne[[1]], divisionOne[[2]], sep ="_") |
myData_ss$variable == paste("binaryTwo",divisionTwo[[1]], divisionTwo[[2]], sep ="_"), "sum" ]
myData_ss$sum <- NULL
} else {
stop("Nothing found for melting division columns")
}
# alphabetically ordered by treatment
uTreatments <- unique(myData$treatment)
uTreatments <- uTreatments[order(uTreatments)]
rm(myData)
#add normalized binary data
if (divisionOne[1] !=FALSE & binaryOne != FALSE){
buffer <- myData_ss[ myData_ss$variable == paste("binaryOne",divisionOne[[1]], divisionOne[[2]], sep ="_"), ]
bufferCountCells <- myData_ss[ myData_ss$variable == "imageCountTracked", ]
buffer$summaryStat <- buffer$summaryStat / bufferCountCells$summaryStat
buffer$variable <- "binaryOneFraction"
myData_ss <- rbind(myData_ss, buffer)
}
if (divisionTwo[1]!=FALSE & binaryTwo != FALSE){
buffer <- myData_ss[ myData_ss$variable == paste("binaryTwo",divisionTwo[[1]], divisionTwo[[2]], sep ="_"), ]
bufferCountCells <- myData_ss[ myData_ss$variable == "imageCountTracked", ]
buffer$summaryStat <- buffer$summaryStat / bufferCountCells$summaryStat
buffer$variable <- "binaryTwoFraction"
myData_ss <- rbind(myData_ss, buffer)
}
# if divided by zero; remove inf values:
myData_ss$summaryStat[ is.infinite(myData_ss$summaryStat) ] <- NA
myData_ss$variable <- factor(myData_ss$variable)
#calculate sd' s over multiple locations/ wells for each condition
myData_ss_w <-myData_ss
myData_ss <- ddply( myData_ss, c("treatment", "dose_uM", "timeAfterExposure", "control", "cell_line", "variable"),
summarize, meanSummaryStat = summaryStatFunction(summaryStat), sd = sd(summaryStat, na.rm = TRUE),
n = length(summaryStat))
# remove first cell speed point as this is not really zero
min.t <- min(as.numeric(as.character(myData_ss$timeAfterExposure)))
myData_ss$meanSummaryStat[myData_ss$variable == "Displacement" & myData_ss$timeAfterExposure == min.t] <- NA
#error <- qt(0.975,df=n-1)*s/sqrt(n)
suppressWarnings(myData_ss$error95 <- qt(0.975, df = myData_ss$n - 1) * myData_ss$sd / sqrt(myData_ss$n))
objetSize <- object.size(myDataL)
if(makeQuantilePlots){
# increase speed by using parallel processing and aggregate instead of ddply
if( objetSize > 800000000 & objetSize %/% 800000000 < 2 & length(whichQuantiles) > 4 ) {
print("Large dataset: corenumber is set to 3 for calculating quantiles to avoid memory usage > 32GB")
registerDoParallel(cores=3)
} else if( objetSize %/% 800000000 >= 2 ) {
registerDoParallel(cores=1)
print("setting multicore to 1 for quantile calculations")
} else {
registerDoParallel(cores=length(whichQuantiles))
}
myData_q <- foreach( qCounter = seq_along(whichQuantiles)) %dopar% {
aggregate( value ~ treatment + dose_uM + timeAfterExposure + control + cell_line + variable,
data = myDataL, quantile, whichQuantiles[qCounter], na.rm=TRUE)
}
for (addQ in seq_along(myData_q)){
myData_q[[addQ]]$quantile <- whichQuantiles[addQ]
}
myData_ssq <- rbind.fill(myData_q)
rm(myData_q)
write.table(file = paste(str_match(dataFileName, '([0-9]{4}[- _]{1}[0-9]{2}[- _]{1}[0-9]{2})')[1], "myData_summarized_quantiles.txt"),
myData_ssq[order(myData_ssq$cell_line, myData_ssq$variable, myData_ssq$treatment, myData_ssq$dose_uM,
myData_ssq$quantile, myData_ssq$timeAfterExposure),], sep = "\t", col.names = NA)
}
p.size <- 6 + round(0.1 *length(unique(paste(myData_ss$treatment,myData_ss$dose_uM))),0)
subplot.char.l <- max(nchar(paste(unique(myData_ss$dose_uM), unique(myData_ss$treatment)) ))
max.t <- max(as.numeric(myData_ss$timeAfterExposure))
cell_lines <- unique(myData_ss$cell_line)
allVars <- as.character(unique(myData_ss$variable))
all.treatments<-as.character(unique(myData_ss$treatment))
#density plot
if(!file.exists(paste(summaryStatsDir, "/densityPlots", sep = ''))){
dir.create(paste(summaryStatsDir, "/densityPlots", sep = ''))
}
if(!file.exists(paste(summaryStatsDir, "/densityPlots/RDataFiles", sep = '')))
{
dir.create(paste(summaryStatsDir, "/densityPlots/RDataFiles", sep = ''))
}
singleCellMeas <- unique(myDataL$variable)
if(densityPlots){
densityPlotFun <- function(oneFeatallTrackDF) {
if(writePDFs) {
pdf(file = paste(summaryStatsDir, "/densityPlots/densityPlot", (singleCellMeas[ singleCellMeas != "imageCountTracked"])[kk],".pdf", sep =""),
height = 6+p.size,width = 10+1.2*p.size)
}
for (ii in seq_along(cell_lines)){
oneFeatallTrackDF_c<- oneFeatallTrackDF[ oneFeatallTrackDF$cell_line == cell_lines[ii], ]
p <- ggplot(oneFeatallTrackDF_c, aes(value, color = doseLevel )) + geom_density(na.rm=TRUE) + facet_wrap(~treatment) +
theme( axis.text.x = element_text(angle = 90, hjust = 1, size = 4 + round(150/max.t,0), colour = "grey50") ) +
theme( strip.text.x = element_text( size = 10)) +
ggtitle( paste( "density ",(singleCellMeas[ singleCellMeas != "imageCountTracked"])[kk], "_", cell_lines[ii], sep ="" ) ) +
theme(plot.title = element_text(lineheight=.8, size = 12 )) + theme_sharp()
save(p, file = paste(summaryStatsDir, "/densityPlots/RdataFiles/densityPlot", (singleCellMeas[ singleCellMeas != "imageCountTracked"])[kk], cell_lines[ii],".RData", sep =""))
if(writePDFs){
suppressWarnings(print(p))
}
} # ii loop cell_lines
if(writePDFs){
dev.off()
}
} #densityPlotFun
# create dose levels -> assign color to dose levels
print("Setting dose levels for density plots:")
myDataL <- myDataL[ order( myDataL[ , "treatment"], myDataL[ , "dose_uM"]), ]
counts.d <- by(data = myDataL, INDICES = myDataL[, "treatment"], function(x) d.levels = unique(x[, "dose_uM"]))
if(sum(lapply(counts.d, length ) >1 ) > 0 ) { # if any compound has more than 1 dose level:
counts.d.l <- sapply(counts.d, as.list)
counts.d.l <- melt(counts.d.l, length)
old.nrow <- nrow(myDataL)
myDataL <- merge(myDataL, counts.d.l, by.x = c( "treatment", "dose_uM"), by.y = c( "L1", "value"), sort = FALSE)
if(nrow(myDataL) != old.nrow){
stop("setting dose levels for density plots failed")
}
myDataL$L2 <- factor(myDataL$L2)
colnames(myDataL)[ colnames(myDataL) == "L2"] <- "doseLevel"
} else {
myDataL$doseLevel <- 1
}# end if multiple dose
cores <- min(c(length(singleCellMeas[ singleCellMeas != "imageCountTracked"]), numberCores))
registerDoParallel(cores=cores)
print("printing density plots:")
foreach(kk = seq_along(singleCellMeas[ singleCellMeas != "imageCountTracked"]),
.packages = c('ggplot2', 'grid', 'plyr'), .export = 'theme_sharp') %dopar%
{
densityPlotFun(subset(myDataL,myDataL$variable == singleCellMeas[ singleCellMeas != "imageCountTracked"][kk]))
}
} # if densityPlots
checkDoseLevel <- unique(myDataL[, c("dose_uM", "treatment", "doseLevel")])
checkDoseLevel<- checkDoseLevel[ order(checkDoseLevel$treatment), ]
write.table(file= paste(summaryStatsDir, "/checkDoseLevels.txt", sep = ''), sep = "\t", checkDoseLevel)
rm( myDataL,checkDoseLevel )
#need to scale the values for plotting all parameters in 1 plot
# decided to scale by average division.
# alternative would be e.g. rescaling with (x-min(x)) / (max(x) - min(x))
scaleF <- ddply(myData_ss, .(variable), summarize, mean = mean(meanSummaryStat, na.rm=TRUE))
myData_ss_scaled = myData_ss
for (scaleCount in 1:nrow(scaleF)) {
myData_ss_scaled[myData_ss$variable == scaleF$variable[scaleCount],"meanSummaryStat"] <-
myData_ss[myData_ss$variable == scaleF$variable[scaleCount],"meanSummaryStat"] / scaleF$mean[scaleCount]
}
myData_ss$dose_uM <- factor(myData_ss$dose_uM, order = T)
myData_ss$timeAfterExposure <- factor(myData_ss$timeAfterExposure, order = T)
myData_ss_scaled$dose_uM <- factor(myData_ss$dose_uM, order = T)
myData_ss_scaled$timeAfterExposure <- factor(myData_ss$timeAfterExposure, order = T)
myData_ss_scaled$sd <- NULL
myData_ss_scaled$error95 <- NULL
myData_ss_scaled$n <- NULL
write.table(file = paste(str_match(dataFileName, '([0-9]{4}[- _]{1}[0-9]{2}[- _]{1}[0-9]{2})')[1], "myData_summarized.txt"),
myData_ss[order(myData_ss$cell_line, myData_ss$variable, myData_ss$treatment, myData_ss$dose_uM,
myData_ss$timeAfterExposure),], sep = "\t", col.names = NA)
write.table(file = paste(str_match(dataFileName, '([0-9]{4}[- _]{1}[0-9]{2}[- _]{1}[0-9]{2})')[1], "myData_summarized_scaled.txt"),
myData_ss_scaled[order(myData_ss_scaled$cell_line, myData_ss_scaled$variable, myData_ss_scaled$treatment, myData_ss_scaled$dose_uM,
myData_ss_scaled$timeAfterExposure),], sep = "\t", col.names = NA)
# bar plots of all conditions, using AUC with function trapz from pracma package
barData <-ddply(myData_ss_w[!is.na(myData_ss_w$summaryStat),], c("treatment", "dose_uM", locationID, "cell_line", "control", "variable"), summarize,
AUC = trapz(as.numeric(timeAfterExposure), as.numeric(summaryStat )) )
barData <-ddply(barData, c("treatment", "dose_uM", "cell_line", "control", "variable"), summarize,
meanAUC = mean(AUC, na.rm = TRUE), sd = sd(AUC, na.rm = TRUE), n = length(AUC))
suppressWarnings(barData$error95 <- qt(0.975, df = barData$n - 1) * barData$sd / sqrt(barData$n))
#test what happens with trapz if multiple graphs
# tested and verified it works as intended
#barData$dose_uM <-factor(barData$dose_uM, levels = unique(barData$dose_uM)[order(unique(barData$dose_uM))],order = TRUE)
barData<-barData[order(barData$cell_line, barData$variable, barData$treatment, barData$dose_uM ),]
# create levels within each treatment for dose
counts.d <- ddply(barData, .(treatment, cell_line, variable), summarize,count.d.l = length(dose_uM))
barData$dose.f <- NA
for (i in 1 : nrow(counts.d))
{
barData$dose.f[ barData$treatment == counts.d$treatment[i] &
barData$cell_line == counts.d$cell_line[i] ] <- gl(counts.d$count.d.l[i], 1)
}
barData$dose.f<-factor(barData$dose.f)
#order the treatments based on average of myFeature
mean.c.l <- ddply(subset(barData, variable == gsub("/", "_",myFeature)), .(treatment), summarize, mean.t = mean(meanAUC))
barData$treatment <- factor((barData$treatment), levels = unique(mean.c.l$treatment)[order(mean.c.l$mean.t)], order = T )
write.table(file = paste(str_match(dataFileName, '([0-9]{4}[- _]{1}[0-9]{2}[- _]{1}[0-9]{2})')[1], "myData_AUC.txt"),
barData, sep = "\t", col.names = NA)
# make name
#function(x) { quantile(x, 0.3, na.rm = TRUE)}
#function(x) { mean(x, na.rm = TRUE) }
summName <- gsub("function \\(x\\) \\{ ", "",paste(deparse(summaryStatFunction), collapse=""))
summName <- gsub( "\\(x" , "", summName)
summName <- gsub( ", na.rm = TRUE\\)\\}", "", summName)
if (!file.exists(paste(summaryStatsDir, "/", "dose", sep =""))){
dir.create(paste(summaryStatsDir, "/", "dose", sep =""))
}
if (errorType == "sd") {
limits <- aes(ymax = meanAUC + 0.5*sd, ymin = meanAUC - 0.5*sd)
} else if ( errorType == "cl95")
{
limits <- aes(ymax = meanAUC + error975, ymin = meanAUC - error975)
} else
{
stop("errorType either \"sd\" or \"cl95\"")
}
p <- ggplot(data = barData, aes(x = treatment , y = meanAUC, fill = dose.f)) + geom_bar(stat = "identity", position = "dodge")
p <- p + theme( axis.text.x = element_text(angle = 90, hjust = 1, vjust =0.4, size = 12 + round(400/ nrow(barData), 0),
colour = "grey50") ) + theme( strip.text.x = element_text( )) +
ggtitle( paste( "MV_AUC", gsub( ".h5","" , hdf5FileName ), summName ) ) +
theme(plot.title = element_text(lineheight=.8, size = 14 ))
dodge <- position_dodge(width=0.9)
p <- p + facet_wrap( variable~cell_line ,ncol = 1, scales = "free_y" ) +
geom_errorbar(limits, width = 0.05, position = dodge)
m.height <- (6 + round(length(barData$treatment)/40))
m.width <- (6 + round(length(barData$treatment)/40))
if (writePDFs){
pdf( file = paste( summaryStatsDir, "/", "MV_barplot", "AUC", gsub( ".h5","" , hdf5FileName ),".pdf", sep ="" ), height = m.height, width = m.width )
print(p)
dev.off()
}
save(p, file = paste( summaryStatsDir, "/", "MV_barplot", "AUC", gsub( ".h5","" , hdf5FileName ),".RData", sep ="" ))
# plot time curves for each compound dose combination
allVarCells<- levels(interaction(allVars, cell_lines, sep ="_"))
myData_ss$allVarCells <- paste(myData_ss$variable, myData_ss$cell_line, sep ="_")
featuresDir <- paste(summaryStatsDir, "time", sep ="/")
if (!file.exists(featuresDir)){
dir.create(featuresDir)
}
if (!file.exists(paste(featuresDir, "RDataFiles", sep ="/"))){
dir.create(paste(featuresDir, "RDataFiles", sep ="/"))
}
myTimeFun <- function(myData_ss_c){
currVar <- unique(myData_ss_c$variable)
currVar<-currVar[currVar!="Displacement"]
currVar<-as.character(currVar)
myData_ss_c$variable <- factor(myData_ss_c$variable, levels = c(currVar, "Displacement"), order = TRUE)
if (!grepl("^Displacement", allVarCells[i] )){
scale.intDist <- max(myData_ss_c$meanSummaryStat[myData_ss_c$variable =="Displacement"], na.rm=TRUE)/
max(myData_ss_c$meanSummaryStat[myData_ss_c$variable !="Displacement"], na.rm=TRUE)
myData_ss_c$meanSummaryStat[myData_ss_c$variable =="Displacement"] <-
myData_ss_c$meanSummaryStat[myData_ss_c$variable =="Displacement"]/ scale.intDist
myData_ss_c$sd[myData_ss_c$variable =="Displacement" & !is.na( myData_ss_c$sd)] <-
myData_ss_c$sd[myData_ss_c$variable =="Displacement" & !is.na( myData_ss_c$sd)]/ scale.intDist
}
# error bar
if (errorType == "sd") {
limits <- aes(ymax = meanSummaryStat + 0.5*sd, ymin = meanSummaryStat - 0.5*sd)
} else if ( errorType == "cl95")
{
limits <- aes(ymax = meanSummaryStat + error975, ymin = meanSummaryStat - error975)
} else
{
stop("errorType either \"sd\" or \"cl95\"")
}
###manual
# myData_ss_c<- read.table( file ="H:/DILI screen/2014_02_11/output/2014_02_11 myData_summarized.txt", header = T, sep ="\t")
# myData_ss_c$X <- NULL
# head(myData_ss_c)
# myData_ss_c <- myData_ss_c[ myData_ss_c$variable == "obj_nc_Intensity_MeanIntensity_img_gfp", ]
#
# myData_ss_c <- myData_ss_c[ !myData_ss_c$treatment %in% c("Menadione", "etoposide " ,"Doxorubicin "), ]
## end manual
p<- ggplot( data = myData_ss_c, aes( x = timeAfterExposure , y = meanSummaryStat, colour = variable)) +
geom_point( size = 2, aes(shape = variable ), na.rm = TRUE ) +
geom_smooth( aes(group = variable, color = variable),
se = FALSE, size = 1, method = "loess", na.rm=TRUE, n = max.t) +
geom_errorbar(limits, width = 0.2, span = 0.9)
p <- p + facet_wrap( treatment ~ dose_uM )
p <- p + theme( axis.text.x = element_text(angle = 90, hjust = 1, size = 4 + round(150/max.t,0), colour = "grey50") ) +
theme( strip.text.x = element_text( size = 4 + round( 150/subplot.char.l, 0))) +
ggtitle( paste(allVarCells[i], "summary_", gsub( ".h5","" , hdf5FileName ), summName ) ) +
theme(plot.title = element_text(lineheight=.8, size = 10 )) + theme(legend.position = "bottom") +
theme_sharp()
if(writePDFs) {
pdf( file = paste( featuresDir, "/", allVarCells[i], "_summarytest_", gsub( ".h5","" , hdf5FileName ), ".pdf", sep ="" ),
height = p.size, width = p.size +round(0.2*max.t,0) )
print( p )
dev.off()
}
save(p, file = paste( featuresDir, "/RDataFiles/", allVarCells[i], "_summary_", gsub( ".h5","" , hdf5FileName ), ".RData", sep ="" ))
} # end myTimeFun
cores <- min(c(length(allVarCells), numberCores))
registerDoParallel(cores=cores)
foreach( i = seq_along(allVarCells), .packages = c("ggplot2", "grid"), .export = "theme_sharp") %dopar% {
myTimeFun(myData_ss[ myData_ss$allVarCells==allVarCells[i] |
(myData_ss$variable == "Displacement" &
myData_ss$cell_line == unique(myData_ss$cell_line[myData_ss$allVarCells==allVarCells[i]]) ), ])
}
#quantile plots - all quantiles per single feature
if(makeQuantilePlots){
qVars <- unique(myData_ssq$variable)
qVarsCells <- levels(interaction(qVars,cell_lines, sep ="_"))
myData_ssq$qVarsCells <- paste(myData_ssq$variable, myData_ssq$cell_line, sep = "_")
myData_ssq$quantile <- factor(myData_ssq$quantile)
quantilesDir <- paste(summaryStatsDir, "quantiles", sep ="/")
if (!file.exists(quantilesDir)){
dir.create(quantilesDir)
}
if(!file.exists(paste(quantilesDir, "RdataFiles", sep ="/"))){
dir.create(paste(quantilesDir, "RdataFiles", sep ="/"))
}
quantilePlotFun <- function(myData_ss_c) {
p<- ggplot( data = myData_ss_c, aes( x = timeAfterExposure , y = meanQ, colour = quantile)) +
geom_point( size = 2, aes(shape = quantile ), na.rm= TRUE ) +
geom_smooth( aes(group = quantile, color = quantile), se = FALSE,
size = 1, method = "loess", span = 0.9, na.rm = TRUE)
p <- p + facet_wrap( treatment ~ dose_uM )
p <- p + theme( axis.text.x = element_text(angle = 90, hjust = 1, size = 4 + round(150/max.t,0), colour = "grey50") ) +
theme( strip.text.x = element_text( size = 4 + round( 150/subplot.char.l, 0))) +
ggtitle( paste( qVarsCells[i], "quantiles", gsub( ".h5","" , hdf5FileName ), summName ) ) +
theme(plot.title = element_text(lineheight=.8, size = 10 )) + theme_sharp()
if(writePDFs){
pdf( file = paste( quantilesDir, "/", qVarsCells[i], "quantiles", gsub( ".h5","" , hdf5FileName ), ".pdf", sep ="" ),
height = p.size, width = p.size +round(0.15*max.t,0) )
print( p )
dev.off()
}
save(p, file = paste( quantilesDir, "/RdataFiles/", qVarsCells[i], "quantiles", gsub( ".h5","" , hdf5FileName ), ".RData", sep ="" ))
} # quantilePlot fun
colnames(myData_ssq)[ colnames(myData_ssq) == "value" ] <- "meanQ"
myData_ssq$dose_uM <- round(myData_ssq$dose_uM, 3)
cores <- min(c(length(qVarsCells), numberCores))
registerDoParallel(cores=cores)
foreach( i = 1 : length(qVarsCells), .packages = c("ggplot2", "grid"), .export = 'theme_sharp' ) %dopar% {
suppressWarnings(quantilePlotFun(myData_ssq[ myData_ssq$qVarsCells==qVarsCells[i] , ]))
}
} # end if statement quantileplots
# now time curves for scaled data co-plotted:
chosenVars <- unique(myData_ss_scaled$variable)
chosenVars<-as.character(chosenVars)
#myData_ss_scaled_orig<- myData_ss_scaled
myData_ss_scaled<-myData_ss_scaled[ myData_ss_scaled$variable %in% chosenVars,]
for (i in 1 : length(cell_lines)) {
myData_ss_c_scaled <- myData_ss_scaled[ myData_ss_scaled$cell_line == cell_lines[ i ], ]
p<- ggplot( data = myData_ss_c_scaled, aes( x = timeAfterExposure , y = meanSummaryStat, color = variable, shape = variable)) +
geom_point( size = 3, na.rm = TRUE ) +
scale_shape_manual(values= 1:length(unique(myData_ss_c_scaled$variable)) ) +
geom_smooth(aes(group = variable), se = FALSE, size = 1, method = "loess", span = 0.9, na.rm=TRUE)
p <- p + facet_wrap( treatment ~ dose_uM )
p <- p + theme_sharp() + theme( axis.text.x = element_text(angle = 90, hjust = 1, size = 8 + round(150/max.t,0), colour = "grey50") ) +
theme( strip.text.x = element_text( size = 10 + round( 150/subplot.char.l, 0))) +
ggtitle( paste(cell_lines[i], "summary_scaled", gsub( ".h5","" , hdf5FileName ), summName ) ) +
theme(plot.title = element_text(lineheight=.8, size = 24 ))
if(writePDFs){
pdf( file = paste( summaryStatsDir, "/", "scaled_coPlotted", "_summary_", gsub( ".h5","" , hdf5FileName ), "_",cell_lines[i],".pdf", sep ="" ),
height = 1.8*p.size, width = 1.8*(p.size +round(0.08*max.t,0)) )
print( p )
dev.off()
}
save(p, file = paste( summaryStatsDir, "/", "scaled_coPlotted", "_summary_", gsub( ".h5","" , hdf5FileName ), "_",cell_lines[i],".RData", sep ="" ))
}
#dose response curves
barData$dose_uM <- factor( barData$dose_uM)
for (i in 1 : length(allVars)) {
barDataF <- barData[barData$variable == allVars[i], ]
dose.n<-length(unique(barDataF$dose_uM))
if (errorType == "sd") {
limits <- aes(ymax = meanAUC + 0.5*sd, ymin = meanAUC - 0.5*sd)
} else if ( errorType == "cl95")
{
limits <- aes(ymax = meanAUC + error975, ymin = meanAUC - error975)
} else
{
stop("errorType either \"sd\" or \"cl95\"")
}
p<- ggplot( data = barDataF, aes( x = as.factor(dose_uM) , y = meanAUC, shape = cell_line, color = cell_line )) + geom_point( size = 4, na.rm = TRUE ) +
# geom_smooth(aes(group = variable), se = FALSE, size = 1) +
geom_errorbar(limits, width= 0.2, dodge = T )