Skip to content

Commit

Permalink
WIP delete selection
Browse files Browse the repository at this point in the history
  • Loading branch information
eboileau committed Aug 4, 2024
1 parent 4ad5983 commit aabba1a
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 6 deletions.
9 changes: 6 additions & 3 deletions server/src/scimodom/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,13 +435,16 @@ def batch(input_directory, request_uuids, annotation):
multiple=True,
required=False,
type=click.INT,
help="Selection ID(s) to delete. Repeat parameter to pass multiple selection IDs. Use at your own risk!",
help="Selection ID(s) to delete. Repeat parameter to pass multiple selection IDs.",
)
@click.argument("smid", type=click.STRING)
def delete(smid, selection):
"""Delete a project and all associated
data from the database. Deleting
selections at your own risk.
data from the database. If given, delete
selections (and gene cache) associated
with the project data. Selections
may be associated with other datasets,
delete at your own risk!
SMID is the Sci-ModoM project ID.
"""
Expand Down
12 changes: 9 additions & 3 deletions server/src/scimodom/cli/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from scimodom.services.annotation import AnnotationSource
from scimodom.services.assembly import AssemblyNotFoundError, get_assembly_service
from scimodom.services.dataset import get_dataset_service
from scimodom.services.file import get_file_service
from scimodom.services.project import get_project_service
from scimodom.utils.project_dto import (
ProjectMetaDataDto,
Expand Down Expand Up @@ -295,9 +296,14 @@ def add_selection(

def delete_selection(selection: Selection) -> None:
session = get_session()
session.delete(selection)
session.commit()
# TODO delete gene cache
file_service = get_file_service()
try:
session.delete(selection)
file_service.delete_gene_cache(selection.id)
session.commit()
except Exception:
session.rollback()
raise


def get_selection_from_dataset(dataset: Dataset) -> Iterator[Selection]:
Expand Down
3 changes: 3 additions & 0 deletions server/src/scimodom/cli/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,9 @@ def delete_project(smid: str, selection_ids: list[int]) -> None:
BAM files associated with a dataset belonging
to this project are deleted from the file system.
If given, selection IDs are deleted and
gene cache files are removed.
:param smid: Project ID (SMID)
:type smid: str
:param selection_ids: List of selection IDs to delete,
Expand Down
9 changes: 9 additions & 0 deletions server/src/scimodom/services/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,15 @@ def update_gene_cache(self, selection_id: int, genes: Iterable[str]) -> None:
print(g, file=fh)
flock(fh.fileno(), LOCK_UN)

def delete_gene_cache(self, selection_id: int) -> None:
"""Remove a gene cache file for a given selection.
:param selection_id: Selection ID
:type selection_id: int
"""
path = Path(self._get_gene_cache_dir(), str(selection_id))
path.unlink()

def _get_gene_cache_dir(self) -> Path:
return Path(self._data_path, self.CACHE_DEST)

Expand Down
4 changes: 4 additions & 0 deletions server/tests/unit/services/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ class MockFileService:
def __init__(self, session):
self._session = session
self.deleted_bam_files: list[str] = []
self.deleted_gene_cache: list[int] = []

def delete_gene_cache(self, selection_id: int) -> None:
self.deleted_gene_cache.append(selection_id)

def remove_bam_file(self, bam_file):
self.deleted_bam_files.append(bam_file.original_file_name)
Expand Down

0 comments on commit aabba1a

Please sign in to comment.