hipA.pvals=read.delim(file="new_out/modA_hip.matrix.tsv", header=T, row.names=1); #get rid of the extra column: (a column called "X" gets added to the dataframe (because of a tab at the end of each line in the input file)) hipA.pvals = subset(hipA.pvals, select=-c(X)) save(hipA.pvals, file="results/pval.matrices/A/hipA.pvals.RData") livA.pvals=read.delim(file="new_out/modA_liv.matrix.tsv", header=T, row.names=1); livA.pvals = subset(livA.pvals, select=-c(X)) save(livA.pvals, file="results/pval.matrices/A/livA.pvals.RData") lunA.pvals=read.delim(file="new_out/modA_lun.matrix.tsv", header=T, row.names=1); lunA.pvals = subset(lunA.pvals, select=-c(X)) save(lunA.pvals, file="results/pval.matrices/A/lunA.pvals.RData") go2name <- read.delim(file='lib/GO2name.txt', sep='\t') hip.genes.pvals=read.delim(file="new_out/modA_hip.pval_0.001andBelow.i10000.txt", header=T) head(hip.genes.pvals) unique(hip.genes.pvals$module) unique(hip.genes.pvals$phenotype) getLowPvals <- function(pvalues, thr){ values=pvalues[pvalues< thr] phenotypes=colnames(pvalues)[col(pvalues)[pvalues< thr]] modules=rownames(pvalues)[row(pvalues)[pvalues< thr]] d=data.frame(pval=values, phenos=phenotypes, module=modules) return(d) } hip.lowpvals=getLowPvals(hipA.pvals, 0.001) #GO ANALYSIS M=read.table("../go_analysis/modA_hip_mod_genes.mat", header=T); load("GOM.RData") hipA.pval.go=matrix(NA, nrow=dim(GOM)[2],ncol=dim(M)[2]) colnames(hipA.pval.go)=colnames(M) rownames(hipA.pval.go)=colnames(GOM) fisher.func <- function(X, genes){ X <- as.factor(X); if (nlevels(X) == 2){ f<-fisher.test(X,genes); return(f$p.value) } else return(1) } for(i in 1: dim(M)[2]){ col=M[,i] hipA.pval.go[,i]=unlist(apply(X=GOM,FUN=fisher.func, MARGIN=2,col)) } save(hipA.pval.go, "/data/www/go_analysis/hipA.pval.go.RData") load("../go_analysis/hipA.pval.go.RData") go2name <- read.delim(file='../go_analysis/GO2name.txt', sep='\t') getLowPvals <- function(pvalues, go2name, thr){ values=pvalues[pvalues< thr] goterms=rownames(pvalues)[row(pvalues)[pvalues< thr]] modules=colnames(pvalues)[col(pvalues)[pvalues< thr]] matches=match(goterms, go2name[,1]) d=data.frame(pval=values, goterm=goterms, module=modules,desc=go2name[matches,2]) return(d) } cutoff=0.001; hip.lowpvals=getLowPvals(hipA.pval.go, go2name, cutoff) head(hip.lowpvals) hip.lowpvals.ordered=hip.lowpvals[order(hip.lowpvals$pval),] head(hip.lowpvals.ordered)