Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion formats/file-renaming-tool/.bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.2.4
current_version = 0.2.5-dev0
commit = True
tag = False
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\-(?P<release>[a-z]+)(?P<dev>\d+))?
Expand All @@ -22,6 +22,12 @@ replace = version = "{new_version}"

[bumpversion:file:plugin.json]

[bumpversion:file:FileRenaming.cwl]

[bumpversion:file:ict.yaml]

[bumpversion:file:VERSION]

[bumpversion:file:README.md]

[bumpversion:file:src/polus/images/formats/file_renaming/__init__.py]
10 changes: 10 additions & 0 deletions formats/file-renaming-tool/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,13 @@
### Added
- Pytests to test this plugin
- Added a support for recursively searching for files within a directory and its subdirectories of specified pattern by passing value either raw or map for `mapDirectory` input argument.

## [0.2.4-dev2] - 2024-12-17
### Added
- Integrated filepattern in this tool
- Modified the sorting dictionary letters key with respect to length

## [0.2.5-dev0] - 2026-03-04
### Added
- Updated dependencies and base container image
- refactored code
3 changes: 2 additions & 1 deletion formats/file-renaming-tool/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
FROM polusai/bfio:2.3.6
FROM polusai/bfio:2.5.0

# environment variables defined in polusai/bfio
ENV EXEC_DIR="/opt/executables"
ENV POLUS_IMG_EXT=".ome.tif"
ENV POLUS_TAB_EXT=".csv"
ENV POLUS_LOG="INFO"
ENV NUM_THREADS=8

# Work directory defined in the base container
WORKDIR ${EXEC_DIR}
Expand Down
88 changes: 81 additions & 7 deletions formats/file-renaming-tool/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# File Renaming(0.2.4-dev0)
This WIPP plugin uses supplied file naming patterns to dynamically
rename and save files in an image collection to a new image collection.
# File Renaming(v0.2.5-dev0)
This WIPP plugin renames files in an image collection (typically microscopy images) using powerful, user-defined filename patterns for both input matching and output naming.

It is particularly useful for:
- Standardizing file names across experiments
- Converting channel names (GFP, DAPI, TXRED…) to numeric indices
- Adding zero-padding consistently
- Reorganizing naming schemes
- Working with nested directory structures

## Example Usage
* The user can upload an image collection where all files contain similar
Expand All @@ -16,12 +22,14 @@ naming conventions.
`newdata_x001_y001_c002.tif`
`newdata_x001_y001_c003.tif`

* **User input pattern:**
* **filePattern:**
`img_x{row:dd}_y{col:dd}_{channel:c+}.ome.tif`

* **User output pattern:**
* **outFilePattern:**
`newdata_x{row:ddd}_y{col:ddd}_c{channel:ddd}.ome.tif`

**Important rules:**

* The user can format the output digit using the number of digits
specified in the output format.
* `d` represents *digit*
Expand All @@ -38,7 +46,41 @@ exception:
then the script sorts the strings that match the character pattern and
assigns numbers 0+ to them.

* New optional feature `mapDirectory` implemented to include directory name in renamed files. This plugin also handles nested directories and one level up directory name is added to renamed files if `raw` value passed, `map` for mapped subdirectories `d0, d1, d2, ... dn` and if not passed then no directory name is added in renamed files.
* Implemented a new optional boolean feature `mapDirectory` to append mapped directory names in renamed files.


## Renaming files within a complex nested directory structure:
In specific scenarios where users need to rename files within nested subdirectories, this functionality can be leveraged by providing an appropriate pattern

For Example

```
BBBC001
└── raw
├── Ground_Truth
│ └── groundtruth_images
│ ├── AS_09125_050118150001_A03f00d0.tif
│ ├── AS_09125_050118150001_A03f01d0.tif
│ ├── AS_09125_050118150001_A03f02d0.tif
│ ├── AS_09125_050118150001_A03f03d0.tif
│ ├── AS_09125_050118150001_A03f04d0.tif
│ └── AS_09125_050118150001_A03f05d0.tif
└── Images
└── human_ht29_colon_cancer_1_images
├── AS_09125_050118150001_A03f00d0.tif
├── AS_09125_050118150001_A03f01d0.tif
├── AS_09125_050118150001_A03f02d0.tif
├── AS_09125_050118150001_A03f03d0.tif
├── AS_09125_050118150001_A03f04d0.tif
└── AS_09125_050118150001_A03f05d0.tif

```

Now, renaming files within the `human_ht29_colon_cancer_1_images` is achievable by providing a `filepattern` such as `/.*/Images/(?P<directory>.*)/.*_{row:c}{col:dd}f{f:dd}d{channel:d}.tif`, and specifying `outFilePattern` as `x{row:dd}_y{col:dd}_p{f:dd}_c{channel:d}.tif`. If the mapDirectory option is not utilized, the raw directory name will be appended in the renamed files. To handle directory names containing both letters and digits, employ `(?P<directory>.*)`; use `{directory:c+}` or `{directory:d+}` if it contains solely letters or digits, respectively.

#### Note:
To extract directory names, the pattern should start with a backslash



Contact [Melanie Parham](mailto:melanie.parham@axleinfo.com), [Hamdah Shafqat abbasi](mailto:hamdahshafqat.abbasi@nih.gov) for more
Expand All @@ -57,6 +99,38 @@ To build the Docker image for the conversion plugin, run
If WIPP is running, navigate to the plugins page and add a new plugin.
Paste the contents of `plugin.json` into the pop-up window and submit.

## Docker / CLI Examples

Basic

```
docker run --rm \
-v "/path/to/input/images:/data/input" \
-v "/path/to/output:/data/output" \
polusai/file-renaming-tool:0.2.5-dev0 \
--inpDir /data/input \
--outDir /data/output \
--filePattern 'img_x{row:dd}_y{col:dd}_{channel:c+}.tif' \
--outFilePattern 'r{row:03d}_c{col:03d}_ch{channel:03d}.ome.tif'


```
Directory mapping

```
docker run --rm \
-v "/path/to/dataset:/data" \
polusai/file-renaming-tool:0.2.5-dev0 \
--inpDir /data/input \
--outDir /data/output \
--filePattern '/.*/Images/(?P<directory>.*)/.*_{row:c}{col:dd}f{f:dd}d{channel:d}.tif' \
--outFilePattern 'x{row:dd}_y{col:dd}_p{f:dd}_c{channel:d}_dir{directory}.tif' \
--mapDirectory


```


## Options

This plugin takes three input argument and one output argument:
Expand All @@ -67,5 +141,5 @@ This plugin takes three input argument and one output argument:
| `--filePattern` | Input filename pattern | Input | string |
| `--outDir` | Output collection | Output | collection |
| `--outFilePattern` | Output filename pattern | Input | string |
| `--mapDirectory` | Directory name (`raw`, `map`) | Input | enum |
| `--mapDirectory` | Extract mapped directory name | Input | boolean |
| `--preview` | Generate a JSON file with outputs | Output | JSON |
2 changes: 1 addition & 1 deletion formats/file-renaming-tool/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.2.4
0.2.5-dev0
4 changes: 2 additions & 2 deletions formats/file-renaming-tool/filerenaming.cwl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ inputs:
mapDirectory:
inputBinding:
prefix: --mapDirectory
type: string?
type: boolean?
outDir:
inputBinding:
prefix: --outDir
Expand All @@ -28,7 +28,7 @@ outputs:
type: Directory
requirements:
DockerRequirement:
dockerPull: polusai/file-renaming-tool:0.2.4-dev0
dockerPull: polusai/file-renaming-tool:0.2.5-dev0
InitialWorkDirRequirement:
listing:
- entry: $(inputs.outDir)
Expand Down
108 changes: 52 additions & 56 deletions formats/file-renaming-tool/ict.yaml
Original file line number Diff line number Diff line change
@@ -1,65 +1,61 @@
author:
- Melanie Parham
- Hamdah Shafqat
contact: melanie.parham@axleinfo.com
container: polusai/file-renaming-tool:0.2.4-dev0
- Hamdah Shafqat
- Melanie Parham
contact: hamdahshafqat.abbasi@nih.gov
container: polusai/file-renaming-tool:0.2.5-dev0
description: Rename and store image collection files in a new image collection
entrypoint: python3 -m polus.images.formats.file_renaming
inputs:
- description: Filename pattern used to separate data
format:
- string
name: filePattern
required: true
type: string
- description: Input image collection to be processed by this plugin
format:
- collection
name: inpDir
required: true
type: path
- description: Desired filename pattern used to rename and separate data
format:
- string
name: outFilePattern
required: true
type: string
- description: Get directory name incorporated in renamed files
format:
- enum
name: mapDirectory
required: false
type: string
- description: Input image collection to be processed by this plugin
format:
- collection
name: inpDir
required: true
type: path
- description: Filename pattern used to separate data
format:
- string
name: filePattern
required: true
type: string
- description: Desired filename pattern used to rename and separate data
format:
- string
name: outFilePattern
required: true
type: string
- description: Incorporate mapped directory names into renamed files
format:
- boolean
name: mapDirectory
required: false
type: boolean
name: polusai/FileRenaming
outputs:
- description: Output collection
format:
- collection
name: outDir
required: true
type: path
repository: https://github.com/PolusAI/polus-plugins
- description: Output collection
format:
- collection
name: outDir
required: true
type: path
repository: https://github.com/PolusAI/image-tools
specVersion: 1.0.0
title: File Renaming
ui:
- description: Filename pattern used to separate data
key: inputs.filePattern
title: Filename pattern
type: text
- description: Input image collection to be processed by this plugin
key: inputs.inpDir
title: Input collection
type: path
- description: Desired filename pattern used to rename and separate data
key: inputs.outFilePattern
title: Output filename pattern
type: text
- description: Get directory name incorporated in renamed files
fields:
- raw
- map
- default
key: inputs.mapDirectory
title: mapDirectory
type: select
version: 0.2.4-dev0
- description: Input image collection to be processed by this plugin
key: inputs.inpDir
title: Input collection
type: path
- description: Filename pattern used to separate data
key: inputs.filePattern
title: Filename pattern
type: text
- description: Desired filename pattern used to rename and separate data
key: inputs.outFilePattern
title: Output filename pattern
type: text
- description: Incorporate mapped directory names into renamed files
key: inputs.mapDirectory
title: mapDirectory
type: checkbox
version: 0.2.5-dev0
Loading
Loading