# Path: kipoiseq/extractors/protein.py
# class SingleVariantProteinVCFSeqExtractor(SingleVariantExtractorMixin, ProteinVCFSeqExtractor):
#     pass
# 
# class TranscriptSeqExtractor(GenericMultiIntervalSeqExtractor):
# 
#     def __init__(self, gtf_file, fasta_file):
#         self.fasta_file = str(fasta_file)
#         self.gtf_file = str(gtf_file)
# 
#         cds_fetcher = CDSFetcher(self.gtf_file)
# 
#         extractor = FastaStringExtractor(self.fasta_file, use_strand=False)
# 
#         super().__init__(
#             extractor=extractor,
#             interval_fetcher=cds_fetcher
#         )
# 
#     @property
#     def df(self):
#         return self.extractor.df
# 
#     @property
#     def cds(self):
#         return self.extractor.df
# 
#     @classmethod
#     def _prepare_seq(
#             cls,
#             seqs: List[str],
#             intervals: List[Interval],
#             reverse_complement: Union[str, bool],
#             # **kwargs
#     ) -> str:
#         """
#         Prepare the dna sequence in the final variant, which should be
#         translated in amino acid sequence
#         :param seqs: current dna sequence
#         :param intervals: the list of intervals corresponding to the sequence snippets
#         :param reverse_complement: should the dna be reverse-complemented?
#         :return: prepared dna sequence ready for translation into amino acid sequence
#         """
#         seq = super()._prepare_seq(
#             seqs=seqs,
#             intervals=intervals,
#             reverse_complement=reverse_complement,
#         )
#         tag = intervals[0].attrs["tag"]
#         seq = cut_transcript_seq(seq, tag)
#         return seq
# 
#     def get_protein_seq(self, transcript_id: str):
#         """
#         Extract amino acid sequence for given transcript_id
#         :param transcript_id: 
#         :return: amino acid sequence
#         """
#         return translate(self.get_seq(transcript_id), hg38=True)
# 
# class SingleSeqProteinVCFSeqExtractor(SingleSeqExtractorMixin, ProteinVCFSeqExtractor):
#     pass
# 
# Path: kipoiseq/transforms/functional.py
# def translate(seq: str, hg38=False):
#     """Translate the DNA/RNA sequence into AA.
# 
#     Note: it stops after it encounters a stop codon
# 
#     # Arguments
#         seq: DNA/RNA sequence
#         stop_none: return None if a stop codon is encountered
#     """
#     if len(seq) % 3 != 0:
#         raise ValueError("len(seq) % 3 != 0")
# 
#     outl = [''] * (len(seq) // 3)
#     if hg38:
#         for i in range(0, len(seq), 3):
#             codon = seq[i:i + 3]
#             outl[i // 3] = TRANSLATION_TABLE_FOR_HG38[codon]
#     else:
#         for i in range(0, len(seq), 3):
#             codon = seq[i:i + 3]
#             outl[i // 3] = TRANSLATION_TABLE[codon]
# 
#     return "".join(outl)


from tqdm import tqdm_notebook as tqdm
from kipoiseq.extractors.protein import SingleVariantProteinVCFSeqExtractor, TranscriptSeqExtractor, SingleSeqProteinVCFSeqExtractor
from kipoiseq.transforms.functional import translate
from pyfaidx import Fasta
from conftest import gtf_file_GRCh38, fasta_file_GRCh38, vcf_file_for_testing_synonymous_mutations, protein_file_GRCh38, uniprot_seq_ref
import pytest
import os
    for t_id in single_var_seq:
        count += len(list(t_id))

    assert count == 825


@pytestmark_gtf
@pytestmark_fasta
@pytestmark_vcf
@pytestmark_protein
def test_vcf_single_seq_variants(ssp):
    single_seqs = list(ssp.extract_all())
    assert len(single_seqs) == 5


@pytestmark_gtf
@pytestmark_fasta
@pytestmark_vcf
@pytestmark_protein
def test_ensembl_uniprot_seq(tse):
    id_and_seq = {}
    with open(uniprot_seq_ref, 'r+') as f:
        key = ""
        for line in f:
            if '>' in line:
                key = (line.replace('>', '')).rstrip()
            else:
                id_and_seq[key] = line.rstrip()

    for transkript_id, ref_seq in tqdm(id_and_seq.items()):

# Path: kipoiseq/extractors/protein.py
# class SingleVariantProteinVCFSeqExtractor(SingleVariantExtractorMixin, ProteinVCFSeqExtractor):
#     pass
# 
# class TranscriptSeqExtractor(GenericMultiIntervalSeqExtractor):
# 
#     def __init__(self, gtf_file, fasta_file):
#         self.fasta_file = str(fasta_file)
#         self.gtf_file = str(gtf_file)
# 
#         cds_fetcher = CDSFetcher(self.gtf_file)
# 
#         extractor = FastaStringExtractor(self.fasta_file, use_strand=False)
# 
#         super().__init__(
#             extractor=extractor,
#             interval_fetcher=cds_fetcher
#         )
# 
#     @property
#     def df(self):
#         return self.extractor.df
# 
#     @property
#     def cds(self):
#         return self.extractor.df
# 
#     @classmethod
#     def _prepare_seq(
#             cls,
#             seqs: List[str],
#             intervals: List[Interval],
#             reverse_complement: Union[str, bool],
#             # **kwargs
#     ) -> str:
#         """
#         Prepare the dna sequence in the final variant, which should be
#         translated in amino acid sequence
#         :param seqs: current dna sequence
#         :param intervals: the list of intervals corresponding to the sequence snippets
#         :param reverse_complement: should the dna be reverse-complemented?
#         :return: prepared dna sequence ready for translation into amino acid sequence
#         """
#         seq = super()._prepare_seq(
#             seqs=seqs,
#             intervals=intervals,
#             reverse_complement=reverse_complement,
#         )
#         tag = intervals[0].attrs["tag"]
#         seq = cut_transcript_seq(seq, tag)
#         return seq
# 
#     def get_protein_seq(self, transcript_id: str):
#         """
#         Extract amino acid sequence for given transcript_id
#         :param transcript_id: 
#         :return: amino acid sequence
#         """
#         return translate(self.get_seq(transcript_id), hg38=True)
# 
# class SingleSeqProteinVCFSeqExtractor(SingleSeqExtractorMixin, ProteinVCFSeqExtractor):
#     pass
# 
# Path: kipoiseq/transforms/functional.py
# def translate(seq: str, hg38=False):
#     """Translate the DNA/RNA sequence into AA.
# 
#     Note: it stops after it encounters a stop codon
# 
#     # Arguments
#         seq: DNA/RNA sequence
#         stop_none: return None if a stop codon is encountered
#     """
#     if len(seq) % 3 != 0:
#         raise ValueError("len(seq) % 3 != 0")
# 
#     outl = [''] * (len(seq) // 3)
#     if hg38:
#         for i in range(0, len(seq), 3):
#             codon = seq[i:i + 3]
#             outl[i // 3] = TRANSLATION_TABLE_FOR_HG38[codon]
#     else:
#         for i in range(0, len(seq), 3):
#             codon = seq[i:i + 3]
#             outl[i // 3] = TRANSLATION_TABLE[codon]
# 
#     return "".join(outl)


# Path: tests/test_5_additional_tests_for_extractors.py
from tqdm import tqdm_notebook as tqdm
from kipoiseq.extractors.protein import SingleVariantProteinVCFSeqExtractor, TranscriptSeqExtractor, SingleSeqProteinVCFSeqExtractor
from kipoiseq.transforms.functional import translate
from pyfaidx import Fasta
from conftest import gtf_file_GRCh38, fasta_file_GRCh38, vcf_file_for_testing_synonymous_mutations, protein_file_GRCh38, uniprot_seq_ref
import pytest
import os

    for t_id in single_var_seq:
        count += len(list(t_id))

    assert count == 825


@pytestmark_gtf
@pytestmark_fasta
@pytestmark_vcf
@pytestmark_protein
def test_vcf_single_seq_variants(ssp):
    single_seqs = list(ssp.extract_all())
    assert len(single_seqs) == 5


@pytestmark_gtf
@pytestmark_fasta
@pytestmark_vcf
@pytestmark_protein
def test_ensembl_uniprot_seq(tse):
    id_and_seq = {}
    with open(uniprot_seq_ref, 'r+') as f:
        key = ""
        for line in f:
            if '>' in line:
                key = (line.replace('>', '')).rstrip()
            else:
                id_and_seq[key] = line.rstrip()

    for transkript_id, ref_seq in tqdm(id_and_seq.items()):

        test_seq = translate(tse.get_seq(transkript_id), True)