# Path: ariba/sequence_metadata.py
# class Error (Exception): pass
# class SequenceMetadata:
#     def __init__(self, line):
#     def __eq__(self, other):
#     def __lt__(self, other):
#     def __hash__(self):
#     def __str__(self):
#     def to_string(self, separator='\t'):
#     def has_variant(self, seq):
# 
# Path: ariba/cdhit.py
# class Error (Exception): pass
# class Runner:
#     def __init__(
#       self,
#       infile,
#       seq_identity_threshold=0.9,
#       threads=1,
#       length_diff_cutoff=0.0,
#       memory_limit=None,
#       verbose=False,
#       min_cluster_number=0
#     ):
#     def fake_run(self):
#     def _load_user_clusters_file(filename, all_ref_seqs, rename_dict=None):
#     def run_get_clusters_from_file(self, clusters_infile, all_ref_seqs, rename_dict=None):
#     def _get_clusters_from_bak_file(filename, min_cluster_number=0):
#     def get_run_cmd(self, output_file):
#     def run(self):


import json
import os
import sys
import re
import copy
import pyfastaq
from ariba import sequence_metadata, cdhit

            # if this is non_coding, we shouldn't have any amino acid variants
            if metadata_dict['seq_type'] != 'p':
                for position in metadata_dict['p']:
                    for metadata in metadata_dict['p'][position]:
                        print(sequence_name, 'variant is an amino acid change, but sequence is non-coding. Removing. Line of file was:', metadata, file=log_fh)
                        log_lines += 1

                metadata_dict['p'] = {}

            # take out variant metadata that doesn't make sense (eg bases not matching ref sequence)
            for variant_type in ['n', 'p']:
                positions_to_remove = []
                for position in metadata_dict[variant_type]:
                    meta_to_remove = []
                    for metadata in metadata_dict[variant_type][position]:
                        to_translate = variant_type == 'p'

                        if not metadata.variant.sanity_check_against_seq(sequences[sequence_name], translate_seq=to_translate):
                            print(sequence_name, 'variant does not match reference. Removing. Line of file was:', metadata, file=log_fh)
                            log_lines += 1
                            meta_to_remove.append(metadata)
                            continue

                        if metadata_dict['variant_only']:
                            variants_only_genes_found_variant.add(sequence_name)

                    for metadata in meta_to_remove:
                        metadata_dict[variant_type][position].remove(metadata)
                    if len(metadata_dict[variant_type][position]) == 0:

# Path: ariba/sequence_metadata.py
# class Error (Exception): pass
# class SequenceMetadata:
#     def __init__(self, line):
#     def __eq__(self, other):
#     def __lt__(self, other):
#     def __hash__(self):
#     def __str__(self):
#     def to_string(self, separator='\t'):
#     def has_variant(self, seq):
# 
# Path: ariba/cdhit.py
# class Error (Exception): pass
# class Runner:
#     def __init__(
#       self,
#       infile,
#       seq_identity_threshold=0.9,
#       threads=1,
#       length_diff_cutoff=0.0,
#       memory_limit=None,
#       verbose=False,
#       min_cluster_number=0
#     ):
#     def fake_run(self):
#     def _load_user_clusters_file(filename, all_ref_seqs, rename_dict=None):
#     def run_get_clusters_from_file(self, clusters_infile, all_ref_seqs, rename_dict=None):
#     def _get_clusters_from_bak_file(filename, min_cluster_number=0):
#     def get_run_cmd(self, output_file):
#     def run(self):


# Path: ariba/reference_data.py
import json
import os
import sys
import re
import copy
import pyfastaq
from ariba import sequence_metadata, cdhit


            # if this is non_coding, we shouldn't have any amino acid variants
            if metadata_dict['seq_type'] != 'p':
                for position in metadata_dict['p']:
                    for metadata in metadata_dict['p'][position]:
                        print(sequence_name, 'variant is an amino acid change, but sequence is non-coding. Removing. Line of file was:', metadata, file=log_fh)
                        log_lines += 1

                metadata_dict['p'] = {}

            # take out variant metadata that doesn't make sense (eg bases not matching ref sequence)
            for variant_type in ['n', 'p']:
                positions_to_remove = []
                for position in metadata_dict[variant_type]:
                    meta_to_remove = []
                    for metadata in metadata_dict[variant_type][position]:
                        to_translate = variant_type == 'p'

                        if not metadata.variant.sanity_check_against_seq(sequences[sequence_name], translate_seq=to_translate):
                            print(sequence_name, 'variant does not match reference. Removing. Line of file was:', metadata, file=log_fh)
                            log_lines += 1
                            meta_to_remove.append(metadata)
                            continue

                        if metadata_dict['variant_only']:
                            variants_only_genes_found_variant.add(sequence_name)

                    for metadata in meta_to_remove:
                        metadata_dict[variant_type][position].remove(metadata)
                    if len(metadata_dict[variant_type][position]) == 0:

                        positions_to_remove.append(position)