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/scherfX.ftsv")) DY = dataset.read_ftsv(open("../../data/scherf/scherfY.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")) DYg = dataset.read_ftsv(open("../../data/uma/Yg133.ftsv")) DY = dataset.read_ftsv(open("../../data/uma/Yd.ftsv")) Y = DY.asarray().astype('d') gene_ids = DX.get_identifiers('gene_ids', sorted=True) # use subset with defined 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) X = DX.asarray() index = DX.get_indices('gene_ids', gene_ids) X = X[:,index] 1/0 # Use only subset defined on GO ontology = 'BP' print "\n\nFiltering genes by Go terms " # use subset based on SAM or IQR subset = 'not' if subset=='sam': # select subset genes by SAM rpy.r.library("siggenes") rpy.r.library("qvalue") rpy.r.assign("data", X.T) cl = dot(DY.asarray(), diag(arange(Y.shape[1])+1)).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.01 index = where(qvals