Skip to content

Commit

Permalink
add cubi-isa-templates dependency, remove local templates (#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikkonie committed May 12, 2023
1 parent 79e85bf commit 51c6090
Show file tree
Hide file tree
Showing 51 changed files with 14 additions and 1,698 deletions.
3 changes: 2 additions & 1 deletion cubi_tk/archive/readme.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@

import attr
from cookiecutter.main import cookiecutter
from cubi_isa_templates import IsaTabTemplate
from logzero import logger

from . import common
from ..common import execute_shell_commands
from ..isa_tpl import IsaTabTemplate


_TEMPLATE_DIR = os.path.join(os.path.dirname(__file__), "templates")

Expand Down
125 changes: 4 additions & 121 deletions cubi_tk/isa_tpl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,152 +18,35 @@
Available Templates
-------------------
The `Cookiecutter`_ directories are located in this module's directory. Currently available templates are:
- ``isatab-generic``
- ``isatab-germline``
- ``isatab-microarray``
- ``isatab-ms_meta_biocrates``
- ``isatab-single_cell_rnaseq``
- ``isatab-bulk_rnaseq``
- ``isatab-tumor_normal_dna``
- ``isatab-tumor_normal_triplets``
- ``isatab-stem_cell_core_bulk``
- ``isatab-stem_cell_core_sc``
These have been moved to a separate repository: see `cubi-isa-templates`_.
Adding Templates
----------------
Adding templates consists of the following steps:
1. Add a new template directory below ``cubi_tk/isa_tpl``.
2. Register it appending a ``IsaTabTemplate`` object to ``_TEMPLATES`` in ``cubi_tk.isa_tpl``.
3. Add it to the list above in the docstring.
The easiest way to start out is to copy an existing cookiecutter template and registration.
See `cubi-isa-templates`_.
More Information
----------------
Also see ``cubi-tk isa-tpl`` CLI documentation and ``cubi-tk isa-tab --help`` for more information.
.. _Cookiecutter: https://cookiecutter.readthedocs.io/
.. _cubi-isa-templates: https://github.com/bihealth/cubi-isa-templates
"""

import argparse
from functools import partial
import json
import os
from pathlib import Path
import typing

import attr
from cookiecutter.main import cookiecutter
from cubi_isa_templates import TEMPLATES
from logzero import logger
from toolz import curry

from ..common import run_nocmd, yield_files_recursively


@attr.s(frozen=True, auto_attribs=True)
class IsaTabTemplate:
"""Information regarding an ISA-tab template."""

#: Name of the ISA-tab template.
name: str

#: Path to template directory.
path: str

#: Configuration loaded from ``cookiecutter.json``.
configuration: typing.Dict[str, typing.Any]

#: Optional description string.
description: typing.Optional[str] = None


#: Base directory to this file.
_BASE_DIR = os.path.dirname(__file__)


def load_variables(template_name, extra=None):
"""Load variables given the template name."""
extra = extra or {}
config_path = os.path.join(_BASE_DIR, template_name, "cookiecutter.json")
with open(config_path, "rt") as inputf:
result = json.load(inputf)
result.update(extra)
return result


#: Known ISA-tab templates (internal, mapping generated below).
_TEMPLATES = (
IsaTabTemplate(
name="single_cell_rnaseq",
path=os.path.join(_BASE_DIR, "isatab-single_cell_rnaseq"),
description="single cell RNA sequencing ISA-tab template",
configuration=load_variables("isatab-single_cell_rnaseq"),
),
IsaTabTemplate(
name="bulk_rnaseq",
path=os.path.join(_BASE_DIR, "isatab-bulk_rnaseq"),
description="bulk RNA sequencing ISA-tab template",
configuration=load_variables("isatab-generic"),
),
IsaTabTemplate(
name="tumor_normal_dna",
path=os.path.join(_BASE_DIR, "isatab-tumor_normal_dna"),
description="Tumor-Normal DNA sequencing ISA-tab template",
configuration=load_variables("isatab-tumor_normal_dna", {"is_triplet": False}),
),
IsaTabTemplate(
name="tumor_normal_triplets",
path=os.path.join(_BASE_DIR, "isatab-tumor_normal_triplets"),
description="Tumor-Normal DNA+RNA sequencing ISA-tab template",
configuration=load_variables("isatab-tumor_normal_triplets", {"is_triplet": True}),
),
IsaTabTemplate(
name="germline",
path=os.path.join(_BASE_DIR, "isatab-germline"),
description="germline DNA sequencing ISA-tab template",
configuration=load_variables("isatab-germline"),
),
IsaTabTemplate(
name="generic",
path=os.path.join(_BASE_DIR, "isatab-generic"),
description="generic RNA sequencing ISA-tab template",
configuration=load_variables("isatab-generic"),
),
IsaTabTemplate(
name="microarray",
path=os.path.join(_BASE_DIR, "isatab-microarray"),
description="microarray ISA-tab template",
configuration=load_variables("isatab-microarray"),
),
IsaTabTemplate(
name="ms_meta_biocrates",
path=os.path.join(_BASE_DIR, "isatab-ms_meta_biocrates"),
description="MS Metabolomics Biocrates kit ISA-tab template",
configuration=load_variables("isatab-ms_meta_biocrates"),
),
IsaTabTemplate(
name="stem_cell_core_bulk",
path=os.path.join(_BASE_DIR, "isatab-stem_cell_core_bulk"),
description="Bulk RNA sequencing ISA-tab template from hiPSC for stem cell core projects",
configuration=load_variables("isatab-stem_cell_core_bulk"),
),
IsaTabTemplate(
name="stem_cell_core_sc",
path=os.path.join(_BASE_DIR, "isatab-stem_cell_core_sc"),
description="Single cell RNA sequencing ISA-tab template from hiPSC for stem cell core projects",
configuration=load_variables("isatab-stem_cell_core_sc"),
),
)

#: Known ISA-tab templates.
TEMPLATES = {tpl.name: tpl for tpl in _TEMPLATES}


@curry
def run_cookiecutter(tpl, args, _parser=None, _subparser=None, no_input=False):
"""Run cookiecutter, ``tpl`` will be bound with ``toolz.curry``."""
Expand Down
17 changes: 0 additions & 17 deletions cubi_tk/isa_tpl/isatab-bulk_rnaseq/cookiecutter.json

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

58 changes: 0 additions & 58 deletions cubi_tk/isa_tpl/isatab-generic/cookiecutter.json

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 51c6090

Please sign in to comment.