Exemple #1
0
    def test_manual_build(self):
        print('Testing: Build from empty nice cx')
        niceCx = ndex2.create_empty_nice_cx() #NiceCXNetwork()

        fox_node_id = niceCx.create_node(node_name='Fox')
        mouse_node_id = niceCx.create_node(node_name='Mouse')
        bird_node_id = niceCx.create_node(node_name='Bird')

        fox_bird_edge = niceCx.create_edge(edge_source=fox_node_id, edge_target=bird_node_id, edge_interaction='interacts-with')
        fox_mouse_edge = niceCx.create_edge(edge_source=fox_node_id, edge_target=mouse_node_id, edge_interaction='interacts-with')

        niceCx.add_node_attribute(property_of=fox_node_id, name='Color', values='Red')
        niceCx.add_node_attribute(property_of=mouse_node_id, name='Color', values='Gray')
        niceCx.add_node_attribute(property_of=bird_node_id, name='Color', values='Blue')

        upload_message = niceCx.upload_to(upload_server, upload_username, upload_password)
    def test_manual_build(self):
        print('Testing: Build from empty nice cx')
        niceCx = ndex2.create_empty_nice_cx() #NiceCXNetwork()

        fox_node_id = niceCx.create_node(node_name='Fox')
        mouse_node_id = niceCx.create_node(node_name='Mouse')
        bird_node_id = niceCx.create_node(node_name='Bird')

        fox_bird_edge = niceCx.create_edge(edge_source=fox_node_id, edge_target=bird_node_id, edge_interaction='interacts-with')
        fox_mouse_edge = niceCx.create_edge(edge_source=fox_node_id, edge_target=mouse_node_id, edge_interaction='interacts-with')

        niceCx.add_node_attribute(property_of=fox_node_id, name='Color', values='Red')
        niceCx.add_node_attribute(property_of=mouse_node_id, name='Color', values='Gray')
        niceCx.add_node_attribute(property_of=bird_node_id, name='Color', values='Blue')

        upload_message = niceCx.upload_to(upload_server, upload_username, upload_password)
    def test_load_edges(self):
        niceCx = ndex2.create_empty_nice_cx()  #NiceCXNetwork()
        niceCx.create_node(id=1,
                           node_name='node%s' % str(1),
                           node_represents='ABC')
        niceCx.create_node(id=2,
                           node_name='node%s' % str(2),
                           node_represents='DEF')
        niceCx.create_edge(id=1,
                           edge_source=1,
                           edge_target=2,
                           edge_interaction='neighbor')

        upload_message = niceCx.upload_to(upload_server, upload_username,
                                          upload_password)
        self.assertTrue(upload_message)
    def test_load_nodes(self):
        niceCx = ndex2.create_empty_nice_cx()  #NiceCXNetwork()
        gene_list = [
            'OR2J3', 'AANAT', 'CCDC158', 'PLAC8L1', 'CLK1', 'GLTP', 'PITPNM2',
            'TRAPPC8', 'EIF2S2', 'ST14', 'NXF1', 'H3F3B', 'FOSB', 'MTMR4',
            'USP46', 'CDH11', 'ENAH', 'CNOT7', 'STK39', 'CAPZA1', 'STIM2',
            'DLL4', 'WEE1', 'MYO1D', 'TEAD3'
        ]
        for i in range(1, 10):
            niceCx.create_node(id=i,
                               node_name='node%s' % str(i),
                               node_represents=gene_list[i])

        upload_message = niceCx.upload_to(upload_server, upload_username,
                                          upload_password)
        self.assertTrue(upload_message)
    def test_pandas_loading(self):
        path_to_network = os.path.join(path_this, 'MDA1.txt')

        with open(path_to_network, 'rU') as tsvfile:
            header = [h.strip() for h in tsvfile.readline().split('\t')]

            df = pd.read_csv(tsvfile,
                             delimiter='\t',
                             engine='python',
                             names=header)

            niceCx = ndex2.create_empty_nice_cx()  #NiceCXNetwork()
            for index, row in df.iterrows():
                niceCx.create_node(id=row['Bait'],
                                   node_name=row['Bait'],
                                   node_represents=row['Bait'])
                niceCx.create_node(id=row['Prey'],
                                   node_name=row['Prey'],
                                   node_represents=row['Prey'])

                niceCx.create_edge(id=index,
                                   edge_source=row['Bait'],
                                   edge_target=row['Prey'],
                                   edge_interaction='interacts-with')

            niceCx.add_metadata_stub('nodes')
            niceCx.add_metadata_stub('edges')
            if niceCx.nodeAttributes:
                niceCx.add_metadata_stub('nodeAttributes')
            if niceCx.edgeAttributes:
                niceCx.add_metadata_stub('edgeAttributes')
            upload_message = niceCx.upload_to(upload_server, upload_username,
                                              upload_password)

            #print(df)

        my_df = pd.DataFrame(data=[(4, 14), (5, 15), (6, 16), (7, 17)],
                             index=range(0, 4),
                             columns=['A', 'B'])
        self.assertIsNotNone(my_df)
    def test_data_types_with_special_chars2(self):
        self.assertFalse(upload_username == 'username')
        niceCx = ndex2.create_empty_nice_cx()

        fox_node_id = niceCx.create_node(node_name='A#"')
        mouse_node_id = niceCx.create_node(node_name='B!@#$%')
        bird_node_id = niceCx.create_node(node_name='*&^%^$')

        fox_bird_edge = niceCx.create_edge(edge_source=fox_node_id, edge_target=bird_node_id, edge_interaction='&"""""""')
        fox_mouse_edge = niceCx.create_edge(edge_source=fox_node_id, edge_target=mouse_node_id, edge_interaction='//////\\\\\\')

        niceCx.add_node_attribute(property_of=fox_node_id, name='Color', values='Red')
        niceCx.add_node_attribute(property_of=mouse_node_id, name='Color', values='Gray')
        niceCx.add_node_attribute(property_of=bird_node_id, name='Color', values='Blue')


        upload_message = niceCx.upload_to(upload_server, upload_username, upload_password)
        spec_char_network_uuid = upload_message.split('\\')[-1]

        #niceCx = ndex2.create_nice_cx_from_server(server='public.ndexbio.org', uuid='fc63173e-df66-11e7-adc1-0ac135e8bacf') #NiceCXNetwork(server='dev2.ndexbio.org', username='******', password='******', uuid='9433a84d-6196-11e5-8ac5-06603eb7f303')

        self.assertTrue(upload_message)
Exemple #7
0
    def test_data_types_with_special_chars2(self):
        self.assertFalse(upload_username == 'username')
        niceCx = ndex2.create_empty_nice_cx()

        fox_node_id = niceCx.create_node(node_name='A#"')
        mouse_node_id = niceCx.create_node(node_name='B!@#$%')
        bird_node_id = niceCx.create_node(node_name='*&^%^$')

        fox_bird_edge = niceCx.create_edge(edge_source=fox_node_id, edge_target=bird_node_id, edge_interaction='&"""""""')
        fox_mouse_edge = niceCx.create_edge(edge_source=fox_node_id, edge_target=mouse_node_id, edge_interaction='//////\\\\\\')

        niceCx.add_node_attribute(property_of=fox_node_id, name='Color', values='Red')
        niceCx.add_node_attribute(property_of=mouse_node_id, name='Color', values='Gray')
        niceCx.add_node_attribute(property_of=bird_node_id, name='Color', values='Blue')


        upload_message = niceCx.upload_to(upload_server, upload_username, upload_password)
        spec_char_network_uuid = upload_message.split('\\')[-1]

        #niceCx = ndex2.create_nice_cx_from_server(server='public.ndexbio.org', uuid='fc63173e-df66-11e7-adc1-0ac135e8bacf') #NiceCXNetwork(server='dev2.ndexbio.org', username='******', password='******', uuid='9433a84d-6196-11e5-8ac5-06603eb7f303')

        self.assertTrue(upload_message)
    def test_manual_build(self):
        niceCx = ndex2.create_empty_nice_cx()  #NiceCXNetwork()

        fox_node_id = niceCx.create_node(node_name='Fox')
        mouse_node_id = niceCx.create_node(node_name='Mouse')
        bird_node_id = niceCx.create_node(node_name='Bird')

        fox_bird_edge = niceCx.create_edge(edge_source=fox_node_id,
                                           edge_target=bird_node_id,
                                           edge_interaction='interacts-with')
        fox_mouse_edge = niceCx.create_edge(edge_source=fox_node_id,
                                            edge_target=mouse_node_id,
                                            edge_interaction='interacts-with')

        niceCx.add_node_attribute(property_of=fox_node_id,
                                  name='Color',
                                  values='Red')
        niceCx.add_node_attribute(property_of=mouse_node_id,
                                  name='Color',
                                  values='Gray')
        niceCx.add_node_attribute(property_of=bird_node_id,
                                  name='Color',
                                  values='Blue')
    def test_create_from_small_cx(self):
        my_cx = [{
            "numberVerification": [{
                "longNumber": 281474976710655
            }]
        }, {
            "metaData": [{
                "consistencyGroup": 1,
                "elementCount": 2,
                "idCounter": 2,
                "name": "nodes",
                "version": "1.0"
            }, {
                "consistencyGroup": 1,
                "elementCount": 1,
                "idCounter": 1,
                "name": "edges",
                "version": "1.0"
            }]
        }, {
            "nodes": [{
                "@id": 1,
                "n": "node1",
                "r": "ABC"
            }, {
                "@id": 2,
                "n": "node2",
                "r": "DEF"
            }]
        }, {
            "edges": [{
                "@id": 1,
                "s": 1,
                "t": 2,
                "i": "neighbor"
            }]
        }, {
            "status": [{
                "error": "",
                "success": True
            }]
        }]

        #niceCx = NiceCXNetwork(cx=my_cx)

        #data = [('Source', 'Target', 'interaction', 'EdgeProp'), ('ABC', 'DEF', 'interacts-with', 'Edge property 1'), ('DEF', 'XYZ', 'neighbor-of', 'Edge property 2')]
        #df = pd.DataFrame.from_records(data)
        #niceCx = NiceCXNetwork(pandas_df=df)

        df = pd.DataFrame.from_items([
            ('Source', ['ABC', 'DEF']), ('Target', ['DEF', 'XYZ']),
            ('Interaction', ['interacts-with', 'neighbor-of']),
            ('EdgeProp', ['Edge property 1', 'Edge property 2'])
        ])

        niceCx = ndex2.create_empty_nice_cx()  #NiceCXNetwork()
        niceCx.create_from_pandas(df,
                                  source_field='Source',
                                  target_field='Target',
                                  edge_attr=['EdgeProp'],
                                  edge_interaction='Interaction')

        niceCx = ''  #NiceCXNetwork(server='public.ndexbio.org', uuid='f1dd6cc3-0007-11e6-b550-06603eb7f303')
Exemple #10
0
 def test_create_empty_nice_cx(self):
     net = ndex2.create_empty_nice_cx()
     self.assertEqual(None, net.get_name())
     self.assertEqual(0, len(net.get_nodes()))
     self.assertEqual(0, len(net.get_edges()))