Esempio n. 1
0
def A_from_structure(structure_filepath):
    """User defined function, to build the A matrices.

    Parameters
    ----------
    structure : string, filepath to the structure

    Return
    ------
    A, structure
    Those two objects will be accessible via global variables: A and STRUCTURE
    """
    sys.path.append(
        os.path.join(os.getenv('HOME'), 'gits', 'scripts',
                     '2013_brainomics_genomics'))
    from bgutils.build_websters import group_pw_snp2
    #a terme on passe ici la fichier vers les données de contrainte
    group, group_names, snpList = group_pw_snp2(fic='go_synaptic_snps_gene',
                                                cache=True)
    tmp = []
    for i in group:
        tmp.extend(group[i])
    p = len(set(tmp))
    print "DEBUG: ", p
    import parsimony.functions.nesterov.gl as gl
    weights = [np.sqrt(len(group[i])) for i in group]
    A = gl.A_from_groups(p, groups=group, weights=weights)
    structure = None

    return A, structure
Esempio n. 2
0
def load_globals(config):
    import mapreduce as GLOBAL  # access to global variables
    GLOBAL.DATA = GLOBAL.load_data(config["data"])
    from bgutils.build_websters import group_pw_snp2
    fic = 'go_synaptic_snps_gene'  #'go_synaptic_snps_gene10'
    groups, group_names, snpList = group_pw_snp2(fic=fic, cache=True)

    GLOBAL.groups = groups
Esempio n. 3
0
def mapreduce_parameterize():
    #    n_samples, shape = 200, (100, 100, 1)
    #    base = "classif_%ix%ix%ix%i_" % tuple([n_samples] + list(shape))
    #    X3d, y, beta3d, proba = datasets.classification.dice5.load(n_samples=n_samples,
    #                                        shape=shape, snr=5, random_seed=1)
    #    X = X3d.reshape((n_samples, np.prod(beta3d.shape)))

    base = 'grid'
    # 1- read constraints : we do not use Group Constraint here
    sys.path.append(
        os.path.join(os.getenv('HOME'), 'gits', 'scripts',
                     '2013_brainomics_genomics'))
    from bgutils.build_websters import group_pw_snp2, get_websters_logr, pw_gene_snp2
    group, group_names, snpList = group_pw_snp2(fic='go_synaptic_snps_gene10',
                                                cache=True)
    pw, _ = pw_gene_snp2(fic='go_synaptic_snps_gene10', cache=True)

    # 2- get the snps list to get a data set w/ y continous variable
    # convenient snp order
    # subject order granted by the method
    snp_subset = np.asarray(snpList, dtype=str).tolist()
    y, X = get_websters_logr(snp_subset=snp_subset)
    #3 ajout regresseur 1
    X = np.hstack((np.ones((X.shape[0], 1)), X))

    # create set of train test
    cv = StratifiedKFold(y.ravel(), n_folds=5)
    cv = [[tr.tolist(), te.tolist()] for tr, te in cv]

    # parameters grid
    alphas = [.01, .05, .1, .5, 1.]
    #    couplage_kl_g = np.array([[1., 0., 1], [0., 1., 1], [.1, .9, 1], [.9, .1, 1], [.5, .5, 1]])
    couplage_kl_g = np.array([[1., 0., 1], [0., 0., 1], [.1, 0., 1],
                              [.9, 0., 1], [.5, 0., 1]])
    #    k_range = np.arange(0, 1., .1)
    k_range = np.arange(0, 3., .5)
    alphas = [.01, .05, .1, .5, 1.]
    l2l1k = [
        np.array([[float(1 - k), float(1 - k), k]]) * couplage_kl_g
        for k in k_range
    ]
    l2l1k.append(np.array([[0., 0., 1.]]))
    l2l1k = np.concatenate(l2l1k)
    alphal2l1k = np.concatenate([
        np.c_[np.array([[alpha]] * l2l1k.shape[0]), l2l1k] for alpha in alphas
    ])

    params = [params.tolist() for params in alphal2l1k]

    # Save X, y, mask structure and cv
    np.save(base + 'X.npy', X)
    np.save(base + 'y.npy', y)
    #    nibabel.Nifti1Image(np.ones(shape), np.eye(4)).to_filename(base+'mask.nii')

    # Save everything in a single file config.json
    config = dict(
        data="%s?.npy" % base,
        structure=base + 'mask.nii',
        params=params,
        resample=cv,
        map_output=base + "map_results",
        job_file=base + "jobs.json",
        user_func=
        "/home/vf140245/gits/scripts/2013_brainomics_genomics/scripts/cv_webs_logr_ridge_gl.py",
        cores=8,
        reduce_input=base + "map_results/*/*",
        reduce_group_by=base + "map_results/.*/(.*)")

    o = open("config.json", "w")
    json.dump(config, o)
    o.close()
Esempio n. 4
0
#"""
#run /home/hl237680/gits/scripts/2013_imagen_bmi/scripts/15_cv_multivariate_residualized_BMI.py
#"""
if __name__ == "__main__":
    ## Set pathes
    #WD = "/home/fh235918/git/scripts/2013_brainomics_genomics/test"
    WD = OUTPUT_DIR
    if not os.path.exists(WD): os.makedirs(WD)

    print '#############'
    print '# Read data #'
    print '#############'

    fic = 'go_synaptic_snps_gene'  #'go_synaptic_snps_gene10'
    groups, group_names, snpList = group_pw_snp2(fic=fic, cache=True)

    # 2- get the snps list to get a data set w/ y continous variable
    # convenient snp order
    # subject order granted by the method
    y, X_orig = get_websters_logr(snp_subset=snpList.tolist())

    # 3- fix X : add a ones constant regressor
    n, p = X_orig.shape  # keep orig size
    X = np.hstack((np.ones((X_orig.shape[0], 1)), X_orig))  # add intercept

    print "#####################"
    print "# Build config file #"
    print "#####################"
    ## Parameterize the mapreduce
    ##   1) pathes
Esempio n. 5
0
@author: vf140245
Copyrignt : CEA NeuroSpin - 2014
"""
import sys, os
import numpy as np
import time
import matplotlib.pyplot as plt
sys.path.append(os.path.join(os.getenv('HOME'),
                                'gits','scripts','2013_brainomics_genomics'))



if __name__=="__main__":
    # read constraints : we do not use Group Constraint here
    from bgutils.build_websters import group_pw_snp2,get_websters_linr, pw_gene_snp2
    group, group_names, snpList = group_pw_snp2(fic='go_synaptic_snps_gene10')
    pw, _ = pw_gene_snp2(fic='go_synaptic_snps_gene10')    
    
    # get the snps list to get a data set w/ y continous variable
    # convenient snp order
    # subject order granted by the method
    snp_subset=np.asarray(snpList,dtype=str).tolist()
    y, X = get_websters_linr(snp_subset=snp_subset)

    # fix X : add a ones constant regressor
    p = (X.shape)[1]                            # keep orig size
    X = np.hstack((np.ones((X.shape[0],1)),X))  # add intercept
    
    # build A matrix
    import parsimony.functions.nesterov.gl as gl
    weights = [np.sqrt(len(group[i])) for i in group]
Esempio n. 6
0
        x = transcode(chr_plot_info[k], x)
        y = beta[indices]
        #        if k == u'chr3':
        #            print indices
        #            print x
        #            print y
        plt.vlines(x, [0], y, lw=2)

    plt.subplots_adjust(left=0.01, right=0.99, top=0.99, bottom=0.01)
    plt.show()


def get_gene_from_pw(pw):
    gene_list = []
    for i in pw:
        for j in pw[i]:
            gene_list.append(j)

    return np.unique(gene_list).tolist()


if __name__ == "__main__":
    # read constraints : we do not use Group Constraint here
    from bgutils.build_websters import group_pw_snp2, pw_gene_snp2
    cache = True
    group, group_names, snpList = group_pw_snp2(nb=10, cache=cache)
    pw, _ = pw_gene_snp2(nb=10, cache=cache)

    beta = np.random.uniform(-1, 1, 539)
    plot_pw(beta, pway=pw, snplist=snpList)