django-to-galaxy 0.7.0.0__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.
Files changed (68) hide show
  1. django_to_galaxy/__init__.py +1 -0
  2. django_to_galaxy/admin/__init__.py +13 -0
  3. django_to_galaxy/admin/galaxy_element.py +6 -0
  4. django_to_galaxy/admin/galaxy_instance.py +26 -0
  5. django_to_galaxy/admin/galaxy_output_file.py +79 -0
  6. django_to_galaxy/admin/galaxy_user.py +183 -0
  7. django_to_galaxy/admin/history.py +91 -0
  8. django_to_galaxy/admin/invocation.py +154 -0
  9. django_to_galaxy/admin/tag.py +17 -0
  10. django_to_galaxy/admin/utils.py +116 -0
  11. django_to_galaxy/admin/workflow.py +131 -0
  12. django_to_galaxy/api/__init__.py +0 -0
  13. django_to_galaxy/api/serializers/asymetricslugrelatedfield.py +31 -0
  14. django_to_galaxy/api/serializers/create_dataset_collection.py +118 -0
  15. django_to_galaxy/api/serializers/create_history.py +6 -0
  16. django_to_galaxy/api/serializers/galaxy_instance.py +10 -0
  17. django_to_galaxy/api/serializers/galaxy_output_file.py +17 -0
  18. django_to_galaxy/api/serializers/galaxy_user.py +20 -0
  19. django_to_galaxy/api/serializers/history.py +17 -0
  20. django_to_galaxy/api/serializers/invocation.py +22 -0
  21. django_to_galaxy/api/serializers/invoke_workflow.py +24 -0
  22. django_to_galaxy/api/serializers/upload_to_history.py +25 -0
  23. django_to_galaxy/api/serializers/workflow.py +41 -0
  24. django_to_galaxy/api/urls.py +53 -0
  25. django_to_galaxy/api/views/create_dataset_collection.py +461 -0
  26. django_to_galaxy/api/views/create_history.py +23 -0
  27. django_to_galaxy/api/views/galaxy_instance.py +13 -0
  28. django_to_galaxy/api/views/galaxy_output_file.py +15 -0
  29. django_to_galaxy/api/views/galaxy_user.py +13 -0
  30. django_to_galaxy/api/views/history.py +14 -0
  31. django_to_galaxy/api/views/invocation.py +45 -0
  32. django_to_galaxy/api/views/invoke_workflow.py +181 -0
  33. django_to_galaxy/api/views/upload_to_history.py +78 -0
  34. django_to_galaxy/api/views/workflow.py +14 -0
  35. django_to_galaxy/apps.py +6 -0
  36. django_to_galaxy/migrations/0001_new_initial.py +171 -0
  37. django_to_galaxy/migrations/0002_rename_state_history_galaxy_state_and_more.py +37 -0
  38. django_to_galaxy/migrations/0003_invocation_create_time.py +20 -0
  39. django_to_galaxy/migrations/0004_alter_galaxyuser_email_galaxyoutputfile.py +46 -0
  40. django_to_galaxy/migrations/0005_alter_galaxyoutputfile_invocation_and_more.py +37 -0
  41. django_to_galaxy/migrations/0006_tag_history_tags_workflow_tags.py +42 -0
  42. django_to_galaxy/migrations/0007_format_alter_history_tags_alter_workflow_tags_and_more.py +63 -0
  43. django_to_galaxy/migrations/0008_workflowinput_label.py +21 -0
  44. django_to_galaxy/migrations/0009_galaxyoutputfile_unique_galaxy_id_per_invocation.py +20 -0
  45. django_to_galaxy/migrations/0010_workflow__is_meta_workflow__step_jobs_count.py +23 -0
  46. django_to_galaxy/migrations/0011_rename__step_jobs_count_workflow__step_count_and_more.py +23 -0
  47. django_to_galaxy/migrations/0012_workflowinput_collection_type_and_more.py +136 -0
  48. django_to_galaxy/migrations/__init__.py +0 -0
  49. django_to_galaxy/models/__init__.py +8 -0
  50. django_to_galaxy/models/accepted_input.py +139 -0
  51. django_to_galaxy/models/galaxy_element.py +52 -0
  52. django_to_galaxy/models/galaxy_instance.py +29 -0
  53. django_to_galaxy/models/galaxy_output_file.py +53 -0
  54. django_to_galaxy/models/galaxy_user.py +94 -0
  55. django_to_galaxy/models/history.py +73 -0
  56. django_to_galaxy/models/invocation.py +251 -0
  57. django_to_galaxy/models/workflow.py +440 -0
  58. django_to_galaxy/schemas/__init__.py +0 -0
  59. django_to_galaxy/schemas/dataset.py +16 -0
  60. django_to_galaxy/settings.py +8 -0
  61. django_to_galaxy/templates/admin/import_workflows.html +89 -0
  62. django_to_galaxy/urls.py +3 -0
  63. django_to_galaxy/utils.py +61 -0
  64. django_to_galaxy/version.py +3 -0
  65. django_to_galaxy-0.7.0.0.dist-info/METADATA +17 -0
  66. django_to_galaxy-0.7.0.0.dist-info/RECORD +68 -0
  67. django_to_galaxy-0.7.0.0.dist-info/WHEEL +4 -0
  68. django_to_galaxy-0.7.0.0.dist-info/licenses/LICENSE +661 -0
@@ -0,0 +1,131 @@
1
+ from django.contrib import admin, messages
2
+ from django_to_galaxy.admin.utils import update_workflowinputs
3
+
4
+ from django_to_galaxy.models.workflow import Workflow
5
+ from django_to_galaxy.models.accepted_input import (
6
+ Format,
7
+ WorkflowInput,
8
+ WorkflowInputTextOption,
9
+ )
10
+
11
+ from .galaxy_element import GalaxyElementAdmin
12
+
13
+
14
+ @admin.register(Workflow)
15
+ class WorkflowAdmin(GalaxyElementAdmin):
16
+ list_display = (
17
+ "id",
18
+ "name",
19
+ "annotation",
20
+ "galaxy_id",
21
+ "get_is_meta",
22
+ "get_step_count",
23
+ "published",
24
+ "galaxy_owner",
25
+ "get_tags",
26
+ )
27
+ readonly_fields = (
28
+ "id",
29
+ "name",
30
+ "annotation",
31
+ "galaxy_id",
32
+ "get_is_meta",
33
+ "get_step_count",
34
+ "published",
35
+ "galaxy_owner",
36
+ "get_tags",
37
+ )
38
+ actions = ["update_workflow_inputs"]
39
+
40
+ def get_is_meta(self, obj):
41
+ return obj.get_is_meta()
42
+
43
+ def get_step_count(self, obj):
44
+ return obj.get_step_count()
45
+
46
+ def get_tags(self, obj):
47
+ return ", ".join([p.label for p in obj.tags.all()])
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
+
75
+
76
+ @admin.register(Format)
77
+ class FormatAdmin(GalaxyElementAdmin):
78
+ list_display = (
79
+ "id",
80
+ "format",
81
+ )
82
+ readonly_fields = (
83
+ "id",
84
+ "format",
85
+ )
86
+
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
+
98
+ @admin.register(WorkflowInput)
99
+ class WorkflowInputAdmin(GalaxyElementAdmin):
100
+ # Limit 20 items per page
101
+ list_per_page = 20
102
+ list_max_show_all = 50
103
+
104
+ list_display = (
105
+ "id",
106
+ "galaxy_step_id",
107
+ "label",
108
+ "workflow",
109
+ "input_type",
110
+ "get_formats",
111
+ "parameter_type",
112
+ "collection_type",
113
+ "optional",
114
+ "default_value",
115
+ "multiple",
116
+ )
117
+ readonly_fields = (
118
+ "id",
119
+ "galaxy_step_id",
120
+ "label",
121
+ "workflow",
122
+ "get_formats",
123
+ "parameter_type",
124
+ "collection_type",
125
+ "optional",
126
+ "default_value",
127
+ "multiple",
128
+ )
129
+
130
+ def get_formats(self, obj):
131
+ return ", ".join([p.format for p in obj.formats.all()])
File without changes
@@ -0,0 +1,31 @@
1
+ from collections import OrderedDict
2
+
3
+ from rest_framework.relations import SlugRelatedField
4
+
5
+
6
+ class AsymetricSlugRelatedField(SlugRelatedField):
7
+ def to_representation(self, value):
8
+ return self.serializer_class(value).data
9
+
10
+ # Get choices used by DRF autodoc and expect to_representation() to return an ID
11
+ # We overload to use item.pk instead of to_representation()
12
+ def get_choices(self, cutoff=None):
13
+ queryset = self.get_queryset()
14
+ if queryset is None:
15
+ return {}
16
+
17
+ if cutoff is not None:
18
+ queryset = queryset[:cutoff]
19
+
20
+ return OrderedDict([(item.pk, self.display_value(item)) for item in queryset])
21
+
22
+ # DRF skip validations when it only has id, we deactivate that
23
+ def use_pk_only_optimization(self):
24
+ return False
25
+
26
+ @classmethod
27
+ def from_serializer(cls, serializer, name=None, *args, **kwargs):
28
+ if name is None:
29
+ name = f"{serializer.__class__.__name__}AsymetricSlugAutoField"
30
+
31
+ return type(name, (cls,), {"serializer_class": serializer})(*args, **kwargs)
@@ -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()
@@ -0,0 +1,10 @@
1
+ from rest_framework import serializers
2
+
3
+
4
+ from django_to_galaxy.models.galaxy_instance import GalaxyInstance
5
+
6
+
7
+ class GalaxyInstanceSerializer(serializers.ModelSerializer):
8
+ class Meta:
9
+ model = GalaxyInstance
10
+ fields = ["id", "url", "name"]
@@ -0,0 +1,17 @@
1
+ from rest_framework import serializers
2
+
3
+ from django_to_galaxy.models.galaxy_output_file import GalaxyOutputFile
4
+
5
+
6
+ class GalaxyOutputFileSerializer(serializers.ModelSerializer):
7
+ class Meta:
8
+ model = GalaxyOutputFile
9
+ fields = [
10
+ "id",
11
+ "galaxy_id",
12
+ "workflow_name",
13
+ "galaxy_state",
14
+ "history_name",
15
+ "src",
16
+ "invocation",
17
+ ]
@@ -0,0 +1,20 @@
1
+ from rest_framework import serializers
2
+
3
+ from django_to_galaxy.api.serializers.galaxy_instance import GalaxyInstanceSerializer
4
+ from django_to_galaxy.models.galaxy_user import GalaxyUser
5
+ from django_to_galaxy.models.galaxy_instance import GalaxyInstance
6
+
7
+ from .asymetricslugrelatedfield import AsymetricSlugRelatedField
8
+
9
+
10
+ class GalaxyUserSerializer(serializers.ModelSerializer):
11
+ galaxy_instance = AsymetricSlugRelatedField.from_serializer(
12
+ GalaxyInstanceSerializer,
13
+ queryset=GalaxyInstance.objects.all(),
14
+ slug_field="id",
15
+ required=False,
16
+ )
17
+
18
+ class Meta:
19
+ model = GalaxyUser
20
+ fields = ["id", "email", "galaxy_instance"]
@@ -0,0 +1,17 @@
1
+ from rest_framework import serializers
2
+
3
+ from django_to_galaxy.models.history import History
4
+
5
+
6
+ class HistorySerializer(serializers.ModelSerializer):
7
+ class Meta:
8
+ model = History
9
+ fields = [
10
+ "id",
11
+ "galaxy_id",
12
+ "name",
13
+ "annotation",
14
+ "published",
15
+ "galaxy_owner",
16
+ "galaxy_state",
17
+ ]
@@ -0,0 +1,22 @@
1
+ from rest_framework import serializers
2
+
3
+ from django_to_galaxy.models.invocation import Invocation
4
+
5
+
6
+ class InvocationSerializer(serializers.ModelSerializer):
7
+ class Meta:
8
+ model = Invocation
9
+ fields = [
10
+ "id",
11
+ "galaxy_id",
12
+ "galaxy_state",
13
+ "status",
14
+ "workflow",
15
+ "history",
16
+ "create_time",
17
+ ]
18
+
19
+
20
+ class UpdateOutputFilesResponseSerializer(serializers.Serializer):
21
+ message = serializers.CharField()
22
+ galaxy_output_file_ids = serializers.ListField(child=serializers.IntegerField())
@@ -0,0 +1,24 @@
1
+ from rest_framework import serializers
2
+
3
+ from .upload_to_history import FileSerializer
4
+
5
+
6
+ class DatamapSerializer(serializers.Serializer):
7
+ id = serializers.CharField(required=False, default="")
8
+ src = serializers.CharField()
9
+
10
+
11
+ class InvokeWorkflowSerializer(serializers.Serializer):
12
+ workflow_id = serializers.IntegerField()
13
+ history_id = serializers.IntegerField()
14
+ datamap = serializers.DictField(child=DatamapSerializer())
15
+
16
+
17
+ class ExecuteWorkflowSerializer(serializers.Serializer):
18
+ workflow_id = serializers.IntegerField()
19
+ galaxy_user_id = serializers.IntegerField()
20
+ fake_datamap = serializers.DictField(child=FileSerializer())
21
+
22
+
23
+ class GenericDictSerializer(serializers.Serializer):
24
+ data = serializers.DictField()
@@ -0,0 +1,25 @@
1
+ import django.apps
2
+ from django.core.exceptions import ValidationError
3
+ from rest_framework import serializers
4
+
5
+
6
+ class FileSerializer(serializers.Serializer):
7
+ model = serializers.CharField()
8
+ path_field = serializers.CharField()
9
+ file_type = serializers.CharField()
10
+ id = serializers.IntegerField()
11
+
12
+ def validate(self, attrs):
13
+ old_attrs = attrs.copy()
14
+ for key, value in old_attrs.items():
15
+ if key == "model":
16
+ all_models = django.apps.apps.get_models()
17
+ all_models_dict = {m.__name__.lower(): m for m in all_models}
18
+ if value not in all_models_dict.keys():
19
+ raise ValidationError(f"model <{value}> does not exist on the app.")
20
+ return attrs
21
+
22
+
23
+ class UploadHistorySerializer(serializers.Serializer):
24
+ history_id = serializers.IntegerField()
25
+ file = FileSerializer()
@@ -0,0 +1,41 @@
1
+ from rest_framework import serializers
2
+
3
+ from django_to_galaxy.models.workflow import Workflow
4
+
5
+
6
+ class WorkflowSerializer(serializers.ModelSerializer):
7
+ tags = serializers.SerializerMethodField()
8
+ workflowinputs = serializers.SerializerMethodField()
9
+
10
+ class Meta:
11
+ model = Workflow
12
+ fields = [
13
+ "id",
14
+ "galaxy_id",
15
+ "name",
16
+ "annotation",
17
+ "tags",
18
+ "published",
19
+ "galaxy_owner",
20
+ "workflowinputs",
21
+ ]
22
+ read_only_fields = ["tags", "workflowinputs"]
23
+
24
+ def get_tags(self, obj):
25
+ return [tag.label for tag in obj.tags.all()]
26
+
27
+ def get_workflowinputs(self, obj):
28
+ return [
29
+ {
30
+ "galaxy_step_id": input.galaxy_step_id,
31
+ "label": input.label,
32
+ "input_type": input.input_type,
33
+ "formats": [format.format for format in input.formats.all()],
34
+ "parameter_type": input.parameter_type,
35
+ "collection_type": input.collection_type,
36
+ "optional": input.optional,
37
+ "default_value": input.default_value,
38
+ "multiple": input.multiple,
39
+ }
40
+ for input in obj.workflowinput_set.all()
41
+ ]
@@ -0,0 +1,53 @@
1
+ from django.urls import path
2
+ from rest_framework import routers
3
+
4
+ from django_to_galaxy.api.views.create_history import CreateHistoryView
5
+ from django_to_galaxy.api.views.galaxy_instance import GalaxyInstanceViewSet
6
+ from django_to_galaxy.api.views.galaxy_output_file import GalaxyOutputFileViewSet
7
+ from django_to_galaxy.api.views.galaxy_user import GalaxyUserViewSet
8
+ from django_to_galaxy.api.views.history import HistoryViewSet
9
+ from django_to_galaxy.api.views.invocation import (
10
+ InvocationViewSet,
11
+ UpdateOutputFilesView,
12
+ )
13
+ from django_to_galaxy.api.views.workflow import WorkflowViewSet
14
+ from django_to_galaxy.api.views.upload_to_history import UploadToHistoryView
15
+ from django_to_galaxy.api.views.invoke_workflow import (
16
+ InvokeWorkflowView,
17
+ GetWorkflowDatamapTemplateView,
18
+ # GetWorkflowInputsView,
19
+ ExecuteWorkflowView,
20
+ )
21
+ from django_to_galaxy.api.views.create_dataset_collection import (
22
+ CreateDatasetListCollectionView,
23
+ CreateDatasetListPairedCollectionView,
24
+ CreateDatasetPairedCollectionView,
25
+ )
26
+
27
+ api_router = routers.DefaultRouter()
28
+ api_router.register(r"instances", GalaxyInstanceViewSet)
29
+ api_router.register(r"galaxy_output_files", GalaxyOutputFileViewSet)
30
+ api_router.register(r"galaxy_users", GalaxyUserViewSet)
31
+ api_router.register(r"histories", HistoryViewSet)
32
+ api_router.register(r"invocations", InvocationViewSet)
33
+ api_router.register(r"workflows", WorkflowViewSet)
34
+
35
+ urlpatterns = [
36
+ path("create_history/<int:pk>", CreateHistoryView.as_view()),
37
+ path("upload_to_history/", UploadToHistoryView.as_view()),
38
+ path("invoke_workflow/", InvokeWorkflowView.as_view()),
39
+ path("execute_workflow/", ExecuteWorkflowView.as_view()),
40
+ path("update_galaxy_output_files/<int:pk>", UpdateOutputFilesView.as_view()),
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()),
51
+ ]
52
+
53
+ urlpatterns += api_router.urls