Skip to content

Commit

Permalink
First update
Browse files Browse the repository at this point in the history
  • Loading branch information
rudolphpienaar committed Aug 28, 2024
1 parent 39ce640 commit c311156
Showing 1 changed file with 23 additions and 22 deletions.
45 changes: 23 additions & 22 deletions bulky.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
from argparse import ArgumentParser, Namespace, ArgumentDefaultsHelpFormatter

from chris_plugin import chris_plugin, PathMapper
import shutil

__version__ = '1.0.0'
__version__ = "1.0.0"

DISPLAY_TITLE = r"""
_ _ _
Expand All @@ -19,16 +20,16 @@
"""


parser = ArgumentParser(description='!!!CHANGE ME!!! An example ChRIS plugin which '
'counts the number of occurrences of a given '
'word in text files.',
formatter_class=ArgumentDefaultsHelpFormatter)
parser.add_argument('-w', '--word', required=True, type=str,
help='word to count')
parser.add_argument('-p', '--pattern', default='**/*.txt', type=str,
help='input file filter glob')
parser.add_argument('-V', '--version', action='version',
version=f'%(prog)s {__version__}')
parser = ArgumentParser(
description="""
A dummy bulk processor. Move along. Not much to see here.
""",
formatter_class=ArgumentDefaultsHelpFormatter,
)
parser.add_argument(
"--pattern", default="**/*.dcm", type=str, help="input file filter glob"
)
parser.add_argument("--version", action="version", version=f"%(prog)s {__version__}")


# The main function of this *ChRIS* plugin is denoted by this ``@chris_plugin`` "decorator."
Expand All @@ -37,11 +38,11 @@
# documentation: https://fnndsc.github.io/chris_plugin/chris_plugin.html#chris_plugin
@chris_plugin(
parser=parser,
title='A bulk processor',
category='', # ref. https://chrisstore.co/plugins
min_memory_limit='100Mi', # supported units: Mi, Gi
min_cpu_limit='1000m', # millicores, e.g. "1000m" = 1 CPU core
min_gpu_limit=0 # set min_gpu_limit=1 to enable GPU
title="A bulk processor",
category="", # ref. https://chrisstore.co/plugins
min_memory_limit="100Mi", # supported units: Mi, Gi
min_cpu_limit="1000m", # millicores, e.g. "1000m" = 1 CPU core
min_gpu_limit=0, # set min_gpu_limit=1 to enable GPU
)
def main(options: Namespace, inputdir: Path, outputdir: Path):
"""
Expand All @@ -53,7 +54,6 @@ def main(options: Namespace, inputdir: Path, outputdir: Path):
:param inputdir: directory containing (read-only) input files
:param outputdir: directory where to write output files
"""

print(DISPLAY_TITLE)

# Typically it's easier to think of programs as operating on individual files
Expand All @@ -63,15 +63,16 @@ def main(options: Namespace, inputdir: Path, outputdir: Path):
#
# Refer to the documentation for more options, examples, and advanced uses e.g.
# adding a progress bar and parallelism.
mapper = PathMapper.file_mapper(inputdir, outputdir, glob=options.pattern, suffix='.count.txt')
mapper = PathMapper.file_mapper(
inputdir, outputdir, glob=options.pattern, suffix=".bak.dcm"
)
for input_file, output_file in mapper:
# The code block below is a small and easy example of how to use a ``PathMapper``.
# It is recommended that you put your functionality in a helper function, so that
# it is more legible and can be unit tested.
data = input_file.read_text()
frequency = data.count(options.word)
output_file.write_text(str(frequency))
print(f"copying {input_file} to {output_file}")
shutil.copy(input_file, output_file)


if __name__ == '__main__':
if __name__ == "__main__":
main()

0 comments on commit c311156

Please sign in to comment.