def test_create_pileup_image_returns_none_for_bad_region(self): self.mock_ref_reader.is_valid_interval.return_value = False self.dv_call.variant.start = 3 self.assertIsNone(self.pic.create_pileup_images(self.dv_call)) test_utils.assert_called_once_workaround( self.mock_ref_reader.is_valid_interval) self.mock_ref_reader.bases.assert_not_called()
def test_get_reference_bases_bad_region_returns_none(self): self.mock_ref_reader.is_valid_interval.return_value = False self.dv_call.variant.start = 3 self.assertIsNone(self.pic.get_reference_bases(self.variant)) test_utils.assert_called_once_workaround( self.mock_ref_reader.is_valid_interval) self.mock_ref_reader.bases.assert_not_called()
def test_on_demand_initialization_called_if_not_initialized(self): self.assertFalse(self.processor.initialized) self.processor.in_memory_sam_reader = mock.Mock() mock_rr = self.add_mock('region_reads', retval=[]) mock_cir = self.add_mock('candidates_in_region', retval=([], [])) self.processor.process(self.region) test_utils.assert_called_once_workaround(self.mock_init) mock_rr.assert_called_once_with(self.region) self.processor.in_memory_sam_reader.replace_reads.assert_called_once_with( []) mock_cir.assert_called_once_with(self.region)
def test_get_training_batches(self, compressed_inputs): golden_dataset = make_golden_dataset(compressed_inputs) batch_size = 16 with tf.Session() as sess: mock_model = mock.MagicMock(autospec=modeling.DeepVariantModel) mock_model.preprocess_image.side_effect = functools.partial( tf.image.resize_image_with_crop_or_pad, target_height=107, target_width=221) batch = data_providers.make_training_batches( golden_dataset.get_slim_dataset(), mock_model, batch_size) # We should have called our preprocess_image exactly once. We don't have # the actual objects to test for the call, though. test_utils.assert_called_once_workaround( mock_model.preprocess_image) # Get our images, labels, and variants for further testing. sess.run(tf.global_variables_initializer()) coord = tf.train.Coordinator() threads = tf.train.start_queue_runners(coord=coord, sess=sess) images, labels, variants = sess.run(batch) # Checks that our labels are the right shape and are one-hot encoded. self.assertEqual( (batch_size, 107, 221, pileup_image.DEFAULT_NUM_CHANNEL), images.shape) self.assertEqual((batch_size, ), labels.shape) for label in labels: self.assertTrue(0 <= label <= 2) # Check that our variants has the shape we expect and actually contain # variants by decoding them and checking the reference_name. self.assertEqual((batch_size, ), variants.shape) for variant in variantutils.decode_variants(variants): self.assertEqual(variant.reference_name, 'chr20') # Shutdown tensorflow coord.request_stop() coord.join(threads)