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

remove unconnected nodes from gt files

parent a3dc5740
No related branches found
No related tags found
No related merge requests found
...@@ -13,6 +13,7 @@ django.setup() ...@@ -13,6 +13,7 @@ django.setup()
KERNEL = 6 KERNEL = 6
def _internal_expression_scores(drugstone_id: str) -> dict: def _internal_expression_scores(drugstone_id: str) -> dict:
""" Looks up the tissue specific expression scores for a given protein. """ Looks up the tissue specific expression scores for a given protein.
The scores are loaded from the django database. The scores are loaded from the django database.
...@@ -38,6 +39,7 @@ def _internal_expression_scores(drugstone_id: str) -> dict: ...@@ -38,6 +39,7 @@ def _internal_expression_scores(drugstone_id: str) -> dict:
return tissue_scores return tissue_scores
def _internal_pdis(dataset_name: str) -> List[dict]: def _internal_pdis(dataset_name: str) -> List[dict]:
""" Fetches all internal protein-drug interactions for a given dataset. """ Fetches all internal protein-drug interactions for a given dataset.
Interactions are taken from the django database. Interactions are taken from the django database.
...@@ -57,6 +59,7 @@ def _internal_pdis(dataset_name: str) -> List[dict]: ...@@ -57,6 +59,7 @@ def _internal_pdis(dataset_name: str) -> List[dict]:
return node_node_interactions return node_node_interactions
def _internal_ppis(dataset_name: str) -> List[dict]: def _internal_ppis(dataset_name: str) -> List[dict]:
""" Fetches all internal protein-protein interactions for a given dataset. """ Fetches all internal protein-protein interactions for a given dataset.
Interactions are taken from the django database. Interactions are taken from the django database.
...@@ -92,7 +95,7 @@ def create_gt(params: Tuple[str, str]) -> None: ...@@ -92,7 +95,7 @@ def create_gt(params: Tuple[str, str]) -> None:
print(f'loading nodes') print(f'loading nodes')
data['nodes'] = serializers.ProteinSerializer(many=True).to_representation( data['nodes'] = serializers.ProteinSerializer(many=True).to_representation(
models.Protein.objects.all() models.Protein.objects.all()
) )
print(f'loading edges/{ppi_dataset}') print(f'loading edges/{ppi_dataset}')
data['edges'] = _internal_ppis(ppi_dataset) data['edges'] = _internal_ppis(ppi_dataset)
...@@ -100,7 +103,7 @@ def create_gt(params: Tuple[str, str]) -> None: ...@@ -100,7 +103,7 @@ def create_gt(params: Tuple[str, str]) -> None:
print(f'loading drugs') print(f'loading drugs')
data['drugs'] = serializers.DrugSerializer(many=True).to_representation( data['drugs'] = serializers.DrugSerializer(many=True).to_representation(
models.Drug.objects.all() models.Drug.objects.all()
) )
print(f'loading drug_edges/{pdi_dataset}') print(f'loading drug_edges/{pdi_dataset}')
data['drug_edges'] = _internal_pdis(pdi_dataset) data['drug_edges'] = _internal_pdis(pdi_dataset)
...@@ -175,6 +178,14 @@ def create_gt(params: Tuple[str, str]) -> None: ...@@ -175,6 +178,14 @@ def create_gt(params: Tuple[str, str]) -> None:
e_type[e] = 'drug-protein' e_type[e] = 'drug-protein'
print("done with drug edges") print("done with drug edges")
# remove unconnected nodes
delete_vertices = set()
for vertex in g.iter_vertices():
if vertex.out_degree() == 0:
delete_vertices.add(vertex)
g.remove_vertex(reversed(sorted(delete_vertices)), fast=True)
# save graph # save graph
filename = f"./data/Networks/internal_{ppi_dataset}_{pdi_dataset}.gt" filename = f"./data/Networks/internal_{ppi_dataset}_{pdi_dataset}.gt"
g.save(filename) g.save(filename)
......
...@@ -4,8 +4,7 @@ python3 manage.py makemigrations drugstone ...@@ -4,8 +4,7 @@ python3 manage.py makemigrations drugstone
python3 manage.py migrate python3 manage.py migrate
python3 manage.py createfixtures python3 manage.py createfixtures
python3 manage.py cleanuptasks python3 manage.py cleanuptasks
python3 manage.py populate_db --update -p python3 manage.py populate_db --update -a
#python3 manage.py populate_db --update -a python3 manage.py make_graphs
#python3 manage.py make_graphs
/usr/bin/supervisord -c "/etc/supervisor/conf.d/supervisord.conf" /usr/bin/supervisord -c "/etc/supervisor/conf.d/supervisord.conf"
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