Skip to content

Commit

Permalink
This is for UD-476 Eliminate UUID of network from config fiile for ST…
Browse files Browse the repository at this point in the history
…RING loader

The STRING Loader is modified to get network summaries for the current user from the server
and check if network with the network that is generated already exists.  If yes, than
the existing network on the server is updated.  If no, then a new network is created on the server.
  • Loading branch information
vrynkov committed Jul 10, 2019
1 parent eca44fd commit a1fd662
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 21 deletions.
64 changes: 49 additions & 15 deletions ndexstringloader/ndexloadstring.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ def __init__(self, args):
self._cutoffscore = args.cutoffscore
self._iconurl = args.iconurl
self._template = None
self._ndex = None

self._output_tsv_file_columns = [
"name1",
Expand Down Expand Up @@ -193,8 +194,6 @@ def _parse_config(self):
self._pass = con.get(self._profile, NDExUtilConfig.PASSWORD)
self._server = con.get(self._profile, NDExUtilConfig.SERVER)

self._hi_conf_network_id = con.get(self._profile, 'hi_confidence')

self._protein_links_url = con.get(self._profile, 'ProteinLinksFile')
self._names_file_url = con.get(self._profile, 'NamesFile')
self._entrez_ids_file_url = con.get(self._profile, 'EntrezIdsFile')
Expand Down Expand Up @@ -522,38 +521,74 @@ def _generate_CX_file(self, file_name, network_name):
logger.debug('CX file for network {} generated\n'.format(network_name))
return new_cx_file

def _update_network_on_server(self, new_cx_file, network_name, network_id):

def _load_or_update_network_on_server(self, new_cx_file, network_name, network_id):

logger.debug('updating network {} on server {} for user {}...'.format(network_name,
self._server,
self._user))

with open(new_cx_file, 'br') as network_out:

my_client = ndex2.client.Ndex2(host=self._server,
username=self._user,
password=self._pass)

try:
my_client.update_cx_network(network_out, network_id)
if network_id is None:
self._ndex.save_cx_stream_as_new_network(network_out)
else:
self._ndex.update_cx_network(network_out, network_id)

except Exception as e:
logger.error('server returned error: {}\n'.format(e))
else:
logger.error('network {} updated on server {} for user {}\n'.format(network_name,
self._server,
self._user))
logger.error('network {} saved on server {} for user {}\n'.format(network_name,
self._server,
self._user))
return


def create_ndex_connection(self):

if self._ndex is None:
try:
self._ndex = ndex2.client.Ndex2(host=self._server, username=self._user, password=self._pass)

except Exception as e:
logger.exception('Caught exception: {}'.format(e))
return None

return self._ndex


def get_network_uuid(self, network_name):

try:
network_summaries = self._ndex.get_network_summaries_for_user(self._user)
except Exception as e:
return None

for summary in network_summaries:
network_name_1 = summary.get('name')

if network_name_1 is not None:
if network_name_1 == network_name:
return summary.get('externalId')

return None


def load_to_NDEx(self):

file_name = self._output_tsv_file_name
network_name = 'STRING - Human Protein Links - ' \
'High Confidence (Score > ' +\
str(self._cutoffscore) + ')'
network_id = self._hi_conf_network_id

if self.create_ndex_connection() is None:
return 2

cx_file_name = self._generate_CX_file(file_name, network_name)
self._update_network_on_server(cx_file_name, network_name, network_id)

network_id = self.get_network_uuid(network_name)

self._load_or_update_network_on_server(cx_file_name, network_name, network_id)



Expand All @@ -579,7 +614,6 @@ def main(args):
{user} = <NDEx username>
{password} = <NDEx password>
{server} = <NDEx server(omit http) ie public.ndexbio.org>
hi_confidence = 311b0e5f-6570-11e9-8c69-525400c25d22
ProteinLinksFile = https://stringdb-static.org/download/protein.links.full.v11.0/9606.protein.links.full.v11.0.txt.gz
NamesFile = https://string-db.org/mapping_files/STRING_display_names/human.name_2_string.tsv.gz
EntrezIdsFile = https://stringdb-static.org/mapping_files/entrez/human.entrez_2_string.2018.tsv.gz
Expand Down
11 changes: 5 additions & 6 deletions tests/test_ndexloadstring.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def setUp(self):
def tearDown(self):
"""Tear down test fixtures, if any."""

@unittest.skip("skip it for now - will add later")
@unittest.skip("skip it now - will add later")
def test_parse_config(self):

temp_dir = tempfile.mkdtemp()
Expand All @@ -75,8 +75,7 @@ def test_parse_config(self):
finally:
shutil.rmtree(temp_dir)



@unittest.skip("skip it now - uncomment later")
def test_remove_duplicate_edges(self):

# some duplicate records in the same format as in STRING 9606.protein.links.full.v11.0.txt
Expand Down Expand Up @@ -178,8 +177,7 @@ def test_remove_duplicate_edges(self):
finally:
shutil.rmtree(temp_dir)



@unittest.skip("skip it now - uncomment later")
def test_exception_on_duplicate_edge_with_different_scores(self):


Expand Down Expand Up @@ -252,4 +250,5 @@ def test_exception_on_duplicate_edge_with_different_scores(self):
]



def test_get_network_uuid(self):
pass

0 comments on commit a1fd662

Please sign in to comment.