# Path: test/utils/vcf_test.py
# class MockVcfReader(object):
#     def __init__(self,
#                  input_filepath="vcfName",
#                  metaheaders=None,
#                  column_header='#CHROM\tPOS\tID\tREF\tALT\tQUAL\tFILTER\tINFO\tFORMAT\tNORMAL\tTUMOR',
#                  content=None,
#                  records=None,
#                  sample_names=None):
# 
#         if content is None:
#             self.content = ["foo"]
#         else:
#             self.content = content
# 
#         if metaheaders is None:
#             self.metaheaders = ["##metaheaders"]
#         else:
#             self.metaheaders = metaheaders
# 
#         if records:
#             self.records = records
#         elif content:
#             self.records = [MockVcfRecord.parse_record(line) for line in self.content]
#         else:
#             self.records = []
# 
#         if sample_names is None:
#             self.sample_names = []
#         else:
#             self.sample_names = sample_names
#         self.file_name = input_filepath
#         self.input_filepath = input_filepath
#         self.column_header = column_header
#         self.split_column_header = self.column_header.strip("#").split("\t")
#         self.opened = False
#         self.closed = False
#         self._caller_name = "mockCaller"
#         self.qualified_sample_names = self._create_qualified_sample_names()
#         self.format_tags={}
# 
#     def open(self):
#         self.opened = True
#     #pylint:disable=unused-argument
#     def vcf_records(self, dummy=None, qualified=False):
#         for record in self.records:
#             yield record
# 
#     def tagged_vcf_records(self):
#         for record in self.records:
#             yield record
# 
#     def _get_tag_metaheaders(self, regex_exp):
#         tag_dict = {}
#         for metaheader in self.metaheaders:
#             tag = re.match(regex_exp, metaheader)
#             if tag:
#                 tag_key = tag.group(1)
#                 tag_dict[tag_key] = metaheader.strip()
# 
#         return tag_dict
# 
#     @property
#     def format_metaheaders(self):
#         return dict(self._get_tag_metaheaders("^##FORMAT=.*?[<,]ID=([^,>]*)"))
# 
#     @property
#     def info_metaheaders(self):
#         return dict(self._get_tag_metaheaders("^##INFO=.*?[<,]ID=([^,>]*)"))
# 
#     @property
#     def filter_metaheaders(self):
#         return dict(self._get_tag_metaheaders("^##FILTER=.*?[<,]ID=([^,>]*)"))
# 
#     @property
#     def contig_metaheaders(self):
#         return dict(self._get_tag_metaheaders("^##contig=.*?[<,]ID=([^,>]*)"))
# 
#     @property
#     def non_format_metaheaders(self):
#         return self.metaheaders
# 
#     def _create_qualified_sample_names(self):
#         patient_prefix = self.file_name.split(".")[0]
#         qualified_names = []
#         if self.sample_names:
#             for sample_name in self.sample_names:
#                 qualified_names.append("|".join([patient_prefix, sample_name]))
#         else:
#             qualified_names.append("|".join(["foo", "bar"]))
#         return qualified_names
# 
#     def modify_metaheader(self, original_metaheader, transformed_tag):
#         pass
# 
#     def store_format_tags(self, original_tag, new_tag):
#         self.format_tags[original_tag] = new_tag
# 
#     @property
#     def caller_name(self):
#         return self._caller_name
# 
#     def close(self):
#         self.closed = True
# 
# class MockFileWriter(object):
#     def __init__(self):
#         self._content = []
#         self.opened = False
#         self.closed = False
# 
#     def open(self):
#         self.opened = True
# 
#     def write(self, content):
#         if content == None:
#             return
#         self._content.extend(content.splitlines())
# 
#     def lines(self):
#         return self._content
# 
#     def close(self):
#         self.closed = True


from collections import OrderedDict
from argparse import Namespace
from testfixtures import TempDirectory
from test.utils.vcf_test import MockVcfReader, MockFileWriter
import os
import jacquard.expand as expand
import jacquard.utils.logger
import jacquard.utils.utils as utils
import jacquard.utils.vcf as vcf
import test.utils.mock_logger
import test.utils.test_case as test_case
                                   "qual|filter|info|format|"
                                   "sampleA|sampleB")
        mock_vcf_reader = MockVcfReader(metaheaders=metaheaders,
                                        column_header=column_header,
                                        sample_names=sample_names)

        actual_cols = expand._create_potential_column_list(mock_vcf_reader)
        expected_cols = OrderedDict([("chrom", None),
                                     ("pos", None),
                                     ("id", None),
                                     ("ref", None),
                                     ("alt", None),
                                     ("qual", None),
                                     ("filter", None),
                                     ("info", None),
                                     ("AA", "AA"),
                                     ("AF", "AF"),
                                     ("GQ|sampleA", "GQ"),
                                     ("GQ|sampleB", "GQ"),
                                     ("GT|sampleA", "GT"),
                                     ("GT|sampleB", "GT")])
        self.assertEquals(expected_cols, actual_cols)

    def test_create_potential_column_list_preservesSampleOrdering(self):
        metaheaders = ['##FORMAT=<ID=B,Number=1>', '##FORMAT=<ID=A,Number=1>']
        sample_names = ["sample1", "sample2", "sample10"]
        column_header = self.entab("#chrom|pos|id|ref|alt|"
                                   "qual|filter|info|format|"
                                   "sample1|sample2|sample10")


# Path: test/utils/vcf_test.py
# class MockVcfReader(object):
#     def __init__(self,
#                  input_filepath="vcfName",
#                  metaheaders=None,
#                  column_header='#CHROM\tPOS\tID\tREF\tALT\tQUAL\tFILTER\tINFO\tFORMAT\tNORMAL\tTUMOR',
#                  content=None,
#                  records=None,
#                  sample_names=None):
# 
#         if content is None:
#             self.content = ["foo"]
#         else:
#             self.content = content
# 
#         if metaheaders is None:
#             self.metaheaders = ["##metaheaders"]
#         else:
#             self.metaheaders = metaheaders
# 
#         if records:
#             self.records = records
#         elif content:
#             self.records = [MockVcfRecord.parse_record(line) for line in self.content]
#         else:
#             self.records = []
# 
#         if sample_names is None:
#             self.sample_names = []
#         else:
#             self.sample_names = sample_names
#         self.file_name = input_filepath
#         self.input_filepath = input_filepath
#         self.column_header = column_header
#         self.split_column_header = self.column_header.strip("#").split("\t")
#         self.opened = False
#         self.closed = False
#         self._caller_name = "mockCaller"
#         self.qualified_sample_names = self._create_qualified_sample_names()
#         self.format_tags={}
# 
#     def open(self):
#         self.opened = True
#     #pylint:disable=unused-argument
#     def vcf_records(self, dummy=None, qualified=False):
#         for record in self.records:
#             yield record
# 
#     def tagged_vcf_records(self):
#         for record in self.records:
#             yield record
# 
#     def _get_tag_metaheaders(self, regex_exp):
#         tag_dict = {}
#         for metaheader in self.metaheaders:
#             tag = re.match(regex_exp, metaheader)
#             if tag:
#                 tag_key = tag.group(1)
#                 tag_dict[tag_key] = metaheader.strip()
# 
#         return tag_dict
# 
#     @property
#     def format_metaheaders(self):
#         return dict(self._get_tag_metaheaders("^##FORMAT=.*?[<,]ID=([^,>]*)"))
# 
#     @property
#     def info_metaheaders(self):
#         return dict(self._get_tag_metaheaders("^##INFO=.*?[<,]ID=([^,>]*)"))
# 
#     @property
#     def filter_metaheaders(self):
#         return dict(self._get_tag_metaheaders("^##FILTER=.*?[<,]ID=([^,>]*)"))
# 
#     @property
#     def contig_metaheaders(self):
#         return dict(self._get_tag_metaheaders("^##contig=.*?[<,]ID=([^,>]*)"))
# 
#     @property
#     def non_format_metaheaders(self):
#         return self.metaheaders
# 
#     def _create_qualified_sample_names(self):
#         patient_prefix = self.file_name.split(".")[0]
#         qualified_names = []
#         if self.sample_names:
#             for sample_name in self.sample_names:
#                 qualified_names.append("|".join([patient_prefix, sample_name]))
#         else:
#             qualified_names.append("|".join(["foo", "bar"]))
#         return qualified_names
# 
#     def modify_metaheader(self, original_metaheader, transformed_tag):
#         pass
# 
#     def store_format_tags(self, original_tag, new_tag):
#         self.format_tags[original_tag] = new_tag
# 
#     @property
#     def caller_name(self):
#         return self._caller_name
# 
#     def close(self):
#         self.closed = True
# 
# class MockFileWriter(object):
#     def __init__(self):
#         self._content = []
#         self.opened = False
#         self.closed = False
# 
#     def open(self):
#         self.opened = True
# 
#     def write(self, content):
#         if content == None:
#             return
#         self._content.extend(content.splitlines())
# 
#     def lines(self):
#         return self._content
# 
#     def close(self):
#         self.closed = True


# Path: test/expand_test.py
from collections import OrderedDict
from argparse import Namespace
from testfixtures import TempDirectory
from test.utils.vcf_test import MockVcfReader, MockFileWriter
import os
import jacquard.expand as expand
import jacquard.utils.logger
import jacquard.utils.utils as utils
import jacquard.utils.vcf as vcf
import test.utils.mock_logger
import test.utils.test_case as test_case

                                   "qual|filter|info|format|"
                                   "sampleA|sampleB")
        mock_vcf_reader = MockVcfReader(metaheaders=metaheaders,
                                        column_header=column_header,
                                        sample_names=sample_names)

        actual_cols = expand._create_potential_column_list(mock_vcf_reader)
        expected_cols = OrderedDict([("chrom", None),
                                     ("pos", None),
                                     ("id", None),
                                     ("ref", None),
                                     ("alt", None),
                                     ("qual", None),
                                     ("filter", None),
                                     ("info", None),
                                     ("AA", "AA"),
                                     ("AF", "AF"),
                                     ("GQ|sampleA", "GQ"),
                                     ("GQ|sampleB", "GQ"),
                                     ("GT|sampleA", "GT"),
                                     ("GT|sampleB", "GT")])
        self.assertEquals(expected_cols, actual_cols)

    def test_create_potential_column_list_preservesSampleOrdering(self):
        metaheaders = ['##FORMAT=<ID=B,Number=1>', '##FORMAT=<ID=A,Number=1>']
        sample_names = ["sample1", "sample2", "sample10"]
        column_header = self.entab("#chrom|pos|id|ref|alt|"
                                   "qual|filter|info|format|"
                                   "sample1|sample2|sample10")


        mock_vcf_reader = MockVcfReader(metaheaders=metaheaders,