# Path: ariba/samtools_variants.py
# class Error (Exception): pass
# class SamtoolsVariants:
#     def __init__(self,
#       ref_fa,
#       bam,
#       outprefix,
#       log_fh=sys.stdout,
#       min_var_read_depth=4,
#       min_second_var_read_depth=2,
#       max_allele_freq=0.90
#     ):
#     def _make_vcf_and_read_depths_files(self):
#     def _get_read_depths(cls, read_depths_file, sequence_name, position):
#     def _get_variant_positions_from_vcf(cls, vcf_file):
#     def _get_variants(vcf_file, read_depths_file, positions=None):
#     def total_depth_per_contig(read_depths_file):
#     def variants_in_coords(nucmer_matches, vcf_file):
#     def get_depths_at_position(self, seq_name, position):
#     def run(self):


import unittest
import os
import filecmp
import pyfastaq
from ariba import samtools_variants
        os.unlink(tmp_prefix + '.contig_depths')


    def test_get_read_depths(self):
        '''test _get_read_depths'''
        read_depths_file = os.path.join(data_dir, 'samtools_variants_test_get_read_depths.gz')

        tests = [
            ( ('ref1', 42), None ),
            ( ('ref2', 1), None ),
            ( ('ref1', 0), ('G', 1, '1') ),
            ( ('ref1', 2), ('T,A', 3, '2,1') ),
            ( ('ref1', 3), ('C,A,G', 42, '21,11,10') ),
            ( ('ref1', 4), ('C,AC', 41, '0,42') )
        ]

        for (name, position), expected in tests:
            self.assertEqual(expected, samtools_variants.SamtoolsVariants._get_read_depths(read_depths_file, name, position))


    def test_get_variant_positions_from_vcf(self):
        '''test _get_variant_positions_from_vcf'''
        vcf_file = os.path.join(data_dir, 'samtools_variants_test_get_variant_positions_from_vcf.vcf')

        expected = [
            ('16__cat_2_M35190.scaffold.1', 92),
            ('16__cat_2_M35190.scaffold.1', 179),
            ('16__cat_2_M35190.scaffold.1', 263),
            ('16__cat_2_M35190.scaffold.6', 93)
        ]

# Path: ariba/samtools_variants.py
# class Error (Exception): pass
# class SamtoolsVariants:
#     def __init__(self,
#       ref_fa,
#       bam,
#       outprefix,
#       log_fh=sys.stdout,
#       min_var_read_depth=4,
#       min_second_var_read_depth=2,
#       max_allele_freq=0.90
#     ):
#     def _make_vcf_and_read_depths_files(self):
#     def _get_read_depths(cls, read_depths_file, sequence_name, position):
#     def _get_variant_positions_from_vcf(cls, vcf_file):
#     def _get_variants(vcf_file, read_depths_file, positions=None):
#     def total_depth_per_contig(read_depths_file):
#     def variants_in_coords(nucmer_matches, vcf_file):
#     def get_depths_at_position(self, seq_name, position):
#     def run(self):


# Path: ariba/tests/samtools_variants_test.py
import unittest
import os
import filecmp
import pyfastaq
from ariba import samtools_variants

        os.unlink(tmp_prefix + '.contig_depths')


    def test_get_read_depths(self):
        '''test _get_read_depths'''
        read_depths_file = os.path.join(data_dir, 'samtools_variants_test_get_read_depths.gz')

        tests = [
            ( ('ref1', 42), None ),
            ( ('ref2', 1), None ),
            ( ('ref1', 0), ('G', 1, '1') ),
            ( ('ref1', 2), ('T,A', 3, '2,1') ),
            ( ('ref1', 3), ('C,A,G', 42, '21,11,10') ),
            ( ('ref1', 4), ('C,AC', 41, '0,42') )
        ]

        for (name, position), expected in tests:
            self.assertEqual(expected, samtools_variants.SamtoolsVariants._get_read_depths(read_depths_file, name, position))


    def test_get_variant_positions_from_vcf(self):
        '''test _get_variant_positions_from_vcf'''
        vcf_file = os.path.join(data_dir, 'samtools_variants_test_get_variant_positions_from_vcf.vcf')

        expected = [
            ('16__cat_2_M35190.scaffold.1', 92),
            ('16__cat_2_M35190.scaffold.1', 179),
            ('16__cat_2_M35190.scaffold.1', 263),
            ('16__cat_2_M35190.scaffold.6', 93)
        ]

        self.assertEqual(expected, samtools_variants.SamtoolsVariants._get_variant_positions_from_vcf(vcf_file))