Skip to content
Snippets Groups Projects
Commit 48aac012 authored by Hervé  MENAGER's avatar Hervé MENAGER
Browse files

add an admin task to update Compound cross-links

parent 915bd48c
No related branches found
Tags v0.2.62
No related merge requests found
...@@ -424,6 +424,24 @@ def generate_pca_plot(): ...@@ -424,6 +424,24 @@ def generate_pca_plot():
print("Successfully generated PCA biplot data") print("Successfully generated PCA biplot data")
def set_compound_links(compound_ids: List[int]) -> List[int]:
"""
set/update links with external databases:
DrugBank, ChEMBL, PubChem
for each compound of a queryset
:param qs: queryset over the compounds to be processed
:type qs: QuerySet
"""
qs = Compound.objects.filter(id__in=compound_ids)
for c in qs:
c.set_drugbank_link()
c.set_chembl_link()
c.set_pubchem_link()
c.save()
return [c.id for c in qs]
@task(base=MonitorTask, bind=True) @task(base=MonitorTask, bind=True)
def run_compute_compound_properties(self: MonitorTask, compound_id: int) -> int: def run_compute_compound_properties(self: MonitorTask, compound_id: int) -> int:
""" """
...@@ -506,9 +524,30 @@ def run_compute_drugbank_similarity( ...@@ -506,9 +524,30 @@ def run_compute_drugbank_similarity(
@task(base=MonitorTask, bind=True) @task(base=MonitorTask, bind=True)
def run_validate( def run_set_compound_links(self: MonitorTask, compound_id: int) -> int:
self: MonitorTask, compound_ids: List[int] = None """
) -> List[int]: task to set/update the DB cross-links for a compound
:param self: the task the function is binded to as a method
:type self: MonitorTask
:param compound_id: the ID of the compound
:type compound_id: int
:return: the ID of the compound
:rtype: int
"""
self.update_state(state=states.STARTED)
cj = CompoundJob()
cj.compound = Compound.objects.get(id=compound_id)
cj.job = Job.objects.get(task_result__task_id=self.task_id)
cj.save()
self.write(std_out=f"Starting setting external cross-links for {compound_id}")
result_compound_ids = set_compound_links([compound_id])
self.write(std_out=f"Finished setting external cross-links for {compound_id}")
return result_compound_ids[0]
@task(base=MonitorTask, bind=True)
def run_validate(self: MonitorTask, compound_ids: List[int] = None) -> List[int]:
""" """
task "run method" to validate a list of compounds task "run method" to validate a list of compounds
...@@ -598,3 +637,16 @@ def launch_plots_computing(): ...@@ -598,3 +637,16 @@ def launch_plots_computing():
""" """
workflow = chain(run_le_lle_plot.si(), run_pca_plot.si()) workflow = chain(run_le_lle_plot.si(), run_pca_plot.si())
workflow.delay() workflow.delay()
def launch_set_compound_links():
"""
Launch the tasks to set/update compound links
"""
link_jobs_group = group(
[
run_set_compound_links.si(compound.id)
for compound in Compound.objects.validated()
]
)
link_jobs_group.delay()
...@@ -6,6 +6,7 @@ from ippidb.tasks import ( ...@@ -6,6 +6,7 @@ from ippidb.tasks import (
launch_update_compound_cached_properties, launch_update_compound_cached_properties,
run_compute_drugbank_similarity, run_compute_drugbank_similarity,
launch_plots_computing, launch_plots_computing,
launch_set_compound_links,
) )
from django.shortcuts import render from django.shortcuts import render
from ippidb.models import Job from ippidb.models import Job
...@@ -36,6 +37,10 @@ class IppidbAdmin(admin.AdminSite): ...@@ -36,6 +37,10 @@ class IppidbAdmin(admin.AdminSite):
"launch_plots_computing/", "launch_plots_computing/",
self.admin_view(self.launch_plots_computing_view), self.admin_view(self.launch_plots_computing_view),
), ),
path(
"launch_set_compound_links/",
self.admin_view(self.launch_set_compound_links_view),
),
path("tasklog/", self.admin_view(self.tasklog), name="tasklog"), path("tasklog/", self.admin_view(self.tasklog), name="tasklog"),
] ]
return my_urls + urls return my_urls + urls
...@@ -90,3 +95,11 @@ class IppidbAdmin(admin.AdminSite): ...@@ -90,3 +95,11 @@ class IppidbAdmin(admin.AdminSite):
launch_plots_computing() launch_plots_computing()
messages.add_message(request, messages.INFO, "Plots computing launched") messages.add_message(request, messages.INFO, "Plots computing launched")
return redirect("/admin/ippidb/job") return redirect("/admin/ippidb/job")
def launch_set_compound_links_view(self, request):
"""
This view launches the task to set/update compound DB cross-links.
"""
launch_set_compound_links()
messages.add_message(request, messages.INFO, "DB links update launched")
return redirect("/admin/ippidb/job")
\ No newline at end of file
...@@ -58,7 +58,12 @@ ...@@ -58,7 +58,12 @@
style="display:block">{% csrf_token %} style="display:block">{% csrf_token %}
<input type="submit" value="Plots generation" name="_save"/> <input type="submit" value="Plots generation" name="_save"/>
</form> </form>
<hr/> <hr/>
<form method="POST" action="/admin/launch_set_compound_links/"
style="display:block">{% csrf_token %}
<input type="submit" value="DB links update" name="_save"/>
</form>
<hr/>
</div> </div>
......
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