示例#1
0
    def test_call_end2end(self, compressed_inputs):
        FLAGS.infile = make_golden_dataset(compressed_inputs)
        FLAGS.ref = test_utils.CHR20_FASTA
        FLAGS.outfile = test_utils.test_tmpfile('calls.vcf')

        postprocess_variants.main(['postprocess_variants.py'])

        self.assertEqual(
            tf.gfile.FastGFile(FLAGS.outfile).readlines(),
            tf.gfile.FastGFile(
                test_utils.GOLDEN_POSTPROCESS_OUTPUT).readlines())
示例#2
0
 def test_catches_bad_argv(self):
   # Define valid flags to ensure raise occurs due to argv issues.
   FLAGS.infile = make_golden_dataset(False)
   FLAGS.ref = testdata.CHR20_FASTA
   FLAGS.outfile = test_utils.test_tmpfile('nonempty_outfile.vcf')
   with mock.patch.object(logging, 'error') as mock_logging,\
       mock.patch.object(sys, 'exit') as mock_exit:
     postprocess_variants.main(['postprocess_variants.py', 'extra_arg'])
   mock_logging.assert_called_once_with(
       'Command line parsing failure: postprocess_variants does not accept '
       'positional arguments but some are present on the command line: '
       '"[\'postprocess_variants.py\', \'extra_arg\']".')
   mock_exit.assert_called_once_with(errno.ENOENT)
示例#3
0
  def test_reading_empty_input_should_raise_error(self):
    empty_shard_one = test_utils.test_tmpfile(
        'no_records.tfrecord-00000-of-00002')
    empty_shard_two = test_utils.test_tmpfile(
        'no_records.tfrecord-00001-of-00002')
    io_utils.write_tfrecords([], empty_shard_one)
    io_utils.write_tfrecords([], empty_shard_two)
    FLAGS.infile = test_utils.test_tmpfile('no_records.tfrecord@2')
    FLAGS.ref = testdata.CHR20_FASTA
    FLAGS.outfile = test_utils.test_tmpfile('no_records.vcf')

    with self.assertRaisesRegexp(ValueError, 'Cannot find any records in'):
      postprocess_variants.main(['postprocess_variants.py'])
 def test_catches_bad_argv(self):
   # Define valid flags to ensure raise occurs due to argv issues.
   FLAGS.infile = make_golden_dataset(False)
   FLAGS.ref = testdata.CHR20_FASTA
   FLAGS.outfile = test_utils.test_tmpfile('nonempty_outfile.vcf')
   with mock.patch.object(logging, 'error') as mock_logging,\
       mock.patch.object(sys, 'exit') as mock_exit:
     postprocess_variants.main(['postprocess_variants.py', 'extra_arg'])
   mock_logging.assert_called_once_with(
       'Command line parsing failure: postprocess_variants does not accept '
       'positional arguments but some are present on the command line: '
       '"[\'postprocess_variants.py\', \'extra_arg\']".')
   mock_exit.assert_called_once_with(errno.ENOENT)
示例#5
0
 def test_catches_bad_flags(self):
   FLAGS.infile = make_golden_dataset(False)
   FLAGS.ref = testdata.CHR20_FASTA
   FLAGS.outfile = 'nonempty_outfile.vcf'
   FLAGS.nonvariant_site_tfrecord_path = (
       testdata.GOLDEN_POSTPROCESS_GVCF_INPUT)
   # This is the bad flag.
   FLAGS.gvcf_outfile = ''
   with mock.patch.object(logging, 'error') as mock_logging, \
       mock.patch.object(sys, 'exit') as mock_exit:
     postprocess_variants.main(['postprocess_variants.py'])
   mock_logging.assert_called_once_with(
       'gVCF creation requires both nonvariant_site_tfrecord_path and '
       'gvcf_outfile flags to be set.')
   mock_exit.assert_called_once_with(errno.ENOENT)
示例#6
0
  def test_reading_sharded_input_with_empty_shards_does_not_crash(self):
    valid_variants = io_utils.read_tfrecords(
        testdata.GOLDEN_POSTPROCESS_INPUT,
        proto=deepvariant_pb2.CallVariantsOutput)
    empty_shard_one = test_utils.test_tmpfile(
        'reading_empty_shard.tfrecord-00000-of-00002')
    none_empty_shard_two = test_utils.test_tmpfile(
        'reading_empty_shard.tfrecord-00001-of-00002')
    io_utils.write_tfrecords([], empty_shard_one)
    io_utils.write_tfrecords(valid_variants, none_empty_shard_two)
    FLAGS.infile = test_utils.test_tmpfile('reading_empty_shard.tfrecord@2')
    FLAGS.ref = testdata.CHR20_FASTA
    FLAGS.outfile = test_utils.test_tmpfile('calls_reading_empty_shard.vcf')

    postprocess_variants.main(['postprocess_variants.py'])
 def test_catches_bad_flags(self):
   FLAGS.infile = make_golden_dataset(False)
   FLAGS.ref = testdata.CHR20_FASTA
   FLAGS.outfile = 'nonempty_outfile.vcf'
   FLAGS.nonvariant_site_tfrecord_path = (
       testdata.GOLDEN_POSTPROCESS_GVCF_INPUT)
   # This is the bad flag.
   FLAGS.gvcf_outfile = ''
   with mock.patch.object(logging, 'error') as mock_logging, \
       mock.patch.object(sys, 'exit') as mock_exit:
     postprocess_variants.main(['postprocess_variants.py'])
   mock_logging.assert_called_once_with(
       'gVCF creation requires both nonvariant_site_tfrecord_path and '
       'gvcf_outfile flags to be set.')
   mock_exit.assert_called_once_with(errno.ENOENT)
  def test_call_end2end(self, compressed_inputs):
    FLAGS.infile = make_golden_dataset(compressed_inputs)
    FLAGS.ref = testdata.CHR20_FASTA
    FLAGS.outfile = test_utils.test_tmpfile('calls.vcf')
    FLAGS.nonvariant_site_tfrecord_path = (
        testdata.GOLDEN_POSTPROCESS_GVCF_INPUT)
    FLAGS.gvcf_outfile = test_utils.test_tmpfile('gvcf_calls.vcf')

    postprocess_variants.main(['postprocess_variants.py'])

    self.assertEqual(
        tf.gfile.FastGFile(FLAGS.outfile).readlines(),
        tf.gfile.FastGFile(testdata.GOLDEN_POSTPROCESS_OUTPUT).readlines())
    self.assertEqual(
        tf.gfile.FastGFile(FLAGS.gvcf_outfile).readlines(),
        tf.gfile.FastGFile(testdata.GOLDEN_POSTPROCESS_GVCF_OUTPUT).readlines())
示例#9
0
  def test_call_end2end(self, compressed_inputs_and_outputs):
    FLAGS.infile = make_golden_dataset(compressed_inputs_and_outputs)
    FLAGS.ref = testdata.CHR20_FASTA
    FLAGS.outfile = create_outfile('calls.vcf', compressed_inputs_and_outputs)
    FLAGS.nonvariant_site_tfrecord_path = (
        testdata.GOLDEN_POSTPROCESS_GVCF_INPUT)
    FLAGS.gvcf_outfile = create_outfile('gvcf_calls.vcf',
                                        compressed_inputs_and_outputs)

    postprocess_variants.main(['postprocess_variants.py'])

    self.assertEqual(
        tf.gfile.GFile(FLAGS.outfile).readlines(),
        tf.gfile.GFile(testdata.GOLDEN_POSTPROCESS_OUTPUT_COMPRESSED
                       if compressed_inputs_and_outputs else testdata
                       .GOLDEN_POSTPROCESS_OUTPUT).readlines())
    self.assertEqual(
        tf.gfile.GFile(FLAGS.gvcf_outfile).readlines(),
        tf.gfile.GFile(testdata.GOLDEN_POSTPROCESS_GVCF_OUTPUT_COMPRESSED
                       if compressed_inputs_and_outputs else testdata
                       .GOLDEN_POSTPROCESS_GVCF_OUTPUT).readlines())
    if compressed_inputs_and_outputs:
      self.assertTrue(tf.gfile.Exists(FLAGS.outfile + '.tbi'))
      self.assertTrue(tf.gfile.Exists(FLAGS.gvcf_outfile + '.tbi'))