changeset 0:14525b8c8d67 draft default tip

planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/points2labelimage/ commit 356f2556bd629e5473d6711ec71372ea17d3e28f
author thomaswollmann
date Wed, 12 Dec 2018 05:12:06 -0500
parents
children
files points2label.py points2label.xml test-data/galaxyIcon_noText.tif test-data/out.tif test-data/points.csv
diffstat 5 files changed, 84 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/points2label.py	Wed Dec 12 05:12:06 2018 -0500
@@ -0,0 +1,44 @@
+import argparse
+import sys
+import numpy as np
+import skimage.io
+import pandas as pd
+import warnings
+
+def points2label(labels, shape, output_file=None, has_header=False, is_TSV=False):
+    labelimg = np.zeros([shape[0], shape[1]], dtype=np.int32)
+
+    if is_TSV:
+        if has_header:
+            df = pd.read_csv(labels, sep='\t', skiprows=1, header=None)
+        else:
+            df = pd.read_csv(labels, sep='\t', header=None)
+    else:
+        if has_header:
+            df = pd.read_csv(labels, skiprows=1, header=None)
+        else:
+            df = pd.read_csv(labels, header=None)
+
+    for i in range(0, len(df)):
+        a_row = df.iloc[i]
+        labelimg[a_row[0], a_row[1]] = i+1
+
+    if output_file is not None:
+        with warnings.catch_warnings():
+            warnings.simplefilter("ignore")
+            skimage.io.imsave(output_file, labelimg, plugin='tifffile')
+    else:
+        return labelimg
+
+if __name__ == "__main__":
+    parser = argparse.ArgumentParser()
+    parser.add_argument('label_file', type=argparse.FileType('r'), default=sys.stdin, help='label file')
+    parser.add_argument('out_file', type=argparse.FileType('w'), default=sys.stdin, help='out file')
+    parser.add_argument('org_file', type=argparse.FileType('r'), default=sys.stdin, help='input original file')
+    parser.add_argument('--has_header', dest='has_header', type=bool, default=False, help='label file has header')
+    parser.add_argument('--is_tsv', dest='is_tsv', type=bool, default=False, help='label file is TSV')
+    args = parser.parse_args()
+
+    original_shape = skimage.io.imread(args.org_file.name, plugin='tifffile').shape
+
+    points2label(args.label_file.name, original_shape, args.out_file.name, args.has_header, args.is_tsv)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/points2label.xml	Wed Dec 12 05:12:06 2018 -0500
@@ -0,0 +1,33 @@
+<tool id="points2labelimage" name="Points 2 Label" version="0.2">
+  <description>Points to Label Image</description>
+  <requirements>
+    <requirement type="package" version="1.15.4">numpy</requirement>
+    <requirement type="package" version="0.14.0">scikit-image</requirement>
+    <requirement type="package" version="0.23.4">pandas</requirement>
+  </requirements>
+  <command>
+    <![CDATA[
+        python '$__tool_directory__/points2label.py' '$input' '$output' '$org_file' $has_header $is_tsv
+    ]]>
+  </command>
+  <inputs>
+    <param name="input" type="data" format="csv" label="Point CSV file"/>
+    <param name="org_file" type="data" format="tiff" label="Original label image file"/>
+    <param name="has_header" type="boolean" checked="false" truevalue="--has_header True" falsevalue="" optional="true" label="Does point file contain header?" /> 
+    <param name="is_tsv" optional="true" type="boolean" checked="false" truevalue="--is_tsv True" falsevalue="" help="tab separated input file"/>
+  </inputs>
+  <outputs>
+    <data name="output" format="tiff"/>
+  </outputs>
+  <tests>
+    <test>
+      <param name="input" value="points.csv"/>
+      <param name="org_file" value="galaxyIcon_noText.tif"/>
+      <output name="output" file="out.tif" ftype="tiff" compare="sim_size"/><!--to allow a change in e.g. date-->
+    </test>
+  </tests>
+    <help> This tool converts points to a label image. </help>
+  <citations>
+    <citation type="doi">10.1016/j.jbiotec.2017.07.019</citation> 
+  </citations>
+</tool>
Binary file test-data/galaxyIcon_noText.tif has changed
Binary file test-data/out.tif has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/points.csv	Wed Dec 12 05:12:06 2018 -0500
@@ -0,0 +1,7 @@
+5,3
+10,2
+8,4
+15,15
+8,5
+8,6
+8,7