changeset 85:9b43f5773db9 draft

Uploaded
author greg
date Fri, 05 Jan 2018 08:28:51 -0500
parents daeba7e9dd11
children 3e19f09ca68d
files ideas_genome_tracks.R
diffstat 1 files changed, 31 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/ideas_genome_tracks.R	Thu Jan 04 14:44:47 2018 -0500
+++ b/ideas_genome_tracks.R	Fri Jan 05 08:28:51 2018 -0500
@@ -109,41 +109,42 @@
     s_indexes = c();
     s_names = c();
     s_colors = c();
-    if (is.null(state_indexes)) {
-        # Generate state colors automatically.
-        index = 0;
-        para_files = list.files(path=input_dir_para, full.names=TRUE);
-        for (para_file in para_files) {
-            data_frame = read.table(para_file, comment="!", header=T);
-            color_hex_code = create_heatmap(data_frame);
-            s_indexes = c(s_indexes, index);
-            s_names = c(s_names, toString(index));
-            s_colors = c(s_colors, color_hex_code);
-        }
-    } else {
-        # Split state_indexes into a list of integers.
+    # Generate the default state colors.
+    index = 0;
+    para_files = list.files(path=input_dir_para, full.names=TRUE);
+    for (para_file in para_files) {
+        data_frame = read.table(para_file, comment="!", header=T);
+        color_hex_code = create_heatmap(data_frame);
+        s_indexes = c(s_indexes, index);
+        s_names = c(s_names, toString(index));
+        s_colors = c(s_colors, color_hex_code);
+        index = index + 1;
+    }
+    if (!is.null(state_indexes)) {
+        # Replace default name with specified name and default
+        # color with specified color for each selected state.
+        # Split state_indexes into a list of strings.
         index_str = as.character(state_indexes);
-        items = strsplit(index_str, ",")
-        for (item in items) {
-            s_indexes = c(s_indexes, as.integer(item));
-        }
+        state_index_items = strsplit(index_str, ",");
         # Split state_names into a list of strings.
         name_str = as.character(state_names);
-        items = strsplit(name_str, ",");
-        item_index = 0;
-        for (item in items) {
-            item_index = item_index + 1;
-            # Handle the special string "use state index".
-            if (identical(item, "use state index")) {
-                item = s_indexes[item_index];
-            }
-            s_names = c(s_names, item);
-        }
+        state_name_items = strsplit(name_str, ",");
         # Split state_colors into a list of strings.
         color_str = as.character(state_colors);
-        items = strsplit(color_str, ",");
-        for (item in items) {
-            s_colors = c(s_colors, item);
+        state_color_items = strsplit(color_str, ",");
+        # Replace default names and colors.
+        specified_item_index = 1;
+        for (state_index_item in state_index_items) {
+            specified_index = as.integer(state_index_item);
+            # Replace default name with specified name.
+            specified_name = state_name_items[specified_item_index];
+            # Handle the special string "use state index".
+            if (identical(specified_name, "use state index")) {
+                specified_name = state_index_item;
+            }
+            s_names[specified_index] = specified_name;
+            # Replace default color with specified color.
+            s_colors[specified_index] = state_color_items[specified_item_index];
         }
     }
     base_track_file_name <- paste(tracks_dir, hub_name, sep="");