Ejemplo n.º 1
0
 def gene_interaction_parse(cls, *args, **kwargs):
     stage_output_file = cls._get_stage_output_file(*args, **kwargs)
     download_file = cls._get_download_file(*args, **kwargs)
     section = kwargs['section']
     config = None
     if 'config' in kwargs:
         config = kwargs['config']
     GeneInteractions.gene_interaction_parse(download_file, stage_output_file, section, config=config)
Ejemplo n.º 2
0
    def test_interactor_json_decorator(self):
        '''Test if the dict passed is returned as json with the interactor and evidence as the keys'''
        json_a = GeneInteractions.interactor_json_decorator({"geneA": None})
        self.assertDictEqual(json_a, {'interactor': 'geneA'}, "JSON equal for geneA")

        json_b = GeneInteractions.interactor_json_decorator({"geneA": "evidenceA"})
        self.assertDictEqual(json_b, {'interactor': 'geneA', 'pubmed': 'evidenceA'},
                             "JSON equal for geneA with evidence")
Ejemplo n.º 3
0
    def test_group_binary_interactions(self):
        '''
        Test if the interactors are grouped correctly
        '''
        binary_interactions = [('0', '1'), ('0', '2'), ('1', '2'), ('2', '1'), ('1', '3'), ('2', '3'), ('3', '4'),
                               ('4', '5'), ('5', '6'), ('5', '7'), ('6', '8'), ('7', '8'), ('8', '9'), ('8', '9')]

        expected_dict = {
            '0': [{'1': None}, {'2': None}],
            '1': [{'0': None}, {'2': None}, {'3': None}],
            '2': [{'0': None}, {'1': None}, {'3': None}],
            '3': [{'1': None}, {'2': None}, {'4': None}],
            '4': [{'3': None}, {'5': None}],
            '5': [{'4': None}, {'6': None}, {'7': None}],
            '6': [{'5': None}, {'8': None}],
            '7': [{'5': None}, {'8': None}],
            '8': [{'6': None}, {'7': None}, {'9': None}],
            '9': [{'8': None}]
            }

        grouped_interactions = GeneInteractions._group_binary_interactions(binary_interactions)

        self.assertDictEqual(grouped_interactions, expected_dict, "Grouping of interactions done OK")
        self.assertTrue(10 == len(grouped_interactions), "dict contains 10 groups")
        self.assertIn('8', expected_dict, "key 8 is in dict")
        self.assertIn({'9': None}, grouped_interactions['8'], "value 9 is in dict['8'] ")
        self.assertIn({'1': None}, grouped_interactions['0'], "value 1 is in dict['0'] ")
Ejemplo n.º 4
0
    def test_check_binary_interactions(self):
        '''Test if the grouping of the binary interactions including the evidence is working correctly'''
        gene_interactors = {
            'gene0': [{'gene1:evidence1'}, {'gene2:evidence2'}],
            'gene1': [{'gene0:evidence0'}, {'gene2:evidence2'}, {'gene3:evidence3'}]
            }

        interactorA = "gene0"
        interactorB = "gene4"
        (gene_interactors_list_a, gene_interactors_list_b) = GeneInteractions._check_binary_interactions(gene_interactors,  # @IgnorePep8
                                                                                                         interactorA,
                                                                                                         interactorB,
                                                                                                         evidence_id="evidence4") # @IgnorePep8

        gene_interactors[interactorA] = gene_interactors_list_a
        gene_interactors[interactorB] = gene_interactors_list_b

        processed_interactors1 = {'gene0': [{'gene1:evidence1'}, {'gene2:evidence2'}, {'gene4': 'evidence4'}],
                                  'gene1': [{'gene0:evidence0'}, {'gene2:evidence2'}, {'gene3:evidence3'}],
                                  'gene4': [{'gene0': 'evidence4'}],
                                  }

        self.assertDictEqual(gene_interactors, processed_interactors1, "Grouping OK first iteration")

        interactorA = "gene4"
        interactorB = "gene5"
        (gene_interactors_list_a, gene_interactors_list_b) = GeneInteractions._check_binary_interactions(gene_interactors, # @IgnorePep8
                                                                                                         interactorA,
                                                                                                         interactorB,
                                                                                                         evidence_id="evidence5") # @IgnorePep8

        gene_interactors[interactorA] = gene_interactors_list_a
        gene_interactors[interactorB] = gene_interactors_list_b

        processed_interactors2 = {'gene0': [{'gene1:evidence1'}, {'gene2:evidence2'}, {'gene4': 'evidence4'}],
                                  'gene1': [{'gene0:evidence0'}, {'gene2:evidence2'}, {'gene3:evidence3'}],
                                  'gene4': [{'gene0': 'evidence4'}, {'gene5': 'evidence5'}],
                                  'gene5': [{'gene4': 'evidence5'}],
                                  }

        self.assertDictEqual(gene_interactors, processed_interactors2, "Grouping OK second iteration")
Ejemplo n.º 5
0
    def test_interaction_json_decorator(self):
        '''Test if the interaction with interactors and source is returned correctly'''
        json_interaction = GeneInteractions.interaction_json_decorator("intact",
                                                                       "geneA",
                                                                       [{"geneB": "1234"},
                                                                        {"geneC": "2345"},
                                                                        {"geneD": "6789"}])

        self.assertIn('"_parent": "geneA"', json_interaction, "_parent found in json")
        self.assertIn('"interaction_source": "intact"', json_interaction, "_parent found in json")

        json_interaction = GeneInteractions.interaction_json_decorator("bioplex",
                                                                       "geneA",
                                                                       [{"geneB": None},
                                                                        {"geneC": None},
                                                                        {"geneD": None}])
        self.assertJSONEqual(json_interaction,
                             json.dumps({"interactors": [{"interactor": "geneB"},
                                                         {"interactor": "geneC"},
                                                         {"interactor": "geneD"}],
                                         "interaction_source": "bioplex", "_parent": "geneA"}),
                             "JSON for interaction equal")
Ejemplo n.º 6
0
 def gene_interaction_parse(cls, *args, **kwargs):
     stage_output_file = cls._get_stage_output_file(*args, **kwargs)
     download_file = cls._get_download_file(*args, **kwargs)
     section = kwargs['section']
     GeneInteractions.gene_interaction_parse(download_file, stage_output_file, section)