Esempio n. 1
0
def test_get_case_files_from_version(
    analysis_store: Store,
    case_id: str,
    real_housekeeper_api: HousekeeperAPI,
    case_hk_bundle_no_files: dict,
    bed_file: str,
    vcf_file: Path,
    project_dir: Path,
    helpers=StoreHelpers,
):
    # GIVEN a store with a case
    case_obj = analysis_store.family(case_id)
    assert case_obj.internal_id == case_id
    # GIVEN a delivery api
    deliver_api = DeliverAPI(
        store=analysis_store,
        hk_api=real_housekeeper_api,
        case_tags=[{"case-tag"}],
        sample_tags=[{"sample-tag"}],
        project_base_path=project_dir,
        delivery_type="balsamic",
    )

    # GIVEN a housekeeper db populated with a bundle including a case specific file and a sample specific file
    case_hk_bundle_no_files["files"] = [
        {
            "path": bed_file,
            "archive": False,
            "tags": ["case-tag"]
        },
        {
            "path": str(vcf_file),
            "archive": False,
            "tags": ["sample-tag", "ADM1"]
        },
    ]
    helpers.ensure_hk_bundle(real_housekeeper_api,
                             bundle_data=case_hk_bundle_no_files)

    # GIVEN a version object where two file exists
    version_obj: hk_models.Version = real_housekeeper_api.last_version(case_id)
    assert len(version_obj.files) == 2

    # GIVEN the sample ids of the samples
    link_objs: List[FamilySample] = analysis_store.family_samples(case_id)
    samples: List[Sample] = [link.sample for link in link_objs]
    sample_ids: Set[str] = set([sample.internal_id for sample in samples])

    # WHEN fetching the case files
    case_files = deliver_api.get_case_files_from_version(
        version_obj=version_obj, sample_ids=sample_ids)

    # THEN we should only get the case specific files back
    nr_files: int = 0
    case_file: Path
    for nr_files, case_file in enumerate(case_files, 1):
        assert case_file.name == Path(bed_file).name
    # THEN assert that only the case-tag file was returned
    assert nr_files == 1
Esempio n. 2
0
def fixture_mip_dna_housekeeper(
    real_housekeeper_api: HousekeeperAPI,
    mip_delivery_bundle: dict,
    fastq_delivery_bundle: dict,
    helpers: StoreHelpers,
) -> HousekeeperAPI:
    helpers.ensure_hk_bundle(real_housekeeper_api,
                             bundle_data=mip_delivery_bundle)
    helpers.ensure_hk_bundle(real_housekeeper_api,
                             bundle_data=fastq_delivery_bundle)
    # assert that the files exists
    version_obj_mip: hk_models.Version = real_housekeeper_api.last_version(
        mip_delivery_bundle["name"])
    version_obj_fastq: hk_models.Version = real_housekeeper_api.last_version(
        fastq_delivery_bundle["name"])
    real_housekeeper_api.include(version_obj=version_obj_mip)
    real_housekeeper_api.include(version_obj=version_obj_fastq)

    return real_housekeeper_api
Esempio n. 3
0
def fixture_upload_genotypes_hk_api(
    real_housekeeper_api: HousekeeperAPI,
    upload_genotypes_hk_bundle: dict,
    analysis_obj: models.Analysis,
    helpers,
) -> HousekeeperAPI:
    """Add and include files from upload genotypes hk bundle"""
    helpers.ensure_hk_bundle(real_housekeeper_api, upload_genotypes_hk_bundle)
    hk_version = real_housekeeper_api.last_version(
        analysis_obj.family.internal_id)
    real_housekeeper_api.include(hk_version)
    return real_housekeeper_api
Esempio n. 4
0
    def get_delivery_report_from_hk(hk_api: HousekeeperAPI, case_id: str) -> str:
        delivery_report_tag_name = "delivery-report"
        version_obj = hk_api.last_version(case_id)
        uploaded_delivery_report_files = hk_api.get_files(
            bundle=case_id,
            tags=[delivery_report_tag_name],
            version=version_obj.id,
        )

        if uploaded_delivery_report_files.count() == 0:
            raise FileNotFoundError(f"No delivery report was found in housekeeper for {case_id}")

        return uploaded_delivery_report_files[0].full_path
Esempio n. 5
0
def _get_multiqc_latest_file(hk_api: HousekeeperAPI, case_name: str) -> str:
    """Get latest multiqc_data.json path for a case_name
    Args:
        case_name(str): onemite
    Returns:
        multiqc_data_path(str): /path/to/multiqc.json
    """
    version_obj = hk_api.last_version(case_name)
    multiqc_json_file = hk_api.get_files(
        bundle=case_name, tags=["multiqc-json"], version=version_obj.id
    )

    if len(list(multiqc_json_file)) == 0:
        raise FileNotFoundError(f"No multiqc.json was found in housekeeper for {case_name}")

    return multiqc_json_file[0].full_path
Esempio n. 6
0
def get_versions(hk_api: HousekeeperAPI,
                 bundle_name: str = None) -> Iterator[hk_models.Version]:
    """Generates versions from hk bundles

    If no bundle name is given generate latest version for every bundle
    """
    if bundle_name:
        bundle = hk_api.bundle(bundle_name)
        if not bundle:
            LOG.info("Could not find bundle %s", bundle_name)
            return
        bundles = [bundle]
    else:
        bundles = hk_api.bundles()

    for bundle in bundles:
        LOG.debug("Check for versions in %s", bundle.name)
        last_version = hk_api.last_version(bundle.name)
        if not last_version:
            LOG.warning("No bundle found for %s in housekeeper", bundle.name)
            return
        yield last_version
Esempio n. 7
0
 def ensure_hk_version(store: HousekeeperAPI, bundle_data: dict) -> hk_models.Version:
     """Utility function to return existing or create an version for tests"""
     _bundle = StoreHelpers.ensure_hk_bundle(store, bundle_data)
     return store.last_version(_bundle.name)