Mercurial > repos > greg > ks_distribution
comparison ks_distribution.R @ 62:a9c1203d5eb6 draft
Uploaded
author | greg |
---|---|
date | Tue, 27 Jun 2017 09:02:48 -0400 |
parents | c19c48db9f79 |
children | b7468c75c4a5 |
comparison
equal
deleted
inserted
replaced
61:c19c48db9f79 | 62:a9c1203d5eb6 |
---|---|
13 parser <- OptionParser(usage="%prog [options] file", option_list=option_list) | 13 parser <- OptionParser(usage="%prog [options] file", option_list=option_list) |
14 args <- parse_args(parser, positional_arguments=TRUE) | 14 args <- parse_args(parser, positional_arguments=TRUE) |
15 opt <- args$options | 15 opt <- args$options |
16 | 16 |
17 set_component_colors = function(colors, number_comp) | 17 set_component_colors = function(colors, number_comp) |
18 { | 18 { |
19 # Handle colors for components. | 19 # Handle colors for components. |
20 if (is.null(colors)) { | 20 if (is.na(colors)) { |
21 # Randomly specify colors for components. | 21 # Randomly specify colors for components. |
22 component_colors <- c('red', 'yellow', 'green', 'black', 'blue', 'darkorange') | 22 component_colors <- c("red", "yellow", "green", "black", "blue", "darkorange") |
23 } else { | 23 } else { |
24 # Handle selected colors for components. | 24 # Handle selected colors for components. |
25 component_colors <- c() | 25 component_colors <- c() |
26 colors <- as.character(colors) | 26 colors <- as.character(colors) |
27 items <- strsplit(colors, ",") | 27 items <- strsplit(colors, ",") |
28 for (item in items) { | 28 for (item in items) { |
29 component_colors <- c(component_colors, item) | 29 component_colors <- c(component_colors, item) |
30 } | 30 } |
31 num_colors_specified <- length(component_colors) | 31 num_colors_specified <- length(component_colors) |
32 if (num_colors_specified < number_comp) { | 32 if (num_colors_specified < number_comp) { |
33 for (i in num_colors_specified:number_comp) { | 33 # The number of selected colors is less than the number of |
34 if (!('red' %in% names(component_colors))) { | 34 # components, so we'll add random colors that were not |
35 component_colors <- c(component_colors, 'red') | 35 # selected to the set of component colors until we have a |
36 } else if (!('yellow' %in% names(component_colors))) { | 36 # color for each component. |
37 component_colors <- c(component_colors, 'yellow') | 37 loop_count <- number_comp - num_colors_specified |
38 } else if (!('green' %in% names(component_colors))) { | 38 for (i in 1:loop_count) { |
39 component_colors <- c(component_colors, 'green') | 39 if (!(is.element("red", component_colors))) { |
40 } else if (!('black' %in% names(component_colors))) { | 40 component_colors <- c(component_colors, "red") |
41 component_colors <- c(component_colors, 'black') | 41 } else if (!(is.element("yellow", component_colors))) { |
42 } else if (!('blue' %in% names(component_colors))) { | 42 component_colors <- c(component_colors, "yellow") |
43 component_colors <- c(component_colors, 'blue') | 43 } else if (!(is.element("green", component_colors))) { |
44 } else { | 44 component_colors <- c(component_colors, "green") |
45 component_colors <- c(component_colors, 'darkorange') | 45 } else if (!(is.element("black", component_colors))) { |
46 component_colors <- c(component_colors, "black") | |
47 } else if (!(is.element("blue", component_colors))) { | |
48 component_colors <- c(component_colors, "blue") | |
49 } else if (!(is.element("darkorange", component_colors))) { | |
50 component_colors <- c(component_colors, "darkorange") | |
46 } | 51 } |
47 } | 52 } |
48 } | 53 } |
49 } | 54 } |
50 return(component_colors) | 55 return(component_colors) |
138 component_colors <- set_component_colors(opt$specified_colors, number_comp) | 143 component_colors <- set_component_colors(opt$specified_colors, number_comp) |
139 | 144 |
140 # Set pi, mu, var. | 145 # Set pi, mu, var. |
141 items <- get_pi_mu_var(components_data, number_comp) | 146 items <- get_pi_mu_var(components_data, number_comp) |
142 if (number_comp == 1) { | 147 if (number_comp == 1) { |
143 pi <- items[1] | 148 pi <- items[1] |
144 mu <- items[2] | 149 mu <- items[2] |
145 var <- items[3] | 150 var <- items[3] |
146 } else if (number_comp == 2) { | 151 } else if (number_comp == 2) { |
147 pi <- items[1:2] | 152 pi <- items[1:2] |
148 mu <- items[3:4] | 153 mu <- items[3:4] |
149 var <- items[5:6] | 154 var <- items[5:6] |
150 } else if (number_comp == 3) { | 155 } else if (number_comp == 3) { |
151 pi <- items[1:3] | 156 pi <- items[1:3] |
152 mu <- items[4:6] | 157 mu <- items[4:6] |
153 var <- items[7:9] | 158 var <- items[7:9] |
154 } else if (number_comp == 4) { | 159 } else if (number_comp == 4) { |
155 pi <- items[1:4] | 160 pi <- items[1:4] |
156 mu <- items[5:8] | 161 mu <- items[5:8] |
157 var <- items[9:12] | 162 var <- items[9:12] |
158 } else if (number_comp == 5) { | 163 } else if (number_comp == 5) { |
159 pi <- items[1:5] | 164 pi <- items[1:5] |
160 mu <- items[6:10] | 165 mu <- items[6:10] |
161 var <- items[11:15] | 166 var <- items[11:15] |
162 } else if (number_comp == 6) { | 167 } else if (number_comp == 6) { |
163 pi <- items[1:6] | 168 pi <- items[1:6] |
164 mu <- items[7:12] | 169 mu <- items[7:12] |
165 var <- items[13:18] | 170 var <- items[13:18] |
166 } | 171 } |
167 | 172 |
168 # Plot the output. | 173 # Plot the output. |
169 plot_ks(opt$kaks_input, number_comp, component_colors, opt$output, pi, mu, var) | 174 plot_ks(opt$kaks_input, number_comp, component_colors, opt$output, pi, mu, var) |