From b01c2a64638a61cb83c83cc2ae841c2dd40966ab Mon Sep 17 00:00:00 2001 From: Morgan Ekmefjord Date: Fri, 13 Dec 2024 23:47:38 +0100 Subject: [PATCH] Updated paths to conform with scilife serve team suggestions. Also fixed bug in chembl version selection. --- docker-compose-single.yml | 1 + ptp/inference/tasks.py | 28 +++++++++++++++++----------- ptp/nginx.conf | 2 +- ptp/ptp/settings.py | 2 +- ptp/supervisord.conf | 6 ++++-- test/smiles_example.csv | 3 ++- 6 files changed, 26 insertions(+), 16 deletions(-) diff --git a/docker-compose-single.yml b/docker-compose-single.yml index 10f4d30..a4fbac9 100644 --- a/docker-compose-single.yml +++ b/docker-compose-single.yml @@ -32,6 +32,7 @@ services: #- EMAIL_HOST_USER=your-email@example.com #- EMAIL_HOST_PASSWORD=your-email-password - SITE_URL=http://localhost:8000 + - CSRF_TRUSTED_ORIGINS=http://localhost:8000 #volumes: # postgres_data: \ No newline at end of file diff --git a/ptp/inference/tasks.py b/ptp/inference/tasks.py index 2fb8b78..1f942b7 100644 --- a/ptp/inference/tasks.py +++ b/ptp/inference/tasks.py @@ -14,7 +14,7 @@ @shared_task def run_inference(job_id): - + import os job = InferenceJob.objects.get(id=job_id) job.status = 'running' job.save() @@ -32,11 +32,12 @@ def run_inference(job_id): else: path = 'conformal_models' + print("JOB CHEMBL VERSION:{}:VERSION".format(job.chembl_version), flush=True) if str(job.chembl_version) == '31': chembl_version = 'chembl_31' - if str(job.chembl_version) == '32': + elif str(job.chembl_version) == '32': chembl_version = 'chembl_32' - if str(job.chembl_version) == '33': + elif str(job.chembl_version) == '33': chembl_version = 'chembl_33' elif str(job.chembl_version) == '34': chembl_version = 'chembl_34' @@ -54,11 +55,8 @@ def run_inference(job_id): results = [] result_filenames = [] print("Running inference...", flush=True) - DEBUG=True + import os - if DEBUG: - print("RUNNING IN DEBUG MODE ONLY CALCULATING 3 MODELS", flush=True) - model_files = model_files#[:5] if max_models: model_files = model_files[:int(max_models)] @@ -115,6 +113,7 @@ def run_inference(job_id): print("Concatenating results...", flush=True) BASE_DIR = os.environ.get("BASE_DIR", "/app/") + import os os.makedirs(f"{BASE_DIR}/interim", exist_ok=True) result_file_path = f"{BASE_DIR}/interim/resultfilepath-{job_id}.csv" @@ -157,7 +156,7 @@ def run_inference(job_id): df_result[target + '_p_i'] = df_result['SMILES'].map(p_i) df_result[target + '_p_a'] = df_result['SMILES'].map(p_a) - df_result.drop(axis='index', labels=0, inplace=True) + ##### df_result.drop(axis='index', labels=0, inplace=True) #print("Finished processing file:", p, flush=True) df_result.to_csv(result_file_path, index=False) #print("saving to resultfile path", flush=True) @@ -184,11 +183,18 @@ def run_inference(job_id): # Save result in Django model #job.result_file.name = f"results/{job_id}_final_result.csv" import uuid - identifier = str(uuid.uuid4()) + identifier = str(uuid.uuid4()).split('-')[0] if result_file_path: with open(result_file_path, 'rb') as f: - result = Result.objects.create(job=job) - result.result_file.save(f"{job_id}_{identifier}_result.csv", f) + try: + result = Result.objects.create(job=job) + result.result_file.save(f"{job_id}_{identifier}_result.csv", f) + result.save() + except Exception as e: + job.status = 'failed' + job.save() + cleanup_output_files(output_dir) + print("Failed to save result from interim:", e, flush=True) #job.result_file.name = f"results/{job_id}_final_result.csv" diff --git a/ptp/nginx.conf b/ptp/nginx.conf index f2fee30..d2726c7 100644 --- a/ptp/nginx.conf +++ b/ptp/nginx.conf @@ -8,7 +8,7 @@ http { alias /app/static/; } location /media/ { - alias /app/media/; + alias /app/ext_storage/media/; types { text/csv csv; } diff --git a/ptp/ptp/settings.py b/ptp/ptp/settings.py index 7f1f833..d93b732 100644 --- a/ptp/ptp/settings.py +++ b/ptp/ptp/settings.py @@ -111,7 +111,7 @@ # Media files (Uploaded files, results) MEDIA_URL = '/media/' -MEDIA_DIR = os.environ.get('MEDIA_DIR', '/app/ext_storage/media') +MEDIA_DIR = os.environ.get('MEDIA_DIR', '/app/ext_storage/') MEDIA_ROOT = os.path.join(MEDIA_DIR, 'media') # Email settings (for sending job completion notifications) diff --git a/ptp/supervisord.conf b/ptp/supervisord.conf index 118f3c6..2f4ef79 100644 --- a/ptp/supervisord.conf +++ b/ptp/supervisord.conf @@ -27,6 +27,8 @@ autostart=true autorestart=true startretries=10 exitcodes=0,2 -stdout_logfile=/var/log/supervisor/celery.log -stderr_logfile=/var/log/supervisor/celery_error.log +#stdout_logfile=/var/log/supervisor/celery.log +#stderr_logfile=/var/log/supervisor/celery_error.log +stdout_logfile=/dev/stdout +stderr_logfile=/dev/stderr startsecs=5 diff --git a/test/smiles_example.csv b/test/smiles_example.csv index 26dbc9b..088841e 100644 --- a/test/smiles_example.csv +++ b/test/smiles_example.csv @@ -1,3 +1,4 @@ SMILES, Name +CC(=O)NCCC1=CNc2c1cc(OC)cc2,Melatonin O=Cc1ccc(O)c(OC)c1,Vanillin -O=Cc1ccc(O)c(OC)c1,Vanillin +