Skip to content

Commit 3b7fb6e

Browse files
author
Alan Christie
committed
feat: Use of openpyxl for simple ordinal to letter conversion
1 parent 3ace4e8 commit 3b7fb6e

File tree

4 files changed

+71
-61
lines changed

4 files changed

+71
-61
lines changed

poetry.lock

+61-33
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ gunicorn = "^21.2.0"
3333
im-squonk2-client = "^1.22.2"
3434
mozilla_django_oidc = "^3.0.0"
3535
mysql-connector-python = "^8.1.0"
36+
openpyxl = "^3.1.2"
3637
pandas = "^1.5.3"
3738
pandoc = "^2.3"
3839
psutil = "^5.9.5"

viewer/cset_upload.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import zipfile
88
from typing import Any, Dict, List, Optional, Tuple
99

10+
from openpyxl.utils import get_column_letter
11+
1012
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "fragalysis.settings")
1113
import django
1214

@@ -500,19 +502,19 @@ def task(self) -> ComputedSet:
500502
len(existing_sets),
501503
latest_ordinal,
502504
)
505+
# ordinals are 1-based
503506
new_ordinal: int = latest_ordinal + 1
504507

505508
# The computed set "name" consists of the "method",
506509
# today's date and a 2-digit ordinal. The ordinal
507510
# is used to distinguish between computed sets uploaded
508511
# with the same method on the same day.
509-
cs_name: str = f"{truncated_submitter_method}-{str(today)}-{new_ordinal:0>2}"
512+
assert new_ordinal > 0
513+
cs_name: str = f"{truncated_submitter_method}-{str(today)}-{get_column_letter(new_ordinal)}"
510514
logger.info('Creating new ComputedSet "%s"', cs_name)
511515

512516
computed_set: ComputedSet = ComputedSet()
513-
computed_set.name = (
514-
f"{truncated_submitter_method}-{str(today)}-{new_ordinal:0>2}"
515-
)
517+
computed_set.name = cs_name
516518
computed_set.md_ordinal = new_ordinal
517519
computed_set.upload_date = today
518520
computed_set.method = truncated_submitter_method

viewer/sdf_check.py

+3-24
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@
55
@author: Warren
66
Script to check sdf file format for Fragalysis upload
77
"""
8-
import datetime
98
import logging
109

1110
import validators
1211
from rdkit import Chem
1312

14-
from viewer.models import ComputedSet, SiteObservation
13+
from viewer.models import SiteObservation
1514

1615
logger = logging.getLogger(__name__)
1716

@@ -24,6 +23,8 @@ def check_property_descriptions():
2423

2524

2625
def check_compound_set(description_mol, validate_dict, update=None):
26+
del update
27+
2728
# Must have a 'generation_date'
2829
if not description_mol.HasProp('generation_date'):
2930
validate_dict = add_warning(
@@ -45,28 +46,6 @@ def check_compound_set(description_mol, validate_dict, update=None):
4546
)
4647
return validate_dict
4748

48-
submitter_dict = {
49-
'submitter__name': description_mol.GetProp('submitter_name'),
50-
'submitter__email': description_mol.GetProp('submitter_email'),
51-
'submitter__institution': description_mol.GetProp('submitter_institution'),
52-
'submitter__generation_date': datetime.date(
53-
int(y_m_d[0]), int(y_m_d[1]), int(y_m_d[2])
54-
),
55-
'submitter__method': description_mol.GetProp('method'),
56-
}
57-
58-
query = ComputedSet.objects.filter(**submitter_dict)
59-
60-
if len(query) != 0 and not update:
61-
validate_dict = add_warning(
62-
molecule_name='File error',
63-
field='compound set',
64-
warning_string="A ComputedSet with the name "
65-
+ query[0].name
66-
+ " already exists (change method name in blank mol method field)",
67-
validate_dict=validate_dict,
68-
)
69-
7049
return validate_dict
7150

7251

0 commit comments

Comments
 (0)