Exemple #1
0
    def test_write_nice_cx_to_file(self):
        temp_dir = tempfile.mkdtemp()
        try:
            p = MagicMock()
            p.datadir = temp_dir
            p.profile = 'foo'
            p.organismloadplan = ndexloadbiogrid.get_organism_load_plan()
            p.chemicalloadplan = ndexloadbiogrid.get_chemical_load_plan()
            p.organismstyle = ndexloadbiogrid.get_organism_style()
            p.chemstyle = ndexloadbiogrid.get_chemical_style()
            p.biogridversion = '1.0.0'
            p.skipdownload = False
            loader = NdexBioGRIDLoader(p)
            loader._network = NiceCXNetwork()
            loader._network.create_node('hi')
            loader._network.set_name('name')
            cxfile = os.path.join(temp_dir, 'some.cx')
            loader._write_nice_cx_to_file(cxfile)

            self.assertTrue(os.path.isfile(cxfile))

            checknet = ndex2.create_nice_cx_from_file(cxfile)
            self.assertEqual('name', checknet.get_name())

        finally:
            shutil.rmtree(temp_dir)
Exemple #2
0
 def test_parse_arguments_defaults(self):
     fakeargs = ['datadir']
     pargs = ndexloadbiogrid._parse_arguments('desc', fakeargs)
     self.assertEqual('datadir', pargs.datadir)
     self.assertEqual('ndexbiogridloader', pargs.profile)
     self.assertEqual('4.2.191', pargs.biogridversion)
     self.assertEqual(ndexloadbiogrid.get_organism_load_plan(),
                      pargs.organismloadplan)
     self.assertEqual(ndexloadbiogrid.get_chemical_load_plan(),
                      pargs.chemicalloadplan)
     self.assertEqual(ndexloadbiogrid.get_organism_style(),
                      pargs.organismstyle)
     self.assertEqual(ndexloadbiogrid.get_chemical_style(),
                      pargs.chemicalstyle)
Exemple #3
0
    def test_update_or_upload_with_retry(self):
        temp_dir = tempfile.mkdtemp()
        try:
            p = MagicMock()
            p.datadir = os.path.join(temp_dir, 'datadir')
            p.profile = 'foo'
            p.organismloadplan = ndexloadbiogrid.get_organism_load_plan()
            p.chemicalloadplan = ndexloadbiogrid.get_chemical_load_plan()
            p.organismstyle = ndexloadbiogrid.get_organism_style()
            p.chemstyle = ndexloadbiogrid.get_chemical_style()
            p.biogridversion = '1.0.0'
            p.skipdownload = False
            loader = NdexBioGRIDLoader(p)
            loader._ndex = MagicMock()
            cxfile = os.path.join(temp_dir, 'file.cx')
            with open(cxfile, 'wb') as f:
                f.write(b'hello')
            loader._ndex.save_cx_stream_as_new_network = MagicMock(
                side_effect=Exception('error'))

            res = loader._update_or_upload_with_retry(cxfile=cxfile,
                                                      network_name='foo',
                                                      network_uuid=None,
                                                      maxretries=1,
                                                      retry_sleep=0)
            self.assertEqual(2, res)

            loader._ndex.update_cx_network = MagicMock(
                side_effect=Exception('error'))

            res = loader._update_or_upload_with_retry(cxfile=cxfile,
                                                      network_name='foo',
                                                      network_uuid='1234',
                                                      maxretries=1,
                                                      retry_sleep=0)
            self.assertEqual(2, res)

            loader._ndex.save_cx_stream_as_new_network = MagicMock(
                return_value={})

            res = loader._update_or_upload_with_retry(cxfile=cxfile,
                                                      network_name='foo',
                                                      maxretries=1,
                                                      retry_sleep=0)
            self.assertEqual(0, res)
        finally:
            shutil.rmtree(temp_dir)
Exemple #4
0
    def test_apply_simple_spring_layout(self):
        net = NiceCXNetwork()
        n_one = net.create_node('node1')
        n_two = net.create_node('node2')
        net.create_edge(n_one, n_two, 'links')
        p = MagicMock()
        p.datadir = 'datadir'
        p.profile = 'foo'
        p.organismloadplan = ndexloadbiogrid.get_organism_load_plan()
        p.chemicalloadplan = ndexloadbiogrid.get_chemical_load_plan()
        p.organismstyle = ndexloadbiogrid.get_organism_style()
        p.chemstyle = ndexloadbiogrid.get_chemical_style()
        p.biogridversion = '1.0.0'
        p.skipdownload = False
        loader = NdexBioGRIDLoader(p)
        loader._apply_simple_spring_layout(net)

        aspect = net.get_opaque_aspect('cartesianLayout')
        self.assertEqual(2, len(aspect))

        # try with 19 nodes
        net = NiceCXNetwork()
        for x in range(0, 19):
            net.create_node(str(x))
        loader._apply_simple_spring_layout(net)

        aspect = net.get_opaque_aspect('cartesianLayout')
        self.assertEqual(19, len(aspect))

        # try with 99 nodes
        net = NiceCXNetwork()
        for x in range(0, 99):
            net.create_node(str(x))
        loader._apply_simple_spring_layout(net)

        aspect = net.get_opaque_aspect('cartesianLayout')
        self.assertEqual(99, len(aspect))

        # try with 101 nodes
        net = NiceCXNetwork()
        for x in range(0, 101):
            net.create_node(str(x))
        loader._apply_simple_spring_layout(net)

        aspect = net.get_opaque_aspect('cartesianLayout')
        self.assertEqual(101, len(aspect))
Exemple #5
0
    def test_check_if_data_dir_exists(self):
        temp_dir = tempfile.mkdtemp()
        try:
            p = MagicMock()
            p.datadir = temp_dir
            p.profile = 'foo'
            p.organismloadplan = ndexloadbiogrid.get_organism_load_plan()
            p.chemicalloadplan = ndexloadbiogrid.get_chemical_load_plan()
            p.organismstyle = ndexloadbiogrid.get_organism_style()
            p.chemstyle = ndexloadbiogrid.get_chemical_style()
            p.biogridversion = '1.0.0'
            p.skipdownload = False
            loader = NdexBioGRIDLoader(p)
            self.assertTrue(loader._check_if_data_dir_exists())

            p.datadir = os.path.join(temp_dir, 'foo')
            loader = NdexBioGRIDLoader(p)
            self.assertFalse(loader._check_if_data_dir_exists())
        finally:
            shutil.rmtree(temp_dir)
Exemple #6
0
    def setupClass(self):
        unittest.TestCase.setUp(self)

        self.__class__._data_dir = ndexloadbiogrid.get_datadir()
        self.__class__._testing_dir = ndexloadbiogrid.get_testsdir()
        self.__class__._biogrid_files_dir = os.path.join(
            self.__class__._testing_dir, 'biogrid_files')

        self._the_args = {
            'profile': 'ndexbiogridloader',
            'biogridversion': '3.5.175',
            'datadir': self.__class__._biogrid_files_dir,
            'organismloadplan': ndexloadbiogrid.get_organism_load_plan(),
            'chemicalloadplan': ndexloadbiogrid.get_chemical_load_plan(),
            'organismstyle': ndexloadbiogrid.get_organism_style(),
            'chemicalstyle': ndexloadbiogrid.get_chemical_style()
        }

        self._the_args = dotdict(self._the_args)
        self.__class__.NdexBioGRIDLoader = NdexBioGRIDLoader(self._the_args)
        self.__class__.NdexBioGRIDLoader._parse_config()

        self.__class__.organism_entries_expected = [
            ['BIOGRID-ORGANISM-Zea_mays', 'Maize, 4577, Zea mays', 'Z. mays'],
            [
                'BIOGRID-ORGANISM-Xenopus_laevis',
                'African clawed frog, 8355, Xenopus laevis', 'X. laevis'
            ],
            [
                'BIOGRID-ORGANISM-Saccharomyces_cerevisiae_S288c',
                'Baker\'s yeast, 559292', 'S. cerevisiae'
            ],
            [
                'BIOGRID-ORGANISM-Rattus_norvegicus',
                'Norway rat, 10116, Rattus norvegicus', 'R. norvegicus'
            ],
            [
                'BIOGRID-ORGANISM-Mus_musculus',
                'House mouse, 10090, Mus musculus', 'M. musculus'
            ],
            [
                'BIOGRID-ORGANISM-Human_papillomavirus_16',
                'HPV, 10566, Human papillomavirus', 'HPV'
            ],
            [
                'BIOGRID-ORGANISM-Human_Immunodeficiency_Virus_2',
                'HIV-2, 11709, Human immunodeficiency virus 2', 'HIV-2'
            ],
            [
                'BIOGRID-ORGANISM-Human_Immunodeficiency_Virus_1',
                'HIV-1, 11676, Human immunodeficiency virus 1', 'HIV-1'
            ],
            [
                'BIOGRID-ORGANISM-Homo_sapiens', 'Human, 9606, H**o sapiens',
                'H. sapiens'
            ],
            [
                'BIOGRID-ORGANISM-Drosophila_melanogaster',
                'Fruit fly, 7227, Drosophila melanogaster', 'D. melanogaster'
            ],
            [
                'BIOGRID-ORGANISM-Danio_rerio', 'Zebrafish, 7955, Danio rerio',
                'D. rerio'
            ],
            [
                'BIOGRID-ORGANISM-Caenorhabditis_elegans',
                'Roundworm, 6239, Cenorhabditis elegans', 'C. elegans'
            ],
            [
                'BIOGRID-ORGANISM-Arabidopsis_thaliana_Columbia',
                'Thale cress, 3702, Arabidopsis thaliana', 'A. thaliana'
            ]
        ]

        self.__class__.chemicals_entries_expected = [[
            'BIOGRID-CHEMICALS', 'Human, 9606, H**o sapiens', 'H. sapiens'
        ]]

        self.__class__._ndex = self.NdexBioGRIDLoader._create_ndex_connection()
        self.assertIsNotNone(self.__class__._ndex,
                             'Unable to to create NDEx client connection')

        status_code = self.NdexBioGRIDLoader._download_biogrid_files()
        self.assertEqual(status_code, 0,
                         'Unable to download required biogrid files ')

        net_summaries, status_code = self.NdexBioGRIDLoader._load_network_summaries_for_user(
        )
        self.assertEqual(status_code, 0, 'Unable to get netwok summaries')

        self.__class__.NdexBioGRIDLoader._load_chemical_style_template()
        self.__class__.NdexBioGRIDLoader._load_organism_style_template()

        self.__class__._organism_template = self.__class__.NdexBioGRIDLoader.__getattribute__(
            '_organism_style_template')
        self.__class__._chemical_template = self.__class__.NdexBioGRIDLoader.__getattribute__(
            '_chem_style_template')
Exemple #7
0
 def test_get_organism_style(self):
     res = ndexloadbiogrid.get_organism_style()
     self.assertTrue(os.path.isfile(res))
     net = ndex2.create_nice_cx_from_file(res)
     props = net.get_opaque_aspect('cyVisualProperties')
     self.assertTrue(isinstance(props, list))