title: "Cleaning the DGE Data" author: "Eric Kernfeld" date: "September 7, 2016" output: html_document


Setup

This chunk sets up the file system and some functions to retrieve reference tables. It also loads in some useful packages and sets up a few hand-picked color schemes.

.onLoad <- function(libname, pkgname) {
  data("ALL_TCR_GENES", 
       package=pkgname, envir=parent.env(environment()))
}

PATH_TO_TABLES = file.path( "tables" ) 

#' @import Seurat 
#' @import ggplot2 
#' @import magrittr

#' @export
if( packageVersion("ggplot2") < "2.2.1.9000" ) { 
  warning("You may need the development version of ggplot2 if you want the 
          `overplot_adjust=T` option in `custom_feature_plot` to work.")
}

#' @export
get_rene_markers = function(){
  markers_df = read.csv( file.path( PATH_TO_TABLES, "cell_type_markers.csv" ), stringsAsFactors = T )
  if( !all( markers_df$marker == Capitalize( markers_df$marker ) ) ){
    warning( paste0( "Not all genes in ", 
                     file.path( PATH_TO_TABLES, "cell_type_markers.csv" ), 
                     " are Capital Case." ) )
  }
  return( markers_df )
}

#' @export
get_ramilowski = function(){
  ramilowski = read.table( file.path( PATH_TO_TABLES, "LigandReceptor_Ramilowski2015_mouse.txt" ), 
                         header = T, sep="\t", stringsAsFactors = F )
  return( ramilowski )
}

#' @export
get_macosko_cc_genes = function( case = "Capital" ){
  cc_genes = read.csv( file.path( PATH_TO_TABLES, "Macosko_cell_cycle_genes.txt" ), 
                       sep = "", header = T, stringsAsFactors=FALSE )
  colnames_temp = colnames( cc_genes )
  if( case == "Capital" ){
    cc_genes = apply( cc_genes, MARGIN = 2, FUN = Capitalize )
  } else if ( case == "UPPER" ) {
    cc_genes = apply( cc_genes, MARGIN = 2, FUN = toupper )
  }
  colnames( cc_genes ) = colnames_temp
  return ( cc_genes )
}

#' @export
get_mouse_tfs = function( capitalization = "all" ){
  mouse_tfs = read.table( file.path( PATH_TO_TABLES, "mouse_tfs.txt" ), header = T )$symbol %>% as.character
  if( capitalization == "all" ){
    mouse_tfs = c( mouse_tfs, Capitalize( mouse_tfs ), toupper( mouse_tfs ) )
  } else if( capitalization == "UPPER" ){
    mouse_tfs =  toupper( mouse_tfs )
  } else if( capitalization == "Capitalized" ){
    mouse_tfs = Capitalize( mouse_tfs )
  } else if( capitalization == "unchanged" ){
    # don't change it!
  }
  return( mouse_tfs )
}

#' @export
get_poised_genes = function(){
  x = read.table( file.path( PATH_TO_TABLES, "Lesch2016_NatGen_PoisedGenes.txt" ), 
                  header = T, stringsAsFactors = F )
  return( x[["mouse_gene_symbol"]] )
}

#' @export
get_ortholog_table = function(){
  ortholog_table_path = file.path( PATH_TO_TABLES, "mousegene_matchedHumanOrth.txt" )
  if( !file.exists( ortholog_table_path ) ){
    stop( "Please put a table of human-mouse orthologs at PATH_TO_TABLES/mousegene_matchedHumanOrth.csv. It should be a CSV file with columns named `mousesym` and `humansym` containing mouse and human gene symbols. ")
  }
  return( read.csv( ortholog_table_path, header = T, stringsAsFactors = F ) )
}


CC_PHASES = c("IG1.S", "S", "G2.M", "M", "M.G1")
blue_gray_red  = colorspace::diverge_hcl   ( 30,          c = 180,          l = c( 40, 80  ) )
Thanksgiving_colors = c("yellow", "orange", "red", "brown")


maehrlab/thymusatlastools documentation built on May 28, 2019, 2:32 a.m.