Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
holtgrewe committed Sep 26, 2023
1 parent 62416c5 commit 5a009e1
Show file tree
Hide file tree
Showing 11 changed files with 341 additions and 94 deletions.
83 changes: 83 additions & 0 deletions cases_files/migrations/0003_auto_20230926_1324.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Generated by Django 3.2.21 on 2023-09-26 13:24

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("cases", "0001_initial"),
("cases_files", "0002_auto_20230919_1422"),
]

operations = [
migrations.AddField(
model_name="individualinternalfile",
name="file_attributes",
field=models.JSONField(default={}),
preserve_default=False,
),
migrations.AddField(
model_name="individualinternalfile",
name="identifier_map",
field=models.JSONField(default={}),
preserve_default=False,
),
migrations.AddField(
model_name="pedigreeinternalfile",
name="file_attributes",
field=models.JSONField(default={}),
preserve_default=False,
),
migrations.AddField(
model_name="pedigreeinternalfile",
name="identifier_map",
field=models.JSONField(default={}),
preserve_default=False,
),
migrations.AlterField(
model_name="individualexternalfile",
name="path",
field=models.CharField(max_length=1024),
),
migrations.AlterField(
model_name="individualinternalfile",
name="designation",
field=models.CharField(max_length=128),
),
migrations.AlterField(
model_name="individualinternalfile",
name="path",
field=models.CharField(max_length=1024),
),
migrations.AlterField(
model_name="pedigreeexternalfile",
name="path",
field=models.CharField(max_length=1024),
),
migrations.AlterField(
model_name="pedigreeinternalfile",
name="designation",
field=models.CharField(max_length=128),
),
migrations.AlterField(
model_name="pedigreeinternalfile",
name="path",
field=models.CharField(max_length=1024),
),
migrations.AlterUniqueTogether(
name="individualexternalfile",
unique_together={("individual", "path")},
),
migrations.AlterUniqueTogether(
name="individualinternalfile",
unique_together={("individual", "path")},
),
migrations.AlterUniqueTogether(
name="pedigreeexternalfile",
unique_together={("pedigree", "path")},
),
migrations.AlterUniqueTogether(
name="pedigreeinternalfile",
unique_together={("pedigree", "path")},
),
]
32 changes: 26 additions & 6 deletions cases_files/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from django.db import models

from cases.models import Individual, Pedigree
from cases_import.proto import FileDesignation
from cases_import.proto import ExternalFileDesignation
from variants.models import Case


Expand All @@ -26,8 +26,6 @@ class AbstractFile(models.Model):
(GENOMEBUILD_GRCH38, GENOMEBUILD_GRCH38),
)

FILE_DESIGNATION_CHOICES = tuple(((val, val) for val in FileDesignation.all_values()))

#: Record UUID.
sodar_uuid = models.UUIDField(default=uuid_object.uuid4, unique=True)
#: DateTime of creation.
Expand All @@ -44,10 +42,8 @@ class AbstractFile(models.Model):

#: The file's path relative to the internal or project's external storage base URI. That is,
#: the path will not start with a slash.
path = models.CharField(max_length=1024, null=False, blank=False, unique=True)
path = models.CharField(max_length=1024, null=False, blank=False)

#: The designation of the file.
designation = models.CharField(max_length=128, null=False, choices=FILE_DESIGNATION_CHOICES)
#: The genome assembly, if any.
genomebuild = models.CharField(max_length=128, null=True, choices=GENOMEBUILD_CHOICES)
#: The file format as MIME type.
Expand All @@ -64,6 +60,11 @@ class ExternalFile(AbstractFile):
before being used in queries etc., or they are used for redisplay only.
"""

FILE_DESIGNATION_CHOICES = tuple(((val, val) for val in ExternalFileDesignation.all_values()))

#: The designation of the external file.
designation = models.CharField(max_length=128, null=False, choices=FILE_DESIGNATION_CHOICES)

#: Whether or not the file was available on the last check.
available = models.BooleanField(null=True, default=None)
#: Date of the last check.
Expand All @@ -83,6 +84,13 @@ class InternalFile(AbstractFile):
Such files are used for queries etc.
"""

#: All file attributes from phenopackets and possibly more.
file_attributes = models.JSONField(null=False)
#: The mapping from individual to file identifiers.
identifier_map = models.JSONField(null=False)
#: The designation of the internal file, more fine-grained as for the exernal ones, but
#: not limited to options as this is not user-facing.
designation = models.CharField(max_length=128, null=False)
#: The checksum of the file.
checksum = models.CharField(max_length=128, null=True)

Expand All @@ -100,6 +108,9 @@ class IndividualExternalFile(ExternalFile):
on_delete=models.CASCADE,
)

class Meta:
unique_together = (("individual", "path"),)


class IndividualInternalFile(InternalFile):
"""Reference to a file on internal storage for an individual."""
Expand All @@ -111,6 +122,9 @@ class IndividualInternalFile(InternalFile):
on_delete=models.CASCADE,
)

class Meta:
unique_together = (("individual", "path"),)


class PedigreeExternalFile(ExternalFile):
"""Reference to a file on external storage for a pedigree."""
Expand All @@ -122,6 +136,9 @@ class PedigreeExternalFile(ExternalFile):
on_delete=models.CASCADE,
)

class Meta:
unique_together = (("pedigree", "path"),)


class PedigreeInternalFile(InternalFile):
"""Reference to a file on internal storage for a pedigree."""
Expand All @@ -132,3 +149,6 @@ class PedigreeInternalFile(InternalFile):
null=False,
on_delete=models.CASCADE,
)

class Meta:
unique_together = (("pedigree", "path"),)
4 changes: 2 additions & 2 deletions cases_files/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
PedigreeExternalFile,
PedigreeInternalFile,
)
from cases_import.proto import FileDesignation
from cases_import.proto import ExternalFileDesignation
from variants.tests.factories import CaseFactory


Expand All @@ -25,7 +25,7 @@ class Meta:
case = factory.SubFactory(CaseFactory)
path = factory.Sequence(lambda n: f"file-{n}.bam")

designation = FileDesignation.READ_ALIGNMENTS.value
designation = ExternalFileDesignation.READ_ALIGNMENTS.value
genomebuild = AbstractFile.GENOMEBUILD_GRCH38
mimetype = MimeTypes.BAM.value

Expand Down
Loading

0 comments on commit 5a009e1

Please sign in to comment.