# from collections import defaultdict
# import sys 
# import os

# from helper_functions import convert_to_bases
# from bcf_vcf import clean_files, handle_infiles


# def Annotate_with_ref_genome(vcffiles, obsfile):


#     obs = defaultdict(list)

#     with open(obsfile) as data:
#         for line in data:
#             if not line.startswith('chrom'):
#                 chrom, pos, ancestral_base, genotype = line.strip().split()
#                 derived_variant = genotype.replace(ancestral_base, '')[0]
#                 ID = f'{chrom}_{pos}'
#                 obs[ID] = [ancestral_base, derived_variant, '']

#     for vcffile in handle_infiles(vcffiles):
#         command = f'bcftools view -a -R {obsfile} {vcffile}'
#         for line in os.popen(command):
#             if line.startswith('#CHROM'):
#                 individuals_in_vcffile = line.strip().split()[9:]

#             if not line.startswith('#'):

#                 chrom, pos, _, ref_allele, alt_allele = line.strip().split()[0:5]
#                 ID =  f'{chrom}_{pos}'
#                 genotypes = [x.split(':')[0] for x in line.strip().split()[9:]]

#                 ancestral_base, derived_base, _ = obs[ID]
#                 found_in = []

#                 for original_genotype, individual in zip(genotypes, individuals_in_vcffile):

#                     if '.' not in original_genotype:
#                         genotype = convert_to_bases(original_genotype, ref_allele, alt_allele)   

#                         if genotype.count(derived_base) > 0:
#                             found_in.append(individual)
#                             #print(pos, individual, original_genotype)

#                 obs[ID] = [ancestral_base, derived_base, ','.join(found_in)]


#     # Clean log files generated by vcf and bcf tools
#     clean_files('out.log')

#     return obs





# Annotate_with_ref_genome('archaicvar/highcov_ind_1.bcf', 'obs/obs.HG00096.txt')
