Skip to content

Commit

Permalink
Merge pull request #654 from xchem/m2ms-1496-tags
Browse files Browse the repository at this point in the history
Shorter versions of crystalform sites-, conformer sites- and canon sites tags (issue 1496)
  • Loading branch information
kaliif authored Sep 5, 2024
2 parents 1648028 + a49db62 commit 852db67
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 13 deletions.
33 changes: 33 additions & 0 deletions viewer/migrations/0061_auto_20240905_1500.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Generated by Django 3.2.25 on 2024-09-05 15:00

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('viewer', '0060_canonsite_centroid_res'),
]

operations = [
migrations.AddField(
model_name='sessionprojecttag',
name='short_tag',
field=models.TextField(help_text='The generated shorter version of tag (without target name)', null=True),
),
migrations.AddField(
model_name='siteobservationtag',
name='short_tag',
field=models.TextField(help_text='The generated shorter version of tag (without target name)', null=True),
),
migrations.AlterField(
model_name='sessionprojecttag',
name='upload_name',
field=models.CharField(help_text='The generated long name of the tag', max_length=200),
),
migrations.AlterField(
model_name='siteobservationtag',
name='upload_name',
field=models.CharField(help_text='The generated long name of the tag', max_length=200),
),
]
18 changes: 18 additions & 0 deletions viewer/migrations/0062_experiment_code_prefix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.25 on 2024-09-05 15:35

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('viewer', '0061_auto_20240905_1500'),
]

operations = [
migrations.AddField(
model_name='experiment',
name='code_prefix',
field=models.TextField(null=True),
),
]
7 changes: 6 additions & 1 deletion viewer/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ class Experiment(models.Model):
type = models.PositiveSmallIntegerField(null=True)
pdb_sha256 = models.TextField(null=True)
prefix_tooltip = models.TextField(null=True)
code_prefix = models.TextField(null=True)
compounds = models.ManyToManyField(
"Compound",
through="ExperimentCompound",
Expand Down Expand Up @@ -1292,11 +1293,15 @@ class Meta:

class Tag(models.Model):
tag = models.CharField(max_length=200, help_text="The (unique) name of the tag")
short_tag = models.TextField(
null=True,
help_text="The generated shorter version of tag (without target name)",
)
tag_prefix = models.TextField(
null=True, help_text="Tag prefix for auto-generated tags"
)
upload_name = models.CharField(
max_length=200, help_text="The generated name of the tag"
max_length=200, help_text="The generated long name of the tag"
)
category = models.ForeignKey(TagCategory, on_delete=models.CASCADE)
target = models.ForeignKey(Target, on_delete=models.CASCADE)
Expand Down
50 changes: 38 additions & 12 deletions viewer/target_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,7 @@ def process_experiment(
"cif_info": str(self._get_final_path(cif_info)),
"map_info": map_info_paths,
"prefix_tooltip": prefix_tooltip,
"code_prefix": code_prefix,
# this doesn't seem to be present
# pdb_sha256:
}
Expand Down Expand Up @@ -1834,18 +1835,23 @@ def process_bundle(self):
so_list = SiteObservation.objects.filter(
canon_site_conf__canon_site=val.instance
)
tag = val.versioned_key
try:
tag = val.versioned_key.split('-')[1]
short_tag = val.versioned_key.split('-')[1][1:]
main_obvs = val.instance.ref_conf_site.ref_site_observation
code_prefix = experiment_objects[main_obvs.experiment.code].index_data[
"code_prefix"
]
tag = f"{code_prefix}{tag}"
short_tag = f"{code_prefix}{short_tag}"
except IndexError:
tag = val.versioned_key
short_tag = tag

self._tag_observations(
tag, prefix, category=cat_canon, site_observations=so_list
tag,
prefix,
category=cat_canon,
site_observations=so_list,
short_tag=short_tag,
)

logger.debug("canon_site objects tagged")
Expand All @@ -1863,19 +1869,24 @@ def process_bundle(self):
site_observation_objects[k].instance for k in val.index_data["members"]
]
# tag = val.instance.name.split('+')[0]
# tag = val.instance.name
tag = val.instance.name
try:
tag = val.instance.name.split('-')[1]
short_tag = val.instance.name.split('-')[1][1:]
main_obvs = val.instance.ref_site_observation
code_prefix = experiment_objects[main_obvs.experiment.code].index_data[
"code_prefix"
]
tag = f"{code_prefix}{tag}"
short_tag = f"{code_prefix}{short_tag}"
except IndexError:
tag = val.instance.name
short_tag = tag

self._tag_observations(
tag, prefix, category=cat_conf, site_observations=so_list, hidden=True
tag,
prefix,
category=cat_conf,
site_observations=so_list,
hidden=True,
short_tag=short_tag,
)

logger.debug("conf_site objects tagged")
Expand Down Expand Up @@ -1967,17 +1978,28 @@ def process_bundle(self):
f"F{val.instance.xtalform.xtalform_num}"
+ f"{val.instance.xtalform_site_num}"
)
# tag = val.instance.xtalform_site_id
tag = val.versioned_key
so_list = [
site_observation_objects[k].instance for k in val.index_data["residues"]
]
tag = val.versioned_key
try:
# remove protein name and 'x'
short_tag = val.instance.xtalform_site_id.split('-')[1][1:]
main_obvs = val.instance.canon_site.ref_conf_site.ref_site_observation
code_prefix = experiment_objects[main_obvs.experiment.code].index_data[
"code_prefix"
]
short_tag = f"{code_prefix}{short_tag}"
except IndexError:
short_tag = tag

self._tag_observations(
tag,
prefix,
category=cat_xtalsite,
site_observations=so_list,
hidden=True,
short_tag=short_tag,
)

logger.debug("xtalform_sites objects tagged")
Expand Down Expand Up @@ -2113,6 +2135,7 @@ def _tag_observations(
category: TagCategory,
site_observations: list,
hidden: bool = False,
short_tag: str | None = None,
) -> None:
try:
# memo to self: description is set to tag, but there's
Expand Down Expand Up @@ -2140,6 +2163,8 @@ def _tag_observations(
so_group.save()

name = f"{prefix} - {tag}" if prefix else tag
short_tag = name if short_tag is None else f"{prefix} - {short_tag}"

try:
so_tag = SiteObservationTag.objects.get(
upload_name=name, target=self.target
Expand All @@ -2150,13 +2175,14 @@ def _tag_observations(
so_tag.mol_group = so_group
except SiteObservationTag.DoesNotExist:
so_tag = SiteObservationTag(
tag=tag,
tag=short_tag,
tag_prefix=prefix,
upload_name=name,
category=category,
target=self.target,
mol_group=so_group,
hidden=hidden,
short_tag=short_tag,
)

so_tag.save()
Expand Down

0 comments on commit 852db67

Please sign in to comment.