Ejemplo n.º 1
0
 def test_external_with_successful_hidefdatafile_from_docker(self):
     er = cdapsutil.ExternalResultsRunner()
     cd = cdapsutil.CommunityDetection(runner=er)
     datafile = os.path.join(self.get_data_dir(), 'cdhidef:0.2.2.out')
     net_cx = self.get_human_hiv_as_nice_cx()
     hier_net = cd.run_community_detection(net_cx=net_cx,
                                           algorithm=datafile)
     self.assertEqual(105, len(hier_net.get_nodes()))
     self.assertEqual(121, len(hier_net.get_edges()))
     self.assertEqual('cdhidef:0.2.2.out_(none)_HIV-human PPI',
                      hier_net.get_name())
     self.assertEqual(
         '0',
         hier_net.get_network_attribute('__CD_OriginalNetwork')['v'])
Ejemplo n.º 2
0
 def test_apply_style(self):
     temp_dir = tempfile.mkdtemp()
     try:
         net_cx = ndex2.nice_cx_network.NiceCXNetwork()
         cd = cdapsutil.CommunityDetection()
         cd._apply_style(net_cx)
         res = net_cx.get_opaque_aspect('cyVisualProperties')
         self.assertEqual('network', res[0]['properties_of'])
         net_cx = ndex2.nice_cx_network.NiceCXNetwork()
         cd._apply_style(net_cx,
                         style=os.path.join(self.get_data_dir(),
                                            'hiv_human_ppi.cx'))
         altres = net_cx.get_opaque_aspect(('cyVisualProperties'))
         self.assertNotEqual(res, altres)
     finally:
         shutil.rmtree(temp_dir)
Ejemplo n.º 3
0
    def test_run_community_detection_with_all_algorithms(self):
        sr = self.get_service_runner()
        cd_dict = self.get_algorithms()
        algos = []
        for algo in cd_dict.keys():
            algos.append(algo)
        self.assertTrue(len(algos) > 0)
        net_cx = self.get_human_hiv_as_nice_cx()
        cd = cdapsutil.CommunityDetection(runner=sr)
        failures = []
        for algo in algos:
            try:
                hier_net = cd.run_community_detection(net_cx=net_cx,
                                                      algorithm=algo)
                self.assertTrue(hier_net is not None)
                self.assertTrue(len(hier_net.get_nodes()) > 0)
                self.assertTrue(algo in hier_net.get_name())
            except cdapsutil.CommunityDetectionError as ce:
                failures.append(algo + ' failed : ' + str(ce))

        self.assertEqual('', ' '.join(failures))
Ejemplo n.º 4
0
    def test_service_with_successful_mock_data(self):
        sr = cdapsutil.ServiceRunner(service_endpoint='http://foo',
                                     max_retries=1,
                                     poll_interval=0)
        cd = cdapsutil.CommunityDetection(runner=sr)
        net_cx = self.get_human_hiv_as_nice_cx()
        json_res = self.get_infomap_res_as_dict()

        with requests_mock.Mocker() as m:
            m.post('http://foo', json={'id': 'taskid'}, status_code=202)
            m.get('http://foo/taskid/status',
                  status_code=200,
                  json={'progress': 100})
            m.get('http://foo/taskid', status_code=200, json=json_res)
            hier_net = cd.run_community_detection(net_cx, algorithm='infomap')

            self.assertEqual(68, len(hier_net.get_nodes()))
            self.assertEqual(67, len(hier_net.get_edges()))
            self.assertEqual('infomap_(none)_HIV-human PPI',
                             hier_net.get_name())
            self.assertEqual(
                '0',
                hier_net.get_network_attribute('__CD_OriginalNetwork')['v'])
Ejemplo n.º 5
0
    def test_run_community_detection_with_all_algorithms_via_docker(self):
        cd_dict = self.get_algorithms()
        algos = []
        for algo in cd_dict.keys():
            algos.append(cd_dict[algo]['dockerImage'])
        self.assertTrue(len(algos) > 0)
        net_cx = self.get_human_hiv_as_nice_cx()
        cd = cdapsutil.CommunityDetection(runner=cdapsutil.DockerRunner())
        failures = []
        for algo in algos:
            temp_dir = tempfile.mkdtemp(dir=os.getcwd())
            try:
                hier_net = cd.run_community_detection(net_cx=net_cx,
                                                      algorithm=algo,
                                                      temp_dir=temp_dir)
                self.assertTrue(hier_net is not None)
                self.assertTrue(len(hier_net.get_nodes()) > 0)
                self.assertTrue(algo in hier_net.get_name())
            except cdapsutil.CommunityDetectionError as ce:
                failures.append(algo + ' failed : ' + str(ce))
            finally:
                shutil.rmtree(temp_dir)

        self.assertEqual('', ' '.join(failures))
Ejemplo n.º 6
0
 def test_constructor_none_for_runner(self):
     try:
         cdapsutil.CommunityDetection(runner=None)
         self.fail('Expected CommunityDetectionError')
     except cdapsutil.CommunityDetectionError as ce:
         self.assertEqual('runner is None', str(ce))
Ejemplo n.º 7
0
 def test_get_node_dictionary(self):
     net_cx = self.get_human_hiv_as_nice_cx()
     cd = cdapsutil.CommunityDetection()
     node_dict = cd._get_node_dictionary(net_cx)
     self.assertEqual(471, len(node_dict))
     self.assertEqual('REV', node_dict[738])