junifer 0.0.5.dev27__py3-none-any.whl → 0.0.5.dev33__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
junifer/_version.py CHANGED
@@ -12,5 +12,5 @@ __version__: str
12
12
  __version_tuple__: VERSION_TUPLE
13
13
  version_tuple: VERSION_TUPLE
14
14
 
15
- __version__ = version = '0.0.5.dev27'
16
- __version_tuple__ = version_tuple = (0, 0, 5, 'dev27')
15
+ __version__ = version = '0.0.5.dev33'
16
+ __version_tuple__ = version_tuple = (0, 0, 5, 'dev33')
junifer/api/cli.py CHANGED
@@ -8,7 +8,7 @@ import pathlib
8
8
  import subprocess
9
9
  import sys
10
10
  from pathlib import Path
11
- from typing import Dict, List, Tuple, Union
11
+ from typing import Dict, List, Optional, Tuple, Union
12
12
 
13
13
  import click
14
14
  import pandas as pd
@@ -20,6 +20,7 @@ from ..utils.logging import (
20
20
  warn_with_log,
21
21
  )
22
22
  from .functions import collect as api_collect
23
+ from .functions import list_elements as api_list_elements
23
24
  from .functions import queue as api_queue
24
25
  from .functions import reset as api_reset
25
26
  from .functions import run as api_run
@@ -451,6 +452,69 @@ def reset(
451
452
  api_reset(config)
452
453
 
453
454
 
455
+ @cli.command()
456
+ @click.argument(
457
+ "filepath",
458
+ type=click.Path(
459
+ exists=True, readable=True, dir_okay=False, path_type=pathlib.Path
460
+ ),
461
+ )
462
+ @click.option("--element", type=str, multiple=True)
463
+ @click.option(
464
+ "-o",
465
+ "--output-file",
466
+ type=click.Path(dir_okay=False, writable=True, path_type=pathlib.Path),
467
+ )
468
+ @click.option(
469
+ "-v",
470
+ "--verbose",
471
+ type=click.UNPROCESSED,
472
+ callback=_validate_verbose,
473
+ default="info",
474
+ )
475
+ def list_elements(
476
+ filepath: click.Path,
477
+ element: Tuple[str],
478
+ output_file: Optional[click.Path],
479
+ verbose: Union[str, int],
480
+ ) -> None:
481
+ """Element listing command for CLI.
482
+
483
+ \f
484
+
485
+ Parameters
486
+ ----------
487
+ filepath : click.Path
488
+ The filepath to the configuration file.
489
+ element : tuple of str
490
+ The element to operate on.
491
+ output_file : click.Path or None
492
+ The path to write the output to. If not None, writing to
493
+ stdout is not performed.
494
+ verbose : click.Choice
495
+ The verbosity level: warning, info or debug (default "info").
496
+
497
+ """
498
+ configure_logging(level=verbose)
499
+ # Parse YAML
500
+ config = parse_yaml(filepath) # type: ignore
501
+ # Fetch datagrabber
502
+ datagrabber = config["datagrabber"]
503
+ # Parse elements
504
+ elements = _parse_elements(element, config)
505
+ # Perform operation
506
+ listed_elements = api_list_elements(
507
+ datagrabber=datagrabber,
508
+ elements=elements,
509
+ )
510
+ # Check if output file is provided
511
+ if output_file is not None:
512
+ output_file.touch()
513
+ output_file.write_text(listed_elements)
514
+ else:
515
+ click.secho(listed_elements, fg="blue")
516
+
517
+
454
518
  @cli.group()
455
519
  def setup() -> None: # pragma: no cover
456
520
  """Configure commands for Junifer."""
junifer/api/functions.py CHANGED
@@ -361,3 +361,44 @@ def reset(config: Dict) -> None:
361
361
  shutil.rmtree(job_dir)
362
362
  # Remove directory
363
363
  job_dir.parent.rmdir()
364
+
365
+
366
+ def list_elements(
367
+ datagrabber: Dict,
368
+ elements: Union[str, List[Union[str, Tuple]], Tuple, None] = None,
369
+ ) -> str:
370
+ """List elements of the datagrabber filtered using `elements`.
371
+
372
+ Parameters
373
+ ----------
374
+ datagrabber : dict
375
+ DataGrabber to index. Must have a key ``kind`` with the kind of
376
+ DataGrabber to use. All other keys are passed to the DataGrabber
377
+ constructor.
378
+ elements : str or tuple or list of str or tuple, optional
379
+ Element(s) to filter using. Will be used to index the DataGrabber
380
+ (default None).
381
+
382
+ """
383
+ # Get datagrabber to use
384
+ datagrabber_object = _get_datagrabber(datagrabber)
385
+
386
+ # Fetch elements
387
+ raw_elements_to_list = []
388
+ with datagrabber_object:
389
+ if elements is not None:
390
+ for element in datagrabber_object.filter(elements):
391
+ raw_elements_to_list.append(element)
392
+ else:
393
+ for element in datagrabber_object:
394
+ raw_elements_to_list.append(element)
395
+
396
+ elements_to_list = []
397
+ for element in raw_elements_to_list:
398
+ # Stringify elements if tuple for operation
399
+ str_element = (
400
+ ",".join(element) if isinstance(element, tuple) else element
401
+ )
402
+ elements_to_list.append(str_element)
403
+
404
+ return "\n".join(elements_to_list)
@@ -14,6 +14,7 @@ from ruamel.yaml import YAML
14
14
  from junifer.api.cli import (
15
15
  _parse_elements_file,
16
16
  collect,
17
+ list_elements,
17
18
  queue,
18
19
  reset,
19
20
  run,
@@ -297,6 +298,88 @@ def test_reset(
297
298
  assert reset_result.exit_code == 0
298
299
 
299
300
 
301
+ @pytest.mark.parametrize(
302
+ "elements",
303
+ [
304
+ ("sub-01", "sub-02"),
305
+ ("sub-03", "sub-04"),
306
+ ],
307
+ )
308
+ def test_list_elements_stdout(
309
+ elements: Tuple[str, ...],
310
+ ) -> None:
311
+ """Test elements listing to stdout.
312
+
313
+ Parameters
314
+ ----------
315
+ elements : tuple of str
316
+ The parametrized elements for filtering.
317
+
318
+ """
319
+ # Get test config
320
+ infile = Path(__file__).parent / "data" / "partly_cloudy_agg_mean_tian.yml"
321
+ # List elements command arguments
322
+ list_elements_args = [
323
+ str(infile.absolute()),
324
+ "--verbose",
325
+ "debug",
326
+ "--element",
327
+ elements[0],
328
+ "--element",
329
+ elements[1],
330
+ ]
331
+ # Invoke list elements command
332
+ list_elements_result = runner.invoke(list_elements, list_elements_args)
333
+ # Check
334
+ assert list_elements_result.exit_code == 0
335
+ assert f"{elements[0]}\n{elements[1]}" in list_elements_result.stdout
336
+
337
+
338
+ @pytest.mark.parametrize(
339
+ "elements",
340
+ [
341
+ ("sub-01", "sub-02"),
342
+ ("sub-03", "sub-04"),
343
+ ],
344
+ )
345
+ def test_list_elements_output_file(
346
+ tmp_path: Path,
347
+ elements: Tuple[str, ...],
348
+ ) -> None:
349
+ """Test elements listing to output file.
350
+
351
+ Parameters
352
+ ----------
353
+ tmp_path : pathlib.Path
354
+ The path to the test directory.
355
+ elements : tuple of str
356
+ The parametrized elements for filtering.
357
+
358
+ """
359
+ # Get test config
360
+ infile = Path(__file__).parent / "data" / "partly_cloudy_agg_mean_tian.yml"
361
+ # Output file
362
+ output_file = tmp_path / "elements.txt"
363
+ # List elements command arguments
364
+ list_elements_args = [
365
+ str(infile.absolute()),
366
+ "--verbose",
367
+ "debug",
368
+ "--element",
369
+ elements[0],
370
+ "--element",
371
+ elements[1],
372
+ "--output-file",
373
+ str(output_file.resolve()),
374
+ ]
375
+ # Invoke list elements command
376
+ list_elements_result = runner.invoke(list_elements, list_elements_args)
377
+ # Check
378
+ assert list_elements_result.exit_code == 0
379
+ with open(output_file) as f:
380
+ assert f"{elements[0]}\n{elements[1]}" == f.read()
381
+
382
+
300
383
  def test_wtf_short() -> None:
301
384
  """Test short version of wtf command."""
302
385
  # Invoke wtf command
@@ -7,13 +7,13 @@
7
7
 
8
8
  import logging
9
9
  from pathlib import Path
10
- from typing import Dict, List, Tuple, Union
10
+ from typing import Dict, List, Optional, Tuple, Union
11
11
 
12
12
  import pytest
13
13
  from ruamel.yaml import YAML
14
14
 
15
15
  import junifer.testing.registry # noqa: F401
16
- from junifer.api.functions import collect, queue, reset, run
16
+ from junifer.api.functions import collect, list_elements, queue, reset, run
17
17
  from junifer.datagrabber.base import BaseDataGrabber
18
18
  from junifer.pipeline.registry import build
19
19
 
@@ -637,3 +637,28 @@ def test_reset_queue(
637
637
 
638
638
  assert not Path(storage["uri"]).exists()
639
639
  assert not (tmp_path / "junifer_jobs" / job_name).exists()
640
+
641
+
642
+ @pytest.mark.parametrize(
643
+ "elements",
644
+ [
645
+ ["sub-01"],
646
+ None,
647
+ ],
648
+ )
649
+ def test_list_elements(
650
+ datagrabber: Dict[str, str],
651
+ elements: Optional[List[str]],
652
+ ) -> None:
653
+ """Test elements listing.
654
+
655
+ Parameters
656
+ ----------
657
+ datagrabber : dict
658
+ Testing datagrabber as dictionary.
659
+ elements : str of list of str
660
+ The parametrized elements for filtering.
661
+
662
+ """
663
+ listed_elements = list_elements(datagrabber, elements)
664
+ assert "sub-01" in listed_elements
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: junifer
3
- Version: 0.0.5.dev27
3
+ Version: 0.0.5.dev33
4
4
  Summary: JUelich NeuroImaging FEature extractoR
5
5
  Author-email: Fede Raimondo <f.raimondo@fz-juelich.de>, Synchon Mandal <s.mandal@fz-juelich.de>
6
6
  Maintainer-email: Fede Raimondo <f.raimondo@fz-juelich.de>, Synchon Mandal <s.mandal@fz-juelich.de>
@@ -1,10 +1,10 @@
1
1
  junifer/__init__.py,sha256=x1UR2jUcrUdm2HNl-3Qvyi4UUrU6ms5qm2qcmNY7zZk,391
2
- junifer/_version.py,sha256=F2Z7xVB6hG84y0R3P4KaCGrxH_Hu1PR-l82F-5zd5fw,426
2
+ junifer/_version.py,sha256=jt9kLyfcxL6vsRdlQhCf9n5sfrkEAsJvCn1rzMM5Cxg,426
3
3
  junifer/stats.py,sha256=sU5IZ2qFZWbzgSutQS_z42miIVItpSGmQYBn6KkD5fA,6162
4
4
  junifer/api/__init__.py,sha256=YILu9M7SC0Ri4CVd90fELH2OnK_gvCYAXCoqBNCFE8E,257
5
- junifer/api/cli.py,sha256=_fC35jp0YzqNIpO5yvTb_5QBmUpw6sRFgVjBeoRbhO8,13627
5
+ junifer/api/cli.py,sha256=wtU7Rv9tDIT-4KQAkG6WxiE6mop3cuz6XxGDewceHPs,15329
6
6
  junifer/api/decorators.py,sha256=8bnwHPAe7VgzKxl--M_e0umdAlTVSzaJQHEJZ5kof5k,2580
7
- junifer/api/functions.py,sha256=N59KM2GqxIwMU2tXc44oYCqogclgqD45qI_ULrfGYDQ,11616
7
+ junifer/api/functions.py,sha256=29bGcpFueL3mjOcoNWU0xaHpM5aIrRQod-U2o-5_TSs,12938
8
8
  junifer/api/parser.py,sha256=a3SSC2xO-PF1pqXZXFq8Sh9aVd-dmHolJbCkGyOUTAM,4416
9
9
  junifer/api/utils.py,sha256=dyjTdPMwX9qeCrn8SQT2Pjshfnu-y1FEyujV7lCzvm0,3333
10
10
  junifer/api/queue_context/__init__.py,sha256=x0fT0ax-jPI0Fefg2quJ6VCIwhJ9rUQEjCNqxDXw7WM,287
@@ -32,8 +32,8 @@ junifer/api/res/fsl/img2imgcoord,sha256=Zmaw3oJYrEltcXiPyEubXry9ppAq3SND52tdDWGg
32
32
  junifer/api/res/fsl/run_fsl_docker.sh,sha256=mRLtZo0OgDwleoee2MG6rYI37HVuGNk9zOADwcl97RA,1122
33
33
  junifer/api/res/fsl/std2imgcoord,sha256=-X5wRH6XMl0yqnTACJX6MFhO8DFOEWg42MHRxGvimXg,49
34
34
  junifer/api/tests/test_api_utils.py,sha256=zDRQiqFOaoO02FpzJCxEbZvsP4u4__Yr25e5k5MJwuI,2713
35
- junifer/api/tests/test_cli.py,sha256=FYGuTLlqjB9IifMIdvHEGSQSSy6ym6623fKKPs8PsM8,8871
36
- junifer/api/tests/test_functions.py,sha256=mvxdaGHxPje-aQGS2fo95xjU7jOf8TYaTWqwFZ5T0oY,17215
35
+ junifer/api/tests/test_cli.py,sha256=kyDu-51lBmIBlQ2MnmmecC3nENrQuZRpk0bCkAPqmWM,10969
36
+ junifer/api/tests/test_functions.py,sha256=unLxIMwB3f7HF3ESq0JCfRaQhNB9Xj0JEi1OMkWsgtQ,17753
37
37
  junifer/api/tests/test_parser.py,sha256=eUz2JPVb0_cxvoeI1O_C5PMNs5v_lDzGsN6fV1VW5Eg,6109
38
38
  junifer/api/tests/data/gmd_mean.yaml,sha256=Ohb_C5cfQMK-59U9O1ZhejXyBtzLc5Y4cv8QyYq2azg,330
39
39
  junifer/api/tests/data/gmd_mean_htcondor.yaml,sha256=f7NLv_KIJXTiPNFmOWl2Vw8EfwojhfkGtwbh5prbd6w,417
@@ -256,10 +256,10 @@ junifer/utils/logging.py,sha256=furcU3XIUpUvnpe4PEwzWWIWgmH4j2ZA4MQdvSGWjj0,9216
256
256
  junifer/utils/tests/test_fs.py,sha256=WQS7cKlKEZ742CIuiOYYpueeAhY9PqlastfDVpVVtvE,923
257
257
  junifer/utils/tests/test_helpers.py,sha256=k5qqfxK8dFyuewTJyR1Qn6-nFaYNuVr0ysc18bfPjyU,929
258
258
  junifer/utils/tests/test_logging.py,sha256=l8oo-AiBV7H6_IzlsNcj__cLeZBUvgIGoaMszD9VaJg,7754
259
- junifer-0.0.5.dev27.dist-info/AUTHORS.rst,sha256=rmULKpchpSol4ExWFdm-qu4fkpSZPYqIESVJBZtGb6E,163
260
- junifer-0.0.5.dev27.dist-info/LICENSE.md,sha256=MqCnOBu8uXsEOzRZWh9EBVfVz-kE9NkXcLCrtGXo2yU,34354
261
- junifer-0.0.5.dev27.dist-info/METADATA,sha256=jvrOkuBla5IlTKRbbmZz3d9Pxe8cPSEo60ZO30t3N9E,8234
262
- junifer-0.0.5.dev27.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
263
- junifer-0.0.5.dev27.dist-info/entry_points.txt,sha256=DxFvKq0pOqRunAK0FxwJcoDfV1-dZvsFDpD5HRqSDhw,48
264
- junifer-0.0.5.dev27.dist-info/top_level.txt,sha256=4bAq1R2QFQ4b3hohjys2JBvxrl0GKk5LNFzYvz9VGcA,8
265
- junifer-0.0.5.dev27.dist-info/RECORD,,
259
+ junifer-0.0.5.dev33.dist-info/AUTHORS.rst,sha256=rmULKpchpSol4ExWFdm-qu4fkpSZPYqIESVJBZtGb6E,163
260
+ junifer-0.0.5.dev33.dist-info/LICENSE.md,sha256=MqCnOBu8uXsEOzRZWh9EBVfVz-kE9NkXcLCrtGXo2yU,34354
261
+ junifer-0.0.5.dev33.dist-info/METADATA,sha256=j_mfDEzO4eaJ9s-1WYuy6T_KOVkQNEWeO-Kha3dBCqE,8234
262
+ junifer-0.0.5.dev33.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
263
+ junifer-0.0.5.dev33.dist-info/entry_points.txt,sha256=DxFvKq0pOqRunAK0FxwJcoDfV1-dZvsFDpD5HRqSDhw,48
264
+ junifer-0.0.5.dev33.dist-info/top_level.txt,sha256=4bAq1R2QFQ4b3hohjys2JBvxrl0GKk5LNFzYvz9VGcA,8
265
+ junifer-0.0.5.dev33.dist-info/RECORD,,