def test_merge_two_files(self): result = merge_files(tu.abs_path('misc/geneset1.txt'), tu.abs_path('misc/geneset2.txt')) assert_equal(list(result), ['1 2 x2 y2 z3 x2 y2 z8', '2 3 x1 y1 z4 x1 y1 z10', '1 1 x1 y1 z6 x4 y5 z9', '2 4 x2 y2 z5 x2 y2 z12'], 'wrong merge result')
def test_neighbors(self): '''Test retrieving node's pedigree neighbors.''' p = itu.Templates.problem_hut() node = 1298 expected = np.genfromtxt(tu.abs_path('ibd_distant/nbhrs_' + repr(node) + '.txt'), dtype=int).tolist() tu.assert_equal_as_sets(p.pedigree.neighbors(node, 4, False), expected, 'Incorrect genotyped neighbor list') expected = np.genfromtxt(tu.abs_path('ibd_distant/nbhrs_' + repr(node) + '_genotyped.txt'), dtype=int).tolist() tu.assert_equal_as_sets(p.pedigree.neighbors(node, 4, True), expected, 'Incorrect genotyped neighbor list')
def setUp(self): '''Load segments from a test file.''' self.segments = map(lambda line: map(int, line), csv.reader(open(tu.abs_path('segment/segments-0-100.out'), 'rb'), delimiter=' ', skipinitialspace=True)) self.num_samples = 1415 start, stop, min_len = 0, 99, 0.4 * MEGA_BASE_PAIR self.selected_segments = it.ifilter(lambda line: max(start, line[0]) < min(stop, line[1]) and line[3] - line[2] >= min_len, self.segments)
class TestItemUtil(unittest.TestCase): #--------------------------------------------- # Constants #--------------------------------------------- __FILE = tu.abs_path('misc/hutt.chr22.snplist') #--------------------------------------------- # Test Methods #--------------------------------------------- def test_file_line_selection(self): '''Test selecting lines from a file.''' f = open(TestItemUtil.__FILE, 'rb') num_lines = iu.ilen(f) assert_equal(num_lines, 3218, 'Wrong item count') f = open(TestItemUtil.__FILE, 'rb') a = list(iu.linerange(f, 0, num_lines, 100)) assert_equal(len(a), 33, 'Wrong item range') assert_equal(a[0], 'SNP_A-2141031', 'Wrong item') assert_equal(a[-1], 'rs2015453', 'Wrong item') def test_segment_range(self): '''Test getting the start and end of equidistant intervals in an item collection.''' # Non-divisible case self.__test_segment_range(100, 7, 1) # Divisible case self.__test_segment_range(100, 10, 1) # Less trivial item list self.__test_segment_range(100, 7, 2) self.__test_segment_range(100, 10, 2) def test_groupby_with_range(self): '''Test the groupby_with_range() function.''' assert_equal(iu.groupby_with_range(''), []) assert_equal(iu.groupby_with_range('AAAABBBCCDAABBB'), [('A', (0, 3)), ('B', (4, 6)), ('C', (7, 8)), ('D', (9, 9)), ('A', (10, 11)), ('B', (12, 14))]) #--------------------------------------------- # Private Methods #--------------------------------------------- def __test_segment_range(self, n, step, c): '''Test getting the start and end of equidistant intervals in an item collection.''' items = np.arange(0, n, c) segments = iu.segmentrange(items, step) assert_equal(segments[:, 0], range(0, n, c * step), 'Wrong start array') assert_equal(segments[:, 1], range(c * (step - 1), n, c * step) + ([n - c] if np.mod(n, step) else []), 'Wrong end array')
def setUp(self): '''Load segments from a test file.''' self.segments = map( lambda line: map(int, line), csv.reader(open(tu.abs_path('segment/segments-0-100.out'), 'rb'), delimiter=' ', skipinitialspace=True)) self.num_samples = 1415 start, stop, min_len = 0, 99, 0.4 * MEGA_BASE_PAIR self.selected_segments = it.ifilter( lambda line: max(start, line[0]) < min(stop, line[1]) and line[3] - line[2] >= min_len, self.segments)
def setUp(self): '''Use a localhost UCSC copy.''' self.idcoef_dao = IdCoefDao(tu.abs_path('pedigree/example.id')) self.kinship_dao = KinshipDao(tu.abs_path('pedigree/example.kinship'))
Created on May 31, 2012 @author: Oren Livne <*****@*****.**> ============================================================ ''' import networkx as nx, numpy as np, test_util as tu from numpy.testing.utils import assert_equal from impute.data.problem import Problem from impute.data import io, io_pedigree, io_genotype from impute.phasing.examples import OUT_PHASING #--------------------------------------------- # Constants #--------------------------------------------- '''Hutterites pedigree - test file name. This file was obtained from Jessica and Gaixin (minped.3671).''' HUTT_PED = tu.abs_path('pedigree/hutterites.tfam') HUTT_GENOTYPED_PED = tu.abs_path('pedigree/hutterites.genotyped.tfam') '''Small test pedigree''' SMALL_FILE = tu.abs_path('network/small.tfam') '''Genotype hutt data with 1 SNP''' GENOTYPE_SAMPLE = tu.abs_path('sample/sample') '''Synthetic data on a duo (proband + single parent) with several SNPs''' GENOTYPE_DUO = tu.abs_path('duo/duo') # Contains solution to the trio phasing problem: parent genotypes and child haplotypes GENOTYPE_DUO_SOLUTION = tu.abs_path('duo/duo_solution') '''Synthetic data on a trio (proband + parents) with several SNPs''' GENOTYPE_TRIO = tu.abs_path('trio/trio') # Contains solution to the trio phasing problem: parent genotypes and child haplotypes
Created on May 31, 2012 @author: Oren Livne <*****@*****.**> ============================================================ ''' import networkx as nx, numpy as np, test_util as tu from numpy.testing.utils import assert_equal from impute.data.problem import Problem from impute.data import io, io_pedigree, io_genotype from impute.phasing.examples import OUT_PHASING #--------------------------------------------- # Constants #--------------------------------------------- '''Hutterites pedigree - test file name. This file was obtained from Jessica and Gaixin (minped.3671).''' HUTT_PED = tu.abs_path('pedigree/hutterites.tfam') HUTT_GENOTYPED_PED = tu.abs_path('pedigree/hutterites.genotyped.tfam') '''Small test pedigree''' SMALL_FILE = tu.abs_path('network/small.tfam') '''Genotype hutt data with 1 SNP''' GENOTYPE_SAMPLE = tu.abs_path('sample/sample') '''Synthetic data on a duo (proband + single parent) with several SNPs''' GENOTYPE_DUO = tu.abs_path('duo/duo') # Contains solution to the trio phasing problem: parent genotypes and child haplotypes GENOTYPE_DUO_SOLUTION = tu.abs_path('duo/duo_solution') '''Synthetic data on a trio (proband + parents) with several SNPs''' GENOTYPE_TRIO = tu.abs_path('trio/trio') # Contains solution to the trio phasing problem: parent genotypes and child haplotypes GENOTYPE_TRIO_SOLUTION = tu.abs_path('trio/trio_solution') '''Data on all SNPs and a single nuclear family. If not otherwise specified, data is from chr22.''' FAMILY7 = tu.abs_path('family7/family7')
def test_hash_file(self): result = hash_file(tu.abs_path('misc/geneset1.txt'), ' ', [0, 1]) assert_equal(result, [(3, 4), (1, 1), (1, 2), (2, 3), (2, 4)], 'file hash is wrong')