Beispiel #1
0
def find_vstructures(bfile, pfile, gfile, cisfile, assoc0file, window, vfile,
                     startTraitIdx, nTraits):
    """
    running association scan

    input:
    pfile      :   phenotype file
    cfile      :   covariance file
    ffile      :   fixed effects file
    cisfile    :   file containing cis anchors
    assoc0file :   file containing the results from the initial association scan
    vfile      :   file containing v-structures
    """
    preader = phenoReader.PhenoReaderFile(pfile)
    greader = bedReader.BedReader(bfile)

    model = gnetlmm.GNetLMM(preader, greader, window=window)

    genecorr_reader = reader.FileReader(gfile + '.pv')
    model.set_genecorr_reader(genecorr_reader)

    assoc0Reader = reader.FileReader(assoc0file + '.pv')
    model.set_assoc0_reader(assoc0Reader)

    model.load_cis_anchors(cisfile)
    model.find_vstructures(startTraitIdx, nTraits)
    model.save_vstructures(vfile + '.csv')
Beispiel #2
0
def scan(bfile, pfile, cfile, ffile, vfile, assocfile, startTraitIdx, nTraits):
    """
    running association scan

    input:
    bfile      :   basefilename of plink file
    pfile      :   phenotype file
    cfile      :   covariance file
    ffile      :   fixed effects file
    vfile      :   file containing vstructures
    assocfile  :   file for saving results
    """
    K = None
    if cfile is not None:
        K = np.loadtxt(cfile)

    Covs = None
    if ffile is not None:
        Covs = np.loadtxt(ffile)

    preader = phenoReader.PhenoReaderFile(pfile)
    greader = bedReader.BedReader(bfile)
    model = gnetlmm.GNetLMM(preader, greader, Covs=Covs, K=K)
    model.load_vstructures(vfile + ".csv")
    model.update_associations(startTraitIdx, nTraits)
    model.save_updates(assocfile)
Beispiel #3
0
def plot_power(bfile, pfile, assoc0file, assocfile, plotfile, window):
    # reading out p-values
    score = {}
    assoc0Reader = reader.FileReader(assoc0file + '.pv')
    score['LMM'] = -np.log10(assoc0Reader.getMatrix())
    assocReader = reader.FileReader(assocfile + '.pv')
    score['GNetLMM'] = -np.log10(assocReader.getMatrix())

    # get network
    Agene = np.loadtxt(pfile + '.Agene')

    # gene info
    preader = phenoReader.PhenoReaderFile(pfile)
    gene_start = preader.getGeneStart()
    gene_end = preader.getGeneEnd()
    gene_chrom = preader.getGeneChrom()

    # snp info
    breader = bedReader.BedReader(bfile)
    snp_pos = breader.getSnpPos()
    snp_chrom = breader.getSnpChrom()

    P_cis, P_trans = get_groundtruth(Agene, snp_pos, snp_chrom, gene_start,
                                     gene_chrom, window)

    # delete cis-associations
    for key in score.keys():
        score[key][P_cis] = 0

    # compute receiver operator characteristics
    FPR = {}
    TPR = {}
    for key in score.keys():
        FPR[key], TPR[key] = roc.roc(P_trans, score[key])

    # plotting results
    plotting.plotROCcurve(['LMM', 'GNetLMM'],
                          TPR,
                          FPR,
                          xlim=(0, 0.05),
                          ylim=(0, 0.42),
                          fn=plotfile)
Beispiel #4
0
def gene_has_cis_anchor(bfile, pfile, assoc0, cis_thresh, cis_window, cisfile):
    """
    tests if a gene has a cis anchor

    input:
    bfile        :   binary bed file (bfile.bed, bfile.bim and bfile.fam are required)
    pfile        :   phenotype file
    assoc0file   :   basefilename of initial association scan
    cis_thresh   :   thrshold for cis-association
    cis_window   :   maximal distance between cis-snp and gene
    cis_file     :   filename for saving cis assocaitions
    """
    preader = phenoReader.PhenoReaderFile(pfile)
    greader = bedReader.BedReader(bfile)
    model = gnetlmm.GNetLMM(preader, greader, window=cis_window)

    assoc0Reader = reader.FileReader(assoc0 + '.pv')
    model.set_assoc0_reader(assoc0Reader)
    model.gene_has_cis_anchor(cis_thresh)
    model.save_cis_anchors(cisfile)
Beispiel #5
0
def marginal_genecorr(bfile, pfile, gfile):
    """
    running marginal gene-gene correlations

    Input:
    bfile        :   binary bed file (bfile.bed, bfile.bim and bfile.fam are required)
    pfile        :   phenotype file
    cfile        :   covariance matrix file
    ffile        :   covariates file

    gfile        :   basename of output file 
    """
    preader = phenoReader.PhenoReaderFile(pfile)
    greader = bedReader.BedReader(bfile)
    model = gnetlmm.GNetLMM(preader, greader)
    corr, pv = model.marginal_gene_correlations()
    write = writer.Writer(gfile + '.pv')
    write.writeMatrix(pv, fmt='%.4e')
    write = writer.Writer(gfile + '.corr')
    write.writeMatrix(corr, fmt='%.4f')
Beispiel #6
0
def initial_scan(bfile,
                 pfile,
                 cfile,
                 ffile,
                 assoc0file,
                 startSnpIdx=0,
                 nSnps=np.inf,
                 memory_efficient=False):
    """
    running initial scan using a standard linear mixed model

    Input:
    bfile        :   binary bed file (bfile.bed, bfile.bim and bfile.fam are required)
    pfile        :   phenotype file
    cfile        :   covariance matrix file
    ffile        :   covariates file

    assoc0file   :   basename of output file 
    """
    K = None
    if cfile is not None:
        K = np.loadtxt(cfile)

    Covs = None
    if ffile is not None:
        Covs = np.loadtxt(ffile)

    preader = phenoReader.PhenoReaderFile(pfile)
    greader = bedReader.BedReader(bfile)
    model = gnetlmm.GNetLMM(preader, greader, K=K, Covs=Covs)
    beta0, pv0 = model.initial_scan(startSnpIdx, nSnps, memory_efficient)

    write = writer.Writer(assoc0file + '.pv')
    write.writeMatrix(pv0, fmt='%.4e')

    write = writer.Writer(assoc0file + '.beta')
    write.writeMatrix(beta0, fmt='%.4f')