Ejemplo n.º 1
0
def test_add_flowcell_cmd(
    cli_runner: CliRunner,
    flowcell_object: Flowcell,
    demultiplex_context: CGConfig,
    demultiplexed_flowcell_finished_working_directory: Path,
    demultiplex_ready_flowcell: Path,
):
    # GIVEN a cgstats api and a demultiplex api
    # GIVEN that there is a flowcell in the run dir
    assert demultiplex_ready_flowcell.exists()
    # GIVEN that there is a demultiplexed flowcell
    assert demultiplexed_flowcell_finished_working_directory.exists()

    # GIVEN that the flowcell does not exist in the cgstats database
    assert not get_flowcell_id(flowcell_name=flowcell_object.flowcell_id)

    # WHEN running the add flowcell command
    result = cli_runner.invoke(
        add_flowcell_cmd, [flowcell_object.flowcell_full_name], obj=demultiplex_context
    )

    # THEN assert that the run was success
    assert result.exit_code == 0
    # THEN assert that the flowcell was added to cgstats
    assert get_flowcell_id(flowcell_name=flowcell_object.flowcell_id)
Ejemplo n.º 2
0
def test_create_flowcell(stats_api: StatsAPI,
                         bcl2fastq_demux_results: DemuxResults):
    # GIVEN a api without a flowcell object
    assert not find.get_flowcell_id(
        flowcell_name=bcl2fastq_demux_results.flowcell.flowcell_id)

    # WHEN creating a new flowcell
    create.create_flowcell(manager=stats_api,
                           demux_results=bcl2fastq_demux_results)

    # THEN assert that the flowcell was created
    assert find.get_flowcell_id(
        flowcell_name=bcl2fastq_demux_results.flowcell.flowcell_id)
Ejemplo n.º 3
0
def test_create_novaseq_flowcell(stats_api: StatsAPI,
                                 bcl2fastq_demux_results: DemuxResults):
    # GIVEN a setup with an existing sample sheet with information
    assert bcl2fastq_demux_results.flowcell.sample_sheet_path.read_text()
    # GIVEN that the flowcell does not exist in the database
    assert not find.get_flowcell_id(
        flowcell_name=bcl2fastq_demux_results.flowcell.flowcell_id)

    # WHEN creating the novaseq flowcell
    create.create_novaseq_flowcell(manager=stats_api,
                                   demux_results=bcl2fastq_demux_results)

    # THEN assert that the flowcell was created
    assert find.get_flowcell_id(
        flowcell_name=bcl2fastq_demux_results.flowcell.flowcell_id)
Ejemplo n.º 4
0
def test_select_command(
    cli_runner: CliRunner,
    populated_stats_api: StatsAPI,
    demux_results_finished_dir: Path,
    flowcell_object: Flowcell,
    demultiplex_context: CGConfig,
):
    demultiplex_context.cg_stats_api_ = populated_stats_api
    # GIVEN a stats api with some information about a flowcell
    flowcell_id: str = flowcell_object.flowcell_id
    full_flowcell_name: str = flowcell_object.flowcell_full_name
    assert find.get_flowcell_id(flowcell_id)
    demux_results = DemuxResults(
        demux_dir=demux_results_finished_dir / full_flowcell_name,
        flowcell=flowcell_object,
        bcl_converter="bcl2fastq",
    )

    # GIVEN a project id
    project_id: str = ""
    for project in demux_results.projects:
        project_id = project.split("_")[-1]
    assert project_id

    # WHEN exporting the sample information
    result = cli_runner.invoke(select_project_cmd,
                               [flowcell_id, "--project", project_id],
                               obj=demultiplex_context)

    # THEN assert that the command exits with success
    assert result.exit_code == 0
    # THEN assert that the flowcell id if in the printing
    assert flowcell_id in result.output
Ejemplo n.º 5
0
def create_novaseq_flowcell(manager: StatsAPI, demux_results: DemuxResults):
    """Add a novaseq flowcell to CG stats"""
    LOG.info("Adding flowcell information to cgstats")
    support_parameters_id: Optional[int] = find.get_support_parameters_id(
        demux_results=demux_results)
    if not support_parameters_id:
        support_parameters: stats_models.Supportparams = create_support_parameters(
            manager=manager, demux_results=demux_results)
        support_parameters_id: int = support_parameters.supportparams_id
    else:
        LOG.info("Support parameters already exists")

    datasource_id: Optional[int] = find.get_datasource_id(
        demux_results=demux_results)
    if not datasource_id:
        datasource_object: stats_models.Datasource = create_datasource(
            manager=manager,
            demux_results=demux_results,
            support_parameters_id=support_parameters_id,
        )
        datasource_id: int = datasource_object.datasource_id
    else:
        LOG.info("Data source already exists")
    flowcell_id: Optional[int] = find.get_flowcell_id(
        flowcell_name=demux_results.flowcell.flowcell_id)

    if not flowcell_id:
        flowcell: stats_models.Flowcell = create_flowcell(
            manager=manager, demux_results=demux_results)
        flowcell_id: int = flowcell.flowcell_id
    else:
        LOG.info("Flowcell already exists")

    demux_id: Optional[int] = find.get_demux_id(flowcell_object_id=flowcell_id)
    if not demux_id:
        demux_object: stats_models.Demux = create_demux(
            manager=manager,
            demux_results=demux_results,
            flowcell_id=flowcell_id,
            datasource_id=datasource_id,
        )
        demux_id: int = demux_object.demux_id
    else:
        LOG.info("Demux object already exists")

    project_name_to_id = create_projects(manager=manager,
                                         project_names=demux_results.projects)

    create_samples(
        manager=manager,
        demux_results=demux_results,
        project_name_to_id=project_name_to_id,
        demux_id=demux_id,
    )
    manager.commit()
Ejemplo n.º 6
0
def delete_flowcell(manager: StatsAPI, flowcell_name: str):

    flowcell_id: Optional[int] = get_flowcell_id(flowcell_name=flowcell_name)

    if flowcell_id:
        flowcell: List[models.Flowcell] = manager.Flowcell.query.filter_by(
            flowcell_id=flowcell_id).all()
        for entry in flowcell:
            log.info("Removing entry %s in from cgstats", entry.flowcellname)
            manager.delete(flowcell)
            manager.commit()
Ejemplo n.º 7
0
def test_delete_flowcell(populated_stats_api: StatsAPI, flowcell_name: str):
    """Test to delete a flowcell from cg-stats"""

    # GIVEN a populated StatsAPI, with an existing flow cell
    flow_cell_id = get_flowcell_id(flowcell_name=flowcell_name)
    assert flow_cell_id

    # WHEN deleting a flow cell from the StatsAPI
    delete_flowcell(manager=populated_stats_api, flowcell_name=flowcell_name)

    # THEN the flowcell should not exist any longer
    results = populated_stats_api.Flowcell.query.filter_by(
        flowcell_id=flow_cell_id).all()

    assert not results