Skip to content

cli

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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
@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.",
    required=True
)
@click.option(
    "--manifest-path",
    "-m",
    show_default=True,
    help="Path to manifest tsv.",
    required=True
)
@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
    assert api_key_path is not None, "If using gen3 mode an api key path must be provided with --api-key-path"
    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=verbose,
        duplicate=duplicate,
        user_project=None
    )

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
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
@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.",
    required=True
)
@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",
    required=True
)
@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, user_project=None, verbose=verbose, duplicate=duplicate,
    )

pretty_size(bytes)

Integer -> human readable Data Size Pretty Printer

Source code in drs_downloader/cli.py
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
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, user_project, duplicate, string_mode)

Copy files from terra.bio

Source code in drs_downloader/cli.py
 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
136
137
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
@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.",
    required=True
)
@click.option(
    "--manifest-path",
    "-m",
    show_default=True,
    help="Path to manifest tsv.",
    required=True
)
@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(
    "--user-project", "-u",
    default=None,
    show_default=True,
    help="This option is used to specify the Terra Workspace"
         "Google project id if the requester is paying for the download",
)
@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",
)
@click.option(
    "--string-mode",
    default=None,
    show_default=True,
    help="This option is used when you want to run the downloader with URIS"
         "that you provide in string form with uris seperated by commas the command line. ex: 'uri1, uri2, uri3'",
)
def terra(
    verbose: bool,
    destination_dir: str,
    manifest_path: str,
    drs_column_name: str,
    user_project: str,
    duplicate: bool,
    string_mode: str,
):
    """Copy files from terra.bio"""

    # get ids from manifest
    if string_mode is not None:
        ids_from_manifest = string_mode.split(",")
        ids_from_manifest = [s.replace(" ", "") for s in ids_from_manifest]
    else:
        ids_from_manifest = _extract_tsv_info(Path(manifest_path), drs_column_name)

    Contains_AnVIL_Uris = check_for_AnVIL_URIS(ids_from_manifest)
    if Contains_AnVIL_Uris and not user_project:
        file_logger.error(
            ("ERROR: AnVIL Drs URIS starting with  'drs://drs.anv0:' or 'drs://dg.anv0: were"
             "provided in the manifest but no Terra workspace Google project id was given. Specify one with"
             "the --user-project option")
        )
        logger.error(
            ("ERROR: AnVIL Drs URIS starting with  'drs://drs.anv0:' or 'drs://dg.anv0: were"
             "provided in the manifest but no Terra workspace Google project id was given. Specify one with"
             "the --user-project option")
        )
        exit(1)

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

    )