diff --git a/.gitignore b/.gitignore index 9d63e9a6..a978cd5f 100644 --- a/.gitignore +++ b/.gitignore @@ -223,4 +223,6 @@ cython_debug/ # IntelliJ like IDEs (e.g. PyCharm) .idea -tmp* \ No newline at end of file +tmp* +container/nease_events + diff --git a/container/domain/Process/nease_output.py b/container/domain/Process/nease_output.py index aae753fd..2d3b2483 100644 --- a/container/domain/Process/nease_output.py +++ b/container/domain/Process/nease_output.py @@ -1,3 +1,4 @@ +import json import pickle import traceback from io import StringIO @@ -8,6 +9,7 @@ from matplotlib import pyplot as plt +from domain.models import NeaseSaveLocationMapping from domain.nease import nease from domain.nease.process import webify_table from django.conf import settings @@ -16,12 +18,14 @@ images_path = os.path.join(settings.MEDIA_ROOT, 'images/') data_path = os.path.join(settings.MEDIA_ROOT, 'nease_tables/') nease_path = 'nease_events/' +# The subdirectories contain files saved for one week, one month, and six months. To be very lenient, we calculated every month with 31 days. +days_to_folder = {"0": nease_path+"zero_days/", "7": nease_path+"seven_days/", "31": nease_path+"thirtyone_days/", "186": nease_path+"onehundredeightysix_days/"} +default_path = days_to_folder["7"] -for path in [images_path, data_path, nease_path]: +for path in [images_path, data_path] + list(days_to_folder.values()): if not os.path.exists(path): os.makedirs(path) - # web_tables_options is a dictionary that contains the options for webifying the tables web_tables_options = { 'domains': {'link_col': ['Gene name', 'Gene stable ID', 'Exon stable ID', 'Pfam ID'], @@ -50,7 +54,7 @@ } -def run_nease(data, organism, params): +def run_nease(data, organism, params, file_name='', custom_name=''): run_id = str(uuid.uuid4()) image_path = images_path + run_id @@ -97,7 +101,8 @@ def run_nease(data, organism, params): value.drop(columns=['Unnamed: 0'], inplace=True) # save events to pickle - events.save(nease_path + run_id) + events.save(default_path + run_id) + NeaseSaveLocationMapping(run_id=run_id, saved_for_days=7, file_name=file_name, custom_name=custom_name).save() return events, info_tables, run_id @@ -126,7 +131,13 @@ def read_extra_spaces(file_obj): def get_nease_events(run_id): - events = nease.load(nease_path + run_id + '.pkl') + days = NeaseSaveLocationMapping.get_saved_for_days(run_id) + if days not in days_to_folder: + file_path = default_path + else: + file_path = days_to_folder[str(days)] + print(f"Loading events from {file_path + run_id + '.pkl'}") + events = nease.load(file_path + run_id + '.pkl') info_tables = {} try: domains = webify_table(pd.read_csv(f"{data_path}{run_id}_domains.csv"), web_tables_options['domains']) @@ -243,6 +254,27 @@ def create_plot(terms, pvalues, cut_off, filename): plt.clf() plt.close() +def change_save_timing(run_id, days): + mapping = NeaseSaveLocationMapping.objects.get(run_id=run_id) + current_days_folder = mapping.get_number_of_saved_for_days() + if days not in days_to_folder: + new_file_path = default_path + else: + new_file_path = days_to_folder[str(days)] + if current_days_folder not in days_to_folder: + old_file_path = default_path + else: + old_file_path = days_to_folder[str(current_days_folder)] + # move the file + os.rename(old_file_path + run_id + '.pkl', new_file_path + run_id + '.pkl') + # update the database + mapping.saved_for_days = int(days) + mapping.save() + + return json.dumps( + {"logmessage": "Changing the save timing from " + str(current_days_folder) + " to " + str(days) + " was successful.", + "days_left": mapping.days_left()} + ) def match_name_with_format(filename): name_matches = {'deltapsi': 'MAIJQ', diff --git a/container/domain/migrations/0001_initial.py b/container/domain/migrations/0001_initial.py new file mode 100644 index 00000000..b3ff3ff7 --- /dev/null +++ b/container/domain/migrations/0001_initial.py @@ -0,0 +1,38 @@ +# Generated by Django 2.2.28 on 2024-09-09 12:32 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Domain', + fields=[ + ('pfam_id', models.CharField(db_index=True, max_length=10, primary_key=True, serialize=False)), + ('symbol', models.CharField(max_length=20)), + ('description', models.CharField(max_length=150)), + ], + ), + migrations.CreateModel( + name='Gene', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('ensembl_id', models.CharField(max_length=20)), + ('gene_symbol', models.CharField(db_index=True, max_length=20)), + ], + ), + migrations.CreateModel( + name='NeaseSaveLocationMapping', + fields=[ + ('run_id', models.CharField(db_index=True, max_length=36, primary_key=True, serialize=False)), + ('saved_for_days', models.IntegerField()), + ('date_of_creation', models.DateTimeField(auto_now_add=True)), + ], + ), + ] diff --git a/container/domain/migrations/0002_neasesavelocationmapping_name.py b/container/domain/migrations/0002_neasesavelocationmapping_name.py new file mode 100644 index 00000000..d9b67b54 --- /dev/null +++ b/container/domain/migrations/0002_neasesavelocationmapping_name.py @@ -0,0 +1,18 @@ +# Generated by Django 2.2.28 on 2024-09-09 13:22 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('domain', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='neasesavelocationmapping', + name='name', + field=models.CharField(default='', max_length=255), + ), + ] diff --git a/container/domain/migrations/0003_auto_20240910_1357.py b/container/domain/migrations/0003_auto_20240910_1357.py new file mode 100644 index 00000000..d3bab534 --- /dev/null +++ b/container/domain/migrations/0003_auto_20240910_1357.py @@ -0,0 +1,27 @@ +# Generated by Django 2.2.28 on 2024-09-10 11:57 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('domain', '0002_neasesavelocationmapping_name'), + ] + + operations = [ + migrations.RemoveField( + model_name='neasesavelocationmapping', + name='name', + ), + migrations.AddField( + model_name='neasesavelocationmapping', + name='custom_name', + field=models.CharField(default='', max_length=255), + ), + migrations.AddField( + model_name='neasesavelocationmapping', + name='file_name', + field=models.CharField(default='', max_length=255), + ), + ] diff --git a/container/domain/migrations/__init__.py b/container/domain/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/container/domain/models.py b/container/domain/models.py index e80be743..794fd663 100644 --- a/container/domain/models.py +++ b/container/domain/models.py @@ -1,4 +1,5 @@ from django.db import models +from django.utils import timezone class Gene(models.Model): @@ -16,3 +17,28 @@ class Domain(models.Model): #def __str__(self): # return f"Pfam: {self.pfam_id} - Symbol: {self.symbol}" + +class NeaseSaveLocationMapping(models.Model): + run_id = models.CharField(max_length=36, primary_key=True, db_index=True) + saved_for_days = models.IntegerField() + date_of_creation = models.DateTimeField(auto_now_add=True) + file_name = models.CharField(max_length=255, default='') + custom_name = models.CharField(max_length=255, default='') + + # Method to query the database for the run_id and return the saved_for_days + @staticmethod + def get_saved_for_days(run_id): + return str(NeaseSaveLocationMapping.objects.get(run_id=run_id).saved_for_days) + + def get_number_of_saved_for_days(self): + return str(self.saved_for_days) + + # Calculate how many days are left until deletion, negative values are set to 0 + def days_left(self): + return max(0, self.saved_for_days - (timezone.now() - self.date_of_creation).days) + + # Get the custom name and return None if it is empty + def get_custom_name(self): + if self.custom_name == '': + return None + return self.custom_name diff --git a/container/domain/static/domain/initStore.js b/container/domain/static/domain/initStore.js index 9f4afc85..1147d361 100644 --- a/container/domain/static/domain/initStore.js +++ b/container/domain/static/domain/initStore.js @@ -100,7 +100,7 @@ const newValue = value == null ? null - : { value, expiresAt: getExpiration(expiresInDays), name } + : { value, expiresAt: getExpiration(expiresInDays), name , createdAt: Date.now()} setExpiration(newValue?.expiresAt) storage.set(prefixedKey, newValue) }, diff --git a/container/domain/static/domain/loadStore.js b/container/domain/static/domain/loadStore.js index ffc3f6a3..4536d9d6 100644 --- a/container/domain/static/domain/loadStore.js +++ b/container/domain/static/domain/loadStore.js @@ -16,16 +16,16 @@ function removeExpiredData(key) { } // Function to create an HTML template -function createHtmlTemplate(data, expiresInDays = 7) { +function createHtmlTemplate(data) { // subtract 7 days from the expiry date - const createdDate = new Date(data.expiresAt) - (expiresInDays * 24 * 60 * 60 * 1000); + const createdDate = new Date(data.createdAt); // format to readable date const formattedDate = new Date(createdDate).toLocaleString(); return `
●
@@ -49,8 +49,7 @@ function appendTemplateToDiv(template, divId) { } } -function prevAnalysis(id, name) { +function prevAnalysis(id) { document.getElementById('previous_analyses_input').value = id; - document.getElementById('previous_analyses_name').value = name; document.getElementById('submit').click(); } diff --git a/container/domain/static/image/Isoform_mode.svg b/container/domain/static/image/Isoform_mode.svg index c4dff247..17ee6be3 100644 --- a/container/domain/static/image/Isoform_mode.svg +++ b/container/domain/static/image/Isoform_mode.svg @@ -2,23 +2,23 @@ diff --git a/container/domain/static/image/exon_page.svg b/container/domain/static/image/exon_page.svg index 5f37defe..e60fd152 100644 --- a/container/domain/static/image/exon_page.svg +++ b/container/domain/static/image/exon_page.svg @@ -2,23 +2,23 @@ diff --git a/container/domain/static/image/nease_page.png b/container/domain/static/image/nease_page.png index 792e5789..7de7df7b 100644 Binary files a/container/domain/static/image/nease_page.png and b/container/domain/static/image/nease_page.png differ diff --git a/container/domain/static/image/net_page.svg b/container/domain/static/image/net_page.svg index 52d09dc0..fc834c44 100644 --- a/container/domain/static/image/net_page.svg +++ b/container/domain/static/image/net_page.svg @@ -2,23 +2,23 @@ diff --git a/container/domain/templates/setup/nease_setup.html b/container/domain/templates/setup/nease_setup.html index 64928a3b..5207f765 100644 --- a/container/domain/templates/setup/nease_setup.html +++ b/container/domain/templates/setup/nease_setup.html @@ -219,7 +219,6 @@