ups
This commit is contained in:
@@ -23,7 +23,7 @@ data = DX.asarray().T
|
||||
rpy.r.assign("data", data)
|
||||
cl = dot(DY.asarray(), diag([1,2,3])).sum(1)
|
||||
rpy.r.assign("cl", cl)
|
||||
rpy.r.assign("B", 100)
|
||||
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)')
|
||||
@@ -32,63 +32,74 @@ print "SAM done"
|
||||
qq = rpy.r('qobj<-qvalue(sam.out@p.value)')
|
||||
qvals = asarray(qq['qvalues'])
|
||||
# cut off
|
||||
co = 0.001
|
||||
index = where(qvals<0.01)[0]
|
||||
cutoff = 2
|
||||
index = where(qvals<cutoff)[0]
|
||||
|
||||
# Subset data
|
||||
X = DX.asarray()
|
||||
Xr = X[:,index]
|
||||
gene_ids = DX.get_identifiers('gene_ids', index)
|
||||
print "\nWorkiing on subset with %s genes " %len(gene_ids)
|
||||
### Build GO data ####
|
||||
print "\nWorking on subset with %s genes " %len(gene_ids)
|
||||
#gene2ind = {}
|
||||
#for i, gene in enumerate(gene_ids):
|
||||
# gene2ind[gene] = i
|
||||
|
||||
print "Go terms ..."
|
||||
goterms = rpy_go.goterms_from_gene(gene_ids)
|
||||
terms = set()
|
||||
for t in goterms.values():
|
||||
terms.update(t)
|
||||
terms = list(terms)
|
||||
print "Number of go-terms: %s" %len(terms)
|
||||
### Build GO data ####
|
||||
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)
|
||||
rpy.r.library("GOSim")
|
||||
# Go-term similarity matrix
|
||||
methods = ("JiangConrath","Resnik","Lin","CoutoEnriched","CoutoJiangConrath","CoutoResnik","CoutoLin")
|
||||
meth = methods[0]
|
||||
meth = methods[3]
|
||||
print "Term-term similarity matrix (method = %s)" %meth
|
||||
if meth=="CoutoEnriched":
|
||||
rpy.r('setEnrichmentFactors(alpha=0.1,beta=0.5)')
|
||||
print "Calculating term-term similarity matrix"
|
||||
tmat = rpy.r.getTermSim(terms, verbose=False, method=meth)
|
||||
print "\nCalculating term-term similarity matrix"
|
||||
|
||||
rpytmat1 = rpy.with_mode(rpy.NO_CONVERSION, rpy.r.getTermSim)(terms, method=meth,verbose=False)
|
||||
tmat1 = rpy.r.assign("haha", rpytmat1)
|
||||
|
||||
# check if all terms where found
|
||||
nanindex = where(isnan(tmat1[:,0]))[0]
|
||||
if len(nanindex)>0:
|
||||
raise valueError("NANs in tmat")
|
||||
|
||||
# Z-matrix
|
||||
#Z, newind = rpy_go.genego_matrix(terms, tmat, gene_ids, terms,func=mean)
|
||||
#Z = Z.T
|
||||
Z1 = rpy_go.genego_sim(gene2goterms,gene_ids,terms,rpytmat1,go_term_sim="OA",term_sim=meth)
|
||||
|
||||
|
||||
#### do another
|
||||
meth = methods[4]
|
||||
rpytmat = rpy.with_mode(rpy.NO_CONVERSION, rpy.r.getTermSim)(terms, method=meth,verbose=False)
|
||||
tmat = rpy.r.assign("haha", rpytmat)
|
||||
|
||||
# check if all terms where found
|
||||
nanindex = where(isnan(tmat[:,0]))[0]
|
||||
keep=[]
|
||||
has_miss = False
|
||||
if len(nanindex)>0:
|
||||
has_miss = True
|
||||
print "Some terms missing in similarity matrix"
|
||||
keep = where(isnan(tmat[:,0])!=True)[0]
|
||||
print "Number of nans: %d" %len(nanindex)
|
||||
tmat_new = tmat[:,keep][keep,:]
|
||||
new_terms = [i for ind,i in enumerate(terms) if ind in keep]
|
||||
bad_terms = [i for ind,i in enumerate(terms) if ind not in keep]
|
||||
# update go-term dict
|
||||
for gene,trm in goterms.items():
|
||||
for t in trm:
|
||||
if t in bad_terms:
|
||||
trm.remove(t)
|
||||
if len(trm)==0:
|
||||
print "Removing gene: %s" %gene
|
||||
goterms[gene]=trm
|
||||
terms = new_terms
|
||||
tmat = tmat_new
|
||||
raise valueError("NANs in tmat")
|
||||
|
||||
# Z-matrix
|
||||
# func (min, max, median, mean, etc),
|
||||
# func decides on the representation of gene-> goterm when multiple
|
||||
# goterms exist for one gene
|
||||
Z, newind = rpy_go.genego_matrix(goterms, tmat, gene_ids, terms,func=mean)
|
||||
Z = Z.T
|
||||
# update X matrix (no go-terms available)
|
||||
Xr = Xr[:,newind]
|
||||
new_gene_ids = asarray(gene_ids)[newind]
|
||||
#Z, newind = rpy_go.genego_matrix(terms, tmat, gene_ids, terms,func=mean)
|
||||
#Z = Z.T
|
||||
Z = rpy_go.genego_sim(gene2goterms,gene_ids,terms,rpytmat,go_term_sim="OA",term_sim=meth)
|
||||
|
||||
|
||||
|
||||
# update data (X) matrix
|
||||
#newind = [gene2ind[gene] for gene in gene_ids]
|
||||
newind = DX.get_indices('gene_ids', gene_ids)
|
||||
Xr = X[:,newind]
|
||||
#new_gene_ids = asarray(gene_ids)[newind]
|
||||
|
||||
|
||||
######## LPLSR ########
|
||||
@@ -112,11 +123,14 @@ if alpha_check:
|
||||
rmsep , yhat, ce = cv_lpls(Xr, Y, Z, a_max, alpha=alpha)
|
||||
Rmsep.append(rmsep)
|
||||
Yhat.append(yhat)
|
||||
CE.append(yhat)
|
||||
CE.append(ce)
|
||||
Rmsep = asarray(Rmsep)
|
||||
Yhat = asarray(Yhat)
|
||||
CE = asarray(CE)
|
||||
|
||||
figure(200)
|
||||
|
||||
|
||||
|
||||
# Significance Hotellings T
|
||||
Wx, Wz, Wy, = jk_lpls(Xr, Y, Z, aopt)
|
||||
@@ -135,7 +149,13 @@ for a in range(m):
|
||||
ylim([rmsep.min()-.05, rmsep.max()+.05])
|
||||
title('RMSEP')
|
||||
|
||||
figure(2) # Hypoid correlations
|
||||
figure(2)
|
||||
for a in range(m):
|
||||
bar(arange(a_max)+a*bar_w+.1, class_error[:,a], width=bar_w, color=bar_col[a])
|
||||
ylim([class_error.min()-.05, class_error.max()+.05])
|
||||
title('Classification accuracy')
|
||||
|
||||
figure(3) # Hypoid correlations
|
||||
plot_corrloads(Rz, pc1=0, pc2=1, s=tsqz/10.0, c='b', zorder=5, expvar=evz, ax=None)
|
||||
ax = gca()
|
||||
ylabels = DY.get_identifiers('_cat', sorted=True)
|
||||
|
Reference in New Issue
Block a user