Skip to content

Commit

Permalink
Merge pull request #655 from xchem/m2ms-1499-shortcode
Browse files Browse the repository at this point in the history
Updated both short- and longcode (issue 1499)
  • Loading branch information
kaliif authored Sep 6, 2024
2 parents 852db67 + 7f31bb5 commit f6d6b6d
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 11 deletions.
34 changes: 29 additions & 5 deletions viewer/download_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,25 @@ def _create_structures_dict(site_obvs, protein_params, other_params):

# Read through zip_params to compile the parameters
zip_contents: Dict[str, Any] = copy.deepcopy(zip_template)
site_obvs = site_obvs.annotate(
# would there be any point in
# a) adding a method to SiteObservation model_attr
# b) adding the value to database directly?
longlongcode=Concat(
F('experiment__code'),
Value('_'),
F('chain_id'),
Value('_'),
F('seq_id'),
Value('_'),
F('version'),
Value('_'),
F('canon_site_conf__canon_site__name'),
Value('+'),
F('canon_site_conf__canon_site__version'),
output_field=CharField(),
),
)
for so in site_obvs:
for param in protein_params:
if protein_params[param] is True:
Expand All @@ -799,9 +818,12 @@ def _create_structures_dict(site_obvs, protein_params, other_params):
for f in model_attr:
# here the model_attr is already stringified
try:
exp_path = re.search(r"x\d*", so.code).group(0) # type: ignore[union-attr]
except AttributeError:
logger.error('Unexpected shortcodeformat: %s', so.code)
exp_path = so.experiment.code.split('-x')[1]
except IndexError:
logger.error(
'Unexpected experiment code format: %s',
so.experiment.code,
)
exp_path = so.code

apath = Path('crystallographic_files').joinpath(exp_path)
Expand Down Expand Up @@ -843,7 +865,7 @@ def _create_structures_dict(site_obvs, protein_params, other_params):
apath.joinpath(
Path(model_attr.name)
.parts[-1]
.replace(so.longcode, so.code)
.replace(so.longlongcode, so.code)
)
)
else:
Expand Down Expand Up @@ -875,7 +897,9 @@ def _create_structures_dict(site_obvs, protein_params, other_params):
f'{ccp_path.stem}_crystallographic{ccp_path.suffix}'
)
archive_path = str(
apath.joinpath(path.parts[-1].replace(so.longcode, so.code))
apath.joinpath(
path.parts[-1].replace(so.longlongcode, so.code)
)
)

afile = [
Expand Down
20 changes: 14 additions & 6 deletions viewer/target_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -1106,6 +1106,8 @@ def process_canon_site(
conf_sites_ids = extract(key="conformer_site_ids", return_type=list)
ref_conf_site_id = extract(key="reference_conformer_site_id")

centroid_res = f"{centroid_res}_v{version}"

fields = {
"name": canon_site_id,
"version": version,
Expand Down Expand Up @@ -1311,7 +1313,8 @@ def process_site_observation(
experiment = experiments[experiment_id].instance

longcode = (
f"{experiment.code}_{chain}_{str(ligand)}_{str(version)}_{str(v_idx)}"
# f"{experiment.code}_{chain}_{str(ligand)}_{str(version)}_{str(v_idx)}"
f"{experiment.code}_{chain}_{str(ligand)}_v{str(version)}"
)
key = f"{experiment.code}/{chain}/{str(ligand)}"
v_key = f"{experiment.code}/{chain}/{str(ligand)}/{version}"
Expand Down Expand Up @@ -1758,7 +1761,8 @@ def process_bundle(self):
]
# iter_pos = next(suffix)
# code = f"{code_prefix}{so.experiment.code.split('-')[1]}{iter_pos}"
code = f"{code_prefix}{so.experiment.code.split('-')[1]}{next(suffix)}"
# code = f"{code_prefix}{so.experiment.code.split('-')[1]}{next(suffix)}"
code = f"{code_prefix}{so.experiment.code.split('-x')[1]}{next(suffix)}"

# test uniqueness for target
# TODO: this should ideally be solved by db engine, before
Expand Down Expand Up @@ -1858,7 +1862,10 @@ def process_bundle(self):

numerators = {}
cat_conf = TagCategory.objects.get(category="ConformerSites")
for val in canon_site_conf_objects.values(): # pylint: disable=no-member
for val in canon_site_conf_objects.values(): # pylint:
# disable=no-member problem introduced with the sorting of
# canon sites (issue 1498). objects somehow go out of sync
val.instance.refresh_from_db()
if val.instance.canon_site.canon_site_num not in numerators.keys():
numerators[val.instance.canon_site.canon_site_num] = alphanumerator()
prefix = (
Expand Down Expand Up @@ -2163,7 +2170,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}"
tag = tag if short_tag is None else short_tag
short_name = name if short_tag is None else f"{prefix} - {short_tag}"

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

so_tag.save()
Expand Down

0 comments on commit f6d6b6d

Please sign in to comment.