Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

integrated filepattern in filerenaming #572

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
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]
5 changes: 5 additions & 0 deletions formats/file-renaming-tool/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@
### 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
2 changes: 1 addition & 1 deletion formats/file-renaming-tool/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM polusai/bfio:2.3.6
FROM polusai/bfio:2.4.5

# environment variables defined in polusai/bfio
ENV EXEC_DIR="/opt/executables"
Expand Down
44 changes: 39 additions & 5 deletions formats/file-renaming-tool/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# File Renaming(0.2.4-dev0)
# File Renaming(v0.2.5-dev0)
This WIPP plugin uses supplied file naming patterns to dynamically
rename and save files in an image collection to a new image collection.

Expand All @@ -16,10 +16,10 @@ 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`

* The user can format the output digit using the number of digits
Expand All @@ -38,7 +38,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:[email protected]), [Hamdah Shafqat abbasi](mailto:[email protected]) for more
Expand Down Expand Up @@ -67,5 +101,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: [email protected]
container: polusai/file-renaming-tool:0.2.4-dev0
- Hamdah Shafqat
- Melanie Parham
contact: [email protected]
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
43 changes: 17 additions & 26 deletions formats/file-renaming-tool/plugin.json
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
{
"name": "File Renaming",
"version": "0.2.4",
"version": "0.2.5-dev0",
"title": "File Renaming",
"description": "Rename and store image collection files in a new image collection",
"author": "Melanie Parham ([email protected]), Hamdah Shafqat Abbasi ([email protected])",
"author": "Hamdah Shafqat Abbasi ([email protected]), Melanie Parham ([email protected])",
"institution": "National Center for Advancing Translational Sciences, National Institutes of Health",
"repository": "https://github.com/PolusAI/image-tools",
"website": "https://ncats.nih.gov/preclinical/core/informatics",
"citation": "",
"containerId": "polusai/file-renaming-tool:0.2.4",
"containerId": "polusai/file-renaming-tool:0.2.5-dev0",
"baseCommand": [
"python3",
"-m",
"polus.images.formats.file_renaming"
],
"inputs": [
{
"name": "filePattern",
"type": "string",
"description": "Filename pattern used to separate data",
"required": true
},
{
"name": "inpDir",
"type": "collection",
"description": "Input image collection to be processed by this plugin",
"required": true
},
{
"name": "filePattern",
"type": "string",
"description": "Filename pattern used to separate data",
"required": true
},
{
"name": "outFilePattern",
"type": "string",
Expand All @@ -35,16 +35,8 @@
},
{
"name": "mapDirectory",
"type": "enum",
"description": "Get directory name incorporated in renamed files",
"default": "default",
"options": {
"values": [
"raw",
"map",
"default"
]
},
"type": "boolean",
"description": "Incorporate mapped directory names into renamed files",
"required": false
}
],
Expand All @@ -56,16 +48,16 @@
}
],
"ui": [
{
"key": "inputs.filePattern",
"title": "Filename pattern",
"description": "Filename pattern used to separate data"
},
{
"key": "inputs.inpDir",
"title": "Input collection",
"description": "Input image collection to be processed by this plugin"
},
{
"key": "inputs.filePattern",
"title": "Filename pattern",
"description": "Filename pattern used to separate data"
},
{
"key": "inputs.outFilePattern",
"title": "Output filename pattern",
Expand All @@ -74,8 +66,7 @@
{
"key": "inputs.mapDirectory",
"title": "mapDirectory",
"description": "Get directory name incorporated in renamed files",
"default": ""
"description": "Incorporate mapped directory names into renamed files"
}
]
}
14 changes: 10 additions & 4 deletions formats/file-renaming-tool/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[tool.poetry]
name = "polus-images-formats-file-renaming"
version = "0.2.4"
description = "Rename and store image collection files in a new image collection"
version = "0.2.5-dev0"
description = "Convert BioFormats datatypes to ome.tif or ome.zarr file format"
authors = [
"Melanie Parham <[email protected]>",
"Hamdah Shafqat abbasi <[email protected]>"
"Hamdah Shafqat abbasi <[email protected]>",
"Melanie Parham <[email protected]>",
]
readme = "README.md"
packages = [{include = "polus", from = "src"}]
Expand All @@ -14,6 +14,7 @@ python = ">=3.9,<3.12"
typer = "^0.7.0"
tqdm = "^4.64.1"
numpy = "^1.26.3"
filepattern = "^2.0.5"

[tool.poetry.group.dev.dependencies]
bump2version = "^1.0.1"
Expand All @@ -26,3 +27,8 @@ pytest = "^7.2.1"
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[tool.pytest.ini_options]
pythonpath = [
"."
]
12 changes: 7 additions & 5 deletions formats/file-renaming-tool/run-plugin.sh
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
#!/bin/bash
!/bin/bash


version=$(<VERSION)
datapath=$(readlink --canonicalize data)

# Inputs
inpDir=/data/inputs
filePattern=".*_{row:c}{col:dd}_s{s:d}_w{channel:d}.*.tif"
outFilePattern="r01_x{row:c}_y{col:dd}_p{s:d}_c{channel:d}.ome.tif"
mapDirectory="raw"
mapDirectory=true
# Output paths
outDir=/data/output

# Show the help options
docker run polusai/file-renaming-plugin:${version}
docker run polusai/file-renaming-tool:${version}

# Run the plugin
docker run --mount type=bind,source=${datapath},target=/data/ \
polusai/file-renaming-plugin:${version} \
polusai/file-renaming-tool:${version} \
--inpDir ${inpDir} \
--filePattern ${filePattern} \
--outFilePattern ${outFilePattern} \
--mapDirectory ${outFilePattern} \
--mapDirectory
--outDir ${outDir}
Loading
Loading