Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Target loader handling map files (issue 1270) #508

Merged
merged 4 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions viewer/download_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
'bound_file': ('aligned'),
'cif_info': ('aligned'),
'mtz_info': ('aligned'),
# 'map_info': ('aligned'),
'map_info': ('aligned'),
'sigmaa_file': ('aligned'),
'diff_file': ('aligned'),
'event_file': ('aligned'),
Expand All @@ -56,8 +56,9 @@
'bound_file': {}, # x
'cif_info': {}, # from experiment
'mtz_info': {}, # from experiment
'map_info': {}, # from experiment
'event_file': {}, # x
'diff_file': {}, # renamed from diff_file and sigmaa_file
'diff_file': {},
'sigmaa_file': {},
},
'molecules': {
Expand Down Expand Up @@ -229,6 +230,7 @@ def _add_file_to_zip_aligned(ziparchive, code, filepath):
filepath = str(Path(settings.MEDIA_ROOT).joinpath(filepath))

if Path(filepath).is_file():
# strip off the leading parts of path
archive_path = str(Path(*Path(filepath).parts[7:]))
if _is_mol_or_sdf(filepath):
# It's a MOL or SD file.
Expand Down Expand Up @@ -285,9 +287,13 @@ def _protein_files_zip(zip_contents, ziparchive, error_file):
continue

for prot, prot_file in files.items():
if not _add_file_to_zip_aligned(ziparchive, prot.split(":")[0], prot_file):
error_file.write(f'{param},{prot},{prot_file}\n')
prot_errors += 1
# if it's a list of files (map_info) instead of single file
if not isinstance(prot_file, list):
prot_file = [prot_file]
for f in prot_file:
if not _add_file_to_zip_aligned(ziparchive, prot.split(":")[0], f):
error_file.write(f'{param},{prot},{f}\n')
prot_errors += 1

return prot_errors

Expand Down Expand Up @@ -606,10 +612,14 @@ def _create_structures_dict(target, site_obvs, protein_params, other_params):
# getting the param from experiment. more data are
# coming from there, that's why this is in try
# block
# getattr retrieves FieldFile object, hance the .name
zip_contents['proteins'][param][so.code] = getattr(
so.experiment, param
).name
model_attr = getattr(so.experiment, param)
# getattr retrieves FieldFile object, hence the .name
if isinstance(model_attr, list):
# except map_files, this returns a list of files
zip_contents['proteins'][param][so.code] = model_attr
else:
zip_contents['proteins'][param][so.code] = model_attr.name

except AttributeError:
# on the off chance that the data are in site_observation model
zip_contents['proteins'][param][so.code] = getattr(so, param).name
Expand Down Expand Up @@ -686,6 +696,7 @@ def get_download_params(request):
'bound_file',
'cif_info',
'mtz_info',
'map_info',
'event_file',
'sigmaa_file',
'diff_file',
Expand Down
19 changes: 19 additions & 0 deletions viewer/migrations/0034_experiment_map_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 3.2.23 on 2024-01-26 11:16

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
('viewer', '0033_alter_siteobservation_cmpd'),
]

operations = [
migrations.AddField(
model_name='experiment',
name='map_info',
field=models.FileField(
max_length=255, null=True, upload_to='target_loader_data/'
),
),
]
22 changes: 22 additions & 0 deletions viewer/migrations/0035_alter_experiment_event_map_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 3.2.23 on 2024-01-30 08:09

import django.contrib.postgres.fields
from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
('viewer', '0034_experiment_map_info'),
]

operations = [
migrations.AlterField(
model_name='experiment',
name='event_map_info',
field=django.contrib.postgres.fields.ArrayField(
base_field=models.FileField(max_length=255, upload_to=''),
null=True,
size=None,
),
),
]
16 changes: 16 additions & 0 deletions viewer/migrations/0036_remove_experiment_map_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Generated by Django 3.2.23 on 2024-01-30 08:12

from django.db import migrations


class Migration(migrations.Migration):
dependencies = [
('viewer', '0035_alter_experiment_event_map_info'),
]

operations = [
migrations.RemoveField(
model_name='experiment',
name='map_info',
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 3.2.23 on 2024-01-30 08:12

from django.db import migrations


class Migration(migrations.Migration):
dependencies = [
('viewer', '0036_remove_experiment_map_info'),
]

operations = [
migrations.RenameField(
model_name='experiment',
old_name='event_map_info',
new_name='map_info',
),
]
2 changes: 1 addition & 1 deletion viewer/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ class Experiment(models.Model):
cif_info = models.FileField(
upload_to="target_loader_data/", null=True, max_length=255
)
event_map_info = ArrayField(models.FileField(), null=True)
map_info = ArrayField(models.FileField(max_length=255), null=True)
type = models.PositiveSmallIntegerField(null=True)
pdb_sha256 = models.TextField(null=True)
compounds = models.ManyToManyField(
Expand Down
1 change: 1 addition & 0 deletions viewer/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,7 @@ class DownloadStructuresSerializer(serializers.Serializer):
diff_file = serializers.BooleanField(default=False)
event_file = serializers.BooleanField(default=False)
sigmaa_file = serializers.BooleanField(default=False)
map_info = serializers.BooleanField(default=False)
sdf_info = serializers.BooleanField(default=False)
single_sdf_file = serializers.BooleanField(default=False)
metadata_info = serializers.BooleanField(default=False)
Expand Down
Loading
Loading