changeset 0:e576b73a2e2f draft

planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_filter_segmentation_by_features/ commit b2acc1845a25828181597fe5b6982fe116a7796d
author imgteam
date Mon, 22 Jul 2019 05:00:03 -0400
parents
children 6ad1d3cfdea1
files 2d_filter_segmentation_by_features.py 2d_filter_segmentation_by_features.xml test-data/features.tabular test-data/in.tif test-data/out.tif test-data/rules.tabular
diffstat 6 files changed, 74 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/2d_filter_segmentation_by_features.py	Mon Jul 22 05:00:03 2019 -0400
@@ -0,0 +1,29 @@
+import argparse
+import sys
+import skimage.io 
+import skimage.util
+import pandas as pd
+
+if __name__ == "__main__":
+    parser = argparse.ArgumentParser(description='Filter segmentation by features')
+    parser.add_argument('input_file', type=argparse.FileType('r'), default=sys.stdin, help='input file')
+    parser.add_argument('out_file', type=argparse.FileType('w'), default=sys.stdin, help='out file (TIFF)')
+    parser.add_argument('feature_file', type=argparse.FileType('r'), default=sys.stdin, help='feature file (cols: label, f1, f2)')
+    parser.add_argument('rule_file', type=argparse.FileType('r'), default=sys.stdin, help='file with rules per feature (cols: ,f1,2, rows: feature_name, min, max)')
+    args = parser.parse_args()
+
+    img_in = skimage.io.imread(args.input_file.name)
+    features = pd.read_csv(args.feature_file, delimiter="\t")
+    rules = pd.read_csv(args.rule_file, delimiter="\t")
+    
+    cols = [a for a in rules.columns if not 'Unnamed' in a]
+    for a_c in cols:
+        a_min = rules[rules.ix[:, 0] == 'min'][a_c]
+        a_max = rules[rules.ix[:, 0] == 'max'][a_c]
+        for a_l in features.label:
+            a_val = float(features[features['label'] == a_l][a_c])
+            if a_val < float(a_min) or a_val > float(a_max):
+                img_in[img_in == int(a_l)] = 0
+
+    res = skimage.util.img_as_uint(img_in)
+    skimage.io.imsave(args.out_file.name, res, plugin="tifffile")
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/2d_filter_segmentation_by_features.xml	Mon Jul 22 05:00:03 2019 -0400
@@ -0,0 +1,37 @@
+<tool id="ip_2d_filter_segmentation_by_features" name="Filter segmentation" version="0.0.1"> 
+   <description>Filter segmentation by rules</description>
+   <requirements>
+        <requirement type="package" version="0.14.2">scikit-image</requirement> 
+        <requirement type="package" version="5.3.0">pillow</requirement>
+        <requirement type="package" version="0.23.4">pandas</requirement>
+        <requirement type="package" version="0.15.1">tifffile</requirement>
+   </requirements>
+   <command detect_errors="aggressive">
+   <![CDATA[
+   python '$__tool_directory__/2d_filter_segmentation_by_features.py' '$input' '$output' '$feature_file' '$rule_file'
+   ]]>
+   </command>
+   <inputs>
+        <param name="input" type="data" format="tiff" label="Source file" /> 
+        <param name="feature_file" type="data" format="tabular" label="Feature file" /> 
+        <param name="rule_file" type="data" format="tabular" label="Rules file" /> 
+    </inputs>
+    <outputs>
+       <data format="tiff" name="output" />
+    </outputs>
+    <tests>
+        <test>
+            <param name="input" value="in.tif"/>
+            <param name="feature_file" value="features.tabular"/>
+            <param name="rule_file" value="rules.tabular"/>
+            <output name="output" value="out.tif" ftype="tiff" compare="sim_size"/>
+        </test>
+    </tests>
+    <help>
+        Filter label image by rules (e.g., remove large or deformed objects).
+        Rules file has a specific format (cols: ,f1,2, rows: feature_name, min, max). The features have to be also profived in a specific format (cols: label, f1, f2).
+    </help>
+    <citations>
+        <citation type="doi">10.1016/j.jbiotec.2017.07.019</citation>
+    </citations>
+</tool>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/features.tabular	Mon Jul 22 05:00:03 2019 -0400
@@ -0,0 +1,5 @@
+label	area	eccentricity
+1	344	0.42521053699241596
+2	434	0.47679001553231926
+3	907	0.9973539531125177
+4	14320	0.17131009631035327
Binary file test-data/in.tif has changed
Binary file test-data/out.tif has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/rules.tabular	Mon Jul 22 05:00:03 2019 -0400
@@ -0,0 +1,3 @@
+	area	eccentricity
+min	500	0.
+max	100000	0.5