cytoscape / RCy3

New version of RCy3, redesigned and collaboratively maintained by Cytoscape developer community
MIT License
48 stars 20 forks source link

Implement deleteDuplicateEdges with ignoreDirection #130

Open bdemchak opened 3 years ago

bdemchak commented 3 years ago

py4cytoscape now has an extra parameter on delete_duplicate_edges ... it allows edge direction to be ignored.

The overall flow of the function was maintained, but important changes were made to allow different definitions of edge equivalence, and performance was improved considerably. (On my PC, executing the old structure on 3000 edges took about 11 minutes.)

I recommend that the same changes be made to the RCy3 version.

yihangx commented 3 years ago

deleteDuplicateEdges is not working. Probably because the change of .edgeNameToEdgeSUID in RCy3.util.R.

AlexanderPico commented 3 years ago

Fixed with https://github.com/cytoscape/RCy3/commit/3348c653a0167420e0dc7354c927520719868183

yihangx commented 3 years ago

Added internal function first. Still working on this function.

yihangx commented 3 years ago

Fixed.

yihangx commented 3 years ago

Still not working.

AlexanderPico commented 2 years ago

@yihangx Still open or fixed?

yihangx commented 2 years ago

This is still open. In py4cytoscape, it uses list comprehension there: https://github.com/cytoscape/py4cytoscape/blob/ad4ac43919d34c955d88ce07d5fc540a693b6700/py4cytoscape/network_selection.py#L788-L791 In R, there is no list comprehension, and I need to find an alternative way to do this.

bdemchak commented 2 years ago

List comprehensions can be complex, but they still map to a simpler construct. For example:

all_edges = [build_sorted_edge_equivalents(x) for x in parse_edges(all_edges)]

maps to

all_edges = []
for x in parse_edges(all_edges):
  all_edges.append(build_sorted_edge_equivalents(x))

Likewise:

all_edges = [(x, None) for x in all_edges]

maps to

all_edges = []
for x in all_edges:
  all_edges.append((x, None))

Note that in this case, all_edges ends up as a list of tuples:

[(node1,node2), (node1,node3), (node2,node3)] ... for example.

A more complicated example:

dup_edge_suids = [get_edge_suids(unique_edge[0]) + get_edge_suids(unique_edge[1]) for unique_edge in edge_counter if edge_counter[unique_edge] > 1]

maps to:

dup_edge_suids = []
for unique_edge in edge_counter:
  if edge_counter[unique_edge] > 1:
    dup_edge_suids.append(unique_edge[1])

Comprehensions in Python are pretty convenient and concise. I don't know whether R has a similar construct.