From 0e9b05bf4bb7e74232827eb55a3f178137c9f63e Mon Sep 17 00:00:00 2001 From: Alex Lubbock Date: Thu, 14 Sep 2023 17:05:57 +0100 Subject: [PATCH] feat: antigen short names --- .../migrations/0005_antigen_short_name.py | 39 +++++++++++++++++++ .../0006_antigen_short_name_unique.py | 21 ++++++++++ backend/antigenapi/models.py | 1 + backend/antigenapi/views.py | 5 ++- frontend/src/schema.js | 8 ++++ 5 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 backend/antigenapi/migrations/0005_antigen_short_name.py create mode 100644 backend/antigenapi/migrations/0006_antigen_short_name_unique.py diff --git a/backend/antigenapi/migrations/0005_antigen_short_name.py b/backend/antigenapi/migrations/0005_antigen_short_name.py new file mode 100644 index 0000000..060e310 --- /dev/null +++ b/backend/antigenapi/migrations/0005_antigen_short_name.py @@ -0,0 +1,39 @@ +# Generated by Django 4.1.7 on 2023-09-14 10:19 + +import random +import string + +from django.db import migrations, models +from django.db.models import F + + +def copy_uniprot_id_to_short_name(apps, schema_editor): + """Copy UniProt ID to short_name field during migration.""" + MetaDataValue = apps.get_model("antigenapi", "antigen") + db_alias = schema_editor.connection.alias + MetaDataValue.objects.using(db_alias).all().update(short_name=F("uniprot_id")) + + +def generate_random_value(): + """Generate random placeholder string.""" + characters = string.ascii_letters + string.digits + return f"changeme_{''.join(random.choice(characters) for _ in range(16))}" + + +class Migration(migrations.Migration): + + dependencies = [ + ("antigenapi", "0004_remove_sequencingrun_results_date_and_more"), + ] + + operations = [ + migrations.AddField( + model_name="antigen", + name="short_name", + field=models.CharField( + default=generate_random_value, max_length=32, null=True + ), + preserve_default=False, + ), + migrations.RunPython(copy_uniprot_id_to_short_name), + ] diff --git a/backend/antigenapi/migrations/0006_antigen_short_name_unique.py b/backend/antigenapi/migrations/0006_antigen_short_name_unique.py new file mode 100644 index 0000000..1d315b4 --- /dev/null +++ b/backend/antigenapi/migrations/0006_antigen_short_name_unique.py @@ -0,0 +1,21 @@ +# Generated by Django 4.1.7 on 2023-09-14 10:19 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("antigenapi", "0005_antigen_short_name"), + ] + + operations = [ + migrations.AlterField( + model_name="antigen", + name="short_name", + field=models.CharField( + default=None, max_length=32, unique=True, null=False + ), + preserve_default=False, + ), + ] diff --git a/backend/antigenapi/models.py b/backend/antigenapi/models.py index 454e387..3385d08 100644 --- a/backend/antigenapi/models.py +++ b/backend/antigenapi/models.py @@ -60,6 +60,7 @@ class Antigen(Model): uniprot_id = CharField(max_length=16, null=True, unique=True) preferred_name = CharField(max_length=256) + short_name = CharField(max_length=32, unique=True) sequence: str = TextField(validators=[AminoCodeLetters], null=True) molecular_mass: int = IntegerField(null=True) description = TextField( diff --git a/backend/antigenapi/views.py b/backend/antigenapi/views.py index b55fb60..b47f02d 100644 --- a/backend/antigenapi/views.py +++ b/backend/antigenapi/views.py @@ -541,12 +541,13 @@ def download_submission_xlsx(self, request, pk, submission_idx): elisa_well = elisa_wells[(well["plate"], well["location"])] ws[f"B{row}"] = ( - f"{elisa_well.antigen.preferred_name}_" + f"{elisa_well.antigen.short_name}_" f"EP{elisa_well.plate_id}_" f"{PlateLocations.labels[elisa_well.location - 1]}" ) # Own primer name - ws[f"D{row}"] = "PRIMER" + ws[f"D{row}"] = "PHD_SEQ_FWD" + ws[f"F{row}"] = "Yes" # Save to temp file with NamedTemporaryFile() as tmp: diff --git a/frontend/src/schema.js b/frontend/src/schema.js index 2c88649..1ff9a45 100644 --- a/frontend/src/schema.js +++ b/frontend/src/schema.js @@ -158,6 +158,14 @@ const antigenSchema = { showInTable: true, tableColWidth: "w-4/5", }, + { + label: "Short name", + field: "short_name", + type: "text", + formHint: "Leave blank to populate from UniProt", + showInTable: true, + tableColWidth: "w-4/5", + }, { label: "Sequence", field: "sequence",