R/read.gaf.R

Defines functions read.gaf

Documented in read.gaf

#Author: Minghui Wang
read.gaf=function(filename='http://geneontology.org/gene-associations/gene_association.mgi.gz'){
#ftp://ftp.informatics.jax.org/pub/reports/gene_association.mgi
	down=FALSE
	if(grepl('^ftp:\\/\\/',filename) || grepl('^http:\\/\\/',filename)){
		temp <- tempfile()
        code=download.file(filename,temp)
		if(code != 0) stop(paste('Fail to download',filename))
		inf=temp
		down=TRUE
	}else{
		if(! file.exists(filename)) stop('File ',filename,' not available\n')
		inf=filename
	}
	if(grepl('\\.gz$',filename)){
		conn=gzfile(inf,'r')
	}else{
		conn=file(inf,'r')
	}
	dat=read.delim(conn,sep='\t',as.is=TRUE,header=FALSE,quote="",comment.char='!')[,c(2,3,5)]
	close(conn)
	if(down) unlink(temp)
	colnames(dat)=c('ID','Symbol','GO.ID')
	unique(dat)
}
mw201608/msigdb documentation built on Aug. 13, 2021, 10:42 p.m.