diff --git a/analyses/models.py b/analyses/models.py index 9eb3052..1ca7539 100644 --- a/analyses/models.py +++ b/analyses/models.py @@ -207,7 +207,7 @@ def __str__(self): return f"{self.name} {self.version}" if self.version is not None else self.name -class AssemblyManager(ENADerivedManager): +class AssemblyManager(SelectByStatusManagerMixin, ENADerivedManager): def get_queryset(self): return super().get_queryset().select_related("run") @@ -267,6 +267,7 @@ class AssemblyStates(str, Enum): def default_status(cls): return { cls.ASSEMBLY_STARTED: False, + cls.PRE_ASSEMBLY_QC_FAILED: False, cls.ASSEMBLY_FAILED: False, cls.ASSEMBLY_COMPLETED: False, cls.ASSEMBLY_BLOCKED: False, @@ -512,6 +513,7 @@ class AnalysisStates(str, Enum): def default_status(cls): return { cls.ANALYSIS_STARTED: False, + cls.ANALYSIS_QC_FAILED: False, cls.ANALYSIS_COMPLETED: False, cls.ANALYSIS_BLOCKED: False, cls.ANALYSIS_FAILED: False, diff --git a/workflows/flows/analysis_amplicon_study.py b/workflows/flows/analysis_amplicon_study.py index d77f5f6..7e36a6f 100644 --- a/workflows/flows/analysis_amplicon_study.py +++ b/workflows/flows/analysis_amplicon_study.py @@ -62,7 +62,11 @@ def get_analyses_to_attempt( study.refresh_from_db() analyses_worth_trying = ( study.analyses.exclude_by_statuses( - [AnalysisStates.ANALYSIS_COMPLETED, AnalysisStates.ANALYSIS_BLOCKED] + [ + analyses.models.Analysis.AnalysisStates.ANALYSIS_QC_FAILED, + analyses.models.Analysis.AnalysisStates.ANALYSIS_COMPLETED, + analyses.models.Analysis.AnalysisStates.ANALYSIS_BLOCKED, + ] ) .filter(experiment_type=for_experiment_type.value) .order_by("id") @@ -545,7 +549,7 @@ def set_post_analysis_states(amplicon_current_outdir: Path, amplicon_analyses: L if analysis.run.first_accession in qc_failed_runs: task_mark_analysis_status( analysis, - status=AnalysisStates.ANALYSIS_FAILED, + status=AnalysisStates.ANALYSIS_QC_FAILED, reason=qc_failed_runs[analysis.run.first_accession], ) elif analysis.run.first_accession in qc_completed_runs: diff --git a/workflows/flows/assemble_study.py b/workflows/flows/assemble_study.py index 8722b2b..92fa782 100644 --- a/workflows/flows/assemble_study.py +++ b/workflows/flows/assemble_study.py @@ -122,11 +122,12 @@ def get_assemblies_to_attempt(study: analyses.models.Study) -> List[Union[str, i :return: """ study.refresh_from_db() - assemblies_worth_trying = study.assemblies_reads.filter( - **{ - f"status__{analyses.models.Assembly.AssemblyStates.ASSEMBLY_COMPLETED}": False, - f"status__{analyses.models.Assembly.AssemblyStates.ASSEMBLY_BLOCKED}": False, - } + assemblies_worth_trying = study.assemblies_reads.exclude_by_statuses( + [ + analyses.models.Assembly.AssemblyStates.PRE_ASSEMBLY_QC_FAILED, + analyses.models.Assembly.AssemblyStates.ASSEMBLY_COMPLETED, + analyses.models.Assembly.AssemblyStates.ASSEMBLY_BLOCKED, + ] ).values_list("id", flat=True) return assemblies_worth_trying diff --git a/workflows/tests/test_analysis_amplicon_study_flow.py b/workflows/tests/test_analysis_amplicon_study_flow.py index a0452a1..99a31fa 100644 --- a/workflows/tests/test_analysis_amplicon_study_flow.py +++ b/workflows/tests/test_analysis_amplicon_study_flow.py @@ -505,7 +505,7 @@ async def test_prefect_analyse_amplicon_flow( # check failed runs assert ( await analyses.models.Analysis.objects.filter( - status__analysis_failed=True + status__analysis_qc_failed=True ).acount() == 1 )