Mercurial > repos > greg > ks_distribution
comparison ks_distribution.R @ 60:ae25785e78e1 draft
Uploaded
| author | greg |
|---|---|
| date | Tue, 27 Jun 2017 08:06:19 -0400 |
| parents | 9ca7354c86a1 |
| children | c19c48db9f79 |
comparison
equal
deleted
inserted
replaced
| 59:c5fb4e2ed4e2 | 60:ae25785e78e1 |
|---|---|
| 5 option_list <- list( | 5 option_list <- list( |
| 6 make_option(c("-c", "--components_input"), action="store", dest="components_input", help="Ks significant components input dataset"), | 6 make_option(c("-c", "--components_input"), action="store", dest="components_input", help="Ks significant components input dataset"), |
| 7 make_option(c("-k", "--kaks_input"), action="store", dest="kaks_input", help="KaKs analysis input dataset"), | 7 make_option(c("-k", "--kaks_input"), action="store", dest="kaks_input", help="KaKs analysis input dataset"), |
| 8 make_option(c("-n", "--number_comp"), action="store", dest="number_comp", type="integer", help="Number of significant components in the Ks distribution"), | 8 make_option(c("-n", "--number_comp"), action="store", dest="number_comp", type="integer", help="Number of significant components in the Ks distribution"), |
| 9 make_option(c("-o", "--output"), action="store", dest="output", help="Output dataset"), | 9 make_option(c("-o", "--output"), action="store", dest="output", help="Output dataset"), |
| 10 make_option(c("-r", "--colors"), action="store", dest="colors", default=NA, help="List of component colors") | 10 make_option(c("-s", "--specified_colors"), action="store", dest="specified_colors", default=NA, help="List of component colors") |
| 11 ) | 11 ) |
| 12 | 12 |
| 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.na(colors) == 0) { | 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() |
| 50 return(component_colors) | 50 return(component_colors) |
| 51 } | 51 } |
| 52 | 52 |
| 53 get_pi_mu_var = function(components_data, number_comp) | 53 get_pi_mu_var = function(components_data, number_comp) |
| 54 { | 54 { |
| 55 # FixMe: enhance this to generically handle any integer value for number_comp. | |
| 56 if (number_comp == 1) { | 55 if (number_comp == 1) { |
| 57 pi <- c(components_data[1, 9]) | 56 pi <- c(components_data[1, 9]) |
| 58 mu <- c(components_data[1, 7]) | 57 mu <- c(components_data[1, 7]) |
| 59 var <- c(components_data[1, 8]) | 58 var <- c(components_data[1, 8]) |
| 60 } else if (number_comp == 2) { | 59 } else if (number_comp == 2) { |
| 134 # Read in the components data. | 133 # Read in the components data. |
| 135 components_data <- read.delim(opt$components_input, header=TRUE) | 134 components_data <- read.delim(opt$components_input, header=TRUE) |
| 136 number_comp <- as.integer(opt$number_comp) | 135 number_comp <- as.integer(opt$number_comp) |
| 137 | 136 |
| 138 # Set component colors. | 137 # Set component colors. |
| 139 component_colors <- set_component_colors(opt$colors, number_comp) | 138 component_colors <- set_component_colors(opt$specified_colors, number_comp) |
| 140 | 139 |
| 141 # Set pi, mu, var. | 140 # Set pi, mu, var. |
| 142 items <- get_pi_mu_var(components_data, number_comp) | 141 items <- get_pi_mu_var(components_data, number_comp) |
| 143 if (number_comp == 1) { | 142 if (number_comp == 1) { |
| 144 pi <- items[1] | 143 pi <- items[1] |
