Beispiel #1
0
    def test_select_samples(self):
        '''Create sub-problem by selecting samples/family..'''
        p = io.read_npz(itu.FAMILY13_STAGE3)
        f = p.families()[0]
        ps = p.sub_problem(f.member_list)
        pf = p.sub_problem_of_parents(f.father, f.mother)

        # pf has family_info entry, ps doesn't
        assert_equal(ps.pedigree.graph.nodes(), pf.pedigree.graph.nodes(),
                     'Incorrect pedigree graph nodes')
        assert_equal(set(ps.pedigree.graph.edges()),
                     set(pf.pedigree.graph.edges()),
                     'Incorrect pedigree graph edges')
        assert_equal(ps.pedigree.sample_id.tolist(),
                     pf.pedigree.sample_id.tolist(),
                     'Incorrect pedigree sample ID array')
        assert_equal(ps.pedigree, pf.pedigree, 'Incorrect pedigree')
        assert_equal(ps.genotype, pf.genotype, 'Incorrect genotype')
        assert_equal(ps.haplotype, pf.haplotype, 'Incorrect haplotype')
        self.assertTrue(ps.info.family_info != pf.info.family_info,
                        'Incorrect info family')
        assert_not_equal(ps.info, pf.info, 'Incorrect info')
        assert_not_equal(ps, pf,
                         'pf should have a family_info entry, ps shouldn'
                         't')
Beispiel #2
0
def __load_problem(options):
    '''Load data from input files into a Problem object.'''
    # args = dict(prefix=options.prefix, tped=options.tped, tfam=options.tfam)
    # print args
    if options.debug: print 'Input file : %s ...\nOutput file: %s ...' % (options.input, options.output,)
    problem = io.read_npz(options.input)
    if options.debug: print 'Loaded', problem
    return problem
Beispiel #3
0
 def __save_and_load_problem_npz(self, problem):
     '''Save and load a problem from NPZ file.'''
     out_file = tempfile.TemporaryFile()
     io.write_npz(problem, out_file)
     # Only needed here to simulate closing & reopening file; you will need to call 
     # out_file.close() on to prevent file locking in Windows
     out_file.seek(0)
     return io.read_npz(out_file)
Beispiel #4
0
 def test_global_ibd_segments(self):
     '''Test the construction of the global IBD segment dictionary.'''
     problem = io.read_npz(itu.FAMILY225_STAGE1)
     ibd = problem.info.ibd
     assert_equal(ibd.length, 0, 'Unexpected initial # of IBD segments')
     self.phaser.run(problem)
     assert_equal(ibd.length, 21, 'Unexpected final # of IBD segments before grouping')
     ibd.group_to_disjoint()
     assert_equal(ibd.length, 32, 'Unexpected final # of IBD segments after grouping')
 def test_child_comparison_one_parent(self):
     '''Test applying child comparison to a nuclear family with many genotyped kids but only
     one genotyped parent.'''
     problem = io.read_npz(itu.FAMILY945_ONE_PARENT_STAGE2)
     itu.assert_size_equals(problem.genotype, 3218, 8)
     itu.assert_problem_stats(problem, 51488, 44150, 96)
     phaser = family_child_comparison_phaser(debug=False)
     phaser.run(problem)
     itu.assert_problem_stats(problem, 51488, 47343, 101)
 def test_child_comparison_one_parent(self):
     '''Test applying child comparison to a nuclear family with many genotyped kids but only
     one genotyped parent.'''
     problem = io.read_npz(itu.FAMILY945_ONE_PARENT_STAGE2)
     itu.assert_size_equals(problem.genotype, 3218, 8)
     itu.assert_problem_stats(problem, 51488, 44150, 96)
     phaser = family_child_comparison_phaser(debug=False)
     phaser.run(problem)
     itu.assert_problem_stats(problem, 51488, 47343, 101)
Beispiel #7
0
 def __plink_to_npz(self, p, file_name):
     '''Convert p from plink to npz format using the file set specified by file_name.'''
     npz = file_name+'.npz'
     # Save test problem in plink format
     io.write_plink(p, prefix=file_name)
     # Convert plink -> npz
     io.plink_to_npz(file_name, npz)
     # Load npz and check that the problem object didn't change
     p2 = io.read_npz(npz)
     return p2
    def test_family_12(self):
        '''Test comparing sibs with non-genotyped parents (stage 4).'''
        problem = io.read_npz(itu.FAMILY12_STAGE2)
        itu.assert_size_equals(problem.genotype, 3218, 7)
        itu.assert_problem_stats(problem, 45052, 42162, 237)
        assert_equal(len(list(problem.families(genotyped=False))), 1, 'Incorrect number of families')

        phaser = family_sib_comparison_phaser()
        phaser.run(problem, PhaseParam(single_member=1))

        itu.assert_problem_stats(problem, 45052, 42162, 237)
    def test_family_963(self):
        '''Test comparing sibs with non-genotyped parents (stage 4). This was a problematic family.'''
        problem = io.read_npz(itu.FAMILY963_STAGE4)
        itu.assert_size_equals(problem.genotype, 3218, 3)
        itu.assert_problem_stats(problem, 19308, 19286, 23)
        assert_equal(len(list(problem.families(genotyped=False))), 1, 'Incorrect number of families')

        phaser = family_sib_comparison_phaser()
        phaser.run(problem)

        itu.assert_problem_stats(problem, 19308, 19286, 23)
 def setUp(self):
     '''Load test data and expected results.'''
     unittest.TestCase.setUp(self)
     
     # Load test data ready from previous phasing stagees 
     self.problem = io.read_npz(itu.FAMILY_TOO_ZEROED_STAGE1)
     self.family = self.problem.families()[0]
     self.phaser = phase_core.PhaseDecorator(FilterChain([trivial_phaser(),
                                                          family_phaser(),
                                                          family_child_comparison_phaser()]))
     self.comparator = ic.ChildComparator(Struct(problem=self.problem, params=PhaseParam()), self.family)
Beispiel #11
0
def __load_problem(options):
    '''Load data from input files into a Problem object.'''
    # args = dict(prefix=options.prefix, tped=options.tped, tfam=options.tfam)
    # print args
    if options.debug:
        print 'Input file : %s ...\nOutput file: %s ...' % (
            options.input,
            options.output,
        )
    problem = io.read_npz(options.input)
    if options.debug: print 'Loaded', problem
    return problem
Beispiel #12
0
    def test_family_12(self):
        '''Test comparing sibs with non-genotyped parents (stage 4).'''
        problem = io.read_npz(itu.FAMILY12_STAGE2)
        itu.assert_size_equals(problem.genotype, 3218, 7)
        itu.assert_problem_stats(problem, 45052, 42162, 237)
        assert_equal(len(list(problem.families(genotyped=False))), 1,
                     'Incorrect number of families')

        phaser = family_sib_comparison_phaser()
        phaser.run(problem, PhaseParam(single_member=1))

        itu.assert_problem_stats(problem, 45052, 42162, 237)
Beispiel #13
0
    def test_family_963(self):
        '''Test comparing sibs with non-genotyped parents (stage 4). This was a problematic family.'''
        problem = io.read_npz(itu.FAMILY963_STAGE4)
        itu.assert_size_equals(problem.genotype, 3218, 3)
        itu.assert_problem_stats(problem, 19308, 19286, 23)
        assert_equal(len(list(problem.families(genotyped=False))), 1,
                     'Incorrect number of families')

        phaser = family_sib_comparison_phaser()
        phaser.run(problem)

        itu.assert_problem_stats(problem, 19308, 19286, 23)
    def setUp(self):
        '''Load test data and expected results.'''
        unittest.TestCase.setUp(self)

        # Load test data ready from previous phasing stagees
        self.problem = io.read_npz(itu.FAMILY13_STAGE2)
        self.family = self.problem.families()[0]
        self.phaser = phase_core.PhaseDecorator(
            FilterChain([
                trivial_phaser(),
                family_phaser(),
                family_child_comparison_phaser()
            ]))
        self.comparator = ic.ChildComparator(
            Struct(problem=self.problem, params=PhaseParam()), self.family)
    def test_family_2003_need_poo_alignment(self):
        '''Test comparing sibs with non-genotyped parents (stage 4). This case highlights
        the need to align POO-phases, i.e., swap founder haps to correctly patch families at individual
        ID 28412 (our original index 386; in this problem, index 10).'''
        problem = io.read_npz(itu.FAMILY2003_STAGE3)
        itu.assert_size_equals(problem.genotype, 3218, 9)
        itu.assert_problem_stats(problem, 57924, 43339, 85)
        assert_equal(len(list(problem.families(genotyped=False))), 1, 'Incorrect number of families')

        #f = problem.families(genotyped=False)[0]
        #print f.member_list
        #print problem.pedigree.sample_id
        phaser = family_sib_comparison_phaser()
        phaser.run(problem)

        itu.assert_problem_stats(problem, 57924, 57515, 85)
Beispiel #16
0
    def test_family_2003_need_poo_alignment(self):
        '''Test comparing sibs with non-genotyped parents (stage 4). This case highlights
        the need to align POO-phases, i.e., swap founder haps to correctly patch families at individual
        ID 28412 (our original index 386; in this problem, index 10).'''
        problem = io.read_npz(itu.FAMILY2003_STAGE3)
        itu.assert_size_equals(problem.genotype, 3218, 9)
        itu.assert_problem_stats(problem, 57924, 43339, 85)
        assert_equal(len(list(problem.families(genotyped=False))), 1,
                     'Incorrect number of families')

        #f = problem.families(genotyped=False)[0]
        #print f.member_list
        #print problem.pedigree.sample_id
        phaser = family_sib_comparison_phaser()
        phaser.run(problem)

        itu.assert_problem_stats(problem, 57924, 57515, 85)
Beispiel #17
0
    def test_select_samples(self):
        '''Create sub-problem by selecting samples/family..'''
        p = io.read_npz(itu.FAMILY13_STAGE3)
        f = p.families()[0]
        ps = p.sub_problem(f.member_list)
        pf = p.sub_problem_of_parents(f.father, f.mother)

        # pf has family_info entry, ps doesn't
        assert_equal(ps.pedigree.graph.nodes(), pf.pedigree.graph.nodes(), 'Incorrect pedigree graph nodes')
        assert_equal(set(ps.pedigree.graph.edges()), set(pf.pedigree.graph.edges()), 'Incorrect pedigree graph edges')
        assert_equal(ps.pedigree.sample_id.tolist(), pf.pedigree.sample_id.tolist(), 'Incorrect pedigree sample ID array')
        assert_equal(ps.pedigree, pf.pedigree, 'Incorrect pedigree')
        assert_equal(ps.genotype, pf.genotype, 'Incorrect genotype')
        assert_equal(ps.haplotype, pf.haplotype, 'Incorrect haplotype')
        self.assertTrue(ps.info.family_info != pf.info.family_info, 'Incorrect info family')
        assert_not_equal(ps.info, pf.info, 'Incorrect info')
        assert_not_equal(ps, pf, 'pf should have a family_info entry, ps shouldn''t')
Beispiel #18
0
Created on September 7, 2012
@author: Oren Livne <*****@*****.**>
============================================================
"""
import numpy as np, matplotlib.pyplot as plt, util
from impute import impute_test_util as itu
from impute.plot import plots
from impute.data import io

if __name__ == "__main__":
    """
    --------------------------------------------------
    Main program
    --------------------------------------------------
    """

    # Load nuclear family data
    p = io.read_npz(itu.FAMILY2003_STAGE3)
    f = p.families(genotyped=False)[0]
    old_printoptions = np.get_printoptions()
    np.set_printoptions(precision=2)

    children = np.array([x for x in f.children_list if p.is_genotyped(x)])
    h = p.haplotype.data
    plots.plot_hap_corr_matrix(h, children, (0, 0))
    plt.savefig("hap00.png")
    plots.plot_hap_corr_matrix(h, children, (0, 1))
    plt.savefig("hap01.png")

    util.set_printoptions(old_printoptions)
Beispiel #19
0
 def test_draw_pedigree(self):
     '''Test famplot pedigree drawing tool integration.'''
     p = read_npz(itu.NBHRS1298_STAGE4)
     self.__test_draw_pedigree(p)
Beispiel #20
0
 def setUp(self):
     '''Load test data and expected results.'''
     unittest.TestCase.setUp(self)
     self.problem = io.read_npz(itu.NBHRS1298_STAGE4)
     # Reset seed for deterministic results
     np.random.seed(0)
Beispiel #21
0
 def test_select_family(self):
     '''Another test of creating a sub-problem by selecting a family..'''
     p = io.read_npz(itu.FAMILY13_STAGE3)
     p.sub_problem_of_parents(0, 1)
Beispiel #22
0
 def test_draw_pedigree(self):
     '''Test famplot pedigree drawing tool integration.'''
     p = read_npz(itu.NBHRS1298_STAGE4)
     self.__test_draw_pedigree(p)
Beispiel #23
0
 def test_save_load_subproblem(self):
     '''Check saving and loading a sub-problem with selected samples.'''
     p = io.read_npz(itu.FAMILY13_STAGE3)
     pp = p.sub_problem(p.families()[0].member_list) 
     self.__test_save_and_load_problem(pp, 'npz')
     self.__test_save_and_load_problem(pp, 'plink')
Beispiel #24
0
 def test_save_load_problem_with_problem_info(self):
     '''Check that saving and loading a problem from file preserves the original object.'''
     self.__test_save_and_load_problem(io.read_npz(itu.FAMILY13_STAGE3), 'npz')
     self.__test_save_and_load_problem(io.read_npz(itu.FAMILY13_STAGE3), 'plink')
Beispiel #25
0
 def test_select_family(self):
     '''Another test of creating a sub-problem by selecting a family..'''
     p = io.read_npz(itu.FAMILY13_STAGE3)
     p.sub_problem_of_parents(0, 1)
Beispiel #26
0
Created on September 7, 2012
@author: Oren Livne <*****@*****.**>
============================================================
'''
import numpy as np, matplotlib.pyplot as plt, util
from impute import impute_test_util as itu
from impute.plot import plots
from impute.data import io

if __name__ == '__main__':
    '''
    --------------------------------------------------
    Main program
    --------------------------------------------------
    '''

    # Load nuclear family data
    p = io.read_npz(itu.FAMILY2003_STAGE3)
    f = p.families(genotyped=False)[0]
    old_printoptions = np.get_printoptions()
    np.set_printoptions(precision=2)

    children = np.array([x for x in f.children_list if p.is_genotyped(x)])
    h = p.haplotype.data
    plots.plot_hap_corr_matrix(h, children, (0, 0))
    plt.savefig('hap00.png')
    plots.plot_hap_corr_matrix(h, children, (0, 1))
    plt.savefig('hap01.png')

    util.set_printoptions(old_printoptions)
Beispiel #27
0
============================================================
'''
from impute import impute_test_util as itu
from impute.plot import plots
import impute.ibd.ibd_child as ic
from impute.data import constants, io

if __name__ == '__main__':
    '''
    --------------------------------------------------
    Main program
    --------------------------------------------------
    '''
    
    # Load nuclear family data
    p = io.read_npz(itu.FAMILY13_STAGE2)
    f = p.families()[0]
    
    # Calculate recombinations
    parent_type = constants.PATERNAL
    template = 2
    parent = f.parents[parent_type]
    (_, _, info) = ic.child_recombinations(p, f, parent_type, template, remove_errors=True)

    # Different ways to visualize the results
    print info.recombination_snp
    info.plot(template=True)
    info.plot(template=False)
    plots.plot_family_comparison(p, f, parent_type, template=template)
    plots.plot_family_comparison(p, f, parent_type)