Skip to content

Commit

Permalink
SCKAN-275 feat: Update models
Browse files Browse the repository at this point in the history
  • Loading branch information
afonsobspinto committed Mar 20, 2024
1 parent 776237e commit 40f20b9
Show file tree
Hide file tree
Showing 9 changed files with 179 additions and 178 deletions.
12 changes: 6 additions & 6 deletions backend/composer/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
Tag,
Via,
FunctionalCircuitRole,
ProjectionPhenotype, Destination, Synonym, AnatomicalEntityMeta, Layer, Region, AnatomicalEntityIntersection
ProjectionPhenotype, Destination, Synonym, AnatomicalEntityMeta, Layer, Region, AnatomicalEntityIntersection,
AnatomicalEntity
)


Expand Down Expand Up @@ -117,10 +118,9 @@ class AnatomicalEntityIntersectionAdmin(admin.ModelAdmin):
raw_id_fields = ('layer', 'region',)


class AnatomicalEntityAdmin(admin.ModelAdmin):
list_display = ('name', 'ontology_uri', 'region_layer',)
search_fields = ('name',)
raw_id_fields = ('region_layer',)
class AnatomicalEntityNewAdmin(admin.ModelAdmin):
raw_id_fields = ('simple_entity', 'region_layer')
search_fields = ('simple_entity', 'region_layer')
inlines = [SynonymInline]


Expand Down Expand Up @@ -232,7 +232,7 @@ def get_form(self, request, obj=None, change=False, **kwargs):
admin.site.register(Layer, LayerAdmin)
admin.site.register(Region, RegionAdmin)
admin.site.register(AnatomicalEntityIntersection, AnatomicalEntityIntersectionAdmin)
admin.site.register(AnatomicalEntity, AnatomicalEntityAdmin)
admin.site.register(AnatomicalEntity, AnatomicalEntityNewAdmin)
admin.site.register(Phenotype)
admin.site.register(Sex)
admin.site.register(ConnectivityStatement, ConnectivityStatementAdmin)
Expand Down
8 changes: 7 additions & 1 deletion backend/composer/management/commands/ingest_statements.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,19 @@ def add_arguments(self, parser):
action='store_true',
help='Set this flag to update upstream statements.',
)
parser.add_argument(
'--update_anatomic_entities',
action='store_true',
help='Set this flag to try move anatomical entities to specific layer, region.',
)

def handle(self, *args, **options):
update_upstream = options['update_upstream']
update_anatomic_entities = options['update_anatomic_entities']

start_time = time.time()

ingest_statements(update_upstream)
ingest_statements(update_upstream, update_anatomic_entities)

end_time = time.time()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 4.1.4 on 2024-03-19 14:14
# Generated by Django 4.1.4 on 2024-03-20 13:39

from django.db import migrations, models
import django.db.models.deletion
Expand Down Expand Up @@ -40,14 +40,19 @@ class Migration(migrations.Migration):
("ontology_uri", models.URLField(unique=True)),
],
options={
"verbose_name_plural": "Anatomical Entities",
"verbose_name_plural": "Anatomical Entities Meta",
"ordering": ["name"],
},
),
migrations.AlterField(
model_name="anatomicalentity",
name="ontology_uri",
field=models.URLField(),
model_name="synonym",
name="anatomical_entity",
field=models.ForeignKey(
null=True,
on_delete=django.db.models.deletion.CASCADE,
related_name="synonyms",
to="composer.anatomicalentity",
),
),
migrations.CreateModel(
name="Layer",
Expand All @@ -66,42 +71,16 @@ class Migration(migrations.Migration):
],
bases=("composer.anatomicalentitymeta",),
),
migrations.CreateModel(
name="Region",
fields=[
(
"anatomicalentitymeta_ptr",
models.OneToOneField(
auto_created=True,
on_delete=django.db.models.deletion.CASCADE,
parent_link=True,
primary_key=True,
serialize=False,
to="composer.anatomicalentitymeta",
),
),
(
"layers",
models.ManyToManyField(
through="composer.AnatomicalEntityIntersection",
to="composer.layer",
),
),
],
bases=("composer.anatomicalentitymeta",),
),
migrations.CreateModel(
name="AnatomicalEntityNew",
fields=[
(
"anatomicalentitymeta_ptr",
models.OneToOneField(
"id",
models.BigAutoField(
auto_created=True,
on_delete=django.db.models.deletion.CASCADE,
parent_link=True,
primary_key=True,
serialize=False,
to="composer.anatomicalentitymeta",
verbose_name="ID",
),
),
(
Expand All @@ -112,22 +91,16 @@ class Migration(migrations.Migration):
to="composer.anatomicalentityintersection",
),
),
(
"simple_entity",
models.OneToOneField(
blank=True,
null=True,
on_delete=django.db.models.deletion.CASCADE,
to="composer.anatomicalentitymeta",
),
),
],
bases=("composer.anatomicalentitymeta",),
),
migrations.AddField(
model_name="anatomicalentityintersection",
name="layer",
field=models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE, to="composer.layer"
),
),
migrations.AddField(
model_name="anatomicalentityintersection",
name="region",
field=models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE, to="composer.region"
),
),
migrations.AddField(
model_name="connectivitystatement",
Expand Down Expand Up @@ -165,7 +138,7 @@ class Migration(migrations.Migration):
name="anatomical_entities_new",
field=models.ManyToManyField(
blank=True,
related_name="via_connection_layers_new",
related_name="via_connection_layers",
to="composer.anatomicalentitynew",
),
),
Expand All @@ -174,4 +147,42 @@ class Migration(migrations.Migration):
name="from_entities_new",
field=models.ManyToManyField(blank=True, to="composer.anatomicalentitynew"),
),
migrations.CreateModel(
name="Region",
fields=[
(
"anatomicalentitymeta_ptr",
models.OneToOneField(
auto_created=True,
on_delete=django.db.models.deletion.CASCADE,
parent_link=True,
primary_key=True,
serialize=False,
to="composer.anatomicalentitymeta",
),
),
(
"layers",
models.ManyToManyField(
through="composer.AnatomicalEntityIntersection",
to="composer.layer",
),
),
],
bases=("composer.anatomicalentitymeta",),
),
migrations.AddField(
model_name="anatomicalentityintersection",
name="layer",
field=models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE, to="composer.layer"
),
),
migrations.AddField(
model_name="anatomicalentityintersection",
name="region",
field=models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE, to="composer.region"
),
),
]
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
# Generated by Django 4.1.4 on 2024-03-19 14:07
# Generated by Django 4.1.4 on 2024-03-20 13:40

from django.db import migrations


def copy_anatomical_entities_to_new(apps, schema_editor):
AnatomicalEntity = apps.get_model('composer', 'AnatomicalEntity')
AnatomicalEntityNew = apps.get_model('composer', 'AnatomicalEntityNew')
AnatomicalEntityMeta = apps.get_model('composer', 'AnatomicalEntityMeta')
Destination = apps.get_model('composer', 'Destination')
Via = apps.get_model('composer', 'Via')
ConnectivityStatement = apps.get_model('composer', 'ConnectivityStatement')
Synonym = apps.get_model('composer', 'Synonym')

# Copy AnatomicalEntity instances to AnatomicalEntityNew
for entity in AnatomicalEntity.objects.all():
new_entity = AnatomicalEntityNew.objects.create(
new_entity_meta = AnatomicalEntityMeta.objects.create(
name=entity.name,
ontology_uri=entity.ontology_uri,
)

new_entity = AnatomicalEntityNew.objects.create(simple_entity=new_entity_meta)

# Update ManyToMany relationships for Destination
for destination in Destination.objects.filter(anatomical_entities=entity):
destination.anatomical_entities_new.add(new_entity)
Expand Down Expand Up @@ -46,6 +49,4 @@ class Migration(migrations.Migration):
("composer", "0046_anatomicalentityintersection_anatomicalentitymeta_and_more"),
]

operations = [
migrations.RunPython(copy_anatomical_entities_to_new),
]
operations = [migrations.RunPython(copy_anatomical_entities_to_new), ]
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Generated by Django 4.1.4 on 2024-03-19 16:03
# Generated by Django 4.1.4 on 2024-03-20 14:13

from django.db import migrations


class Migration(migrations.Migration):
dependencies = [
("composer", "0047_auto_20240319_1414"),
("composer", "0047_auto_20240320_1340"),
]

operations = [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 4.1.4 on 2024-03-19 16:08
# Generated by Django 4.1.4 on 2024-03-20 14:14

from django.db import migrations, models
import django.db.models.deletion
Expand All @@ -19,16 +19,16 @@ class Migration(migrations.Migration):
old_name="from_entities_new",
new_name="from_entities",
),
migrations.RenameField(
model_name="via",
old_name="anatomical_entities_new",
new_name="anatomical_entities",
),
migrations.RenameField(
model_name="via",
old_name="from_entities_new",
new_name="from_entities",
),
# Assuming the intention was to rename 'origins_new' to 'origins',
# 'anatomical_entities_new' to 'anatomical_entities', and similar for other fields
# Note: For ManyToManyFields, if Django's migration system doesn't support direct renaming,
# you may need a more complex approach to adjust the intermediary table instead of simple field renaming.
# For now, let's assume renaming is what you intended:
migrations.RenameField(
model_name="connectivitystatement",
old_name="origins_new",
Expand All @@ -39,19 +39,17 @@ class Migration(migrations.Migration):
old_name="anatomical_entities_new",
new_name="anatomical_entities",
),
migrations.RenameField(
model_name="via",
old_name="anatomical_entities_new",
new_name="anatomical_entities",
),
migrations.RenameField(
model_name="synonym",
old_name="anatomical_entity_new",
new_name="anatomical_entity",
),
migrations.AlterUniqueTogether(
name="synonym",
unique_together=set(),
),
migrations.AlterUniqueTogether(
name="synonym",
unique_together={("anatomical_entity", "name")},
),
]

This file was deleted.

Loading

0 comments on commit 40f20b9

Please sign in to comment.