Unsupervised heatmap analysis based on combinatorial chromatin states from whole crypts in fed vs fasted mice

Christopher Terranova May 2019 based on code from Ayush Raman

Load necessary programs

library(circlize)
library(ComplexHeatmap)
library(pheatmap)
library(dplyr)
library(gplots)
library(ggplot2)
library(genefilter)
library(RColorBrewer)
library(reshape2)
library(vegan)

Identification of most variable chromatin state regions

# set working directory to combined matrix state file from chromStatesMatrixforClustering_particularStates.pl outputsummary
  setwd("~/Desktop/KS_SMINT_ChromXR/")

# set chromatin state for analysis -- can be changed for each chromatin state
  i = 3

# read in combined matrix state file from chromStatesMatrixforClustering_particularStates.pl output
dat <- read.table(paste("CombinedMatrix-",i,"-10000bps.txt",sep =""),header = FALSE,sep = "\t",quote = "",
                    row.names = 1, na.strings = FALSE, stringsAsFactors = FALSE)
  colnames(dat) <- c("NMRL-10F1-1","NMRL-11F4-1","NMRL-10S2-1","NMRL-11S5-1")
  
# sample type labels for plot
  condition.type <- factor(c(rep("FED",2), rep("FASTED",2)))
  
# filtering low variable regions
  dat.state1 <- varFilter(as.matrix(dat), var.cutoff = 0.9)
  print(dim(dat.state1))
## [1] 700   4
# Annotation Data frame
  df1 <- data.frame(Condition = condition.type)
  mut.gene.cols <- brewer.pal(7, "Accent")[5:6]
  condition.cols.assigned <- setNames(mut.gene.cols, unique(levels(df1$Condition)))
  annot1 <- HeatmapAnnotation(df = df1, col = list(Condition = condition.cols.assigned))

Heatmap based on active chromatin state in fed vs fasted mice

print(Heatmap(log2(dat.state1+1), name = "Frequency", show_row_names = FALSE, show_column_names = TRUE,
                 row_dend_reorder = FALSE, column_dend_reorder = TRUE, clustering_distance_rows = "pearson",
                 clustering_distance_columns = "euclidean", clustering_method_rows = "complete",
                 clustering_method_columns = "complete", top_annotation = annot1))

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.