ndexbio / ndex-python

NDEx Python Client v3.1 - Superseded by the NDEx2 Client v1.0
2 stars 6 forks source link
access-ndex ndex ndex-python-client ndex-server

NDEx Python Client v3.1

Overview

NDEx Python Client v3.1 has been superseded by the NDEx2 Client. This is the last version of the NDEx Python Client. It will be maintained as a pip installable module to support current users, but we recommend migration to NDEx2.

The NDEx Python Client module provides methods to access NDEx via the NDEx Server API. It also provides methods for common operations on networks. It includes the NetworkN module and its NdexGraph network object class for convenient NDEx access and a data model for applications.

Note that the NDEx2 client does not support NetworkN, replacing it with the NiceCX object class.

Tutorial

A Jupyter Notebook tutorial on the basic use of the NDEx Python Client is at NDEx Client v3.1 Tutorial

To use this tutorial, clone the ndex-jupyter-notebooks repository to your local machine and start Jupyter Notebooks in the project directory.

For information on installing and using Jupyter Notebooks, go to jupyter.org

Requirements

The NDEx Python Client 3.1 requires Python 2.7.9 and the latest version of the PIP Python package manager for installation. Click here to download the PIP Python package.

Installing the NDEx Python Client Module

The Python NDEx 3.1 module can be installed from the Python Package Index (PyPI) repository using PIP:

pip install ndex

If you already have an older version of the ndex module installed, you can use this command instead:

pip install --upgrade ndex

NDEx Python Client Objects

The NDEx Python Client provides an interface to an NDEx server that is managed via a client object class. An NDEx Client object can be used to access an NDEx server either anonymously or using a specific user account. For each NDEx server and user account that you want to use in your script or application, you create an NDEx Client instance. In this example, a client object is created to access the public NDEx server.

import ndex.client
anon_ndex=ndex.client.Ndex("http://public.ndexbio.org")

A client object using a specific user account can perform operations requiring authentication, such as saving networks to that account.

my_account="your account"
my_password="your password"
my_ndex=ndex.client.Ndex("http://public.ndexbio.org", my_account, my_password)

NDEx Client Object Methods:

Status

update_status()

Users

get_user_by_username(username)

Network

save_new_network(cx)
save_cx_stream_as_new_network(cx_stream)
update_cx_network(cx_stream, network_id)
delete_network(network_id)
get_network_summary(network_id)
Attribute Description Type
creationTme Time at which the network was created timeStamp
description Text description of the network, same meaning as dc:description string
edgeCount The number of edge objects in the network integer
errorMessage If this network is not a valid CX network, this field holds the error message produced by the CX network validator. string
externalId UUID of the network string
isDeleted True if the network is marked as deleted boolean
isReadOnly True if the network is marked as readonly boolean
isShowCase True if the network is showcased boolean
isValid True if the network is a valid CX network boolean
modificationTime Time at which the network was last modified timeStamp
name Name or title of the network, not unique, same meaning as dc:title string
nodeCount The number of node objects in the network integer
owner The userName of the network owner string
ownerUUID The UUID of the networks owner string
properties List of NDExPropertyValuePair objects: describes properties of the networ list
subnetworkIds List of integers which are identifiers of subnetworks list
uri URI of the current network string
version Format is not controlled but best practice is to use a string conforming to Semantic Versioning string
visibility PUBLIC or PRIVATE. PUBLIC means it can be found or read by anyone, including anonymous users. PRIVATE is the default, means that it can only be found or read by users according to their permissions string
warnings List of warning messages produced by the CX network validator list

Property Object Field Description Type
dataType Type of the attribute string
predicateString Name of the attribute. string
value Value of the attribute string
subNetworkId Subnetwork Id of the attribute string

get_network_as_cx_stream(network_id)
set_network_system_properties(network_id, network_system_properties)
make_network_private(network_id)
make_network_public(network_id)
set_read_only(network_id, value)
update_network_group_permission(group_id, network_id, permission)
grant_networks_to_group(group_id, network_ids, permission="READ”)
update_network_user_permission(user_id, network_id, permission)
grant_network_to_user_by_username(username, network_id, permission)
grant_networks_to_user(user_id, network_ids, permission="READ”)
update_network_profile(network_id, network_profile)
set_network_properties(network_id, network_properties)
Attribute Description Type
subNetworkId Optional identifier of the subnetwork to which the property applies. string
predicateString Name of the attribute. string
dataType Data type of this property. Its value has to be one of the attribute data types that CX supports. string
value A string representation of the property value. string

get_provenance(network_id)
set_provenance(network_id, provenance)

Search

search_networks(search_string="", account_name=None, start=0, size=100, include_groups=False)
find_networks(search_string="", account_name=None, start=0, size=100)
get_network_summaries_for_user(account_name)
get_network_ids_for_user(account_name)
get_neighborhood_as_cx_stream(network_id, search_string, search_depth=1, edge_limit=2500)
get_neighborhood(network_id, search_string, search_depth=1, edge_limit=2500)

Task

get_task_by_id(task_id)