annotate calculateZPrimeFactor.pl @ 0:8fb3d398725a draft default tip

Uploaded
author pmac
date Wed, 01 Jun 2016 03:37:27 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
8fb3d398725a Uploaded
pmac
parents:
diff changeset
1 ###############################################################################
8fb3d398725a Uploaded
pmac
parents:
diff changeset
2 # In summary this script calculates the z prime factor for one or more plates
8fb3d398725a Uploaded
pmac
parents:
diff changeset
3 # of data.
8fb3d398725a Uploaded
pmac
parents:
diff changeset
4 #
8fb3d398725a Uploaded
pmac
parents:
diff changeset
5 # Args:
8fb3d398725a Uploaded
pmac
parents:
diff changeset
6 # input.data.frame contains one or more columns of plate data. The first column
8fb3d398725a Uploaded
pmac
parents:
diff changeset
7 # must contain the well annotation ie A01, A02 etc. Each subsequent column represents
8fb3d398725a Uploaded
pmac
parents:
diff changeset
8 # a plate of data where the column name is the plate name.
8fb3d398725a Uploaded
pmac
parents:
diff changeset
9 #
8fb3d398725a Uploaded
pmac
parents:
diff changeset
10 # plate.conf.data.frame is a file of the following format:
8fb3d398725a Uploaded
pmac
parents:
diff changeset
11 # well, type(syntax must be either "poscontr" or "negcontr"), name (name of control)
8fb3d398725a Uploaded
pmac
parents:
diff changeset
12 #
8fb3d398725a Uploaded
pmac
parents:
diff changeset
13 # Returns:
8fb3d398725a Uploaded
pmac
parents:
diff changeset
14 # z'factor for each plate for each combination of each type of positive vs negative control.
8fb3d398725a Uploaded
pmac
parents:
diff changeset
15 #
8fb3d398725a Uploaded
pmac
parents:
diff changeset
16 # Author: gouldkate
8fb3d398725a Uploaded
pmac
parents:
diff changeset
17 ###############################################################################
8fb3d398725a Uploaded
pmac
parents:
diff changeset
18
8fb3d398725a Uploaded
pmac
parents:
diff changeset
19 use strict;
8fb3d398725a Uploaded
pmac
parents:
diff changeset
20 use warnings;
8fb3d398725a Uploaded
pmac
parents:
diff changeset
21 use IO::Handle;
8fb3d398725a Uploaded
pmac
parents:
diff changeset
22 use File::Temp qw/ tempfile tempdir /;
8fb3d398725a Uploaded
pmac
parents:
diff changeset
23 my $tdir = tempdir( CLEANUP => 0 );
8fb3d398725a Uploaded
pmac
parents:
diff changeset
24
8fb3d398725a Uploaded
pmac
parents:
diff changeset
25 # check to make sure having correct input and output files
8fb3d398725a Uploaded
pmac
parents:
diff changeset
26 my $usage = "usage: calculateZPrimeFactor.pl [TABULAR.in] [TABULAR.in] [TABULAR.out] \n";
8fb3d398725a Uploaded
pmac
parents:
diff changeset
27 die $usage unless @ARGV == 3;
8fb3d398725a Uploaded
pmac
parents:
diff changeset
28
8fb3d398725a Uploaded
pmac
parents:
diff changeset
29 #get the input arguments
8fb3d398725a Uploaded
pmac
parents:
diff changeset
30 my $plateData = $ARGV[0];
8fb3d398725a Uploaded
pmac
parents:
diff changeset
31 my $plateConfig = $ARGV[1];
8fb3d398725a Uploaded
pmac
parents:
diff changeset
32 my $zPrimeFactor = $ARGV[2];
8fb3d398725a Uploaded
pmac
parents:
diff changeset
33
8fb3d398725a Uploaded
pmac
parents:
diff changeset
34 #open the input files
8fb3d398725a Uploaded
pmac
parents:
diff changeset
35 open (INPUT1, "<", $plateData) || die("Could not open file $plateData \n");
8fb3d398725a Uploaded
pmac
parents:
diff changeset
36 open (INPUT2, "<", $plateConfig) || die("Could not open file $plateConfig \n");
8fb3d398725a Uploaded
pmac
parents:
diff changeset
37 open (OUTPUT1, ">", $zPrimeFactor) || die("Could not open file $zPrimeFactor \n");
8fb3d398725a Uploaded
pmac
parents:
diff changeset
38
8fb3d398725a Uploaded
pmac
parents:
diff changeset
39 #variable to store the name of the R script file
8fb3d398725a Uploaded
pmac
parents:
diff changeset
40 my $r_script;
8fb3d398725a Uploaded
pmac
parents:
diff changeset
41
8fb3d398725a Uploaded
pmac
parents:
diff changeset
42 # R script to implement the calcualtion of q-values based on multiple simultaneous tests p-values
8fb3d398725a Uploaded
pmac
parents:
diff changeset
43 # construct an R script file and save it in a temp directory
8fb3d398725a Uploaded
pmac
parents:
diff changeset
44 chdir $tdir;
8fb3d398725a Uploaded
pmac
parents:
diff changeset
45 $r_script = "calculateZPrimeFactor.r";
8fb3d398725a Uploaded
pmac
parents:
diff changeset
46
8fb3d398725a Uploaded
pmac
parents:
diff changeset
47 open(Rcmd,">", $r_script) or die "Cannot open $r_script \n\n";
8fb3d398725a Uploaded
pmac
parents:
diff changeset
48 print Rcmd "
8fb3d398725a Uploaded
pmac
parents:
diff changeset
49 #options(show.error.messages = FALSE);
8fb3d398725a Uploaded
pmac
parents:
diff changeset
50 input.data.frame <- read.table(\"$plateData\", head=T, sep=\"\\t\", comment=\"\");
8fb3d398725a Uploaded
pmac
parents:
diff changeset
51 plate.conf.data.frame <- read.table(\"$plateConfig\", head=T, sep=\"\\t\", comment=\"\");
8fb3d398725a Uploaded
pmac
parents:
diff changeset
52
8fb3d398725a Uploaded
pmac
parents:
diff changeset
53 # assumed second column is type ie negcontr or poscontr and third column is name of control
8fb3d398725a Uploaded
pmac
parents:
diff changeset
54 negative.controls.list <- unique(plate.conf.data.frame[which (plate.conf.data.frame[,2] == \"negcontr\"),][,3])
8fb3d398725a Uploaded
pmac
parents:
diff changeset
55 positive.controls.list <- unique(plate.conf.data.frame[which (plate.conf.data.frame[,2] == \"poscontr\"),][,3])
8fb3d398725a Uploaded
pmac
parents:
diff changeset
56
8fb3d398725a Uploaded
pmac
parents:
diff changeset
57 z.prime.factor.report.data.frame <- data.frame()
8fb3d398725a Uploaded
pmac
parents:
diff changeset
58
8fb3d398725a Uploaded
pmac
parents:
diff changeset
59
8fb3d398725a Uploaded
pmac
parents:
diff changeset
60 for (negative.control in negative.controls.list){
8fb3d398725a Uploaded
pmac
parents:
diff changeset
61 for (positive.control in positive.controls.list){
8fb3d398725a Uploaded
pmac
parents:
diff changeset
62 for (i in 2:length(colnames(input.data.frame))){
8fb3d398725a Uploaded
pmac
parents:
diff changeset
63
8fb3d398725a Uploaded
pmac
parents:
diff changeset
64 negative.control.wells <- plate.conf.data.frame[which (plate.conf.data.frame[3] == negative.control),][,1]
8fb3d398725a Uploaded
pmac
parents:
diff changeset
65 positive.control.wells <- plate.conf.data.frame[which (plate.conf.data.frame[3] == positive.control),][,1]
8fb3d398725a Uploaded
pmac
parents:
diff changeset
66
8fb3d398725a Uploaded
pmac
parents:
diff changeset
67 control.duo <- paste(negative.control, positive.control, sep=\"/\")
8fb3d398725a Uploaded
pmac
parents:
diff changeset
68
8fb3d398725a Uploaded
pmac
parents:
diff changeset
69 negative.control.values <- input.data.frame[((input.data.frame[,1] %in% negative.control.wells)&(!(is.na(input.data.frame[,i])))),][,i]
8fb3d398725a Uploaded
pmac
parents:
diff changeset
70 positive.control.values <- input.data.frame[((input.data.frame[,1] %in% positive.control.wells)&(!(is.na(input.data.frame[,i])))),][,i]
8fb3d398725a Uploaded
pmac
parents:
diff changeset
71
8fb3d398725a Uploaded
pmac
parents:
diff changeset
72 if ((length(negative.control.values)==0)|(length(positive.control.values)==0)){
8fb3d398725a Uploaded
pmac
parents:
diff changeset
73 z.prime.factor <- NA
8fb3d398725a Uploaded
pmac
parents:
diff changeset
74 } else {
8fb3d398725a Uploaded
pmac
parents:
diff changeset
75 if ((sum(negative.control.values)) < (sum(positive.control.values))){
8fb3d398725a Uploaded
pmac
parents:
diff changeset
76 low.value.controls <- negative.control.values
8fb3d398725a Uploaded
pmac
parents:
diff changeset
77 high.value.controls <- positive.control.values
8fb3d398725a Uploaded
pmac
parents:
diff changeset
78 } else {
8fb3d398725a Uploaded
pmac
parents:
diff changeset
79 low.value.controls <- positive.control.values
8fb3d398725a Uploaded
pmac
parents:
diff changeset
80 high.value.controls <- negative.control.values
8fb3d398725a Uploaded
pmac
parents:
diff changeset
81 }
8fb3d398725a Uploaded
pmac
parents:
diff changeset
82 z.prime.factor <- round(1 - ((3 * (sd(high.value.controls, na.rm = TRUE) + sd(low.value.controls, na.rm = TRUE))/(abs(mean(high.value.controls, na.rm = TRUE) - mean(low.value.controls, na.rm = TRUE))))), 2)
8fb3d398725a Uploaded
pmac
parents:
diff changeset
83 }
8fb3d398725a Uploaded
pmac
parents:
diff changeset
84
8fb3d398725a Uploaded
pmac
parents:
diff changeset
85 plate.name <- colnames(input.data.frame)[i]
8fb3d398725a Uploaded
pmac
parents:
diff changeset
86 z.prime.factor.current.row.data.frame <- data.frame(plate=plate.name, control.duo=control.duo, z.prime.factor=z.prime.factor, stringsAsFactors=FALSE)
8fb3d398725a Uploaded
pmac
parents:
diff changeset
87 z.prime.factor.report.data.frame <-rbind(z.prime.factor.report.data.frame, z.prime.factor.current.row.data.frame)
8fb3d398725a Uploaded
pmac
parents:
diff changeset
88 }
8fb3d398725a Uploaded
pmac
parents:
diff changeset
89 }
8fb3d398725a Uploaded
pmac
parents:
diff changeset
90 }
8fb3d398725a Uploaded
pmac
parents:
diff changeset
91 z.prime.factor.report.data.frame <- z.prime.factor.report.data.frame[order(z.prime.factor.report.data.frame\$control.duo),]
8fb3d398725a Uploaded
pmac
parents:
diff changeset
92 write.table(z.prime.factor.report.data.frame, file=\"$zPrimeFactor\", quote=F, sep=\"\\t\", row.names=F);
8fb3d398725a Uploaded
pmac
parents:
diff changeset
93 #eof\n";
8fb3d398725a Uploaded
pmac
parents:
diff changeset
94
8fb3d398725a Uploaded
pmac
parents:
diff changeset
95 close Rcmd;
8fb3d398725a Uploaded
pmac
parents:
diff changeset
96
8fb3d398725a Uploaded
pmac
parents:
diff changeset
97 system("R --no-restore --no-save --no-readline < $r_script > $r_script.out");
8fb3d398725a Uploaded
pmac
parents:
diff changeset
98
8fb3d398725a Uploaded
pmac
parents:
diff changeset
99 #close the input and output files
8fb3d398725a Uploaded
pmac
parents:
diff changeset
100 close(OUTPUT1);
8fb3d398725a Uploaded
pmac
parents:
diff changeset
101 close(INPUT1);
8fb3d398725a Uploaded
pmac
parents:
diff changeset
102 close(INPUT2);