Skip to content

Commit

Permalink
Suppression propagation fixes (#344)
Browse files Browse the repository at this point in the history
* fixes progress logging in ena sync scripts

* do not return suppressed study/samples etc

* fixes typo

* 2.4.39
  • Loading branch information
SandyRogers authored Jan 15, 2024
1 parent d2c0a28 commit c00eb19
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 24 deletions.
37 changes: 21 additions & 16 deletions emgapi/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,73 +300,78 @@ def available(self, request=None):
"""
_query_filters = {
'StudyQuerySet': {
'all': [Q(is_private=False),],
'all': [Q(is_private=False, is_suppressed=False),],
},
'StudyDownloadQuerySet': {
'all': [Q(study__is_private=False),],
'all': [Q(study__is_private=False, study__is_suppressed=False),],
},
'SampleQuerySet': {
'all': [Q(is_private=False),],
'all': [Q(is_private=False, is_suppressed=False),],
},
'RunQuerySet': {
'all': [
Q(is_private=False),
Q(is_private=False, is_suppressed=False),
],
},
'AssemblyQuerySet': {
'all': [
Q(is_private=False),
Q(is_private=False, is_suppressed=False),
],
},
'AnalysisJobDownloadQuerySet': {
'all': [
Q(job__study__is_private=False),
Q(job__study__is_private=False, job__study__is_suppressed=False),
Q(job__run__is_private=False) | Q(job__assembly__is_private=False),
Q(job__analysis_status_id=AnalysisStatus.COMPLETED) | Q(job__analysis_status_id=AnalysisStatus.QC_NOT_PASSED)
],
},
'AssemblyExtraAnnotationQuerySet': {
'all': [
Q(assembly__is_private=False),
Q(assembly__is_private=False, assembly__is_suppressed=False),
],
},
'RunExtraAnnotationQuerySet': {
'all': [
Q(run__is_private=False),
Q(run__is_private=False, run__is_suppressed=False),
],
},
}

if request is not None and request.user.is_authenticated:
_username = request.user.username
_query_filters['StudyQuerySet']['authenticated'] = \
[Q(submission_account_id__iexact=_username) | Q(is_private=False)]
[Q(submission_account_id__iexact=_username) | Q(is_private=False, is_suppressed=False)]
_query_filters['StudyDownloadQuerySet']['authenticated'] = \
[Q(study__submission_account_id__iexact=_username) |
Q(study__is_private=False)]
Q(study__is_private=False, study__is_suppressed=False)]
_query_filters['SampleQuerySet']['authenticated'] = \
[Q(submission_account_id__iexact=_username) | Q(is_private=False)]
[Q(submission_account_id__iexact=_username) | Q(is_private=False), Q(is_suppressed=False)]
_query_filters['RunQuerySet']['authenticated'] = \
[Q(study__submission_account_id__iexact=_username, is_private=True) |
Q(is_private=False)]
Q(is_private=False),
Q(is_suppressed=False)]
_query_filters['AssemblyQuerySet']['authenticated'] = \
[Q(samples__studies__submission_account_id__iexact=_username,
is_private=True) |
Q(is_private=False)]
Q(is_private=False),
Q(is_suppressed=False)]
_query_filters['AnalysisJobDownloadQuerySet']['authenticated'] = \
[Q(job__study__submission_account_id__iexact=_username,
job__is_private=True) |
Q(job__study__submission_account_id__iexact=_username,
job__assembly__is_private=True) |
Q(job__run__is_private=False) | Q(job__assembly__is_private=False)]
Q(job__run__is_private=False) | Q(job__assembly__is_private=False),
Q(job__is_suppressed=False)]
_query_filters['AssemblyExtraAnnotationQuerySet']['authenticated'] = \
[Q(assembly__samples__studies__submission_account_id__iexact=_username,
is_private=True) |
Q(assembly__is_private=False)]
Q(assembly__is_private=False),
Q(assembly__is_suppressed=False)]
_query_filters['RunExtraAnnotationQuerySet']['authenticated'] = \
[Q(run__samples__studies__submission_account_id__iexact=_username,
is_private=True) |
Q(run__is_private=False)]
Q(run__is_private=False),
Q(run__is_suppressed=False)]

filters = _query_filters.get(self.__class__.__name__)

Expand Down
2 changes: 1 addition & 1 deletion emgcli/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__: str = "2.4.38"
__version__: str = "2.4.39"
2 changes: 1 addition & 1 deletion emgena/management/commands/sync_assemblies_with_ena.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def handle(self, *args, **kwargs):
emg_assemblies_batch,
["is_private", "is_suppressed", "suppression_reason", "suppressed_at"],
)
logging.info(f"Batch {round(assemblies_count / batch_size)} processed.")
logging.info(f"Batch {round(offset / batch_size)} of {round(assemblies_count / batch_size)} processed.")
offset += batch_size

logging.info("Completed")
2 changes: 1 addition & 1 deletion emgena/management/commands/sync_runs_with_ena.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def handle(self, *args, **kwargs):
emg_runs_batch,
["is_private", "is_suppressed", "suppression_reason", "suppressed_at"],
)
logging.info(f"Batch {round(runs_count / batch_size)} processed.")
logging.info(f"Batch {round(offset / batch_size)} of {round(runs_count / batch_size)} processed.")
offset += batch_size

logging.info("Completed")
2 changes: 1 addition & 1 deletion emgena/management/commands/sync_samples_with_ena.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def handle(self, *args, **kwargs):
emg_samples_batch,
["is_private", "is_suppressed", "suppression_reason", "suppressed_at"],
)
logging.info(f"Batch {round(samples_count / batch_size)} processed.")
logging.info(f"Batch {round(offset / batch_size)} of {round(samples_count / batch_size)} processed.")
offset += batch_size

logging.info("Completed")
2 changes: 1 addition & 1 deletion emgena/management/commands/sync_studies_with_ena.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def handle(self, *args, **kwargs):
"public_release_date",
],
)
logging.info(f"Batch {round(studies_count / batch_size)} processed.")
logging.info(f"Batch {round(offset / batch_size)} of {round(studies_count / batch_size)} processed.")
offset += batch_size

logging.info("Completed")
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ max-line-length = 119
"""

[tool.bumpversion]
current_version = "2.4.38"
current_version = "2.4.39"

[[tool.bumpversion.files]]
filename = "emgcli/__init__.py"
2 changes: 0 additions & 2 deletions tests/ena/test_sync_samples_with_ena.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@
# limitations under the License.

import pytest
import os

from unittest.mock import patch

from django.urls import reverse
from django.core.management import call_command
from emgapi.models import Sample, Assembly, AnalysisJob, Run

Expand Down
7 changes: 7 additions & 0 deletions tests/ena/test_sync_studies_with_ena.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ def test_make_studies_private(self, ena_study_objs_mock, ena_private_studies):
if study in public_studies:
assert study.is_private == True

assert Study.objects.available(None).count() == 0


@patch("emgena.models.Study.objects")
def test_make_studies_public(self, ena_study_objs_mock, ena_public_studies):
ena_study_objs_mock.using("era").filter.return_value = ena_public_studies
Expand All @@ -67,6 +70,8 @@ def test_make_studies_public(self, ena_study_objs_mock, ena_public_studies):
if study in private_studies:
assert study.is_private == False

assert Study.objects.available(None).count() == all_studies.count()

@patch("emgena.models.Study.objects")
def test_suppress_studies(self, ena_study_objs_mock, ena_suppressed_studies):
ena_study_objs_mock.using("era").filter.return_value = ena_suppressed_studies
Expand Down Expand Up @@ -94,6 +99,8 @@ def test_suppress_studies(self, ena_study_objs_mock, ena_suppressed_studies):
== study.get_suppression_reason_display().lower()
)

assert Study.objects.available(None).count() == 0

@patch("emgena.models.Study.objects")
def test_suppress_studies_propagation(self, ena_study_objs_mock, ena_suppression_propagation_studies):
ena_study_objs_mock.using("era").filter.return_value = ena_suppression_propagation_studies
Expand Down

0 comments on commit c00eb19

Please sign in to comment.