Skip to content

Commit

Permalink
Deprecated AnalysisJobAnn
Browse files Browse the repository at this point in the history
  • Loading branch information
MGS-sails committed Sep 30, 2023
1 parent 4cd7721 commit 665a056
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 101 deletions.
25 changes: 25 additions & 0 deletions emgapi/migrations/0012_auto_20230929_1959.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 3.2.18 on 2023-09-29 19:59

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('emgapi', '0011_analysisjob_analysis_summary_json'),
]

operations = [
# migrations.SeparateDatabaseAndState(
# state_operations=[
# migrations.RenameField(
# model_name='analysisjob',
# old_name='analysis_summary_json',
# new_name='analysis_summary',
# ),
# ],
# ),
migrations.DeleteModel(
name='AnalysisJobAnn',
),
]
16 changes: 0 additions & 16 deletions emgapi/migrations/0012_delete_analysisjobann.py

This file was deleted.

95 changes: 14 additions & 81 deletions emgapi/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1474,49 +1474,15 @@ def available(self, request=None):

class AnalysisJobManager(models.Manager):
def get_queryset(self):
"""Customized Analysis Job QS.
There are 2 very custom bits here:
straight_join
-------------
This one is needed because of a mysql bug that causes the optimizer
to https://code.djangoproject.com/ticket/22438
force_index
-----------
This one is more of a mistery to me. The join with PIPELINE_RELEASE
is causing a full table scan on PIPELINE_RELEASE.
| id | select\_type | table | type | possible\_keys | key | key\_len | ref | rows | filtered | Extra |
| :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- |
| 1 | SIMPLE | PIPELINE\_RELEASE | ALL | PRIMARY,PIPELINE\_RELEASE\_PIPELINE\_ID\_RELEASE\_VERSION\_d40fe384\_uniq,PIPELINE\_RELEASE\_PIPELINE\_ID\_index | NULL | NULL | NULL | 6 | 83.33 | Using where; Using join buffer \(Block Nested Loop\) |
By forcing the index PRIMARY on the JOIN the query is faster:
| id | select\_type | table | type | possible\_keys | key | key\_len | ref | rows | filtered | Extra |
| :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- |
| 1 | SIMPLE | PIPELINE\_RELEASE | eq\_ref | PRIMARY | PRIMARY | 2 | emg.ANALYSIS\_JOB.PIPELINE\_ID | 1 | 100 | NULL |
IMPORTANT: it is also required that the ordering of the query set is done by ANALYSIS_JOB.PIPELINE_ID and not a
field of PIPELINE_RELEASE. This was changes in emgapi.viewsets.BaseAnalysisGenericViewSet.ordering
# TODO: figure our what is going on with this query.
# """
# _qs = AnalysisJobAnn.objects.all() \
# .select_related('var')
# return AnalysisJobQuerySet(self.model, using=self._db) \
# .straight_join() \
# .force_index("PRIMARY", table_name="PIPELINE_RELEASE", for_="JOIN") \
# .select_related(
# 'analysis_status',
# 'experiment_type',
# 'run',
# 'study',
# 'assembly',
# 'pipeline',
# 'sample') \
# .prefetch_related(
# Prefetch('analysis_metadata', queryset=_qs),)
return AnalysisJobQuerySet(self.model, using=self._db) \
.select_related(
'analysis_status',
'experiment_type',
'run',
'study',
'assembly',
'pipeline',
'sample')

def available(self, request):
return self.get_queryset().available(request) \
Expand Down Expand Up @@ -1559,7 +1525,7 @@ def _custom_pk(self):
blank=True, null=True)
job_operator = models.CharField(
db_column='JOB_OPERATOR', max_length=15, blank=True, null=True)
analysis_summary_json = models.JSONField(
analysis_summary = models.JSONField(
db_column='ANALYSIS_SUMMARY_JSON', blank=True, null=True)
pipeline = models.ForeignKey(
Pipeline, db_column='PIPELINE_ID', blank=True, null=True,
Expand Down Expand Up @@ -1605,19 +1571,6 @@ def _custom_pk(self):
@property
def release_version(self):
return self.pipeline.release_version

@property
def analysis_summary(self):
if self.analysis_summary_json:
return self.analysis_summary_json

return [
{
'key': v.var.var_name,
'value': v.var_val_ucv
} for v in self.analysis_metadata.all()
]

@property
def downloads(self):
return self.analysis_download.all()
Expand Down Expand Up @@ -1760,31 +1713,11 @@ class Meta:

def __str__(self):
return self.var_name
def __str__(self):
return '%s %s' % (self.job, self.var)


# class AnalysisJobAnnManager(models.Manager):
#
# def get_queryset(self):
# return super().get_queryset().select_related('job', 'var')


# class AnalysisJobAnn(models.Model):
# job = models.ForeignKey(AnalysisJob, db_column='JOB_ID', related_name='analysis_metadata', on_delete=models.CASCADE)
# units = models.CharField(db_column='UNITS', max_length=25, blank=True, null=True)
# var = models.ForeignKey(AnalysisMetadataVariableNames, on_delete=models.CASCADE)
# var_val_ucv = models.CharField(db_column='VAR_VAL_UCV', max_length=4000, blank=True, null=True)
#
# objects = AnalysisJobAnnManager()
#
# class Meta:
# db_table = 'ANALYSIS_JOB_ANN'
# unique_together = (('job', 'var'), ('job', 'var'),)
#
# def __str__(self):
# return '%s %s' % (self.job, self.var)
#
# def multiple_pk(self):
# return '%s/%s' % (self.var.var_name, self.var_val_ucv)
def multiple_pk(self):
return '%s/%s' % (self.var.var_name, self.var_val_ucv)


class CogCat(models.Model):
Expand Down
3 changes: 1 addition & 2 deletions emgapi/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1020,8 +1020,7 @@ class Meta:
'secondary_accession',
'is_suppressed',
'suppressed_at',
'suppression_reason',
'analysis_summary_json'
'suppression_reason'
)


Expand Down
4 changes: 2 additions & 2 deletions emgapianns/management/commands/import_qc.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,10 @@ def import_orf_stats(rootpath, job, emg_db):

@staticmethod
def update_analysis_summary(job, var_key, var_value):
analysis_summary = job.analysis_summary_json or []
analysis_summary = job.analysis_summary or []
analysis_summary.append({
'key': var_key,
'value': var_value,
})
job.analysis_summary_json = analysis_summary
job.analysis_summary = analysis_summary
job.save()

0 comments on commit 665a056

Please sign in to comment.