Skip to content

Commit

Permalink
Merge branch 'master' into archiving-delete-files
Browse files Browse the repository at this point in the history
  • Loading branch information
islean committed Dec 11, 2023
2 parents b6f4b3c + e5c4f09 commit 4753c72
Show file tree
Hide file tree
Showing 49 changed files with 525 additions and 991 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 54.0.0
current_version = 54.2.1
commit = True
tag = True
tag_name = v{new_version}
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ repos:
- id: isort
name: isort
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.289
rev: v0.1.7
hooks:
- id: ruff

2 changes: 1 addition & 1 deletion cg/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__title__ = "cg"
__version__ = "54.0.0"
__version__ = "54.2.1"
16 changes: 15 additions & 1 deletion cg/apps/scout/scoutapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from cg.apps.scout.scout_export import ScoutExportCase, Variant
from cg.constants.constants import FileFormat
from cg.constants.gene_panel import GENOME_BUILD_37
from cg.constants.scout_upload import ScoutCustomCaseReportTags
from cg.constants.scout import ScoutCustomCaseReportTags
from cg.exc import ScoutUploadError
from cg.io.controller import ReadFile, ReadStream
from cg.models.scout.scout_load_config import ScoutLoadConfig
Expand Down Expand Up @@ -69,6 +69,20 @@ def export_panels(self, panels: list[str], build: str = GENOME_BUILD_37) -> list

return list(self.process.stdout_lines())

def export_managed_variants(self, genome_build: str = GENOME_BUILD_37) -> list[str]:
"""Export a list of managed variants."""
export_command = ["export", "managed"]
if genome_build:
export_command.extend(["--build", genome_build])
try:
self.process.run_command(export_command)
if not self.process.stdout:
return []
except CalledProcessError:
LOG.info("Could not export managed variants")
return []
return list(self.process.stdout_lines())

def get_genes(self, panel_id: str, build: str = None) -> list[dict]:
"""Return panel genes."""
export_panel_command = ["export", "panel", panel_id]
Expand Down
2 changes: 0 additions & 2 deletions cg/cli/demultiplex/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
confirm_flow_cell_sync,
copy_novaseqx_flow_cells,
create_manifest_files,
delete_flow_cell,
demultiplex_all,
demultiplex_flow_cell,
)
Expand All @@ -27,7 +26,6 @@ def demultiplex_cmd_group():
for sub_cmd in [
create_manifest_files,
confirm_flow_cell_sync,
delete_flow_cell,
demultiplex_flow_cell,
demultiplex_all,
finish_group,
Expand Down
61 changes: 0 additions & 61 deletions cg/cli/demultiplex/demux.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
)
from cg.constants.demultiplexing import OPTION_BCL_CONVERTER, DemultiplexingDirsAndFiles
from cg.exc import FlowCellError
from cg.meta.demultiplex.delete_demultiplex_api import DeleteDemuxAPI
from cg.meta.demultiplex.utils import (
create_manifest_file,
is_flow_cell_sync_confirmed,
Expand Down Expand Up @@ -121,66 +120,6 @@ def demultiplex_flow_cell(
)


@click.command(name="delete-flow-cell")
@click.option(
"-f",
"--flow-cell-name",
required=True,
help="The name of the flow cell you want to delete, e.g. HVKJCDRXX",
)
@click.option(
"--demultiplexing-dir", is_flag=True, help="Delete flow cell demultiplexed dir on file system"
)
@click.option("--housekeeper", is_flag=True, help="Delete flow cell in housekeeper")
@click.option("--init-files", is_flag=True, help="Delete flow cell init-files")
@click.option("--run-dir", is_flag=True, help="Delete flow cell run on file system")
@click.option(
"--sample-lane-sequencing-metrics",
is_flag=True,
help="Delete flow cell in sample lane sequencing metrics",
)
@click.option(
"--status-db",
is_flag=True,
help="Delete flow cell in status-db, if passed all other entries are also deleted",
)
@click.option("--yes", is_flag=True, help="Pass yes to click confirm")
@DRY_RUN
@click.pass_obj
def delete_flow_cell(
context: CGConfig,
dry_run: bool,
demultiplexing_dir: bool,
housekeeper: bool,
init_files: bool,
run_dir: bool,
sample_lane_sequencing_metrics: bool,
status_db: bool,
yes: bool,
flow_cell_name: str,
):
"""Delete a flow cell. If --status-db is passed then all other options will be treated as True."""

delete_demux_api: DeleteDemuxAPI = DeleteDemuxAPI(
config=context, dry_run=dry_run, flow_cell_name=flow_cell_name
)

if yes or click.confirm(
f"Are you sure you want to delete the flow cell from the following databases:\n"
f"Housekeeper={True if status_db else housekeeper}\nInit_files={True if status_db else init_files}\n"
f"Run-dir={True if status_db else run_dir}\nStatusdb={status_db}\n"
f"\nSample-lane-sequencing-metrics={True if sample_lane_sequencing_metrics else sample_lane_sequencing_metrics}"
):
delete_demux_api.delete_flow_cell(
demultiplexing_dir=demultiplexing_dir,
housekeeper=housekeeper,
init_files=init_files,
sample_lane_sequencing_metrics=sample_lane_sequencing_metrics,
run_dir=run_dir,
status_db=status_db,
)


@click.command(name="copy-completed-flow-cell")
@click.pass_obj
def copy_novaseqx_flow_cells(context: CGConfig):
Expand Down
2 changes: 1 addition & 1 deletion cg/cli/upload/scout.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from cg.cli.upload.utils import suggest_cases_to_upload
from cg.constants import Pipeline
from cg.constants.constants import FileFormat
from cg.constants.scout_upload import ScoutCustomCaseReportTags
from cg.constants.scout import ScoutCustomCaseReportTags
from cg.io.controller import WriteStream
from cg.meta.upload.scout.uploadscoutapi import UploadScoutAPI
from cg.meta.upload.upload_api import UploadAPI
Expand Down
6 changes: 6 additions & 0 deletions cg/cli/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import click


def echo_lines(lines: list[str]) -> None:
for line in lines:
click.echo(line)
21 changes: 19 additions & 2 deletions cg/cli/workflow/mip/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import click

from cg.apps.environ import environ_email
from cg.cli.utils import echo_lines
from cg.cli.workflow.commands import link
from cg.cli.workflow.mip.options import (
ARGUMENT_CASE_ID,
Expand Down Expand Up @@ -59,12 +60,27 @@ def panel(context: CGConfig, case_id: str, dry_run: bool) -> None:

bed_lines: list[str] = analysis_api.get_gene_panel(case_id=case_id)
if dry_run:
for bed_line in bed_lines:
click.echo(bed_line)
echo_lines(lines=bed_lines)
return
analysis_api.write_panel(case_id, bed_lines)


@click.command()
@OPTION_DRY
@ARGUMENT_CASE_ID
@click.pass_obj
def managed_variants(context: CGConfig, case_id: str, dry_run: bool) -> None:
"""Write managed variants file exported from Scout."""

analysis_api: MipAnalysisAPI = context.meta_apis["analysis_api"]
analysis_api.status_db.verify_case_exists(case_internal_id=case_id)
vcf_lines: list[str] = analysis_api.get_managed_variants()
if dry_run:
echo_lines(lines=vcf_lines)
return
analysis_api.write_managed_variants(case_id=case_id, content=vcf_lines)


@click.command()
@QOS_OPTION
@EMAIL_OPTION
Expand Down Expand Up @@ -164,6 +180,7 @@ def start(
analysis_api.prepare_fastq_files(case_id=case_id, dry_run=dry_run)
context.invoke(link, case_id=case_id, dry_run=dry_run)
context.invoke(panel, case_id=case_id, dry_run=dry_run)
context.invoke(managed_variants, case_id=case_id, dry_run=dry_run)
context.invoke(config_case, case_id=case_id, panel_bed=panel_bed, dry_run=dry_run)
context.invoke(
run,
Expand Down
10 changes: 9 additions & 1 deletion cg/cli/workflow/mip_dna/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@
store,
store_available,
)
from cg.cli.workflow.mip.base import config_case, panel, run, start, start_available
from cg.cli.workflow.mip.base import (
config_case,
managed_variants,
panel,
run,
start,
start_available,
)
from cg.meta.workflow.analysis import AnalysisAPI
from cg.meta.workflow.mip_dna import MipDNAAnalysisAPI

Expand All @@ -33,6 +40,7 @@ def mip_dna(
config_case,
ensure_flow_cells_on_disk,
link,
managed_variants,
panel,
resolve_compression,
run,
Expand Down
21 changes: 19 additions & 2 deletions cg/cli/workflow/raredisease/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import click

from cg.cli.utils import echo_lines
from cg.cli.workflow.commands import ARGUMENT_CASE_ID, OPTION_DRY
from cg.constants.constants import MetaApis
from cg.meta.workflow.analysis import AnalysisAPI
Expand Down Expand Up @@ -35,7 +36,23 @@ def panel(context: CGConfig, case_id: str, dry_run: bool) -> None:

bed_lines: list[str] = analysis_api.get_gene_panel(case_id=case_id)
if dry_run:
for bed_line in bed_lines:
click.echo(bed_line)
echo_lines(lines=bed_lines)
return
analysis_api.write_panel(case_id=case_id, content=bed_lines)


@raredisease.command("managed-variants")
@OPTION_DRY
@ARGUMENT_CASE_ID
@click.pass_obj
def managed_variants(context: CGConfig, case_id: str, dry_run: bool) -> None:
"""Write managed variants file exported from Scout."""

analysis_api: RarediseaseAnalysisAPI = context.meta_apis["analysis_api"]
analysis_api.status_db.verify_case_exists(case_internal_id=case_id)

vcf_lines: list[str] = analysis_api.get_managed_variants()
if dry_run:
echo_lines(lines=vcf_lines)
return
analysis_api.write_managed_variants(case_id=case_id, content=vcf_lines)
4 changes: 2 additions & 2 deletions cg/constants/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class CaseActions(StrEnum):

@classmethod
def actions(cls) -> list[str]:
return list(cls)
return list(map(lambda action: action.value, cls))


CONTAINER_OPTIONS = ("Tube", "96 well plate", "No container")
Expand Down Expand Up @@ -71,7 +71,7 @@ class FlowCellStatus(StrEnum):

@classmethod
def statuses(cls) -> list[str]:
return list(cls)
return list(map(lambda status: status.value, cls))


class AnalysisType(StrEnum):
Expand Down
2 changes: 1 addition & 1 deletion cg/constants/gene_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class GenePanelMasterList(StrEnum):
@classmethod
def get_panel_names(cls, panels=None) -> list[str]:
"""Return requested panel names from the Master list, or all panels if none are specified."""
return list(panels) if panels else list(cls)
return list(panels) if panels else list(map(lambda panel: panel.value, cls))

@staticmethod
def collaborators() -> set[str]:
Expand Down
2 changes: 1 addition & 1 deletion cg/constants/housekeeper_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class AlignmentFileTag(StrEnum):

@classmethod
def file_tags(cls) -> list[str]:
return list(cls)
return list(map(lambda tag: tag.value, cls))


class ArchiveTag(StrEnum):
Expand Down
6 changes: 6 additions & 0 deletions cg/constants/scout_upload.py → cg/constants/scout.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from enum import StrEnum

from cg.constants import FileExtensions
from cg.constants.housekeeper_tags import AlignmentFileTag


Expand All @@ -8,6 +9,11 @@ class GenomeBuild(StrEnum):
hg38: str = "38"


class ScoutExportFileName(StrEnum):
MANAGED_VARIANTS: str = f"managed_variants{FileExtensions.VCF}"
PANELS: str = f"gene_panels{FileExtensions.BED}"


class ScoutCustomCaseReportTags(StrEnum):
DELIVERY: str = "delivery_report"
CNV: str = "cnv_report"
Expand Down
Loading

0 comments on commit 4753c72

Please sign in to comment.