import sys import rpy from pylab import gca, figure, subplot from scipy import * from lpls import * import rpy_go sys.path.append("../../fluents") # home of dataset sys.path.append("../../fluents/lib") # home of cx_stats import dataset import cx_stats from plots_lpls import plot_corrloads ######## DATA ########## use_data='uma' if use_data=='smoker': # full smoker data DX = dataset.read_ftsv(open("../../data/smokers-full/Smokers.ftsv")) DY = dataset.read_ftsv(open("../../data/smokers-full/Yg.ftsv")) Y = DY.asarray().astype('d') gene_ids = DX.get_identifiers('gene_ids', sorted=True) elif use_data=='scherf': DX = dataset.read_ftsv(open("../../data/scherf/Scherf.ftsv")) DY = dataset.read_ftsv(open("../../data/scherf/Yd.ftsv")) Y = DY.asarray().astype('d') gene_ids = DX.get_identifiers('gene_ids', sorted=True) elif use_data=='staunton': pass elif use_data=='uma': DX = dataset.read_ftsv(open("../../data/uma/X133.ftsv")) DY = dataset.read_ftsv(open("../../data/uma/Yg133.ftsv")) Y = DY.asarray().astype('d') gene_ids = DX.get_identifiers('gene_ids', sorted=True) # Use only subset defined on GO ontology = 'BP' print "\n\nFiltering genes by Go terms " gene2goterms = rpy_go.goterms_from_gene(gene_ids) all_terms = set() for t in gene2goterms.values(): all_terms.update(t) terms = list(all_terms) print "\nNumber of go-terms: %s" %len(terms) # update genelist gene_ids = gene2goterms.keys() print "\nNumber of genes: %s" %len(gene_ids) # use subset based on SAM or IQR subset = 'm' if subset=='sam': # select subset genes by SAM rpy.r.library("siggenes") rpy.r.library("qvalue") data = DX.asarray().T # data = data[:100,:] rpy.r.assign("data", data) cl = dot(DY.asarray(), diag([1,2,3])).sum(1) rpy.r.assign("cl", cl) rpy.r.assign("B", 20) # Perform a SAM analysis. print "Starting SAM" sam = rpy.r('sam.out<-sam(data=data,cl=cl,B=B,rand=123)') print "SAM done" # Compute the q-values of the genes. qq = rpy.r('qobj<-qvalue(sam.out@p.value)') qvals = asarray(qq['qvalues']) # cut off cutoff = 0.001 index = where(qvals