Skip to content

cli

cli()

Copy DRS objects from the cloud to your local system .

Source code in drs_downloader/cli.py
26
27
28
29
@click.group()
def cli():
    """Copy DRS objects from the cloud to your local system ."""
    pass

gen3(verbose, destination_dir, manifest_path, drs_column_name, api_key_path, endpoint, duplicate)

Copy files from gen3 server.

Source code in drs_downloader/cli.py
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
@cli.command()
@click.option(
    "--verbose",
    "-v",
    is_flag=True,
    show_default=True,
    default=False,
    help="Display every logger",
)
@click.option(
    "--destination-dir",
    "-d",
    show_default=True,
    default=os.getcwd(),
    help="Destination directory.",
)
@click.option("--manifest-path", "-m", show_default=True, help="Path to manifest tsv.")
@click.option(
    "--drs-column-name",
    default="ga4gh_drs_uri",
    show_default=True,
    help="The column header in the TSV file associated with the DRS URIs."
    "Example: pfb:ga4gh_drs_uri",
)
@click.option("--api-key-path", show_default=True, help="Gen3 credentials file")
@click.option("--endpoint", show_default=True, required=True, help="Gen3 endpoint")
@click.option(
    "--duplicate",
    default=False,
    is_flag=True,
    show_default=True,
    help="This flag is used to specify wether \
    or not to download the file again if it already exists in the directory"
    "Example: True",
)
def gen3(
    verbose: bool,
    destination_dir: str,
    manifest_path: str,
    drs_column_name: str,
    api_key_path: str,
    endpoint: str,
    duplicate: bool,
):
    """Copy files from gen3 server."""
    # read from manifest
    ids_from_manifest = _extract_tsv_info(Path(manifest_path), drs_column_name)

    _perform_downloads(
        destination_dir,
        Gen3DrsClient(api_key_path=api_key_path, endpoint=endpoint),
        ids_from_manifest,
        verbose,
        duplicate=duplicate,
    )

mock(verbose, destination_dir, manifest_path, drs_column_name, duplicate)

Generate test files locally, without the need for server.

Source code in drs_downloader/cli.py
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
@cli.command()
@click.option(
    "--verbose",
    "-v",
    is_flag=True,
    show_default=True,
    default=False,
    help="Display every logger",
)
@click.option(
    "--destination-dir",
    "-d",
    show_default=True,
    default=os.getcwd(),
    help="Destination directory.",
)
@click.option("--manifest-path", "-m", show_default=True, help="Path to manifest tsv.")
@click.option(
    "--drs-column-name",
    default="ga4gh_drs_uri",
    show_default=True,
    help="The column header in the TSV file associated with the DRS URIs."
    "Example: pfb:ga4gh_drs_uri",
)
@click.option(
    "--duplicate",
    default=False,
    is_flag=True,
    show_default=True,
    help="This flag is used to specify wether \
    or not to download the file again if it already exists in the directory"
    "Example: True",
)
def mock(
    verbose: bool,
    destination_dir: str,
    manifest_path: str,
    drs_column_name: str,
    duplicate: bool,
):
    """Generate test files locally, without the need for server."""

    #
    # get ids from manifest
    ids_from_manifest = _extract_tsv_info(Path(manifest_path), drs_column_name)

    # perform downloads with a mock drs client
    _perform_downloads(
        destination_dir, MockDrsClient(), ids_from_manifest, verbose, duplicate=duplicate
    )

pretty_size(bytes)

Integer -> human readable Data Size Pretty Printer

Source code in drs_downloader/cli.py
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
def pretty_size(bytes):
    """Integer -> human readable Data Size Pretty Printer"""
    assert (bytes and bytes > 0), f"ERROR, The total download size {bytes} is Zero or None"
    units = [
        (1 << 50, " PB"),
        (1 << 40, " TB"),
        (1 << 30, " GB"),
        (1 << 20, " MB"),
        (1 << 10, " KB"),
        (1, (" bytes")),
    ]
    if (bytes/1000000000 < 1):
        price = 0.1
    else:
        price = '%.2f' % ((bytes/1000000000) * 0.1)

    for factor, suffix in units:
        if bytes >= factor:
            break
    amount = int(bytes / factor)
    return str(amount) + suffix, price

terra(verbose, destination_dir, manifest_path, drs_column_name, duplicate)

Copy files from terra.bio

Source code in drs_downloader/cli.py
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
@cli.command()
@click.option(
    "--verbose",
    "-v",
    is_flag=True,
    show_default=True,
    default=False,
    help="Display every logger",
)
@click.option(
    "--destination-dir",
    "-d",
    show_default=True,
    default=os.getcwd(),
    help="Destination directory.",
)
@click.option("--manifest-path", "-m", show_default=True, help="Path to manifest tsv.")
@click.option(
    "--drs-column-name",
    default=None,
    help="The column header in the TSV file associated with the DRS URIs."
    "Example: pfb:ga4gh_drs_uri",
)
@click.option(
    "--duplicate",
    default=False,
    is_flag=True,
    show_default=True,
    help="This flag is used to specify wether \
    or not to download the file again if it already exists in the directory"
    "Example: True",
)
def terra(
    verbose: bool,
    destination_dir: str,
    manifest_path: str,
    drs_column_name: str,
    duplicate: bool,
):
    """Copy files from terra.bio"""

    # get ids from manifest
    ids_from_manifest = _extract_tsv_info(Path(manifest_path), drs_column_name)

    # perform downloads with a terra drs client
    _perform_downloads(
        destination_dir,
        TerraDrsClient(),
        ids_from_manifest=ids_from_manifest,
        verbose=verbose,
        duplicate=duplicate,
    )