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

fixed entrez and ensembl based gene mapping

Former-commit-id: 062e5930ca636355aae9e8cee146065b2dc2280b [formerly cc56eff0767fbca323b9e3b712be544ad00dea86]
Former-commit-id: 1a42ce84dac905978aa14406dfe68821f790b7ad
parent dc908358
No related branches found
No related tags found
No related merge requests found
......@@ -68,7 +68,6 @@ class Protein(models.Model):
entrez = models.CharField(max_length=15, default='')
drugs = models.ManyToManyField('Drug', through='ProteinDrugInteraction',
related_name='interacting_drugs')
ensembl = models.CharField(max_length=15, default='')
tissue_expression = models.ManyToManyField('Tissue', through='ExpressionLevel',
related_name='interacting_drugs')
......
from typing import List, Tuple
from typing import List, Tuple, Set
from functools import reduce
from django.db.models import Q
from drugstone.models import Protein
from drugstone.models import Protein, EnsemblGene
from drugstone.serializers import ProteinSerializer
def query_proteins_by_identifier(node_ids: List[str], identifier: str) -> Tuple[List[dict], str]:
def query_proteins_by_identifier(node_ids: Set[str], identifier: str) -> Tuple[List[dict], str]:
"""Queries the django database Protein table given a list of identifiers (node_ids) and a identifier name
(identifier).
The identifier name represents any protein attribute, e.g. uniprot or symbol.
......@@ -31,13 +31,16 @@ def query_proteins_by_identifier(node_ids: List[str], identifier: str) -> Tuple[
q_list = map(lambda n: Q(uniprot_code__iexact=n), node_ids)
elif identifier == 'ensg':
protein_attribute = 'ensg'
q_list = map(lambda n: Q(ensg__name__iexact=n), node_ids)
node_ids = map(lambda n: n.protein_id, EnsemblGene.objects.filter(reduce(lambda a,b: a|b, map(lambda n:Q(name__iexact=n),list(node_ids)))))
q_list = map(lambda n: Q(id=n), node_ids)
elif identifier == 'entrez':
protein_attribute = 'entrez'
q_list = map(lambda n: Q(entrez=n), node_ids)
if not node_ids:
# node_ids is an empty list
return [], protein_attribute
q_list = reduce(lambda a, b: a | b, q_list)
node_objects = Protein.objects.filter(q_list)
# serialize
nodes = ProteinSerializer(many=True).to_representation(node_objects)
......
......@@ -4,7 +4,7 @@ python3 manage.py makemigrations drugstone
python3 manage.py migrate
python3 manage.py createfixtures
python3 manage.py cleanuptasks
python3 manage.py populate_db --all
python3 manage.py make_graphs
#python3 manage.py populate_db --update -a
#python3 manage.py make_graphs
/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