Skip to content

Commit

Permalink
feat: antigen short names
Browse files Browse the repository at this point in the history
  • Loading branch information
alubbock committed Sep 14, 2023
1 parent 5924f5c commit 0e9b05b
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 2 deletions.
39 changes: 39 additions & 0 deletions backend/antigenapi/migrations/0005_antigen_short_name.py
Original file line number Diff line number Diff line change
@@ -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),
]
21 changes: 21 additions & 0 deletions backend/antigenapi/migrations/0006_antigen_short_name_unique.py
Original file line number Diff line number Diff line change
@@ -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,
),
]
1 change: 1 addition & 0 deletions backend/antigenapi/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
5 changes: 3 additions & 2 deletions backend/antigenapi/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 8 additions & 0 deletions frontend/src/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 0e9b05b

Please sign in to comment.