<commit_before>create_colors <- function(file_name, color_mode = "auto"){
# scripts to generate color vectors for PCoA --
# input is tab delimited table - rows are samples, columns correspond to metadata to color by
# auto will generate colors from any arbitrary numbers or text
# color_mode set to anything other than "auto" will try to use the text in the table
# as colors.
# output of this script is a table hard coded as my_data.color
# use column referencing of this table to color PCoA e.g.:
# pco(my_data,col=my_data.color[,1],comp=c(1,2),labels="",main="")
# BE SURE TO CHECK THAT ORDER OF COLORS IS SAME AS DATA e.g.:
# create_colors("test_colors.txt")  
# my_data.color <- my_data.color[ colnames(my_data), ]
#
#
#  
## Example
# data_location	/Users/kevin/Documents/Projects/Stuff_for_Others/Dion/tax_filtering_func.Oct_2013
## data_file			dion_SS_data.tax_filtered.terminal_annotation_only.txt
## colors_file		test_colors.txt

## # go to the directory with the data
## setwd("/Users/kevin/Documents/Projects/Stuff_for_Others/Dion/tax_filtering_func.Oct_2013")

## # import the data
## my_data <- data.matrix(read.table("dion_SS_data.tax_filtered.terminal_annotation_only.txt", row.names=1, header=TRUE, sep="\t", comment.char="", quote="", check.names=FALSE))

## # import the script to generate the colors
## source("~/bin/create_colors2.r")

## # generate the colors matrix
## create_colors("test_colors.txt")

## # make sure that colors are in the same order as the data # VERY IMPORTANT
## my_data.color <- my_data.color[ colnames(my_data), ]

## # Generate pcoa colored by first column in colors matrix
## pco(my_data,col=my_data.color[,1],comp=c(1,2),labels="",main="")
## pco(my_data,color=my_data.color[,1]=c(1,2,3),labels="",main="")


## # had to do this - matR pco would not work for some reason
## plot_pcoa.from_object(my_data, colors=my_data.color[,2])

  
# SUBS
############################################################################
# Color methods https://stat.ethz.ch/pipermail/r-help/2002-May/022037.html
############################################################################
# The inverse function to col2rgb()
  col.wheel <- function(num_col, my_cex=0.75) {
    cols <- rainbow(num_col)
    col_names <- vector(mode="list", length=num_col) 
    for (i in 1:num_col){
      col_names[i] <- getColorTable(cols[i])
    }
    # pie(rep(1, length(cols)), labels=col_names, col=cols, cex=my_cex) }
    cols
  }
  
  
  
  # The inverse function to col2rgb()
  rgb2col <- function(rgb) {
    rgb <- as.integer(rgb)
    class(rgb) <- "hexmode"
    rgb <- as.character(rgb)
    rgb <- matrix(rgb, nrow=3)
    paste("#", apply(rgb, MARGIN=2, FUN=paste, collapse=""), sep="")
  }

  # Convert all colors into format "#rrggbb"
  getColorTable <- function(col) {
    rgb <- col2rgb(col);
    col <- rgb2col(rgb);
    sort(unique(col))
  }
  
# MAIN  
############################################################################  
  my_data <- read.table(file_name, header=TRUE, stringsAsFactors=FALSE )
  
  my_data.color <<- my_data
  <commit_msg>edit color script<commit_after>create_colors <- function(file_name, color_mode = "auto"){
# scripts to generate color vectors for PCoA --
# input is tab delimited table - rows are samples, columns correspond to metadata to color by
# auto will generate colors from any arbitrary numbers or text
# color_mode set to anything other than "auto" will try to use the text in the table
# as colors.
# output of this script is a table hard coded as my_data.color
# use column referencing of this table to color PCoA e.g.:
# pco(my_data,col=my_data.color[,1],comp=c(1,2),labels="",main="")
# BE SURE TO CHECK THAT ORDER OF COLORS IS SAME AS DATA e.g.:
# create_colors("test_colors.txt")  
# my_data.color <- my_data.color[ colnames(my_data), ]
#
#
#  
## Example
# data_location	/Users/kevin/Documents/Projects/Stuff_for_Others/Dion/tax_filtering_func.Oct_2013
## data_file			dion_SS_data.tax_filtered.terminal_annotation_only.txt
## colors_file		test_colors.txt

## # go to the directory with the data
## setwd("/Users/kevin/Documents/Projects/Stuff_for_Others/Dion/tax_filtering_func.Oct_2013")

## # import the data
## my_data <- data.matrix(read.table("dion_SS_data.tax_filtered.terminal_annotation_only.txt", row.names=1, header=TRUE, sep="\t", comment.char="", quote="", check.names=FALSE))

## # import the script to generate the colors
## source("~/bin/create_colors2.r")

## # generate the colors matrix
## create_colors("test_colors.txt")

## # make sure that colors are in the same order as the data # VERY IMPORTANT
## my_data.color <- my_data.color[ colnames(my_data), ]

## # Generate pcoa colored by first column in colors matrix
## pco(my_data,col=my_data.color[,1],comp=c(1,2),labels="",main="")
## pco(my_data,color=my_data.color[,1]=c(1,2,3),labels="",main="")


## # had to do this - matR pco would not work for some reason
## plot_pcoa.from_object(my_data, colors=my_data.color[,2])

  
# SUBS
############################################################################
# Color methods https://stat.ethz.ch/pipermail/r-help/2002-May/022037.html
############################################################################
# The inverse function to col2rgb()
  col.wheel <- function(num_col, my_cex=0.75) {
    cols <- rainbow(num_col)
    col_names <- vector(mode="list", length=num_col) 
    for (i in 1:num_col){
      col_names[i] <- getColorTable(cols[i])
    }
    # pie(rep(1, length(cols)), labels=col_names, col=cols, cex=my_cex) }
    cols
  }
  
  
  
  # The inverse function to col2rgb()
  rgb2col <- function(rgb) {
    rgb <- as.integer(rgb)
    class(rgb) <- "hexmode"
    rgb <- as.character(rgb)
    rgb <- matrix(rgb, nrow=3)
    paste("#", apply(rgb, MARGIN=2, FUN=paste, collapse=""), sep="")
  }

  # Convert all colors into format "#rrggbb"
  getColorTable <- function(col) {
    rgb <- col2rgb(col);
    col <- rgb2col(rgb);
    sort(unique(col))
  }
  
# MAIN  
############################################################################  
  my_data <- read.table(file_name, header=TRUE, stringsAsFactors=FALSE, sep="\t", comment.char="", quote="", check.names=FALSE )
  
  my_data.color <<- my_data
  
{'fraction_non_alphanumeric': 0.2078109932497589, 'fraction_numerical': 0.013821922211507553, 'mean_word_length': 4.698717948717949, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4918830', 'n_tokens_mistral': 2200, 'n_tokens_neox': 2044, 'n_words': 496}