Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added pre-qc-failed status filter #24

Merged
merged 4 commits into from
Jan 15, 2025

Conversation

KateSakharova
Copy link
Contributor

@KateSakharova KateSakharova commented Dec 17, 2024

Added filtering for not re-trying pre-qc failed assemlies and amplicons

@KateSakharova KateSakharova force-pushed the fix/add-pre-qc-failed-filter branch from a9a01d7 to 4dea336 Compare December 17, 2024 14:14
@KateSakharova KateSakharova marked this pull request as ready for review December 17, 2024 14:45
analyses/models.py Outdated Show resolved Hide resolved
Copy link
Member

@mberacochea mberacochea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch.. not sure if we should rename the analyses QC to PRE-QC

analyses/models.py Outdated Show resolved Hide resolved
@@ -126,6 +126,7 @@ def get_assemblies_to_attempt(study: analyses.models.Study) -> List[Union[str, i
**{
f"status__{analyses.models.Assembly.AssemblyStates.ASSEMBLY_COMPLETED}": False,
f"status__{analyses.models.Assembly.AssemblyStates.ASSEMBLY_BLOCKED}": False,
f"status__{analyses.models.Assembly.AssemblyStates.PRE_ASSEMBLY_QC_FAILED}": False,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one should go first; it doesn't change how it works—just improves readability

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A little manager mixin helper would be nice for building these more readably:

class SelectByStatusManagerMixin:
    STATUS_FIELDNAME = "status"
    
    def filter_by_statuses(self, statuses_to_be_true: List[Union[str, Enum]] = None, statuses_to_be_false: List[Union[str, Enum]] = None):
        """
        Filter queryset by a combination of statuses in the objects status json field.
        """
        filters = {}
        if statuses_true:
            filters = {
                f"{self.STATUS_FIELDNAME}__{must_be}": True
                for must_be in statuses_true
            }
        if statuses_false:
            filters.update({
                f"{self.STATUS_FIELDNAME}__{must_not_be}": True
                for must_not_be in statuses_false
            })
        return super().get_queryset().filter(**filters)

Then we can do class AssemblyManager(SelectByStatusManagerMixin, ENADerivedManager): ...

and select more readably, like

assemblies_worth_trying = study.assemblies_reads.filter_by_statuses(
    statuses_to_be_false=[
        analyses.models.Assembly.AssemblyStates.ASSEMBLY_COMPLETED,
        analyses.models.Assembly.AssemblyStates.ASSEMBLY_BLOCKED,
        analyses.models.Assembly.AssemblyStates.PRE_ASSEMBLY_QC_FAILED,
    ]
).values_list("id", flat=True)

(or maybe better yet include an exclude_by_statuses chainable method on the mixin).

Happy to add this later as it will need a couple of new tests. Just documenting whilst it came to mind!

@@ -126,6 +126,7 @@ def get_assemblies_to_attempt(study: analyses.models.Study) -> List[Union[str, i
**{
f"status__{analyses.models.Assembly.AssemblyStates.ASSEMBLY_COMPLETED}": False,
f"status__{analyses.models.Assembly.AssemblyStates.ASSEMBLY_BLOCKED}": False,
f"status__{analyses.models.Assembly.AssemblyStates.PRE_ASSEMBLY_QC_FAILED}": False,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A little manager mixin helper would be nice for building these more readably:

class SelectByStatusManagerMixin:
    STATUS_FIELDNAME = "status"
    
    def filter_by_statuses(self, statuses_to_be_true: List[Union[str, Enum]] = None, statuses_to_be_false: List[Union[str, Enum]] = None):
        """
        Filter queryset by a combination of statuses in the objects status json field.
        """
        filters = {}
        if statuses_true:
            filters = {
                f"{self.STATUS_FIELDNAME}__{must_be}": True
                for must_be in statuses_true
            }
        if statuses_false:
            filters.update({
                f"{self.STATUS_FIELDNAME}__{must_not_be}": True
                for must_not_be in statuses_false
            })
        return super().get_queryset().filter(**filters)

Then we can do class AssemblyManager(SelectByStatusManagerMixin, ENADerivedManager): ...

and select more readably, like

assemblies_worth_trying = study.assemblies_reads.filter_by_statuses(
    statuses_to_be_false=[
        analyses.models.Assembly.AssemblyStates.ASSEMBLY_COMPLETED,
        analyses.models.Assembly.AssemblyStates.ASSEMBLY_BLOCKED,
        analyses.models.Assembly.AssemblyStates.PRE_ASSEMBLY_QC_FAILED,
    ]
).values_list("id", flat=True)

(or maybe better yet include an exclude_by_statuses chainable method on the mixin).

Happy to add this later as it will need a couple of new tests. Just documenting whilst it came to mind!

@SandyRogers
Copy link
Member

@KateSakharova I ended up implementing the suggested SelectByStatusManagerMixin (#24 (comment)) in #28 as I needed to fix another bug with status lookups. You can therefore use that for Assembly state lookups here if you wish

@KateSakharova
Copy link
Contributor Author

@SandyRogers thank you, I will rebase from your branch!

@KateSakharova KateSakharova force-pushed the fix/add-pre-qc-failed-filter branch from 3654927 to 562ba4f Compare January 15, 2025 16:01
@KateSakharova KateSakharova changed the base branch from main to analysis-state-filtering January 15, 2025 16:43
@KateSakharova KateSakharova merged commit 06f5495 into analysis-state-filtering Jan 15, 2025
2 checks passed
@KateSakharova KateSakharova deleted the fix/add-pre-qc-failed-filter branch January 15, 2025 16:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants