예제 #1
0
파일: FAM.py 프로젝트: TalShor/SciLMM
    sex = sex.astype(np.bool)
    individuals, parents = rel.nonzero()

    fathers = np.zeros((rel.shape[0]), dtype=np.int32)
    mothers = np.zeros((rel.shape[0]), dtype=np.int32)
    interest = np.zeros((rel.shape[0]), dtype=np.int32)
    # need to add one so 0 is not an entry
    fathers[individuals[sex[parents]]] = parents[sex[parents]] + 1
    mothers[individuals[~sex[parents]]] = parents[~sex[parents]] + 1
    if indices is not None:
        interest[indices] = True
    content = np.vstack((np.zeros((rel.shape[0]), dtype=np.int32),
                         np.arange(rel.shape[0]) + 1,
                         fathers, mothers,
                         ['2' if x else '1' for x in sex],
                         interest))
    np.savetxt(fam_file_path, content.T, delimiter=' ', fmt='%s')


if __name__ == "__main__":
    from Simulation.Pedigree import simulate_tree

    rel, sex, _ = simulate_tree(10000, 0.001, 1.4, 0.9)
    indices = np.array([1, 2, 3])
    write_fam('temp.fam', rel, sex, indices)

    rel_after, sex_after, interest_after, entries_list = read_fam('temp.fam')
    assert (rel_after - rel).nnz == 0
    assert np.count_nonzero(sex - sex_after) == 0
    assert np.count_nonzero(interest_after - indices) == 0
예제 #2
0
    factor = cholesky(V)

    _, L_CT_invV_C, _, fixed_effects = compute_fixed_effects(factor, y, covariates)
    fixed_effects_p_values = compute_fixed_effects_p_value(y, covariates, fixed_effects, L_CT_invV_C)

    sigmas_sigmas = compute_sig_of_sig(mats, covariates, factor, y, sim_num)
    return {"covariance coefficients": mats_coefficients,
            "covariates coefficients": fixed_effects,
            "covariance std": sigmas_sigmas,
            "covariates p-values": fixed_effects_p_values}


if __name__ == "__main__":
    from Simulation.Pedigree import simulate_tree
    from Simulation.Phenotype import simulate_phenotype
    from Matrices.Numerator import simple_numerator
    from Matrices.Epistasis import pairwise_epistasis
    from Matrices.Dominance import dominance

    rel, _, _ = simulate_tree(50000, 0.001, 1.4, 0.9)
    ibd, _, _ = simple_numerator(rel)
    epis = pairwise_epistasis(ibd)
    dom = dominance(rel, ibd)
    cov = np.random.randn(50000, 2)
    y = simulate_phenotype([ibd, epis, dom],
                           cov,
                           np.array([0.3, 0.2, 0.1, 0.4]),
                           np.array([0.01, 0.02, 0.03]),
                           True)
    print(LMM(SparseCholesky(), [ibd, epis, dom], cov, y))