changeset 0:e8f64a98cbc6 draft default tip

"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/3d_tensor_feature_dimension_reduction/ commit e82400162e337b36c29d6e79fb2deb9871475397"
author imgteam
date Thu, 20 Jan 2022 00:45:01 +0000
parents
children
files 3d_tensor_feature_dimension_reduction.py 3d_tensor_feature_dimension_reduction.xml test-data/tensor.h5 test-data/tensor_r.tif
diffstat 4 files changed, 77 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/3d_tensor_feature_dimension_reduction.py	Thu Jan 20 00:45:01 2022 +0000
@@ -0,0 +1,39 @@
+"""
+Copyright 2022 Biomedical Computer Vision Group, Heidelberg University.
+
+Distributed under the MIT license.
+See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
+
+"""
+
+import argparse
+import warnings
+
+import h5py
+import numpy as np
+import tifffile
+import umap
+
+
+def feature_dimension_reduction(tensor_fn, tiff_fn, nCh=5):
+    with h5py.File(tensor_fn, 'r') as hf:
+        ts = np.array(hf[list(hf.keys())[0]])
+
+    assert len(ts.shape) == 3 and ts.shape[-1] > nCh, \
+        'the input tensor data must be three-dimensional'
+
+    embedding = umap.UMAP(n_components=nCh).fit_transform(np.reshape(ts, (-1, ts.shape[-1])))
+    img = np.reshape(embedding, (ts.shape[0], ts.shape[1], -1)).astype(np.float32)
+
+    with warnings.catch_warnings():
+        warnings.simplefilter("ignore")
+        tifffile.imwrite(tiff_fn, np.transpose(img, (2, 0, 1)), imagej=True)
+
+
+if __name__ == "__main__":
+    parser = argparse.ArgumentParser(description="Dimensionality reduction for features (channels) of 3D tensor using UMAP")
+    parser.add_argument("tensor_fn", help="Path to the 3D tensor data")
+    parser.add_argument("nCh", type=int, help="The reduced dimension of features")
+    parser.add_argument("tiff_fn", help="Path to the output file")
+    args = parser.parse_args()
+    feature_dimension_reduction(args.tensor_fn, args.tiff_fn, args.nCh)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/3d_tensor_feature_dimension_reduction.xml	Thu Jan 20 00:45:01 2022 +0000
@@ -0,0 +1,38 @@
+<tool id="ip_3d_tensor_feature_dimension_reduction" name="Dimensionality Reduction" version="0.0.1" profile="20.05"> 
+    <description>for features of 3D tensor data using UMAP</description>
+    <requirements>
+        <requirement type="package" version="1.20.2">numpy</requirement>
+        <requirement type="package" version="3.6.0">h5py</requirement>
+        <requirement type="package" version="2020.10.1">tifffile</requirement>
+        <requirement type="package" version="0.5.2">umap-learn</requirement>
+    </requirements>
+    <command detect_errors="aggressive"><![CDATA[
+        ln -s '$fn_in' ./input.h5 &&
+        python '$__tool_directory__/3d_tensor_feature_dimension_reduction.py'
+        ./input.h5
+        '$nCh'
+        ./output.tif
+    ]]>
+    </command>
+    <inputs>
+        <param name="fn_in" type="data" format="hdf5" label="3D tensor data (rows x cols x features)" />
+        <param name="nCh" type="integer" value="5" optional="true" min="1" max="10" label="Reduced dimensions of features" />
+    </inputs>
+    <outputs>
+        <data format="tiff" name="fn_out" from_work_dir="output.tif" />
+    </outputs>
+    <tests>
+        <test>
+            <param name="fn_in" value="tensor.h5"/>
+            <param name="nCh" value="3"/>
+            <output name="fn_out" value="tensor_r.tif" ftype="tiff" compare="sim_size"/>
+        </test>
+    </tests>
+    <help>
+    **What it does**
+
+    This tool performs dimensionality reduction for features of 3D tensor data (rows x cols x features) using UMAP. The results will be saved as a multi-channel 32-bit TIFF image (features x rows x cols).
+    </help>
+    <citations>
+    </citations>
+</tool>
Binary file test-data/tensor.h5 has changed
Binary file test-data/tensor_r.tif has changed