from kqml import KQMLList
from tfta.tfta import TFTA
from tfta.tfta_module import TFTA_Module
from bioagents.tests.util import ekb_from_text, ekb_kstring_from_text, \
                                 get_request
from bioagents.tests.integration import _IntegrationTest, _FailureTest


#FIND-TF-TARGET
class _TestFindTfTarget(_IntegrationTest):
    def __init__(self, *args):
        super(_TestFindTfTarget, self).__init__(TFTA_Module)

    def create_message(self):
        # Here we create a KQML request that the TFTA needs to respond to
        tf = ekb_kstring_from_text(self.tf)
        content = KQMLList('FIND-TF-TARGET')
        content.set('tf', tf)
        return get_request(content), content

    def check_response_to_message(self, output):
        # Here we check the details of the response and make sure everything
        # we are looking for is in the output
        # First, we check that the response is a success
        assert output.head() == 'SUCCESS', output
        # Then we check that we got the expected number of target
        assert len(output.get('targets')) == 115
        # We could do further checks here to see if a given expected target
        # shows up in the response, etc.


#what genes are regulated by smad2?
class TestFindTfTarget1(_TestFindTfTarget):
    tf = 'SMAD2'
    def check_response_to_message(self, output):
        assert output.head() == 'SUCCESS', output
        assert len(output.get('targets')) == 115, output

#What genes does stat3 regulate?


#what genes are regulated by elk1 and smad2?
class TestFindTfTarget2(_TestFindTfTarget):
    tf = 'ELK1, SMAD2'
    def check_response_to_message(self, output):
        assert output.head() == 'SUCCESS', output
        assert len(output.get('targets')) == 28

#test IS-TF-TARGET
class _TestIsTfTarget(_IntegrationTest):
    def __init__(self, *args):
        super(_TestIsTfTarget, self).__init__(TFTA_Module)
    
    def create_message(self):
        # Here we create a KQML request that the TFTA needs to respond to
        tf = ekb_kstring_from_text(self.tf)
        target = ekb_kstring_from_text(self.target)
        content = KQMLList('IS-TF-TARGET')
        content.set('tf', tf)
        content.set('target', target)
        return get_request(content), content

#Does STAT3 regulate the c-fos gene?
class TestIsTfTarget1(_TestIsTfTarget):
    tf = 'STAT3'
    target = 'c-fos'
    def check_response_to_message(self, output):
        assert output.head() == 'SUCCESS', output
        assert output.gets('result') == 'TRUE', output
        
#TEST FIND-TARGET-TF
class _TestFindTargetTf(_IntegrationTest):
    def __init__(self, *args):
        super(_TestFindTargetTf, self).__init__(TFTA_Module)

    def create_message(self):
        # Here we create a KQML request that the TFTA needs to respond to
        target = ekb_kstring_from_text(self.target)
        content = KQMLList('FIND-TARGET-TF')
        content.set('target', target)
        return get_request(content), content

    def check_response_to_message(self, output):
        # Here we check the details of the response and make sure everything
        # we are looking for is in the output
        # First, we check that the response is a success
        assert output.head() == 'SUCCESS', output
        # Then we check that we got the expected number of target
        assert len(output.get('targets')) == 116
        # We could do further checks here to see if a given expected target
        # shows up in the response, etc.

#Which transcription factors regulate frizzled8?
class TestFindTargetTf1(_TestFindTargetTf):
    target = 'frizzled8'
    def check_response_to_message(self, output):
        assert output.head() == 'SUCCESS', output
        assert len(output.get('tfs')) == 2, output

#What regulates SMURF2?
#What are the regulators of SMURF2?
class TestFindTfTarget2(_TestFindTfTarget):
    target = 'SMURF2'
    def check_response_to_message(self, output):
        assert output.head() == 'SUCCESS', output
        assert len(output.get('tfs')) == 3
    
#

@@ -4047,10 +4047,993 @@
  3%0A    %0A
+#TEST FIND-PATHWAY-GENE%0Aclass _TestFindPathwayGene(_IntegrationTest):%0A    def __init__(self, *args):%0A        super(_TestFindPathwayGene, self).__init__(TFTA_Module)%0A%0A    def create_message(self):%0A        # Here we create a KQML request that the TFTA needs to respond to%0A        gene = ekb_kstring_from_text(self.gene)%0A        content = KQMLList('FIND-PATHWAY-GENE')%0A        content.set('gene', gene)%0A        return get_request(content), content%0A        %0A#What pathways involve SRF?%0Aclass TestFindPathwayGene1(_TestFindPathwayGene):%0A    gene = 'SRF'%0A    def check_response_to_message(self, output):%0A        assert output.head() == 'SUCCESS', output%0A        assert len(output.get('pathways')) == 27, output%0A        %0A#What pathways involve kras and elk1?%0Aclass TestFindPathwayGene2(_TestFindPathwayGene):%0A    gene = 'KRAS, ELK1'%0A    def check_response_to_message(self, output):%0A        assert output.head() == 'SUCCESS', output%0A        assert len(output.get('pathways')) == 23, output%0A%0A
 #%0A

add test to FIND-PATHWAY-GENE