1. This is dataclassification macro   sarkar80_sub.dp   multiplot classif./pred. analysis   4/12/19
2. Purpose: classification/prediction plots with multiple plots per page
3.
4. Q. What protocol and what protocol setting rule best predict the 11 conditions?
5.
6. Ans. 1: 64 subsetted scatter plots of Y vs condition--one plot for each protocol
7.      Does protocol  1 discriminate/predict best?
8.      Does protocol  2 discriminate/predict best?
9.      ...
10.      Does protocol 64 discriminate/predict best?
11.
12. Ans. 2: 16 subsetted scatter plots of Y vs condition--one plot for each setting
13.         of each of the 8 protocol factors
14.      Does protocol factor 1 at the low  setting discriminate/predict best?
15.      Does protocol factor 1 at the high setting discriminate/predict best?
16.      Does protocol factor 2 at the low  setting discriminate/predict best?
17.      Does protocol factor 2 at the high setting discriminate/predict best?
18.      ...
19.      Does protocol factor 8 at the low  setting discriminate/predict best?
20.      Does protocol factor 8 at the high setting discriminate/predict best?
21.
22. Date: 4/10/19
23.
24. Input (required):
25.   jresp (parameter) = id of the response variable used (in a multi-response system)
26.   k     (parameter) = number of protocol factors
27.
28.   y     (vector)    = response
29.   prot  (vector)    = bio-image analysis protocol id (^ndprot = 2**(8-2) levels)
30.   cond  (vector)    = the condition of the sample cells being imaged (^ndcond levels)
31.   image (vector)    = the image id of the cells (^ndimage pictures thus ^ndimage levels)
32.   Note that the vertical axis limits (as defined by ylim) must be done in the calling program.
33.
34. Input (optional):
35.
36. Output:
37.    many fewer than 81 (= 1 + 64 + 2*8) pages of plots
38.
39. Example of calling program: sarkar80.dp
40.
41. -----start point-----
42.
43let dprot = distinct prot
44let ndprot = number dprot
45.
46let dcond = distinct cond
47let ndcond = number dcond
48.
49let dimage = distinct image
50let ndimage = number dimage
51.
52. -----Step 10: Prepare to plot the data-----
53.
54let string stcorn1 = Y^jresp:
55let string stcorn2 = ^stysh^jresp
56let cornh = 4; let cornw = 2     ; . (default: cornh  = 6 and cornw  =  3)
57let cornxp = 3; let cornyp = 97  ; . (default: cornxp = 2 and cornyp = 96)
58ygrid on
59minor x1tic number 0
60.
61y1label log(^sty^jresp + 1)
62x1label Cell Condition (^ndcond)
63.
64. -----Step 11: For all data, scatter plot vs condition (11)-----
65.
66let string header2 = For all the Data, Are the 11 Conditions Different?  Prediction Rules?
67.
68delete qsub
69.
70let string corncol = ^darkgree
71char X all
72lines bl all
73let string header3 = Character Plot
74plot y cond prot
75.
76call write_condition_names_under_horizontal_axis.dp
77let n = number y
78call overlap_score.dp
79move 16 87; just left; hw 2.4 1.2; text n = ^n
80move 84 87; just right; hw 2.4 1.2; text Score = ^score/^npairs
81call write_factors_and_settings_upper_right.dp
82let string stcorn3 = All Prot
83call upperleft.dp
84call annotate.dp
85.
86. -----Step 12: For each protocol (64), scatter plot vs condition (11)-----
87.
88let dothis = 1
89if dothis = 1
90.
91let string header2 = What Protocol Setting (64) Best Discriminates/Predicts the 11 Conditions?  Prediction Rules?
92.
93. ylim 0 5
94frame corner coordinates 0 0 100 100
95grid off
96delete qsub
97.
98x3label
99y1label displacement 15
100x1label displacement 10
101let string corncol = blue
102loop for jprot = 1 1 ^ndprot
103   y1label; x1label
104   x1tics off; x1tic labesl off
105   y1tics off; y1tic labels off
106   let jmod = mod(jprot,8); if jmod = 0; let jmod = 8; end if
107   if jmod = 1; multiplot 2 4; multiplot scale factor 2; delete jprot1; let jprot1 = jprot; end if
108   if jmod = 5; y1label log(^sty^jresp + 1); x1label Condition (^ndcond); end if
109   if jmod >= 5; x1tics on; x1tic labels on; end if
110   if jmod = 1 or jmod = 5; y1tics on; y1tic labels on; end if
111   char 1 2 3 4 5 6 7 8 9 10 11; lines bl
112   let string qsub = subset prot ^jprot
113   plot y cond cond ^qsub
114   .
115   . call write_condition_names_under_horizontal_axis.dp
116   let n = number y ^qsub
117   call overlap_score.dp
118   move 03   95; just left;  hw 2.2 1.1; color blue; text Prot. ^jprot: (^stprot^jprot)
119   move 98.5 95; just right; hw 2.2 1.1; color red;  text ^score; color blue
120   print "----------jprot = ^jprot----------"
121   print scorev1 scorev2
122   print "above jprot = ^jprot   score = ^score"
123   print " "; print " "; print " "
124   . pause
125   . move 01 94; . text n = ^n
126   if jmod = 8
127      multiplot off
128      let jprot2 = jprot
129      call write_factors_and_settings_upper_right.dp
130      call write_conditions_bottom.dp
131      . call check_mark_the_factor_settings.dp
132      let string stcorn3 = Prot
133      let string stcorn4 = ^jprot1-^jprot2
134      call upperleft.dp
135      call annotate.dp
136   end if
137end loop
138multiplot off
139.
140. -----Step 13: For each of the 16 protocol factor settings (8 factors x 2 settings each),  scatter plot vs condition (11)-----
141.
142let dothis13 = 1
143if dothis13 = 1
144let string header2 = What Prot. Factor Setting (8*2 = 16) Best Discriminates/Predicts the 11 Conditions?  Prediction Rules?
145.
146delete qsub
147.
148let string corncol = red
149let count = 0
150loop for jx = 1 1 k
151   loop for jset = -1 2 1
152      let count = count + 1
153      y1label; x1label
154      x1tics off; x1tic labesl off
155      y1tics off; y1tic labels off
156      let jmod = mod(count,8); if jmod = 0; let jmod = 8; end if
157      if jmod = 1; multiplot 2 4; multiplot scale factor 2; delete jx1; let jx1 = jx; end if
158      if jmod = 5; y1label log(^sty^jresp + 1); x1label Condition (^ndcond); end if
159      if jmod >= 5; x1tics on; x1tic labels on; end if
160      if jmod = 1 or jmod = 5; y1tics on; y1tic labels on; end if
161      char 1 2 3 4 5 6 7 8 9 10 11; char color red all; if jset = 1; char color blue all; end if; lines bl
162      let string stout = - (minus); if jset = 1; let string stout = + (plus); end if
163      let string header3 = Scatter Plot Subsetted to a Specific Protocol Factor & Setting
164      let string qsub = subset x^jx ^jset
165      plot y cond cond ^qsub
166      .
167      . call write_condition_names_under_horizontal_axis.dp
168      let n = number y subset x^jx ^jset
169      call overlap_score.dp
170      color red; if jset = 1; color blue; end if
171      move 03   95; just left;  hw 2.2 1.1; text Factor ^jx Setting ^stout; end if
172      move 98.5 95; just right; hw 2.2 1.1; color red;  text ^score; color blue
173      print "----------jx = ^jx    jset = ^jset----------"
174      print scorev1 scorev2
175      print "above jx = ^jx    jset = ^jset   score = ^score"
176      print " "; print " "; print " "
177      . pause
178      . move 16 84; . text n = ^n
179      if jmod = 8
180         multiplot off
181         let jx2 = jx
182         call write_factors_and_settings_upper_right.dp
183         call write_conditions_bottom.dp
184         let string stcorn3 = Factors
185         let string stcorn4 = X^jx1-X^jx2
186         call upperleft.dp
187         call annotate.dp
188      end if
189   end loop
190end loop
191end if;. end of dothis13
192end if;. end of dothis
193.
194. -----Step 99: Finish up-----
195.
196frame corner coordinates 15 20 85 90
197x1tics on; x1tic labels on
198y1tics on; y1tic labels on
199y1label displacement
200x1label displacement
201x2label