def test_get_up_to_date_assembly_annotation_jobs_should_retrieve_all_jobs_in_priority_order(self): study = mgnify.create_study_obj(study_data) accessions = ['ERZ795049', 'ERZ795050'] assemblies = [] for accession in accessions: data = copy.deepcopy(assembly_data) data['analysis_accession'] = accession assemblies.append(mgnify.get_or_save_assembly(ena, accession, data, study)) pipeline = Pipeline(version=4.1) pipeline.save() pipeline = Pipeline(version=5.0) pipeline.save() user = mgnify.create_user(user_data['webin_id'], user_data['email_address'], user_data['first_name'], user_data['surname']) request = mgnify.create_user_request(user, 0, 1) assert 0 == len(AnnotationJob.objects.all()) mgnify.create_annotation_job(request, assemblies[0], 0, 4.1) mgnify.create_annotation_job(request, assemblies[1], 1) up_to_date_assemblies_latest = mgnify.get_up_to_date_assembly_annotation_jobs( study_data['secondary_study_accession']) assert 1 == len(up_to_date_assemblies_latest) up_to_date_assemblies_v4 = mgnify.get_up_to_date_assembly_annotation_jobs( study_data['secondary_study_accession'], 4.1) assert 1 == len(up_to_date_assemblies_v4) up_to_date_assemblies_v5 = mgnify.get_up_to_date_assembly_annotation_jobs( study_data['secondary_study_accession'], 5) assert 1 == len(up_to_date_assemblies_v5)
def create_annotation_jobs_without_ena_services(rt_ticket=0, priority=0): study = mgnify.create_study_obj(study_data) run_accessions = ['ERR164407', 'ERR164408', 'ERR164409'] for run_acc in run_accessions: run_data["run_accession"] = run_acc mgnify.create_run_obj(study, run_data) pipeline = Pipeline(version=4.1) pipeline.save() user = mgnify.create_user(user_data['webin_id'], user_data['email_address'], user_data['first_name'], user_data['surname']) request = mgnify.create_user_request(user, priority, rt_ticket) runs = [] for run_acc in run_accessions: run = mgnify.get_backlog_run(run_acc) runs.append(run) mgnify.create_annotation_job(request, run, 4) return study, runs
def test_create_annotation_job_should_create_annotationjob_for_assembly(self): study = mgnify.create_study_obj(study_data) assembly = mgnify.create_assembly_obj(ena, study, assembly_data, public=True) Pipeline(version=4.1).save() user = User(**user_data) user.save() request = UserRequest(user=user, rt_ticket=1234, priority=1) request.save() inserted_annotation_job = mgnify.create_annotation_job(request, assembly, 1) retrieved_annotation_jobs = AnnotationJob.objects.all() assert len(retrieved_annotation_jobs) == 1 retrieved_annotation_job = retrieved_annotation_jobs[0] assert inserted_annotation_job.pk == retrieved_annotation_job.pk related_assemblies = retrieved_annotation_job.assemblyannotationjob_set.all() assert len(related_assemblies) == 1 assert isinstance(related_assemblies[0].assembly, Assembly) assert related_assemblies[0].assembly.pk == assembly.pk
def test_create_annotation_job_should_create_annotationjob_for_run(self): study = mgnify.create_study_obj(study_data) run = mgnify.create_run_obj(study, run_data) Pipeline(version=4.1).save() user = User(**user_data) user.save() request = UserRequest(user=user, rt_ticket=1234, priority=1) request.save() inserted_annotation_job = mgnify.create_annotation_job(request, run, 1) retrieved_annotation_jobs = AnnotationJob.objects.all() assert len(retrieved_annotation_jobs) == 1 retrieved_annotation_job = retrieved_annotation_jobs[0] assert inserted_annotation_job.pk == retrieved_annotation_job.pk related_runs = retrieved_annotation_job.runannotationjob_set.all() assert len(related_runs) == 1 assert isinstance(related_runs[0].run, Run) assert related_runs[0].run.pk == run.pk
def test_update_annotation_jobs_should_update_by_pipeline_version_only(self): rt_ticket = 0 initial_priority = 1 initial_status = AnnotationJobStatus.objects.get(description='SCHEDULED') final_priority = 2 final_status_description = 'RUNNING' new_pipeline_version = 5.0 assert len(AnnotationJob.objects.all()) == 0 create_annotation_jobs_using_ena_services(rt_ticket, initial_priority) assert len(AnnotationJob.objects.all()) == 3 Pipeline(version=new_pipeline_version).save() request = UserRequest.objects.first() for run in Run.objects.all(): mgnify.create_annotation_job(request=request, assembly_or_run=run, priority=initial_priority) assert len(AnnotationJob.objects.all()) == 6 initial_jobs = AnnotationJob.objects.all() for job in initial_jobs: assert job.priority == initial_priority assert job.status == initial_status mgnify.update_annotation_jobs_from_accessions(priority=final_priority, status_description=final_status_description, pipeline_version=new_pipeline_version) final_jobs = AnnotationJob.objects.all() assert len(initial_jobs) == len(final_jobs) for job in final_jobs: if job.pipeline.version == new_pipeline_version: assert job.priority == final_priority assert job.status.description == final_status_description else: assert job.priority == initial_priority assert job.status == initial_status
def create_annotation_jobs_using_ena_services(rt_ticket=0, priority=0, version=4.1): study = mgnify.create_study_obj(study_data) accessions = ['ERR164407', 'ERR164408', 'ERR164409'] lineage = 'root:Host-Associated:Human:Digestive System' runs = [mgnify.get_or_save_run(ena, accession, study=study, lineage=lineage) for accession in accessions] versions = [1.0, 2.0, 3.0, 4.0, 4.1, 5.0] for _version in versions: Pipeline(version=_version).save() user = mgnify.create_user(user_data['webin_id'], user_data['email_address'], user_data['first_name'], user_data['surname']) request = mgnify.create_user_request(user, priority, rt_ticket) assert len(AnnotationJob.objects.all()) == 0 mgnify.create_annotation_job(request, runs[0], priority, version) # 4.1 mgnify.create_annotation_job(request, runs[1], priority, version) # 4.1 mgnify.create_annotation_job(request, runs[2], priority) # latest pipeline version return study, runs
def test_get_pipeline_by_version_should_return_correct_pipeline(self): versions = [1.0, 2.0, 3.0, 4.0, 4.1, 5.0] for version in versions: Pipeline(version=version).save() assert mgnify.get_pipeline_by_version(5.0).version == 5.0
def test_get_latest_pipeline_should_return_latest_pipeline(self): versions = [1.0, 2.0, 3.0, 4.0, 4.1] for version in versions: Pipeline(version=version).save() assert mgnify.get_latest_pipeline().version == max(versions)