django-to-galaxy 0.6.9.7__py3-none-any.whl → 0.6.9.9__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of django-to-galaxy might be problematic. Click here for more details.

Files changed (26) hide show
  1. django_to_galaxy/admin/__init__.py +7 -1
  2. django_to_galaxy/admin/galaxy_user.py +21 -35
  3. django_to_galaxy/admin/utils.py +112 -0
  4. django_to_galaxy/admin/workflow.py +61 -6
  5. django_to_galaxy/api/serializers/create_dataset_collection.py +118 -0
  6. django_to_galaxy/api/serializers/create_history.py +6 -0
  7. django_to_galaxy/api/serializers/invocation.py +5 -0
  8. django_to_galaxy/api/serializers/invoke_workflow.py +4 -0
  9. django_to_galaxy/api/serializers/workflow.py +6 -0
  10. django_to_galaxy/api/urls.py +15 -0
  11. django_to_galaxy/api/views/create_dataset_collection.py +461 -0
  12. django_to_galaxy/api/views/create_history.py +3 -0
  13. django_to_galaxy/api/views/invocation.py +6 -1
  14. django_to_galaxy/api/views/invoke_workflow.py +23 -21
  15. django_to_galaxy/migrations/0011_rename__step_jobs_count_workflow__step_count_and_more.py +23 -0
  16. django_to_galaxy/migrations/0012_workflowinput_collection_type_and_more.py +136 -0
  17. django_to_galaxy/models/__init__.py +1 -1
  18. django_to_galaxy/models/accepted_input.py +113 -2
  19. django_to_galaxy/models/galaxy_instance.py +1 -1
  20. django_to_galaxy/models/invocation.py +41 -12
  21. django_to_galaxy/models/workflow.py +366 -30
  22. django_to_galaxy/version.py +1 -1
  23. {django_to_galaxy-0.6.9.7.dist-info → django_to_galaxy-0.6.9.9.dist-info}/METADATA +4 -3
  24. {django_to_galaxy-0.6.9.7.dist-info → django_to_galaxy-0.6.9.9.dist-info}/RECORD +26 -20
  25. {django_to_galaxy-0.6.9.7.dist-info → django_to_galaxy-0.6.9.9.dist-info}/WHEEL +1 -1
  26. {django_to_galaxy-0.6.9.7.dist-info → django_to_galaxy-0.6.9.9.dist-info/licenses}/LICENSE +0 -0
@@ -3,5 +3,11 @@ from .galaxy_user import GalaxyUserAdmin # noqa
3
3
  from .galaxy_output_file import GalaxyOutputFileAdmin # noqa
4
4
  from .history import HistoryAdmin # noqa
5
5
  from .invocation import InvocationAdmin # noqa
6
- from .workflow import WorkflowAdmin, WorkflowInputAdmin, FormatAdmin # noqa
6
+ from .workflow import ( # noqa
7
+ WorkflowAdmin, # noqa
8
+ WorkflowInputAdmin, # noqa
9
+ FormatAdmin, # noqa
10
+ WorkflowInputTextOptionAdmin, # noqa
11
+ ) # noqa
7
12
  from .tag import TagAdmin # noqa
13
+ from .utils import * # noqa
@@ -10,7 +10,7 @@ from django.utils.translation import ngettext
10
10
 
11
11
  from django_to_galaxy.models.galaxy_user import GalaxyUser
12
12
  from django_to_galaxy.models.galaxy_element import Tag
13
- from django_to_galaxy.models.accepted_input import Format, WorkflowInput
13
+ from django_to_galaxy.admin.utils import update_workflowinputs
14
14
 
15
15
 
16
16
  @admin.register(GalaxyUser)
@@ -146,40 +146,26 @@ class GalaxyUserAdmin(admin.ModelAdmin):
146
146
  id_tags.append(savedtag.id)
147
147
  if wf.galaxy_id in galaxy_id_to_save:
148
148
  wf.save()
149
- for elem, elem_dict in wf.galaxy_workflow.inputs.items():
150
- for step, step_dict in wf.galaxy_workflow.steps.items():
151
- if step == elem:
152
- (
153
- workflowinput,
154
- created,
155
- ) = WorkflowInput.objects.get_or_create(
156
- galaxy_step_id=step,
157
- label=elem_dict["label"],
158
- workflow=wf,
159
- )
160
- if hasattr(step_dict.tool_inputs, "format"):
161
- for format in step_dict.tool_inputs["format"]:
162
- (
163
- winputformat,
164
- created,
165
- ) = Format.objects.get_or_create(
166
- format=format.strip()
167
- )
168
- workflowinput.formats.add(winputformat.id)
169
- workflowinput.optional = step_dict.tool_inputs[
170
- "optional"
171
- ]
172
- workflowinput.save()
173
- for tag in id_tags:
174
- wf.tags.add(tag)
175
- wf.save()
176
- existing_workflows.append(wf)
177
- new_workflows.remove((wf, tags))
178
- self.message_user(
179
- request,
180
- f"Successfully imported {len(galaxy_id_to_save)} workflow(s)",
181
- messages.SUCCESS,
182
- )
149
+ try:
150
+ update_workflowinputs(wf.id)
151
+ except Exception as e:
152
+ self.message_user(
153
+ request,
154
+ f"Could not import '{wf.name}' workflow: {e}",
155
+ messages.ERROR,
156
+ )
157
+ else:
158
+ for tag in id_tags:
159
+ wf.tags.add(tag)
160
+ wf.save()
161
+ existing_workflows.append(wf)
162
+ new_workflows.remove((wf, tags))
163
+ self.message_user(
164
+ request,
165
+ f"Successfully imported '{wf.name}' workflow",
166
+ messages.SUCCESS,
167
+ )
168
+
183
169
  context = dict(
184
170
  self.admin_site.each_context(request),
185
171
  galaxy_user=galaxy_user,
@@ -0,0 +1,112 @@
1
+ from django_to_galaxy.models.workflow import Workflow
2
+ from django.db import transaction
3
+ from django_to_galaxy.models.accepted_input import (
4
+ Format,
5
+ WorkflowInput,
6
+ DATA,
7
+ COLLECTION,
8
+ PARAMETER,
9
+ P_TEXT,
10
+ WorkflowInputTextOption,
11
+ )
12
+
13
+ """
14
+ Update inputs information of a workflow functions
15
+ """
16
+
17
+
18
+ def search_step_info_value(key, value_none, step_info):
19
+ if key in step_info["tool_inputs"].keys():
20
+ value = step_info["tool_inputs"][key]
21
+ else:
22
+ try:
23
+ value = step_info["target_tools"][0]["tool_input"][key]
24
+ except Exception:
25
+ value = value_none
26
+
27
+ return value
28
+
29
+
30
+ def update_workflowinputs(workflow_id):
31
+ wf = Workflow.objects.get(id=workflow_id)
32
+ try:
33
+ with transaction.atomic():
34
+ # Saving workflow inputs
35
+ input_mapping = wf.get_workflow_inputs()
36
+ for step, step_info in input_mapping.items():
37
+ input_type = step_info["type"]
38
+ if input_type == DATA:
39
+ workflowinput, created = WorkflowInput.objects.get_or_create(
40
+ galaxy_step_id=step,
41
+ label=step_info["label"],
42
+ workflow=wf,
43
+ input_type=input_type,
44
+ parameter_type=None,
45
+ collection_type=None,
46
+ optional=step_info["tool_inputs"]["optional"],
47
+ default_value=None,
48
+ multiple=False,
49
+ )
50
+ elif input_type == COLLECTION:
51
+ workflowinput, created = WorkflowInput.objects.get_or_create(
52
+ galaxy_step_id=step,
53
+ label=step_info["label"],
54
+ workflow=wf,
55
+ input_type=input_type,
56
+ parameter_type=None,
57
+ collection_type=step_info["tool_inputs"]["collection_type"],
58
+ optional=step_info["tool_inputs"]["optional"],
59
+ default_value=None,
60
+ multiple=False,
61
+ )
62
+ elif input_type == PARAMETER:
63
+ parameter_type = step_info["tool_inputs"]["parameter_type"]
64
+ default_value = search_step_info_value("default", None, step_info)
65
+ multiple = search_step_info_value("multiple", False, step_info)
66
+
67
+ workflowinput, created = WorkflowInput.objects.get_or_create(
68
+ galaxy_step_id=step,
69
+ label=step_info["label"],
70
+ workflow=wf,
71
+ input_type=input_type,
72
+ parameter_type=parameter_type,
73
+ collection_type=None,
74
+ optional=step_info["tool_inputs"]["optional"],
75
+ default_value=default_value,
76
+ multiple=multiple,
77
+ )
78
+ if created and parameter_type == P_TEXT:
79
+ # Add TextOption
80
+ if "restrictions" in step_info["tool_inputs"].keys():
81
+ # If there are restrictions, we're saving them
82
+ for value in step_info["tool_inputs"]["restrictions"]:
83
+ (
84
+ workflowinputtextoption,
85
+ _,
86
+ ) = WorkflowInputTextOption.objects.get_or_create(
87
+ workflow_input=workflowinput, text_option=value
88
+ )
89
+ else:
90
+ # If no restrictions, we are getting the options from the 1st tool
91
+ try:
92
+ tool_info = step_info["target_tools"][0]
93
+ for opt in tool_info["tool_input"]["options"]:
94
+ (
95
+ workflowinputtextoption,
96
+ _,
97
+ ) = WorkflowInputTextOption.objects.get_or_create(
98
+ workflow_input=workflowinput, text_option=opt[1]
99
+ )
100
+ except (KeyError, ValueError):
101
+ pass
102
+ if "format" in step_info["tool_inputs"].keys():
103
+ for format in step_info["tool_inputs"]["format"]:
104
+ (
105
+ winputformat,
106
+ _,
107
+ ) = Format.objects.get_or_create(format=format.strip())
108
+ workflowinput.formats.add(winputformat.id)
109
+ except Exception as e:
110
+ raise e
111
+ else:
112
+ return
@@ -1,7 +1,12 @@
1
- from django.contrib import admin
1
+ from django.contrib import admin, messages
2
+ from django_to_galaxy.admin.utils import update_workflowinputs
2
3
 
3
4
  from django_to_galaxy.models.workflow import Workflow
4
- from django_to_galaxy.models.accepted_input import WorkflowInput, Format
5
+ from django_to_galaxy.models.accepted_input import (
6
+ Format,
7
+ WorkflowInput,
8
+ WorkflowInputTextOption,
9
+ )
5
10
 
6
11
  from .galaxy_element import GalaxyElementAdmin
7
12
 
@@ -14,7 +19,7 @@ class WorkflowAdmin(GalaxyElementAdmin):
14
19
  "annotation",
15
20
  "galaxy_id",
16
21
  "get_is_meta",
17
- "get_step_jobs_count",
22
+ "get_step_count",
18
23
  "published",
19
24
  "galaxy_owner",
20
25
  "get_tags",
@@ -25,21 +30,48 @@ class WorkflowAdmin(GalaxyElementAdmin):
25
30
  "annotation",
26
31
  "galaxy_id",
27
32
  "get_is_meta",
28
- "get_step_jobs_count",
33
+ "get_step_count",
29
34
  "published",
30
35
  "galaxy_owner",
31
36
  "get_tags",
32
37
  )
38
+ actions = ["update_workflow_inputs"]
33
39
 
34
40
  def get_is_meta(self, obj):
35
41
  return obj.get_is_meta()
36
42
 
37
- def get_step_jobs_count(self, obj):
38
- return obj.get_step_jobs_count()
43
+ def get_step_count(self, obj):
44
+ return obj.get_step_count()
39
45
 
40
46
  def get_tags(self, obj):
41
47
  return ", ".join([p.label for p in obj.tags.all()])
42
48
 
49
+ @admin.action(description="Update workflow inputs (1 workflow only)")
50
+ def update_workflow_inputs(self, request, queryset):
51
+ if queryset.count() > 1:
52
+ self.message_user(
53
+ request,
54
+ "You can update the workflow inputs of 1 workflow only at a time.",
55
+ messages.ERROR,
56
+ )
57
+ return
58
+ workflow = queryset[0]
59
+
60
+ try:
61
+ update_workflowinputs(workflow.id)
62
+ except Exception as e:
63
+ self.message_user(
64
+ request,
65
+ f"Could not update workflow inputs of '{workflow.name}' workflow: {e}",
66
+ messages.ERROR,
67
+ )
68
+ else:
69
+ self.message_user(
70
+ request,
71
+ f"Successfully updated workflow inputs of '{workflow.name}' workflow",
72
+ messages.SUCCESS,
73
+ )
74
+
43
75
 
44
76
  @admin.register(Format)
45
77
  class FormatAdmin(GalaxyElementAdmin):
@@ -53,15 +85,34 @@ class FormatAdmin(GalaxyElementAdmin):
53
85
  )
54
86
 
55
87
 
88
+ @admin.register(WorkflowInputTextOption)
89
+ class WorkflowInputTextOptionAdmin(GalaxyElementAdmin):
90
+ list_display = ("id", "get_workflow", "workflow_input", "text_option")
91
+
92
+ readonly_fields = ("id", "get_workflow", "workflow_input", "text_option")
93
+
94
+ def get_workflow(self, obj):
95
+ return obj.workflow_input.workflow
96
+
97
+
56
98
  @admin.register(WorkflowInput)
57
99
  class WorkflowInputAdmin(GalaxyElementAdmin):
100
+ # Limit 20 items per page
101
+ list_per_page = 20
102
+ list_max_show_all = 50
103
+
58
104
  list_display = (
59
105
  "id",
60
106
  "galaxy_step_id",
61
107
  "label",
62
108
  "workflow",
109
+ "input_type",
63
110
  "get_formats",
111
+ "parameter_type",
112
+ "collection_type",
64
113
  "optional",
114
+ "default_value",
115
+ "multiple",
65
116
  )
66
117
  readonly_fields = (
67
118
  "id",
@@ -69,7 +120,11 @@ class WorkflowInputAdmin(GalaxyElementAdmin):
69
120
  "label",
70
121
  "workflow",
71
122
  "get_formats",
123
+ "parameter_type",
124
+ "collection_type",
72
125
  "optional",
126
+ "default_value",
127
+ "multiple",
73
128
  )
74
129
 
75
130
  def get_formats(self, obj):
@@ -0,0 +1,118 @@
1
+ from rest_framework import serializers
2
+ from django.core.exceptions import ValidationError
3
+
4
+ dataset_id_error_messages = {
5
+ "min_length": "Dataset ID must be at least 16 characters long.",
6
+ }
7
+
8
+
9
+ class CollectionListSerializer(serializers.Serializer):
10
+ history_id = serializers.IntegerField(
11
+ required=True,
12
+ help_text=(
13
+ "Internal Django to galaxy ID of the Galaxy "
14
+ "history where the collection will be created."
15
+ ),
16
+ )
17
+ collection_name = serializers.CharField(
18
+ required=True, help_text="Name of the dataset collection to be created."
19
+ )
20
+ elements_names = serializers.ListSerializer(
21
+ child=serializers.CharField(required=True),
22
+ help_text="List of names for each element in the collection.",
23
+ )
24
+ elements_ids = serializers.ListSerializer(
25
+ child=serializers.CharField(
26
+ required=True, min_length=16, error_messages=dataset_id_error_messages
27
+ ),
28
+ help_text="List of galaxy dataset IDs corresponding to each element in the collection.",
29
+ )
30
+
31
+ def validate(self, attrs):
32
+ if len(attrs["elements_names"]) != len(attrs["elements_ids"]):
33
+ raise ValidationError(
34
+ {
35
+ "lists_lengths": (
36
+ "List of elements_names and list of "
37
+ "elements_ids must be of same length."
38
+ )
39
+ }
40
+ )
41
+ return attrs
42
+
43
+
44
+ class CollectionListPairedSerializer(serializers.Serializer):
45
+ history_id = serializers.IntegerField(
46
+ required=True,
47
+ help_text=(
48
+ "Internal Django to galaxy ID of the Galaxy "
49
+ "history where the collection will be created."
50
+ ),
51
+ )
52
+ collection_name = serializers.CharField(
53
+ required=True, help_text="Name of the dataset collection to be created."
54
+ )
55
+ pairs_names = serializers.ListSerializer(
56
+ child=serializers.CharField(),
57
+ help_text="List of names for each paired datasets in the collection.",
58
+ )
59
+ first_elements_ids = serializers.ListSerializer(
60
+ child=serializers.CharField(
61
+ required=True, min_length=16, error_messages=dataset_id_error_messages
62
+ ),
63
+ help_text=(
64
+ "List of galaxy dataset IDs corresponding to "
65
+ "the first element in each paired datasets."
66
+ ),
67
+ )
68
+ second_elements_ids = serializers.ListSerializer(
69
+ child=serializers.CharField(
70
+ required=True, min_length=16, error_messages=dataset_id_error_messages
71
+ ),
72
+ help_text=(
73
+ "List of galaxy dataset IDs corresponding to "
74
+ "the second element in each paired datasets."
75
+ ),
76
+ )
77
+
78
+ def validate(self, attrs):
79
+ if (
80
+ len(attrs["first_elements_ids"]) != len(attrs["second_elements_ids"])
81
+ or len(attrs["first_elements_ids"]) != len(attrs["pairs_names"])
82
+ or len(attrs["pairs_names"]) != len(attrs["second_elements_ids"])
83
+ ):
84
+ raise ValidationError(
85
+ {
86
+ "lists_lengths": (
87
+ "List of pairs names and list "
88
+ "of elements ids must be of same length."
89
+ )
90
+ }
91
+ )
92
+
93
+ return attrs
94
+
95
+
96
+ class CollectionPairedSerializer(serializers.Serializer):
97
+ history_id = serializers.IntegerField(
98
+ required=True,
99
+ help_text=(
100
+ "Internal Django to galaxy ID of the Galaxy history"
101
+ " where the collection will be created."
102
+ ),
103
+ )
104
+ collection_name = serializers.CharField(
105
+ required=True, help_text="Name of the dataset collection to be created."
106
+ )
107
+ first_element_id = serializers.CharField(
108
+ required=True,
109
+ min_length=16,
110
+ error_messages=dataset_id_error_messages,
111
+ help_text="Galaxy dataset IDs corresponding to the first element of the paired dataset.",
112
+ )
113
+ second_element_id = serializers.CharField(
114
+ required=True,
115
+ min_length=16,
116
+ error_messages=dataset_id_error_messages,
117
+ help_text="Galaxy dataset IDs corresponding to the second element of the paired dataset.",
118
+ )
@@ -0,0 +1,6 @@
1
+ from rest_framework import serializers
2
+
3
+
4
+ class HistoryCreatedSerializer(serializers.Serializer):
5
+ message = serializers.CharField()
6
+ history_id = serializers.IntegerField()
@@ -15,3 +15,8 @@ class InvocationSerializer(serializers.ModelSerializer):
15
15
  "history",
16
16
  "create_time",
17
17
  ]
18
+
19
+
20
+ class UpdateOutputFilesResponseSerializer(serializers.Serializer):
21
+ message = serializers.CharField()
22
+ galaxy_output_file_ids = serializers.ListField(child=serializers.IntegerField())
@@ -18,3 +18,7 @@ class ExecuteWorkflowSerializer(serializers.Serializer):
18
18
  workflow_id = serializers.IntegerField()
19
19
  galaxy_user_id = serializers.IntegerField()
20
20
  fake_datamap = serializers.DictField(child=FileSerializer())
21
+
22
+
23
+ class GenericDictSerializer(serializers.Serializer):
24
+ data = serializers.DictField()
@@ -28,8 +28,14 @@ class WorkflowSerializer(serializers.ModelSerializer):
28
28
  return [
29
29
  {
30
30
  "galaxy_step_id": input.galaxy_step_id,
31
+ "label": input.label,
32
+ "input_type": input.input_type,
31
33
  "formats": [format.format for format in input.formats.all()],
34
+ "parameter_type": input.parameter_type,
35
+ "collection_type": input.collection_type,
32
36
  "optional": input.optional,
37
+ "default_value": input.default_value,
38
+ "multiple": input.multiple,
33
39
  }
34
40
  for input in obj.workflowinput_set.all()
35
41
  ]
@@ -15,8 +15,14 @@ from django_to_galaxy.api.views.upload_to_history import UploadToHistoryView
15
15
  from django_to_galaxy.api.views.invoke_workflow import (
16
16
  InvokeWorkflowView,
17
17
  GetWorkflowDatamapTemplateView,
18
+ # GetWorkflowInputsView,
18
19
  ExecuteWorkflowView,
19
20
  )
21
+ from django_to_galaxy.api.views.create_dataset_collection import (
22
+ CreateDatasetListCollectionView,
23
+ CreateDatasetListPairedCollectionView,
24
+ CreateDatasetPairedCollectionView,
25
+ )
20
26
 
21
27
  api_router = routers.DefaultRouter()
22
28
  api_router.register(r"instances", GalaxyInstanceViewSet)
@@ -33,6 +39,15 @@ urlpatterns = [
33
39
  path("execute_workflow/", ExecuteWorkflowView.as_view()),
34
40
  path("update_galaxy_output_files/<int:pk>", UpdateOutputFilesView.as_view()),
35
41
  path("get_datamap_template/<int:pk>", GetWorkflowDatamapTemplateView.as_view()),
42
+ path(
43
+ "create_dataset_collection_paired/", CreateDatasetPairedCollectionView.as_view()
44
+ ),
45
+ path("create_dataset_collection_list/", CreateDatasetListCollectionView.as_view()),
46
+ path(
47
+ "create_dataset_collection_list_paired/",
48
+ CreateDatasetListPairedCollectionView.as_view(),
49
+ ),
50
+ # path("get_workflow_inputs/<int:pk>", GetWorkflowInputsView.as_view()),
36
51
  ]
37
52
 
38
53
  urlpatterns += api_router.urls