# Path: kipoiseq/dataloaders/sequence.py
# class SeqIntervalDl(Dataset):
#     """
#     info:
#         doc: >
#             Dataloader for a combination of fasta and tab-delimited input files such as bed files. The dataloader extracts
#             regions from the fasta file as defined in the tab-delimited `intervals_file` and converts them into one-hot encoded
#             format. Returned sequences are of the type np.array with the shape inferred from the arguments: `alphabet_axis`
#             and `dummy_axis`.
#     args:
#         intervals_file:
#             doc: bed3+<columns> file path containing intervals + (optionally) labels
#             example:
#               url: https://raw.githubusercontent.com/kipoi/kipoiseq/master/tests/data/intervals_51bp.tsv
#               md5: a76e47b3df87fd514860cf27fdc10eb4
#         fasta_file:
#             doc: Reference genome FASTA file path.
#             example:
#               url: https://raw.githubusercontent.com/kipoi/kipoiseq/master/tests/data/hg38_chr22_32000000_32300000.fa
#               md5: 01320157a250a3d2eea63e89ecf79eba
#         num_chr_fasta:
#             doc: True, the the dataloader will make sure that the chromosomes don't start with chr.
#         label_dtype:
#             doc: 'None, datatype of the task labels taken from the intervals_file. Example: str, int, float, np.float32'
#         auto_resize_len:
#             doc: None, required sequence length.
#         use_strand:
#             doc: reverse-complement fasta sequence if bed file defines negative strand. Requires a bed6 file
#         alphabet_axis:
#             doc: axis along which the alphabet runs (e.g. A,C,G,T for DNA)
#         dummy_axis:
#             doc: defines in which dimension a dummy axis should be added. None if no dummy axis is required.
#         alphabet:
#             doc: >
#                 alphabet to use for the one-hot encoding. This defines the order of the one-hot encoding.
#                 Can either be a list or a string: 'ACGT' or ['A, 'C', 'G', 'T']. Default: 'ACGT'
#         dtype:
#             doc: 'defines the numpy dtype of the returned array. Example: int, np.int32, np.float32, float'
#         ignore_targets:
#             doc: if True, don't return any target variables
# 
#     output_schema:
#         inputs:
#             name: seq
#             shape: (None, 4)
#             doc: One-hot encoded DNA sequence
#             special_type: DNASeq
#             associated_metadata: ranges
#         targets:
#             shape: (None,)
#             doc: (optional) values following the bed-entry - chr  start  end  target1   target2 ....
#         metadata:
#             ranges:
#                 type: GenomicRanges
#                 doc: Ranges describing inputs.seq
#     postprocessing:
#         variant_effects:
#           bed_input:
#             - intervals_file
#     """
# 
#     def __init__(self,
#                  intervals_file,
#                  fasta_file,
#                  num_chr_fasta=False,
#                  label_dtype=None,
#                  auto_resize_len=None,
#                  # max_seq_len=None,
#                  use_strand=False,
#                  alphabet_axis=1,
#                  dummy_axis=None,
#                  alphabet="ACGT",
#                  ignore_targets=False,
#                  dtype=None):
#         # core dataset, not using the one-hot encoding params
#         self.seq_dl = StringSeqIntervalDl(intervals_file, fasta_file, num_chr_fasta=num_chr_fasta,
#                                           label_dtype=label_dtype, auto_resize_len=auto_resize_len,
#                                           use_strand=use_strand,
#                                           ignore_targets=ignore_targets)
# 
#         self.input_transform = ReorderedOneHot(alphabet=alphabet,
#                                                dtype=dtype,
#                                                alphabet_axis=alphabet_axis,
#                                                dummy_axis=dummy_axis)
# 
#     def __len__(self):
#         return len(self.seq_dl)
# 
#     def __getitem__(self, idx):
#         ret = self.seq_dl[idx]
#         ret['inputs'] = self.input_transform(str(ret["inputs"]))
#         return ret
# 
#     @classmethod
#     def get_output_schema(cls):
#         """Get the output schema. Overrides the default `cls.output_schema`
#         """
#         output_schema = deepcopy(cls.output_schema)
# 
#         # get the default kwargs
#         kwargs = default_kwargs(cls)
# 
#         # figure out the input shape
#         mock_input_transform = ReorderedOneHot(alphabet=kwargs['alphabet'],
#                                                dtype=kwargs['dtype'],
#                                                alphabet_axis=kwargs['alphabet_axis'],
#                                                dummy_axis=kwargs['dummy_axis'])
#         input_shape = mock_input_transform.get_output_shape(
#             kwargs['auto_resize_len'])
# 
#         # modify it
#         output_schema.inputs.shape = input_shape
# 
#         # (optionally) get rid of the target shape
#         if kwargs['ignore_targets']:
#             output_schema.targets = None
# 
#         return output_schema


import kipoi
import kipoi_veff
import kipoi_veff.snv_predict as sp
import pytest
import os
from kipoi_veff.utils.generic import ModelInfoExtractor
from kipoiseq.dataloaders.sequence import SeqIntervalDl
from kipoi.pipeline import install_model_requirements

INSTALL_REQ = False


def test_deepsea():
    model = kipoi.get_model("DeepSEA/variantEffects")
    mie = ModelInfoExtractor(model, SeqIntervalDl)


def test_var_eff_pred_varseq(tmpdir):
    model_name = "DeepSEA/variantEffects"
    if INSTALL_REQ:
        install_model_requirements(model_name, "kipoi", and_dataloaders=True)
    #
    model = kipoi.get_model(model_name, source="kipoi")
    # The preprocessor

# Path: kipoiseq/dataloaders/sequence.py
# class SeqIntervalDl(Dataset):
#     """
#     info:
#         doc: >
#             Dataloader for a combination of fasta and tab-delimited input files such as bed files. The dataloader extracts
#             regions from the fasta file as defined in the tab-delimited `intervals_file` and converts them into one-hot encoded
#             format. Returned sequences are of the type np.array with the shape inferred from the arguments: `alphabet_axis`
#             and `dummy_axis`.
#     args:
#         intervals_file:
#             doc: bed3+<columns> file path containing intervals + (optionally) labels
#             example:
#               url: https://raw.githubusercontent.com/kipoi/kipoiseq/master/tests/data/intervals_51bp.tsv
#               md5: a76e47b3df87fd514860cf27fdc10eb4
#         fasta_file:
#             doc: Reference genome FASTA file path.
#             example:
#               url: https://raw.githubusercontent.com/kipoi/kipoiseq/master/tests/data/hg38_chr22_32000000_32300000.fa
#               md5: 01320157a250a3d2eea63e89ecf79eba
#         num_chr_fasta:
#             doc: True, the the dataloader will make sure that the chromosomes don't start with chr.
#         label_dtype:
#             doc: 'None, datatype of the task labels taken from the intervals_file. Example: str, int, float, np.float32'
#         auto_resize_len:
#             doc: None, required sequence length.
#         use_strand:
#             doc: reverse-complement fasta sequence if bed file defines negative strand. Requires a bed6 file
#         alphabet_axis:
#             doc: axis along which the alphabet runs (e.g. A,C,G,T for DNA)
#         dummy_axis:
#             doc: defines in which dimension a dummy axis should be added. None if no dummy axis is required.
#         alphabet:
#             doc: >
#                 alphabet to use for the one-hot encoding. This defines the order of the one-hot encoding.
#                 Can either be a list or a string: 'ACGT' or ['A, 'C', 'G', 'T']. Default: 'ACGT'
#         dtype:
#             doc: 'defines the numpy dtype of the returned array. Example: int, np.int32, np.float32, float'
#         ignore_targets:
#             doc: if True, don't return any target variables
# 
#     output_schema:
#         inputs:
#             name: seq
#             shape: (None, 4)
#             doc: One-hot encoded DNA sequence
#             special_type: DNASeq
#             associated_metadata: ranges
#         targets:
#             shape: (None,)
#             doc: (optional) values following the bed-entry - chr  start  end  target1   target2 ....
#         metadata:
#             ranges:
#                 type: GenomicRanges
#                 doc: Ranges describing inputs.seq
#     postprocessing:
#         variant_effects:
#           bed_input:
#             - intervals_file
#     """
# 
#     def __init__(self,
#                  intervals_file,
#                  fasta_file,
#                  num_chr_fasta=False,
#                  label_dtype=None,
#                  auto_resize_len=None,
#                  # max_seq_len=None,
#                  use_strand=False,
#                  alphabet_axis=1,
#                  dummy_axis=None,
#                  alphabet="ACGT",
#                  ignore_targets=False,
#                  dtype=None):
#         # core dataset, not using the one-hot encoding params
#         self.seq_dl = StringSeqIntervalDl(intervals_file, fasta_file, num_chr_fasta=num_chr_fasta,
#                                           label_dtype=label_dtype, auto_resize_len=auto_resize_len,
#                                           use_strand=use_strand,
#                                           ignore_targets=ignore_targets)
# 
#         self.input_transform = ReorderedOneHot(alphabet=alphabet,
#                                                dtype=dtype,
#                                                alphabet_axis=alphabet_axis,
#                                                dummy_axis=dummy_axis)
# 
#     def __len__(self):
#         return len(self.seq_dl)
# 
#     def __getitem__(self, idx):
#         ret = self.seq_dl[idx]
#         ret['inputs'] = self.input_transform(str(ret["inputs"]))
#         return ret
# 
#     @classmethod
#     def get_output_schema(cls):
#         """Get the output schema. Overrides the default `cls.output_schema`
#         """
#         output_schema = deepcopy(cls.output_schema)
# 
#         # get the default kwargs
#         kwargs = default_kwargs(cls)
# 
#         # figure out the input shape
#         mock_input_transform = ReorderedOneHot(alphabet=kwargs['alphabet'],
#                                                dtype=kwargs['dtype'],
#                                                alphabet_axis=kwargs['alphabet_axis'],
#                                                dummy_axis=kwargs['dummy_axis'])
#         input_shape = mock_input_transform.get_output_shape(
#             kwargs['auto_resize_len'])
# 
#         # modify it
#         output_schema.inputs.shape = input_shape
# 
#         # (optionally) get rid of the target shape
#         if kwargs['ignore_targets']:
#             output_schema.targets = None
# 
#         return output_schema


# Path: tests/dont_test_4_integration.py
import kipoi
import kipoi_veff
import kipoi_veff.snv_predict as sp
import pytest
import os
from kipoi_veff.utils.generic import ModelInfoExtractor
from kipoiseq.dataloaders.sequence import SeqIntervalDl
from kipoi.pipeline import install_model_requirements


INSTALL_REQ = False


def test_deepsea():
    model = kipoi.get_model("DeepSEA/variantEffects")
    mie = ModelInfoExtractor(model, SeqIntervalDl)


def test_var_eff_pred_varseq(tmpdir):
    model_name = "DeepSEA/variantEffects"
    if INSTALL_REQ:
        install_model_requirements(model_name, "kipoi", and_dataloaders=True)
    #
    model = kipoi.get_model(model_name, source="kipoi")
    # The preprocessor

    Dataloader = SeqIntervalDl