# License: GNU Affero General Public License v3 or later
# A copy of GNU AGPL v3 should have been included in this software package in LICENSE.txt.

# for test files, silence irrelevant and noisy pylint warnings
# pylint: disable=no-self-use,protected-access,missing-docstring

import unittest

from antismash.modules.nrps_pks.at_analysis.at_analysis import run_at_domain_analysis
from antismash.config import build_config, destroy_config


class TestKRAnalysis(unittest.TestCase):
    query_data = {
      'SCO0126_AT1': 'LFPGQGSQYVGMGAELAMLAPTAQAVWDRLGSIRFDGRPLHRAVFPPPAFTEEERAA'
                     'RAALLNATEWAQPALAVHALALLAVVRELGLRPDCVAGHSFGELVALHCAGALDAES'
                     'LVGLARRRGELMREAAATPGAMLAVAADRVRVAEVLAGGGFEDIWPANHNSPRQTVL'
                     'SGSAAAVERARSAFSAAGIASRGLSASTAFHSPLVAPAVEPLAAHLRTVTFSEPRIE'
                     'VYGNTDAAPYPSCPDAVRRRVAGHLASPVLFQDQIEAMYAAGVRTFVEVGAGATLTG'
                     'LVGQILGGREH',
      'SCO0127_AT1': 'EVLGLRPDAAIGYSSGESTALVALGAWPDASGLYEATRESGLFTTELTGELRAVRRY'
                     'WRQRGIGGDRWSSYLVAAPLEAVRAELAGERAVHLMAVNAPGVCVVGGESKACAAVV'
                     'ARLGVDRAIELDYDMAAHAPELAEVREVWREAHRRPTVEVPGVRFYSGATGRAYRPT'
                     'TERAAEALTAQGLGTIDFAATIERAWADGVRVFVEHGPRKLCTGWIKRVLGDREF',
      'SCO6827_AT1': 'VFPGQGSQWPGMGRELLDSEPVFHQAMRDCDDAIRTENGWSVIELLRSADEERLKEL'
                     'DVIQPTLWAIEIALAQLWRSWGIEPDVVIGHSMGESAAAYIAGALSLSDAAAVICRR'
                     'SRLAKRLSGRGTMAWVALPADEAAAALVGHEDTVAVAAINSPTSTLLSGDGEALDQV'
                     'LAGLDARSVDNRRVNVDFASHCPQMDALQEDLLSELSHLTPRAGTIPLHSTLLNEVI'
                     'DGSGMNAEYWVRNIRQPVDFVGAVKGQLDLGDTVFVEVSPHPLLVSGIRETSRMATS'
                     'ADTTAVGSLRRH',
      'SCO6275_AT3': 'LFTGQGSQRLGMGRELYESSPVFAKALDEVCSRFRAELARPVKDVLFAQEDSATAAL'
                     'IDQTAFTQAALFCVEVALYRLFEHHGFTPDYLLGHSIGEVTAAYLSGVLDLDDACCL'
                     'VAERGRLMQAAREGGAMAALQASEEEVYASIAPYGDAVGIAGVNGPESLVISGDEDV'
                     'VEEVTAAWRANGVRTKRLPVSHAFHSSHMDEVLDEFREVASGLSFRPPRIPVVSNVT'
                     'GTLATDAQLTSPDYWATHIREAVRFLDGVRYLEAQGVTDFLELGPDAVLTALTRGSL'
                     'EEEAGVLVAALRRD',
      'SCO6275_AT2': 'LFTGQGAQRAGMGRELYARHPVFAEALDAAFGALDAHLDLPLREVVFAAEGSREAAL'
                     'LDETTYTQPALFALEVALFRLLEHHGVTPGLLAGHSVGELSAAHAAGVLTLDDAAKL'
                     'VAARGRLMQAARSGGAMIAVEAAEEEVLPYLEGRAAGLSVAAVNGPASVVISGDEEP'
                     'ALEVAELLRASGRRTKRLTVSHAFHSPHMDGVLDAFREVASTVAFSAPTVPIVSTVT'
                     'GRLATEAELTSPQYWANQIRAAVRFLDAARELAAQGATVFVEAGPDAVLTALTRAAL'
                     'EDTGATAVPLMR',
      'SCO6273_AT1': 'LFTGQGAQRTGMGMDLYRTFPAYAHAFDTITAQLDPHLDQPLHHTITTGHHLHHTGN'
                     'TQPALFATEVALYRLLETWGITPDYLAGHSIGELTAAHISGILTLQDACTLVTARAR'
                     'LMQNLPTHGTMIALQATEQEILPHLTGHEHHLTIAAINSPTSLVISGNQTAAQHIAT'
                     'QLQAQGRKTKTLTVSHAFHSPHMDGMLHDFHHTATQLTYHEPTIPIVSTLTGNLATH'
                     'NDLRTPTYWTDQLRNTVRYTQAIHTLHTAGVTTYTEIGPDATLTPLTQQTLDTTTAI'
                     'PLLR',
      'SCO6274_AT1': 'LFTGQGAQRTGMGMDLYRTFPAYAHAFDTITAQLDPHLDQPLHHTITTGHHLHHTGN'
                     'TQPALFATEVALYRLLETWGITPDYLAGHSIGELTAAHISGILTLQDACTLVTARAR'
                     'LMQNLPTHGTMIALQATEQEILPHLTGHEHHLTIAAINSPTSLVISGNQTAAQHIAT'
                     'QLQAQGRKTKTLTVSHAFHSPHMDGMLHDFHHTATQLTYHEPTIPIVSTLTGNLATH'
                     'NDLRTPTYWTDQLRNTVRYTQAIHTLHTAGVTTYTEIGPDATLTPLTASTVEDSDGV'
                     'AAIATLRA',
      'SCO6274_AT2': 'LFTGQGAQRTGMGMDLYRTFPAYAHAFDTITAQLDPHLDQPLHHTITTGHHLHHTGN'
                     'TQPALFATEVALYRLLETWGITPDYLAGHSIGELTAAHISGILTLQDACTLVTARAR'
                     'LMQNLPTHGTMIALQATEQEILPHLTGHEHHLTIAAINSPTSLVISGNQTAAQHIAT'
                     'QLQAQGRKTKTLTVSHAFHSPHMDGMLHDFHHTATQLTYHEPTIPIVSTLTGNLATH'
                     'NDLRTPTYWTDQLRNTVRYTQAIHTLHTAGVTTYTEIGPDATLTPLTQQTLDTTTAI'
                     'PLLR',
      'SCO5892_AT1': 'LFGGQGTQYPGMGRDLYDAHPVLARTLRRADAVLRGLGEIPLLDLLFDPDRAEDLAR'
                     'TRYCQPALVALEVALADLWTSCGVRPAAVLGHSVGALAAACVAGVLSLEDALTLAVV'
                     'RGRAMDEQPGEGAMIACVGDPETVREIAAGHDRVALAAVNAPRNLVFSGAADRIAAL'
                     'RGDLERKGVTVRPLAVSHAFHSPLMAGAAEPLLEAARAVEFQPPAIPWISDATGEPV'
                     'TRVDAEYWVRHLLGTVRFADGFARLRAGNAEGGLGCDAFVEIGPHPTLLNLGRSAVA'
                     'DGPEPDGRRTLWLPSLRRG',
      'SCO6275_AT1': 'LFTGQGAQRPGMGQELYAAHPVFADAFDAVAERLDPMLKQPLWEVIASGEGLDETGR'
                     'TQPALFAIEVALFRLLESWGVRPGFLAGHSIGELAAAHVAGVLSLDDAARLVAARAR'
                     'LMQALPAGGAMIAVEATEEEVLPHLEGLEARLSLAAVNGPASVVISGEADAAEDVAA'
                     'RLAEAGRRTKRLTVSHAFHSPLMDGMLKEFHKVAKELTYHAPRIPVVSTLTGALASG'
                     'DDLRTPCYWTDQVRHAVRFADAVRTLGELGATVLLEVGPDAVLSSLADATPTL'
      }

    def setUp(self):
        build_config([])

    def tearDown(self):
        destroy_config()

    def test_full_run(self):
        results = run_at_domain_analysis(self.query_data)
        # check best hits only
        best = {}
        for key, val in results.items():
            if not val.predictions:
                continue
            best[key] = (val.predictions[0][1].name, val.predictions[0][1].score)
        assert best == {'SCO0126_AT1': ('Q83Y48_AT1__mal', 79.16666666666667),
                        'SCO5892_AT1': ('D3Y1I5_AT1__mal', 95.83333333333333),
                        'SCO6273_AT1': ('Q9EWA1_AT4__mal', 91.66666666666667),
                        'SCO6274_AT1': ('Q9EWA1_AT4__mal', 91.66666666666667),
                        'SCO6274_AT2': ('Q9EWA1_AT4__mal', 91.66666666666667),
                        'SCO6275_AT1': ('Q93NX9_AT5__mal', 91.66666666666667),
                        'SCO6275_AT2': ('B5L6K9_AT4__mal', 95.83333333333333),
                        'SCO6275_AT3': ('Q53840_AT1__mal', 100.0),
                        'SCO6827_AT1': ('Q93TW8_AT1__mmal', 91.66666666666667)}
        # ensure that 127 made it in, but that it had no hits
        assert results['SCO0127_AT1'].predictions == []
