targetcentric.py 17.5 KB
Newer Older
Fabien  MAREUIL's avatar
Fabien MAREUIL committed
1
2
from django.db import models
from django.forms import ValidationError
Fabien  MAREUIL's avatar
Fabien MAREUIL committed
3
from django.db.models import Q
Fabien  MAREUIL's avatar
Fabien MAREUIL committed
4
from django.dispatch import receiver
Fabien  MAREUIL's avatar
Fabien MAREUIL committed
5
from django.db.models.signals import pre_delete, post_save
Fabien  MAREUIL's avatar
Fabien MAREUIL committed
6
from .ippidb import Protein
Fabien  MAREUIL's avatar
Fabien MAREUIL committed
7
import json
Fabien  MAREUIL's avatar
Fabien MAREUIL committed
8
9


Fabien  MAREUIL's avatar
Fabien MAREUIL committed
10
11
12
def content(instance, filename):
    return "content/mrc_files/{}".format(filename)

Fabien  MAREUIL's avatar
Fabien MAREUIL committed
13

14
15
def contentinteract(instance, filename):
    return "content/interact_files/{}".format(filename)
Fabien  MAREUIL's avatar
Fabien MAREUIL committed
16

Fabien  MAREUIL's avatar
Fabien MAREUIL committed
17

Fabien  MAREUIL's avatar
Fabien MAREUIL committed
18
19
20
21
22
23
def contentnetwork(instance, filename):
    return "content/networks_files/{}".format(filename)


class Network(models.Model):
    """
Fabien  MAREUIL's avatar
Fabien MAREUIL committed
24
    Network class with json file for networkx
Fabien  MAREUIL's avatar
Fabien MAREUIL committed
25
26
27
28
29
30
31
32
    """

    jsonfile = models.FileField(upload_to=contentnetwork, blank=False)
    default = models.BooleanField(default=False)
    label = models.CharField(max_length=250, blank=False, null=False, unique=True)
    number = models.PositiveIntegerField(
        "Number of the network", unique=True, default=1
    )
Fabien  MAREUIL's avatar
Fabien MAREUIL committed
33
    json = models.TextField(default="{}", blank=True)
Fabien  MAREUIL's avatar
Fabien MAREUIL committed
34
35
36
37
38
39
40

    def save(self, *args, **kwargs):
        if self.default is True:
            Network.objects.all().update(default=False)
        super(Network, self).save(*args, **kwargs)


Fabien  MAREUIL's avatar
Fabien MAREUIL committed
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
@receiver(post_save, sender=Network)
def networkjson_save(sender, instance, **kwargs):
    ippidb_connect_data = []
    edges_connect_data = []
    connect_matrix = []
    if instance.jsonfile:
        with open(instance.jsonfile.path) as json_file:
            for line in json_file:
                splitted = line.split(" = ")
                cleaned_data = splitted[1].strip().rstrip(";").strip("'")
                if splitted[0] == "ippidb_connect_data":
                    ippidb_connect_data = json.loads(cleaned_data)
                elif splitted[0] == "edges_connect_data":
                    edges_connect_data = json.loads(cleaned_data)
                elif splitted[0] == "connect_matrix":
                    connect_matrix = json.loads(cleaned_data)
        jsonnetwork = {
            "ippidb_connect_data": ippidb_connect_data,
            "edges_connect_data": edges_connect_data,
            "connect_matrix": connect_matrix,
        }
Fabien  MAREUIL's avatar
Fabien MAREUIL committed
62
        jsonnetwork = str(jsonnetwork).replace("'", '"').replace("None", "null")
Fabien  MAREUIL's avatar
Fabien MAREUIL committed
63
64
65
66
67
        if not instance.json == jsonnetwork:
            instance.json = jsonnetwork
            instance.save()


Fabien  MAREUIL's avatar
Fabien MAREUIL committed
68
69
70
71
72
@receiver(pre_delete, sender=Network)
def networkdelete(sender, instance, **kwargs):
    instance.jsonfile.delete()


Fabien  MAREUIL's avatar
Fabien MAREUIL committed
73
74
class PDB(models.Model):
    """
75
    PDB class, describe a pdb with file content and the code access
Fabien  MAREUIL's avatar
Fabien MAREUIL committed
76
77
78
79
80
81
82
83
84
85
86
87
    """

    code = models.CharField(max_length=4, unique=True)
    file_content = models.TextField(
        verbose_name="pdb file content", default="no pdb file"
    )

    def is_heterodimer(self):
        """
        return True if pdb is a heterodimer else return False
        """
        chains = self.chain_set.all()
88
        if chains.count() > 1:
Fabien  MAREUIL's avatar
Fabien MAREUIL committed
89
90
91
            return True
        else:
            return False
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

    def __unicode__(self):
        partners = ""
        onprot = ""
        for chain in self.chain_set.all():
            if chain.is_partner():
                partners += " {}".format(chain)
            else:
                onprot += "{}".format(chain)
        for ligand in self.ligand_set.all():
            partners += " {}".format(ligand)
        return "{}{}".format(onprot, partners)

    def __str__(self):
        partners = ""
        onprot = ""
        for chain in self.chain_set.all():
            if chain.is_partner():
                partners += " {}".format(chain)
            else:
                onprot += "{}".format(chain)
        for ligand in self.ligand_set.all():
            partners += " {}".format(ligand)
        return "{}{}".format(onprot, partners)

117
    class Meta:
Fabien  MAREUIL's avatar
Fabien MAREUIL committed
118
119
        indexes = [models.Index(fields=["code"])]

Fabien  MAREUIL's avatar
Fabien MAREUIL committed
120

Fabien  MAREUIL's avatar
Fabien MAREUIL committed
121
122
123
124
125
126
127
class Chain(models.Model):
    """
    Chain class, a protein
    """

    pdb_chain_id = models.CharField(max_length=2, blank=False, null=False)
    protein = models.ForeignKey(
Fabien  MAREUIL's avatar
Fabien MAREUIL committed
128
        Protein, on_delete=models.CASCADE, blank=True, null=True
Fabien  MAREUIL's avatar
Fabien MAREUIL committed
129
130
131
132
133
    )
    pdb = models.ForeignKey(PDB, on_delete=models.CASCADE, blank=False, null=False)
    file_content = models.TextField(
        verbose_name="pdb file content with only one chain", default="no pdb file"
    )
Fabien  MAREUIL's avatar
Fabien MAREUIL committed
134
    mrc_file = models.FileField(upload_to=content, blank=True)
135
136
137
    default_isolevel = models.FloatField(
        default=0.7, verbose_name="Default isolevel value"
    )
Fabien  MAREUIL's avatar
Fabien MAREUIL committed
138
139
140
141

    class Meta:
        unique_together = ("pdb", "pdb_chain_id")

142
    def is_partner(self):
Fabien  MAREUIL's avatar
Fabien MAREUIL committed
143
144
        return self.partner_set.count()

145
146
147
    def __unicode__(self):
        partner_message = ""
        if self.is_partner():
148
            partner_message = "with partner "
149
150
151
152
153
        return "{}{}".format(partner_message, self.protein.recommended_name_long)

    def __str__(self):
        partner_message = ""
        if self.is_partner():
154
            partner_message = "with partner "
155
        return "{}{}".format(partner_message, self.protein.recommended_name_long)
Fabien  MAREUIL's avatar
Fabien MAREUIL committed
156

Fabien  MAREUIL's avatar
Fabien MAREUIL committed
157

158
159
160
class InteractFile(models.Model):
    chain = models.ForeignKey(Chain, on_delete=models.CASCADE)
    label = models.CharField(max_length=250, blank=False, null=False)
161
    interact_file = models.FileField(upload_to=contentinteract, blank=True)
162
163
164
    default_isolevel = models.FloatField(
        default=0.7, verbose_name="Default isolevel value"
    )
165
166
167
168
169
170
171
172

    def __unicode__(self):
        return "{}".format(self.interact_file)

    def __str__(self):
        return "{}".format(self.interact_file)


Fabien  MAREUIL's avatar
Fabien MAREUIL committed
173
174
class Ligand(models.Model):
    """
175
    Ligand, class describe a ligand with file content and the code access
Fabien  MAREUIL's avatar
Fabien MAREUIL committed
176
177
    """

Fabien  MAREUIL's avatar
Fabien MAREUIL committed
178
    supplementary_id = models.CharField(
Fabien  MAREUIL's avatar
Fabien MAREUIL committed
179
180
        "PDB supplementary Ligand ID", max_length=10, blank=False, null=False
    )
Fabien  MAREUIL's avatar
Fabien MAREUIL committed
181
182
183
    pdb_ligand_id = models.CharField(
        "PDB Ligand ID", max_length=3, blank=False, null=False
    )
Fabien  MAREUIL's avatar
Fabien MAREUIL committed
184
185
186
187
    file_content = models.TextField(
        verbose_name="ligand file content", default="no pdb file"
    )
    pdb = models.ForeignKey(PDB, on_delete=models.CASCADE, blank=False, null=False)
Fabien  MAREUIL's avatar
Fabien MAREUIL committed
188
189
190
    canonical_smile = models.TextField(
        verbose_name="Canonical Smiles", blank=True, null=True
    )
191
    iupac_name = models.TextField(verbose_name="IUPAC name", blank=True, null=True)
Fabien  MAREUIL's avatar
Fabien MAREUIL committed
192
193

    class Meta:
Fabien  MAREUIL's avatar
Fabien MAREUIL committed
194
195
196
197
198
199
200
201
202
203
204
205
        unique_together = (
            "pdb",
            "pdb_ligand_id",
            "supplementary_id",
            "canonical_smile",
            "iupac_name",
        )
        indexes = [
            models.Index(fields=["pdb_ligand_id"]),
            models.Index(fields=["iupac_name"]),
            models.Index(fields=["canonical_smile"]),
        ]
Fabien  MAREUIL's avatar
Fabien MAREUIL committed
206

207
    def __unicode__(self):
208
        partner_message = "with ligand "
209
        return "%s%s_%s" % (partner_message, self.pdb_ligand_id, self.supplementary_id)
Fabien  MAREUIL's avatar
Fabien MAREUIL committed
210

211
    def __str__(self):
212
        partner_message = "with ligand "
213
        return "%s%s_%s" % (partner_message, self.pdb_ligand_id, self.supplementary_id)
Fabien  MAREUIL's avatar
Fabien MAREUIL committed
214

Fabien  MAREUIL's avatar
Fabien MAREUIL committed
215

Fabien  MAREUIL's avatar
Fabien MAREUIL committed
216
217
218
219
220
class Partner(models.Model):
    """
    Partner class, a partner can be a ligand or a chain
    """

Fabien  MAREUIL's avatar
Fabien MAREUIL committed
221
    ligand = models.ForeignKey(Ligand, on_delete=models.CASCADE, blank=True, null=True)
Fabien  MAREUIL's avatar
Fabien MAREUIL committed
222
223
224
225
226
227
228
    chain = models.ForeignKey(Chain, on_delete=models.CASCADE, blank=True, null=True)

    def save(self, *args, **kwargs):
        if self.ligand and self.chain:
            raise ValidationError("A partner is only a ligand or a chain not the both")
        super(Partner, self).save(*args, **kwargs)

Fabien  MAREUIL's avatar
Fabien MAREUIL committed
229
230
231
232
233
234
235
236
237
238
239
240
    @property
    def is_ligand(self):
        if self.ligand:
            return True
        return False

    @property
    def is_chain(self):
        if self.chain:
            return True
        return False

Fabien  MAREUIL's avatar
Fabien MAREUIL committed
241
242
243
244
245
246

class Cavity(models.Model):
    """
    Cavity descriptor class
    """

Fabien  MAREUIL's avatar
Fabien MAREUIL committed
247
    full_name = models.CharField(max_length=100, blank=False, null=False, unique=True)
Fabien  MAREUIL's avatar
Fabien MAREUIL committed
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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
    mol2 = models.TextField(verbose_name="mol2 file content", default="no mol2 file")
    chain = models.ForeignKey(Chain, on_delete=models.CASCADE)
    cavity_number = models.PositiveIntegerField("Number of the cavity")
    partner = models.ForeignKey(Partner, on_delete=models.CASCADE)
    asphericity = models.FloatField(verbose_name="Asphericity")
    ca = models.FloatField(verbose_name="CA")
    ca100_110 = models.FloatField(verbose_name="CA100-110")
    ca110_120 = models.FloatField(verbose_name="CA100-120")
    ca120 = models.FloatField(verbose_name="CA120")
    ca40 = models.FloatField(verbose_name="CA40")
    ca40_50 = models.FloatField(verbose_name="CA40-50")
    ca50_60 = models.FloatField(verbose_name="CA50-60")
    ca60_70 = models.FloatField(verbose_name="CA60-70")
    ca70_80 = models.FloatField(verbose_name="CA70-80")
    ca80_90 = models.FloatField(verbose_name="CA80-90")
    ca90_100 = models.FloatField(verbose_name="CA90-100")
    cz = models.FloatField(verbose_name="CZ")
    cz100_110 = models.FloatField(verbose_name="CZ100-110")
    cz110_120 = models.FloatField(verbose_name="CZ110-120")
    cz120 = models.FloatField(verbose_name="CZ120")
    cz40 = models.FloatField(verbose_name="CZ40")
    cz40_50 = models.FloatField(verbose_name="CZ40-50")
    cz50_60 = models.FloatField(verbose_name="CZ50-60")
    cz60_70 = models.FloatField(verbose_name="CZ60-70")
    cz70_80 = models.FloatField(verbose_name="CZ70-80")
    cz80_90 = models.FloatField(verbose_name="CZ80-90")
    cz90_100 = models.FloatField(verbose_name="CZ90-100")
    du = models.FloatField(verbose_name="DU")
    du100_110 = models.FloatField(verbose_name="DU100-110")
    du110_120 = models.FloatField(verbose_name="DU110-120")
    du120 = models.FloatField(verbose_name="DU120")
    du40 = models.FloatField(verbose_name="DU40")
    du40_50 = models.FloatField(verbose_name="DU40-50")
    du50_60 = models.FloatField(verbose_name="DU50-60")
    du60_70 = models.FloatField(verbose_name="DU60-70")
    du70_80 = models.FloatField(verbose_name="DU70-80")
    du80_90 = models.FloatField(verbose_name="DU80-90")
    du90_100 = models.FloatField(verbose_name="DU90-100")
    eccentricity = models.FloatField(verbose_name="Eccentricity")
    inertialshapefactor = models.FloatField(verbose_name="InertialShapeFactor")
    n = models.FloatField(verbose_name="N")
    n100_110 = models.FloatField(verbose_name="N100-110")
    n110_120 = models.FloatField(verbose_name="N110-120")
    n120 = models.FloatField(verbose_name="N120")
    n40 = models.FloatField(verbose_name="N40")
    n40_50 = models.FloatField(verbose_name="N40-50")
    n50_60 = models.FloatField(verbose_name="N50-60")
    n60_70 = models.FloatField(verbose_name="N60-70")
    n70_80 = models.FloatField(verbose_name="N70-80")
    n80_90 = models.FloatField(verbose_name="N80-90")
    n90_100 = models.FloatField(verbose_name="N90-100")
    npr1 = models.FloatField(verbose_name="NPR1")
    npr2 = models.FloatField(verbose_name="NPR2")
    nz = models.FloatField(verbose_name="NZ")
    nz100_110 = models.FloatField(verbose_name="NZ100-110")
    nz110_120 = models.FloatField(verbose_name="NZ110-120")
    nz120 = models.FloatField(verbose_name="NZ120")
    nz40 = models.FloatField(verbose_name="NZ40")
    nz40_50 = models.FloatField(verbose_name="NZ40-50")
    nz50_60 = models.FloatField(verbose_name="NZ50-60")
    nz60_70 = models.FloatField(verbose_name="NZ60-70")
    nz70_80 = models.FloatField(verbose_name="NZ70-80")
    nz80_90 = models.FloatField(verbose_name="NZ80-90")
    nz90_100 = models.FloatField(verbose_name="NZ90-100")
    o = models.FloatField(verbose_name="O")
    o100_110 = models.FloatField(verbose_name="O100-110")
    o110_120 = models.FloatField(verbose_name="O110-120")
    o120 = models.FloatField(verbose_name="O120")
    o40 = models.FloatField(verbose_name="O40")
    o40_50 = models.FloatField(verbose_name="O40-50")
    o50_60 = models.FloatField(verbose_name="O50-60")
    o60_70 = models.FloatField(verbose_name="O60-70")
    o70_80 = models.FloatField(verbose_name="O70-80")
    o80_90 = models.FloatField(verbose_name="O80-90")
    o90_100 = models.FloatField(verbose_name="O90-100")
    od1 = models.FloatField(verbose_name="OD1")
    od1100_110 = models.FloatField(verbose_name="OD1100-110")
    od1110_120 = models.FloatField(verbose_name="OD1110-120")
    od1120 = models.FloatField(verbose_name="OD1120")
    od140 = models.FloatField(verbose_name="OD140")
    od140_50 = models.FloatField(verbose_name="OD140-50")
    od150_60 = models.FloatField(verbose_name="OD150-60")
    od160_70 = models.FloatField(verbose_name="OD160-70")
    od170_80 = models.FloatField(verbose_name="OD170-80")
    od180_90 = models.FloatField(verbose_name="OD180-90")
    od190_100 = models.FloatField(verbose_name="OD190-100")
    og = models.FloatField(verbose_name="OG")
    og100_110 = models.FloatField(verbose_name="OG100-110")
    og110_120 = models.FloatField(verbose_name="OG110-120")
    og120 = models.FloatField(verbose_name="OG120")
    og40 = models.FloatField(verbose_name="OG40")
    og40_50 = models.FloatField(verbose_name="OG40-50")
    og50_60 = models.FloatField(verbose_name="OG50-60")
    og60_70 = models.FloatField(verbose_name="OG60-70")
    og70_80 = models.FloatField(verbose_name="OG70-80")
    og80_90 = models.FloatField(verbose_name="OG80-90")
    og90_100 = models.FloatField(verbose_name="OG90-100")
    pmi1 = models.FloatField(verbose_name="PMI1")
    pmi2 = models.FloatField(verbose_name="PMI2")
    pmi3 = models.FloatField(verbose_name="PMI3")
    rgyr = models.FloatField(verbose_name="RGYR")
    spherocityindex = models.FloatField(verbose_name="SpherocityIndex")
    t100_110 = models.FloatField(verbose_name="T100-110")
    t110_120 = models.FloatField(verbose_name="T110-120")
Fabien  MAREUIL's avatar
Fabien MAREUIL committed
352
    t120 = models.FloatField(verbose_name="T120")
Fabien  MAREUIL's avatar
Fabien MAREUIL committed
353
354
355
356
357
358
359
360
361
362
363
    t40 = models.FloatField(verbose_name="T40")
    t40_50 = models.FloatField(verbose_name="T40-50")
    t50_60 = models.FloatField(verbose_name="T50-60")
    t60_70 = models.FloatField(verbose_name="T60-70")
    t70_80 = models.FloatField(verbose_name="T70-80")
    t80_90 = models.FloatField(verbose_name="T80-90")
    t90_100 = models.FloatField(verbose_name="T90-100")
    volume = models.FloatField(verbose_name="Volume")

    class Meta:
        unique_together = ("full_name", "chain", "cavity_number", "partner")
364
        verbose_name_plural = "Cavities"
Fabien  MAREUIL's avatar
Fabien MAREUIL committed
365

Fabien  MAREUIL's avatar
Fabien MAREUIL committed
366
367
    @property
    def near_cavities(self):
368
369
370
        """
        return a queryset of distance with the 5 more little distance
        """
Fabien  MAREUIL's avatar
Fabien MAREUIL committed
371

Fabien  MAREUIL's avatar
Fabien MAREUIL committed
372
373
374
375
376
377
378
379
        queryset_pl = Distance.objects.filter(
            (Q(cavity1=self) & Q(cavity2__partner__ligand__isnull=False))
            | (Q(cavity2=self) & Q(cavity1__partner__ligand__isnull=False))
        ).order_by("distance")[:5]
        queryset_hd = Distance.objects.filter(
            (Q(cavity1=self) & Q(cavity2__partner__chain__isnull=False))
            | (Q(cavity2=self) & Q(cavity1__partner__chain__isnull=False))
        ).order_by("distance")[:5]
Fabien  MAREUIL's avatar
Fabien MAREUIL committed
380
        queryset = queryset_pl | queryset_hd
Fabien  MAREUIL's avatar
Fabien MAREUIL committed
381
        return queryset.order_by("distance")
Fabien  MAREUIL's avatar
Fabien MAREUIL committed
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396

    def save(self, *args, **kwargs):
        if not self.t120:
            self.t120 = 100 - (
                self.t40
                + self.t40_50
                + self.t50_60
                + self.t60_70
                + self.t70_80
                + self.t80_90
                + self.t90_100
                + self.t100_110
                + self.t110_120
            )
        super(Cavity, self).save(*args, **kwargs)
Fabien  MAREUIL's avatar
Fabien MAREUIL committed
397

398

Fabien  MAREUIL's avatar
Fabien MAREUIL committed
399
class Distance(models.Model):
Fabien  MAREUIL's avatar
Fabien MAREUIL committed
400
401
402
403
404
405
406
407
408
409
    """
    Distance between two cavity
    """

    cavity1 = models.ForeignKey(
        Cavity, on_delete=models.CASCADE, related_name="first_cavity"
    )
    cavity2 = models.ForeignKey(
        Cavity, on_delete=models.CASCADE, related_name="second_cavity"
    )
Fabien  MAREUIL's avatar
Fabien MAREUIL committed
410
411
412
413
414
415
    distance = models.DecimalField(
        verbose_name="Distance", max_digits=11, decimal_places=8
    )

    class Meta:
        unique_together = ("cavity1", "cavity2")
Fabien  MAREUIL's avatar
Fabien MAREUIL committed
416
417
418
419
420
421


class MetaInformation(models.Model):
    """
    Average and Standard deviation from the Distances Matrix
    """
Fabien  MAREUIL's avatar
Fabien MAREUIL committed
422

Fabien  MAREUIL's avatar
Fabien MAREUIL committed
423
424
425
426
427
428
429
430
431
432
433
434
    average = models.DecimalField(
        verbose_name="Average", max_digits=11, decimal_places=8
    )
    std = models.DecimalField(
        verbose_name="Standard Deviation", max_digits=11, decimal_places=8
    )
    maximum = models.DecimalField(
        verbose_name="Maximum", max_digits=11, decimal_places=8
    )
    minimum = models.DecimalField(
        verbose_name="Minimum", max_digits=11, decimal_places=8
    )
Fabien  MAREUIL's avatar
Fabien MAREUIL committed
435
436
437
438
439
440
441
442
    normalize_factor = models.DecimalField(
        blank=True,
        null=True,
        default=4.58599730,
        verbose_name="Normalize Factor",
        max_digits=11,
        decimal_places=8,
    )
443
444
445
446
447
448
449
450
451
452
453
454
455
456

    class Meta:
        verbose_name_plural = "MetaInformation"


@receiver(pre_delete, sender=Partner)
@receiver(pre_delete, sender=Chain)
@receiver(pre_delete, sender=PDB)
def mrcdelete(sender, instance, **kwargs):
    if isinstance(instance, PDB):
        chains = instance.chain_set.all()
    elif isinstance(instance, Chain):
        chains = [instance]
    elif isinstance(instance, Partner):
Fabien  MAREUIL's avatar
Fabien MAREUIL committed
457
458
459
460
        if instance.chain:
            chains = [instance.chain]
        else:
            chains = []
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475

    for chain in chains:
        if chain.mrc_file.storage.exists(chain.mrc_file.name):
            chain.mrc_file.delete()


@receiver(pre_delete, sender=Partner)
@receiver(pre_delete, sender=Chain)
@receiver(pre_delete, sender=PDB)
def interactdelete(sender, instance, **kwargs):
    if isinstance(instance, PDB):
        chains = instance.chain_set.all()
    elif isinstance(instance, Chain):
        chains = [instance]
    elif isinstance(instance, Partner):
Fabien  MAREUIL's avatar
Fabien MAREUIL committed
476
477
478
479
        if instance.chain:
            chains = [instance.chain]
        else:
            chains = []
480
481
482
483
484
485
486

    for chain in chains:
        for interactfile in chain.interactfile_set.all():
            if interactfile.interact_file.storage.exists(
                interactfile.interact_file.name
            ):
                interactfile.interact_file.delete()