def net_ggsvd(name=nu.default_name, reset=0): hardcopy = False try: if reset: raise Exception("compute") return nw.readnet(name, hardcopy=hardcopy) except Exception as e: if e.args[0] != "compute": raise Exception() nw.claim_reset() ggn = nu.net_genegene_norm(reset=mod(reset, 2)) U, S, Vh = lin.svd(ggn) V = Vh.T dosave = (U, S, V) nw.writenet(name, dosave, hardcopy=hardcopy) print """ Ran ggsvd. No hardcopies have been saved yet""" if reset: net_ggsvd_U(reset=2) net_ggsvd_V(reset=2) net_ggsvd_S(reset=2) print """ ...saved hardcopies of U,S,V """ return dosave
def net_square_svd(name=nu.default_name, reset=0): hardcopy = False try: if reset: raise Exception("compute") return nw.readnet(name, hardcopy=hardcopy) except Exception as e: if e.args[0] != "compute": raise Exception() nw.claim_reset() sqa = nu.net_square_affinity(reset=mod(reset, 2)) U, S, Vh = lin.svd(sqa) V = Vh.T uvecs = U[:, : len(S)] vvecs = V dosave = (sqa[1], (uvecs, S, vvecs)) nw.writenet(name, dosave, hardcopy=hardcopy) print """ Ran net square svd for the current values. Nothing has yet been saved to HD. """ if reset: net_square_svd_U(reset=2) net_square_svd_V(reset=2) net_square_svd_S(reset=2) print """ ...saved hardcopies of U,S,V """ return dosave
def get_net(name = 'unsup' , reset = 0): hardcopy = True try: if reset: raise Exception('compute') return nw.readnet(name, hardcopy = hardcopy) except Exception, e: if e.args[0] != 'compute': raise Exception() nw.claim_reset() net = parse_name(name) nw.writenet(name, net, hardcopy = hardcopy) return net
def net_cluster_ggsvdV(k = k,reset = 0): hardcopy = True try: if reset: raise Exception('compute') out,sxs = nw.rn2(name, hardcopy = hardcopy) if not sxs: raise Exception() except Exception as e: if e.args[0] != 'compute': raise Exception() nw.claim_reset() gg = ns.net_ggsvd_V().T kmeans = mlpy.Kmeans(k) clustered = kmeans.compute(gg[0:maxgenes,:]) means = kmeans.means nw.wn2(name, (clustered, means) ,hardcopy = hardcopy) return out
def net_cluster_genes_by_tf(k= k, reset = 0): hardcopy = True try: if reset: raise Exception('compute') out,sxs = nw.rn2(name, hardcopy = hardcopy) if not sxs: raise Exception() except Exception as e: if e.args[0] != 'compute': raise Exception() nw.claim_reset() gg = nu.net_affinity(reset = mod(reset,2)) kmeans = mlpy.Kmeans(k) clustered = kmeans.compute(gg[0:maxgenes,:]) means = kmeans.means out = (clustered,means) nw.wn2(name, (clustered, means) ,hardcopy = hardcopy) return out
def net_svd(name=nu.default_name, reset=0): hardcopy = True try: if reset: raise Exception("compute") return nw.readnet(name=nu.default_name, hardcopy=hardcopy) except Exception as e: if e.args[0] != "compute": raise Exception() nw.claim_reset() a = nu.net_affinity(reset=mod(reset, 2))[0] N = a[0] U, S, Vh = lin.svd(N) V = Vh.T U = U[:, len(S)] dosave = (a[1], (U, S, V)) nw.writenet(name, dosave, hardcopy=hardcopy) return dosave