Skip to content

Commit

Permalink
network: remove_zero_degree method
Browse files Browse the repository at this point in the history
  • Loading branch information
deeenes committed Jan 13, 2020
1 parent f87b834 commit 2a5abb4
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/pypath/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -1922,7 +1922,9 @@ def organisms_check(

self._log(
'Finished checking organisms. '
'%u nodes have been removed, '
'%u nodes and %u interactions remained.' % (
len(to_remove),
self.vcount,
self.ecount,
)
Expand Down Expand Up @@ -2216,6 +2218,42 @@ def remove_interaction(self, entity_a, entity_b):
self.remove_node(entity_b)


def remove_zero_degree(self):
"""
Removes all nodes with no interaction.
"""

self._log(
'Removing zero degree nodes. '
'%u nodes and %u interactions before.' % (
self.vcount,
self.ecount,
)
)

to_remove = set()

for node, interactions in iteritems(self.interactions_by_nodes):

if not interactions:

to_remove.add(node)

for node in to_remove:

self.remove_node(node)

self._log(
'Finished removing zero degree nodes. '
'%u nodes have been removed, '
'%u nodes and %u interactions remained.' % (
len(to_remove),
self.vcount,
self.ecount,
)
)


@property
def resources(self):
"""
Expand Down

0 comments on commit 2a5abb4

Please sign in to comment.