-
-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathrelation_serializers.py
More file actions
282 lines (236 loc) · 6.64 KB
/
Copy pathrelation_serializers.py
File metadata and controls
282 lines (236 loc) · 6.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
##
# Contains helper serializers needed by other serializers
# * These are the same as the old serializers from serializers.py used
# by other serializers except with "Relation" added in the name
# * Some of these relation serializers are dependent on each other
##
from rest_framework import serializers
from data_refinery_common.models import (
ComputationalResult,
ComputationalResultAnnotation,
ComputedFile,
DownloaderJob,
Organism,
OrganismIndex,
Processor,
ProcessorJob,
Sample,
)
##
# Organisms
##
class OrganismRelationSerializer(serializers.ModelSerializer):
class Meta:
model = Organism
fields = (
"name",
"taxonomy_id",
)
read_only_fields = fields
##
# Computed Files
##
class ComputedFileRelationSerializer(serializers.ModelSerializer):
class Meta:
model = ComputedFile
fields = (
"id",
"filename",
"size_in_bytes",
"is_smashable",
"is_qc",
"sha1",
"s3_bucket",
"s3_key",
"created_at",
"last_modified_at",
)
read_only_fields = fields
class ComputedFileWithUrlRelationSerializer(serializers.ModelSerializer):
class Meta:
model = ComputedFile
fields = (
"id",
"filename",
"size_in_bytes",
"is_smashable",
"is_qc",
"sha1",
"s3_bucket",
"s3_key",
"download_url",
"created_at",
"last_modified_at",
)
read_only_fields = fields
##
# Samples
##
class DetailedExperimentSampleSerializer(serializers.ModelSerializer):
class Meta:
model = Sample
fields = (
"accession_code",
"platform_name",
"pretty_platform",
"technology",
"is_processed",
"is_unable_to_be_processed",
)
read_only_fields = fields
class SampleRelationSerializer(serializers.ModelSerializer):
organism = OrganismRelationSerializer(many=False)
class Meta:
model = Sample
fields = (
"id",
"title",
"accession_code",
"source_database",
"organism",
"platform_accession_code",
"platform_name",
"pretty_platform",
"technology",
"manufacturer",
"protocol_info",
"is_processed",
"is_unable_to_be_processed",
"created_at",
"last_modified_at",
)
read_only_fields = fields
##
# Jobs
##
class DownloaderJobRelationSerializer(serializers.ModelSerializer):
class Meta:
model = DownloaderJob
fields = (
"id",
"downloader_task",
"num_retries",
"retried",
"was_recreated",
"worker_id",
"worker_version",
"batch_job_id",
"failure_reason",
"success",
"original_files",
"start_time",
"end_time",
"created_at",
"last_modified_at",
)
read_only_fields = fields
class ProcessorJobRelationSerializer(serializers.ModelSerializer):
class Meta:
model = ProcessorJob
fields = (
"id",
"pipeline_applied",
"num_retries",
"retried",
"worker_id",
"ram_amount",
"volume_index",
"batch_job_queue",
"worker_version",
"failure_reason",
"batch_job_id",
"success",
"original_files",
"datasets",
"start_time",
"end_time",
"created_at",
"last_modified_at",
)
read_only_fields = fields
##
# Transcriptome Index
##
class OrganismIndexRelationSerializer(serializers.ModelSerializer):
organism_name = serializers.StringRelatedField(source="organism", read_only=True)
download_url = serializers.SerializerMethodField()
class Meta:
model = OrganismIndex
fields = (
"id",
"assembly_name",
"organism_name",
"database_name",
"release_version",
"index_type",
"salmon_version",
"download_url",
"result_id",
"last_modified_at",
)
read_only_fields = fields
def get_download_url(self, obj):
computed_file = obj.get_computed_file()
if computed_file is not None:
return computed_file.s3_url
return None
##
# Processors
##
class ProcessorRelationSerializer(serializers.ModelSerializer):
class Meta:
model = Processor
fields = ("id", "name", "version", "docker_image", "environment")
read_only_fields = fields
##
# Results
##
class ComputationalResultAnnotationRelationSerializer(serializers.ModelSerializer):
class Meta:
model = ComputationalResultAnnotation
fields = ("id", "data", "is_ccdl", "created_at", "last_modified_at")
read_only_fields = fields
class ComputationalResultRelationSerializer(serializers.ModelSerializer):
annotations = ComputationalResultAnnotationRelationSerializer(
many=True, source="computationalresultannotation_set"
)
processor = ProcessorRelationSerializer(many=False)
organism_index = OrganismIndexRelationSerializer(many=False)
files = ComputedFileRelationSerializer(many=True, source="computedfile_set")
class Meta:
model = ComputationalResult
fields = (
"id",
"commands",
"processor",
"is_ccdl",
"annotations",
"files",
"organism_index",
"time_start",
"time_end",
"created_at",
"last_modified_at",
)
read_only_fields = fields
class ComputationalResultNoFilesRelationSerializer(serializers.ModelSerializer):
annotations = ComputationalResultAnnotationRelationSerializer(
many=True, source="computationalresultannotation_set"
)
processor = ProcessorRelationSerializer(many=False)
organism_index = OrganismIndexRelationSerializer(many=False)
class Meta:
model = ComputationalResult
fields = (
"id",
"commands",
"processor",
"is_ccdl",
"annotations",
"organism_index",
"time_start",
"time_end",
"created_at",
"last_modified_at",
)
read_only_fields = fields