Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
114 lines (85 sloc) 4.69 KB
title author date output
Make Timeseries Heatmaps
Russ Poldrack
November 1, 2014
html_document

Timeseries heatmap figures for the MyConnectome dataset

Code available at: https://github.com/poldrack/myconnectome/blob/master/myconnectome/timeseries/Make_Timeseries_Heatmaps.Rmd

basedir=Sys.getenv('MYCONNECTOME_DIR')
save_files=FALSE

library(gplots)

behav=load_behav_data()
wincorr=load_fmri_data('wincorr')
netdata=load_network_data()
xvars=c('panas.positive','panas.negative','panas.fatigue','afterscan.Anxietyduringscan','afterscan.diastolic','afterscan.pulse','afterscan.systolic','morning.Sleepquality','morning.Soreness','prevevening.Alcohol','prevevening.Guthealth','prevevening.Psoriasisseverity','prevevening.Stress', 'prevevening.Timespentoutdoors','temp.mean',"email.LIWCcdi","email.LIWCnegemo","email.LIWCposemo",'zeo.zq')


behav_keep=subset(behav,select=c(xvars,'date'))
behav_keep$FedFasted=behav$TuesThurs
behav_keep$FedFasted[is.na(behav_keep$FedFasted)]=1

behav_names=c('positive mood','negative mood','fatigue','anxiety during scan','diastolic BP','pulse','systolic BP','sleep quality (rating)','soreness','alcohol intake','gut health','psoriasis severity','stress','time outdoors','mean outdoor temperature','email: categorical-dynamic index','email: negative emotion','email:positive emotion','sleep (ZEO ZQ)','fed vs. fasted')

Heatmap for behavioral data

behav_dates=c(format(behav$date[1],'%Y-%m'))
anchor=behav$date[1]
for (i in 2:length(behav$date)) {
  if (months(behav$date[i]) != months(anchor) && behav_dates[i-1]=='') {
		behav_dates[i]=format(behav$date[i],'%Y-%m')
		anchor=behav$date[i]
		} else {
			behav_dates[i]=''
		}
	}
b=subset(behav_keep,select=-c(date))

xmar=10
ymar=16

heatmap.2(t(as.matrix(b)),trace='row',scale='row',margins=c(xmar,ymar),dendrogram='row',Colv=FALSE,na.rm=TRUE,na.color='gray',tracecol='black',linecol=FALSE,labRow=behav_names,labCol=behav_dates)

if (save_files) {
  pdf(file=sprintf('%s/timeseries/behav_heatmap.pdf',basedir),width=16,height=10)
  heatmap.2(t(as.matrix(b)),trace='row',scale='row',margins=c(10,16),dendrogram='row',Colv=FALSE,na.rm=TRUE,na.color='gray',tracecol='black',linecol=FALSE,labRow=behav_names,labCol=behav_dates)
  dev.off()
}

Heatmap for within-network connectivity

w=subset(wincorr,select=-c(date))
wincorr_names=c('default mode','second visual','fronto-parietal','first visual','dorsal attention','ventral attention','salience','cingulo-opercular','somatomotor','fronto-parietal-2','medial parietal','parieto-occipital')

scan_dates=c(format(wincorr$date[1],'%Y-%m'))
anchor=wincorr$date[1]
for (i in 2:length(wincorr $date)) {
  if (months(wincorr$date[i]) != months(anchor) && scan_dates[i-1]=='') {
		scan_dates[i]=format(wincorr$date[i],'%Y-%m')
		anchor= wincorr$date[i]
		} else {
			scan_dates[i]=''
		}
	}

heatmap.2(t(as.matrix(w)),trace='row',scale='row',margins=c(xmar,ymar),dendrogram='row',Colv=FALSE,na.rm=TRUE,na.color='gray',tracecol='black',linecol=FALSE,labRow=wincorr_names,labCol=scan_dates,key=FALSE)

if (save_files) {
  pdf(file=sprintf('%s/timeseries/wincorr_heatmap.pdf',basedir),width=16,height=10)
  heatmap.2(t(as.matrix(w)),trace='row',scale='row',margins=c(10,16),dendrogram='row',Colv=FALSE,na.rm=TRUE,na.color='gray',tracecol='black',linecol=FALSE,labRow=wincorr_names,labCol=scan_dates,key=FALSE)
  dev.off()
}

Heatmap for WGCNA gene expression modules

rnaseq_wgcna=load_rnaseq_data(limit_ME_to_enriched=TRUE)
rna=subset(rnaseq_wgcna,select=-c(date))
draw_dates=c(format(rnaseq_wgcna$date[1],'%Y-%m'))
anchor= rnaseq_wgcna$date[1]
for (i in 2:length(rnaseq_wgcna$date)) {
	if (months(rnaseq_wgcna$date[i]) != months(anchor) && draw_dates[i-1]=='') {
		draw_dates[i]=format(rnaseq_wgcna$date[i],'%Y-%m')
		anchor= rnaseq_wgcna$date[i]
		} else {
			draw_dates[i]=''
		}
	}

heatmap.2(t(as.matrix(rna)),trace='row',scale='row',margins=c(xmar,ymar),dendrogram='row',Colv=FALSE,na.rm=TRUE,na.color='gray',tracecol='black',linecol=FALSE,labRow=names(rna),labCol=draw_dates,key=FALSE)

if (save_files) {
  pdf(file=sprintf('%s/timeseries/wgcna_heatmap.pdf',basedir),width=16,height=10)
  heatmap.2(t(as.matrix(rna)),trace='row',scale='row',margins=c(10,16),dendrogram='row',Colv=FALSE,na.rm=TRUE,na.color='gray',tracecol='black',linecol=FALSE,labRow=names(rna),labCol=draw_dates,key=FALSE)

  dev.off()
}