Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Cosy-Bio
Drugst.One
backend
Commits
2932cfbf
Commit
2932cfbf
authored
2 years ago
by
AndiMajore
Browse files
Options
Downloads
Patches
Plain Diff
try to fix tissue expression route
Former-commit-id:
5ab77506
parent
8a24c048
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
drugstone/urls.py
+3
-3
3 additions, 3 deletions
drugstone/urls.py
drugstone/views.py
+43
-50
43 additions, 50 deletions
drugstone/views.py
with
46 additions
and
53 deletions
drugstone/urls.py
+
3
−
3
View file @
2932cfbf
...
...
@@ -17,9 +17,9 @@ from django.contrib import admin
from
django.urls
import
path
from
drugstone.views
import
map_nodes
,
tasks_view
,
result_view
,
\
graph_export
,
TissueView
,
TissueExpressionView
,
query_tissue_proteins
,
TaskView
,
\
graph_export
,
TissueView
,
query_tissue_proteins
,
TaskView
,
\
adjacent_drugs
,
adjacent_disorders
,
fetch_edges
,
create_network
,
load_network
,
get_license
,
get_datasets
,
\
get_max_tissue_expression
get_max_tissue_expression
,
get_tissue_expression
# cache time is 6 hours
urlpatterns
=
[
...
...
@@ -33,7 +33,7 @@ urlpatterns = [
path
(
'
query_tissue_proteins/
'
,
query_tissue_proteins
),
path
(
'
adjacent_drugs/
'
,
adjacent_drugs
),
path
(
'
adjacent_disorders/
'
,
adjacent_disorders
),
path
(
'
tissue_expression/
'
,
T
issue
E
xpression
View
.
as_view
()
),
path
(
'
tissue_expression/
'
,
get_t
issue
_e
xpression
),
path
(
'
tissue_max_expression/
'
,
get_max_tissue_expression
),
path
(
'
tissues/
'
,
TissueView
.
as_view
()),
path
(
'
admin/
'
,
admin
.
site
.
urls
),
...
...
This diff is collapsed.
Click to expand it.
drugstone/views.py
+
43
−
50
View file @
2932cfbf
...
...
@@ -653,56 +653,49 @@ class TissueView(APIView):
return
Response
(
TissueSerializer
(
many
=
True
).
to_representation
(
tissues
))
class
TissueExpressionView
(
APIView
):
"""
Expression of host proteins in tissues.
"""
def
get
(
self
,
request
)
->
Response
:
return
self
.
post
(
request
)
@api_view
([
'
POST
'
,
'
GET
'
])
def
get_tissue_expression
(
request
)
->
Response
:
tissue
=
Tissue
.
objects
.
get
(
id
=
request
.
query_params
.
get
(
'
tissue
'
))
def
post
(
self
,
request
)
->
Response
:
tissue
=
Tissue
.
objects
.
get
(
id
=
request
.
query_params
.
get
(
'
tissue
'
))
if
request
.
query_params
.
get
(
'
proteins
'
):
ids
=
json
.
loads
(
request
.
query_params
.
get
(
'
proteins
'
))
proteins
=
list
(
Protein
.
objects
.
filter
(
id__in
=
ids
).
all
())
elif
request
.
query_params
.
get
(
'
token
'
):
proteins
=
[]
task
=
Task
.
objects
.
get
(
token
=
request
.
query_params
[
'
token
'
])
result
=
task_result
(
task
)
network
=
result
[
'
network
'
]
node_attributes
=
result
.
get
(
'
node_attributes
'
)
if
not
node_attributes
:
node_attributes
=
{}
node_types
=
node_attributes
.
get
(
'
node_types
'
)
if
not
node_types
:
node_types
=
{}
parameters
=
json
.
loads
(
task
.
parameters
)
seeds
=
parameters
[
'
seeds
'
]
nodes
=
network
[
'
nodes
'
]
for
node
in
nodes
+
seeds
:
node_type
=
node_types
.
get
(
node
)
details
=
None
if
node_type
==
'
protein
'
:
if
details
:
proteins
.
append
(
details
)
else
:
try
:
prot
=
Protein
.
objects
.
get
(
uniprot_code
=
node
)
if
prot
not
in
proteins
:
proteins
.
append
(
Protein
.
objects
.
get
(
uniprot_code
=
node
))
except
Protein
.
DoesNotExist
:
pass
pt_expressions
=
{}
for
protein
in
proteins
:
try
:
expression_level
=
ExpressionLevel
.
objects
.
get
(
protein
=
protein
,
tissue
=
tissue
)
pt_expressions
[
ProteinSerializer
().
to_representation
(
protein
)[
'
drugstone_id
'
]]
=
expression_level
.
expression_level
except
ExpressionLevel
.
DoesNotExist
:
pt_expressions
[
ProteinSerializer
().
to_representation
(
protein
)[
'
drugstone_id
'
]]
=
None
if
request
.
query_params
.
get
(
'
proteins
'
):
ids
=
json
.
loads
(
request
.
query_params
.
get
(
'
proteins
'
))
proteins
=
list
(
Protein
.
objects
.
filter
(
id__in
=
ids
).
all
())
elif
request
.
query_params
.
get
(
'
token
'
):
proteins
=
[]
task
=
Task
.
objects
.
get
(
token
=
request
.
query_params
[
'
token
'
])
result
=
task_result
(
task
)
network
=
result
[
'
network
'
]
node_attributes
=
result
.
get
(
'
node_attributes
'
)
if
not
node_attributes
:
node_attributes
=
{}
node_types
=
node_attributes
.
get
(
'
node_types
'
)
if
not
node_types
:
node_types
=
{}
parameters
=
json
.
loads
(
task
.
parameters
)
seeds
=
parameters
[
'
seeds
'
]
nodes
=
network
[
'
nodes
'
]
for
node
in
nodes
+
seeds
:
node_type
=
node_types
.
get
(
node
)
details
=
None
if
node_type
==
'
protein
'
:
if
details
:
proteins
.
append
(
details
)
else
:
try
:
prot
=
Protein
.
objects
.
get
(
uniprot_code
=
node
)
if
prot
not
in
proteins
:
proteins
.
append
(
Protein
.
objects
.
get
(
uniprot_code
=
node
))
except
Protein
.
DoesNotExist
:
pass
pt_expressions
=
{}
for
protein
in
proteins
:
try
:
expression_level
=
ExpressionLevel
.
objects
.
get
(
protein
=
protein
,
tissue
=
tissue
)
pt_expressions
[
ProteinSerializer
().
to_representation
(
protein
)[
'
drugstone_id
'
]]
=
expression_level
.
expression_level
except
ExpressionLevel
.
DoesNotExist
:
pt_expressions
[
ProteinSerializer
().
to_representation
(
protein
)[
'
drugstone_id
'
]]
=
None
return
Response
(
pt_expressions
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment