Skip to content
Snippets Groups Projects
Commit a32cb948 authored by AndiMajore's avatar AndiMajore
Browse files

analysis on analysis working properly

parent 356abbba
No related branches found
No related tags found
No related merge requests found
...@@ -370,7 +370,7 @@ def result_view(request) -> Response: ...@@ -370,7 +370,7 @@ def result_view(request) -> Response:
edges = parameters['input_network']['edges'] edges = parameters['input_network']['edges']
edge_endpoint_ids = set() edge_endpoint_ids = set()
# TODO check for custom edges when working again # TODO check for custom edges when working again with ensemble gene ids
for edge in edges: for edge in edges:
edge_endpoint_ids.add(edge['from']) edge_endpoint_ids.add(edge['from'])
edge_endpoint_ids.add(edge['to']) edge_endpoint_ids.add(edge['to'])
...@@ -378,30 +378,43 @@ def result_view(request) -> Response: ...@@ -378,30 +378,43 @@ def result_view(request) -> Response:
nodes_mapped, id_key = query_proteins_by_identifier(edge_endpoint_ids, identifier) nodes_mapped, id_key = query_proteins_by_identifier(edge_endpoint_ids, identifier)
# change data structure to dict in order to be quicker when merging # change data structure to dict in order to be quicker when merging
nodes_mapped_dict = {node[id_key]: node for node in nodes_mapped} print(nodes_mapped)
for edge in edges: # nodes_mapped_dict = {node[id_key][0]: node for node in nodes_mapped}
# change edge endpoints if they were matched with a protein in the database # nodes_mapped_dict_reverse = {}
edge['from'] = nodes_mapped_dict[edge['from']][node_name_attribute] if edge['from'] in nodes_mapped_dict else \ # for id, node in nodes_mapped_dict.items():
edge['from'] # for drugstone_id in node[node_name_attribute]:
edge['to'] = nodes_mapped_dict[edge['to']][node_name_attribute] if edge['to'] in nodes_mapped_dict else edge[ # nodes_mapped_dict_reverse[node[drugstone_id]] = id
'to']
if 'autofill_edges' in parameters['config'] and parameters['config']['autofill_edges']: print(nodes)
proteins = {node_name[1:] for nodes in map(lambda n: n[node_name_attribute], # for edge in edges:
filter(lambda n: node_name_attribute in n, # # change edge endpoints if they were matched with a protein in the database
parameters['input_network']['nodes'])) for node_name in nodes} # edge['from'] = nodes_mapped_dict[edge['from']][node_name_attribute] if edge['from'] in nodes_mapped_dict else \
# edge['from']
# edge['to'] = nodes_mapped_dict[edge['to']][node_name_attribute] if edge['to'] in nodes_mapped_dict else edge[
# 'to']
if 'autofill_edges' in parameters['config'] and parameters['config']['autofill_edges']:
proteins = {node_name[1:] for nodes in map(lambda n: 'drugstoneType' in n and n[node_name_attribute],
filter(lambda n: n.drugstoneType == 'protein' ,filter(lambda n: 'drugstoneType' in n and node_name_attribute in n ,parameters['input_network']['nodes']))) for node_name in nodes}
dataset = DEFAULTS['ppi'] if 'interaction_protein_protein' not in parameters['config'] else \ dataset = DEFAULTS['ppi'] if 'interaction_protein_protein' not in parameters['config'] else \
parameters['config'][ parameters['config'][
'interaction_protein_protein'] 'interaction_protein_protein']
dataset_object = models.PPIDataset.objects.filter(name__iexact=dataset).last() dataset_object = models.PPIDataset.objects.filter(name__iexact=dataset).last()
interaction_objects = models.ProteinProteinInteraction.objects.filter( interaction_objects = models.ProteinProteinInteraction.objects.filter(
Q(ppi_dataset=dataset_object) & Q(from_protein__in=proteins) & Q(to_protein__in=proteins)) Q(ppi_dataset=dataset_object) & Q(from_protein__in=proteins) & Q(to_protein__in=proteins))
auto_edges = list( auto_edges = list(map(lambda n: {"from": f'p{n.from_protein_id}', "to": f'p{n.to_protein_id}'},
map(lambda n: {"from": f'p{n.from_protein_id}', "to": f'p{n.to_protein_id}'}, interaction_objects)) interaction_objects))
edges.extend(auto_edges) edges.extend(auto_edges)
# TODO check what to do with edges with from and to id lists
result['network']['edges'].extend(edges) result['network']['edges'].extend(edges)
uniq_edges = dict() uniq_edges = dict()
for edge in result['network']['edges']: for edge in result['network']['edges']:
print(edge)
hash = edge['from'] + edge['to'] hash = edge['from'] + edge['to']
uniq_edges[hash] = edge uniq_edges[hash] = edge
result['network']['edges'] = list(uniq_edges.values()) result['network']['edges'] = list(uniq_edges.values())
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment