Skip to content

Commit

Permalink
lc filter in place
Browse files Browse the repository at this point in the history
  • Loading branch information
proost committed Nov 30, 2017
1 parent de84b01 commit 0d29350
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
3 changes: 2 additions & 1 deletion conekt/controllers/ecc.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,14 @@ def ecc_graph_multi_json():
:param ecc_id: internal ID of the sequence to sequence ECC relationship
:return: JSON object compatible with cytoscape.js
"""
network, family = SequenceSequenceECCAssociation.get_ecc_multi_network(2, [230458, 35796, 162930])
network, family = SequenceSequenceECCAssociation.get_ecc_multi_network(1, [162930, 56261, 203621, 94050])

network_cytoscape = CytoscapeHelper.parse_network(network)
network_cytoscape = CytoscapeHelper.add_descriptions_nodes(network_cytoscape)
network_cytoscape = CytoscapeHelper.add_family_data_nodes(network_cytoscape, family)
network_cytoscape = CytoscapeHelper.add_lc_data_nodes(network_cytoscape)
network_cytoscape = CytoscapeHelper.add_species_data_nodes(network_cytoscape)
network_cytoscape = CytoscapeHelper.connect_homologs(network_cytoscape)
network_cytoscape = CytoscapeHelper.prune_unique_lc(network_cytoscape)

return json.dumps(network_cytoscape)
38 changes: 38 additions & 0 deletions conekt/helpers/cytoscape.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from copy import deepcopy
from collections import Counter

from flask import url_for
from sqlalchemy.orm import joinedload
Expand Down Expand Up @@ -407,6 +408,43 @@ def add_depth_data_edges(network):

return colored_network

@staticmethod
def prune_unique_lc(network):
"""
Remove genes from network that have an lc that occurs only once
:param network: dict containing the network
:return: Cytoscape.js compatible network with the pruned network
"""

lc_labels = []
for node in network["nodes"]:
if 'lc_label' in node['data'].keys():
lc_labels.append(node['data']['lc_label'])

lc_counter = Counter(lc_labels)

print(lc_counter)

pruned_network = {'nodes': [], 'edges': []}

good_nodes = []

for node in network['nodes']:
if 'lc_label' in node['data'].keys():
if lc_counter[node['data']['lc_label']] > 1:
good_nodes.append(node['data']['name'])
pruned_network['nodes'].append(deepcopy(node))
else:
good_nodes.append(node['data']['name'])
pruned_network['nodes'].append(deepcopy(node))

for edge in network['edges']:
if edge['data']['source'] in good_nodes and edge['data']['target'] in good_nodes:
pruned_network['edges'].append(deepcopy(edge))

return pruned_network

@staticmethod
def merge_networks(network_one, network_two):
"""
Expand Down

0 comments on commit 0d29350

Please sign in to comment.