コード例 #1
0
ファイル: stats.py プロジェクト: dianalir/tskit
 def __init__(self, tree_sequence):
     self._tree_sequence = tree_sequence
     self._ll_ld_calculator = _tskit.LdCalculator(
         tree_sequence.get_ll_tree_sequence())
     # To protect low-level C code, only one method may execute on the
     # low-level objects at one time.
     self._instance_lock = threading.Lock()
コード例 #2
0
ファイル: test_lowlevel.py プロジェクト: grahamgower/tsnn
    def test_get_r2_array(self):
        ts = self.get_example_tree_sequence()
        calc = _tskit.LdCalculator(ts)

        self.assertRaises(TypeError, calc.get_r2_array)
        self.assertRaises(TypeError, calc.get_r2_array, None)
        # Doesn't support buffer protocol, so raises typeerror
        self.assertRaises(TypeError, calc.get_r2_array, None, 0)

        n = ts.get_num_sites()
        self.assertGreater(n, 2)
        with self.assertRaises(BufferError):
            calc.get_r2_array(bytes(100), 0)

        buff = bytearray(1024)
        with self.assertRaises(ValueError):
            calc.get_r2_array(buff, 0, max_distance=-1)
        with self.assertRaises(ValueError):
            calc.get_r2_array(buff, 0, direction=1000)
        # TODO this API is poor, we should explicitly catch these negative
        # size errors.
        for bad_max_mutations in [-2, -3, -2**32]:
            with self.assertRaises(BufferError):
                calc.get_r2_array(buff, 0, max_mutations=bad_max_mutations)
        for bad_start_pos in [-1, n, n + 1]:
            with self.assertRaises(_tskit.LibraryError):
                calc.get_r2_array(buff, bad_start_pos)
コード例 #3
0
 def __init__(self, tree_sequence):
     self._tree_sequence = tree_sequence
     self._ll_ld_calculator = _tskit.LdCalculator(
         tree_sequence.get_ll_tree_sequence())
     item_size = struct.calcsize('d')
     self._buffer = bytearray(tree_sequence.get_num_mutations() * item_size)
     # To protect low-level C code, only one method may execute on the
     # low-level objects at one time.
     self._instance_lock = threading.Lock()
コード例 #4
0
ファイル: test_lowlevel.py プロジェクト: grahamgower/tsnn
 def test_get_r2(self):
     ts = self.get_example_tree_sequence()
     calc = _tskit.LdCalculator(ts)
     n = ts.get_num_sites()
     for bad_id in [-1, n, n + 1]:
         with self.assertRaises(_tskit.LibraryError):
             calc.get_r2(0, bad_id)
         with self.assertRaises(_tskit.LibraryError):
             calc.get_r2(bad_id, 0)