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

analysis on analysis working properly

Former-commit-id: fb902939317d198792f948c63cf948a0f1a13ca6 [formerly 6d3e3bebb7185a47f8605d7314c7e297bc00e0b1]
Former-commit-id: 5d15ef555c3b3f9dc5541b941874548fb3b59d1c
parent 56815305
No related branches found
No related tags found
No related merge requests found
......@@ -370,7 +370,7 @@ def result_view(request) -> Response:
edges = parameters['input_network']['edges']
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:
edge_endpoint_ids.add(edge['from'])
edge_endpoint_ids.add(edge['to'])
......@@ -378,30 +378,43 @@ def result_view(request) -> Response:
nodes_mapped, id_key = query_proteins_by_identifier(edge_endpoint_ids, identifier)
# change data structure to dict in order to be quicker when merging
nodes_mapped_dict = {node[id_key]: node for node in nodes_mapped}
for edge in edges:
# change edge endpoints if they were matched with a protein in the database
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: n[node_name_attribute],
filter(lambda n: node_name_attribute in n,
parameters['input_network']['nodes'])) for node_name in nodes}
print(nodes_mapped)
# nodes_mapped_dict = {node[id_key][0]: node for node in nodes_mapped}
# nodes_mapped_dict_reverse = {}
# for id, node in nodes_mapped_dict.items():
# for drugstone_id in node[node_name_attribute]:
# nodes_mapped_dict_reverse[node[drugstone_id]] = id
print(nodes)
# for edge in edges:
# # change edge endpoints if they were matched with a protein in the database
# 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 \
parameters['config'][
'interaction_protein_protein']
dataset_object = models.PPIDataset.objects.filter(name__iexact=dataset).last()
interaction_objects = models.ProteinProteinInteraction.objects.filter(
Q(ppi_dataset=dataset_object) & Q(from_protein__in=proteins) & Q(to_protein__in=proteins))
auto_edges = list(
map(lambda n: {"from": f'p{n.from_protein_id}', "to": f'p{n.to_protein_id}'}, interaction_objects))
auto_edges = list(map(lambda n: {"from": f'p{n.from_protein_id}', "to": f'p{n.to_protein_id}'},
interaction_objects))
edges.extend(auto_edges)
# TODO check what to do with edges with from and to id lists
result['network']['edges'].extend(edges)
uniq_edges = dict()
for edge in result['network']['edges']:
print(edge)
hash = edge['from'] + edge['to']
uniq_edges[hash] = edge
result['network']['edges'] = list(uniq_edges.values())
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment