"""Validates that a VCF file and a FASTA reference file correspond.

They correspond if:
a) they cover the same contigs,
b) the reference covers every variant in the vcf file, and
c) they agree on the reference bases covered by the variants.
"""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import sys

from absl import app

from deepvariant.util.io import fasta
from deepvariant.util.io import vcf
from deepvariant.util import variant_utils


def validate_contigs(ref_contigs, vcf_contigs):
  """Validate that the two lists of ContigInfos have the same set of names."""
  ref_names = {ci.name for ci in ref_contigs}
  vcf_names = {ci.name for ci in vcf_contigs}
  if ref_names != vcf_names:
    print('Contig names differ!')
    print('The following contigs are in one but not both: ')
    print(ref_names ^ vcf_names)
    sys.exit(-1)


def validate_variant(ref_reader, variant):
  """Validate that variant is covered by the reference and agrees with it."""
  var_range = variant_utils.variant_range(variant)
  ref_bases = ref_reader.query(var_range)
  if ref_bases != variant.reference_bases:
    print('In range {}:{}-{} '.format(
        var_range.reference_name, var_range.start, var_range.end))
    print('Reference says ', ref_bases)
    print('But variant says ', variant.reference_bases)
    sys.exit(-1)


def main(argv):
  if len(argv) != 3:
    print('Usage: {} <input_ref> <input_vcf>'.format(argv[0]))
    sys.exit(-1)
  in_ref = argv[1]
  in_vcf = argv[2]

  with fasta.RefFastaReader(in_ref) as ref_reader:
    with vcf.VcfReader(in_vcf, use_index=False) as vcf_reader:
      validate_contigs(ref_reader.header.contigs, vcf_reader.header.contigs)
      for variant in vcf_reader:
        validate_variant(ref_reader, variant)

  # VCF is valid!
  sys.exit(0)


if __name__ == '__main__':
  app.run(main)

@@ -1,16 +1,1538 @@
+# Copyright 2018 Google Inc.%0A#%0A# Redistribution and use in source and binary forms, with or without%0A# modification, are permitted provided that the following conditions%0A# are met:%0A#%0A# 1. Redistributions of source code must retain the above copyright notice,%0A#    this list of conditions and the following disclaimer.%0A#%0A# 2. Redistributions in binary form must reproduce the above copyright%0A#    notice, this list of conditions and the following disclaimer in the%0A#    documentation and/or other materials provided with the distribution.%0A#%0A# 3. Neither the name of the copyright holder nor the names of its%0A#    contributors may be used to endorse or promote products derived from this%0A#    software without specific prior written permission.%0A#%0A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS %22AS IS%22%0A# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE%0A# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE%0A# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE%0A# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR%0A# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF%0A# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS%0A# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN%0A# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)%0A# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE%0A# POSSIBILITY OF SUCH DAMAGE.%0A
 %22%22%22Validates tha

Add copyright notice to validate_vcf.py