Skip to content

Module dcm2bids.scaffold⚓︎

scaffold module

None

View Source
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
"""scaffold module"""

import sys

import argparse

import datetime

import os

import shutil

import importlib.resources as resources

from typing import Optional

from ..utils import write_txt

def _get_arguments():

    """Load arguments for main"""

    parser = argparse.ArgumentParser(

        formatter_class=argparse.RawDescriptionHelpFormatter,

        description="""

            Create basic BIDS files and directories

            """,

        epilog="""

            Documentation at https://github.com/unfmontreal/Dcm2Bids

            """,

    )

    parser.add_argument(

        "-o",

        "--output_dir",

        required=False,

        default=os.getcwd(),

        help="Output BIDS directory, Default: current directory",

    )

    args = parser.parse_args()

    return args

def scaffold(output_dir_override: Optional[str] = None):

    """scaffold entry point"""

    args = _get_arguments()

    output_dir_ = output_dir_override if output_dir_override is not None else args.output_dir

    for _ in ["code", "derivatives", "sourcedata"]:

        os.makedirs(os.path.join(output_dir_, _), exist_ok=True)

    for _ in [

        "dataset_description.json",

        "participants.json",

        "participants.tsv",

        "README",

    ]:

        dest = os.path.join(output_dir_, _)

        with resources.path(__name__, _) as src:

            shutil.copyfile(src, dest)

    with resources.path(__name__, "CHANGES") as changes_template:

        with open(changes_template) as _:

            data = _.read().format(datetime.date.today().strftime("%Y-%m-%d"))

        write_txt(

            os.path.join(output_dir_, "CHANGES"),

            data.split("\n")[:-1],

    )

Functions⚓︎

scaffold⚓︎

1
2
3
def scaffold(
    output_dir_override: Optional[str] = None
)

scaffold entry point

View Source
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
def scaffold(output_dir_override: Optional[str] = None):

    """scaffold entry point"""

    args = _get_arguments()

    output_dir_ = output_dir_override if output_dir_override is not None else args.output_dir

    for _ in ["code", "derivatives", "sourcedata"]:

        os.makedirs(os.path.join(output_dir_, _), exist_ok=True)

    for _ in [

        "dataset_description.json",

        "participants.json",

        "participants.tsv",

        "README",

    ]:

        dest = os.path.join(output_dir_, _)

        with resources.path(__name__, _) as src:

            shutil.copyfile(src, dest)

    with resources.path(__name__, "CHANGES") as changes_template:

        with open(changes_template) as _:

            data = _.read().format(datetime.date.today().strftime("%Y-%m-%d"))

        write_txt(

            os.path.join(output_dir_, "CHANGES"),

            data.split("\n")[:-1],

    )

Last update: 2022-06-17
Back to top