changeset 0:dd513c9f5230 draft

planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/points2binaryimage/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
author imgteam
date Sat, 09 Feb 2019 14:43:25 -0500
parents
children 90385ec28b34
files __pycache__/points2binaryimage.cpython-36.pyc points2binaryimage.py points2binaryimage.xml test-data/out.tiff test-data/points.tsv
diffstat 5 files changed, 105 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
Binary file __pycache__/points2binaryimage.cpython-36.pyc has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/points2binaryimage.py	Sat Feb 09 14:43:25 2019 -0500
@@ -0,0 +1,53 @@
+import argparse
+import sys
+import numpy as np
+import skimage.io
+import pandas as pd
+import os
+import warnings
+
+
+def points2binaryimage(point_file, out_file, shape=[500, 500], has_header=False, invert_xy=False):
+
+    img = np.zeros(shape, dtype=np.int16)
+    if os.path.exists(point_file) and os.path.getsize(point_file) > 0:
+        if has_header:
+            df = pd.read_csv(point_file, skiprows=1, header=None, delimiter="\t")
+        else:
+            df = pd.read_csv(point_file, header=None, delimiter="\t")
+
+        for i in range(0, len(df)):
+            a_row = df.iloc[i]
+            if int(a_row[0]) < 0 or int(a_row[1]) < 0:
+                raise IndexError("Point {},{} is out of image with bounds {},{}.".format(int(a_row[0]), int(a_row[1]), shape[0], shape[1]))
+
+            if invert_xy:
+                if img.shape[0]<=int(a_row[0]) or img.shape[1]<=int(a_row[1]):
+                    raise IndexError("Point {},{} is out of image with bounds {},{}.".format(int(a_row[0]), int(a_row[1]), shape[0], shape[1]))
+                else:
+                    img[int(a_row[1]), int(a_row[0])] = 32767
+            else:
+                if img.shape[0]<=int(a_row[1]) or img.shape[1]<=int(a_row[0]):
+                    raise IndexError("Point {},{} is out of image with bounds {},{}.".format(int(a_row[1]), int(a_row[0]), shape[0], shape[1]))
+                else:
+                    img[int(a_row[0]), int(a_row[1])] = 32767
+    else:
+        raise Exception("{} is empty or does not exist.".format(point_file)) # appropriate built-in error?
+
+    with warnings.catch_warnings():
+        warnings.simplefilter("ignore")
+        skimage.io.imsave(out_file, img, plugin='tifffile') # otherwise we get problems with the .dat extension
+
+if __name__ == "__main__":
+    parser = argparse.ArgumentParser()
+    parser.add_argument('point_file', type=argparse.FileType('r'), help='label file')
+    parser.add_argument('out_file', type=str, help='out file (TIFF)')
+    parser.add_argument('shapex', type=int, help='shapex')
+    parser.add_argument('shapey', type=int, help='shapey')
+    parser.add_argument('--has_header', dest='has_header', default=False, help='set True if CSV has header')
+    parser.add_argument('--invert_xy', dest='invert_xy', default=False, help='invert x and y in CSV')
+
+    args = parser.parse_args()
+
+    #TOOL
+    points2binaryimage(args.point_file.name, args.out_file, [args.shapey, args.shapex], has_header=args.has_header, invert_xy=args.invert_xy)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/points2binaryimage.xml	Sat Feb 09 14:43:25 2019 -0500
@@ -0,0 +1,43 @@
+<tool id="ip_points_to_binaryimage" name="Points to Binary Image" version="0.1">
+    <description>Converts points to a binary image</description>
+    <requirements> 
+        <requirement type="package" version="0.14.2">scikit-image</requirement>
+        <requirement type="package" version="1.15.4">numpy</requirement>
+        <requirement type="package" version="0.23.4">pandas</requirement>
+        <requirement type="package" version="2018.7">pytz</requirement><!--pandas seems to have additional requirements that are not automatically installed-->
+        <requirement type="package" version="2.4.1">dateutil</requirement>
+    </requirements>
+    <command>
+        <![CDATA[
+        python '$__tool_directory__/points2binaryimage.py' '$input' '$output' $shapex $shapey $has_header $invert_xy
+        ]]>
+    </command>
+    <inputs> 
+        <param name="input" type="data" format="tabular" label="CSV point file"/> 
+        <param name="shapex" type="integer" value="500" optional="true" min="1" max="2000" label="Width of output image" />
+        <param name="shapey" type="integer" value="500" optional="true" min="1" max="2000" label="Height of output image" />
+        <param name="has_header" type="boolean" checked="false" truevalue="--has_header True" falsevalue="" optional="true" label="Does point file contain header?" /> 
+        <param name="invert_xy" type="boolean" checked="false" falsevalue="" truevalue="--invert_xy True" optional="true" label="Inverts x and y in CSV point file" />
+    </inputs>
+    <outputs>
+        <data name="output" format="tiff" />
+    </outputs>
+    <tests>
+        <test>
+            <param name="input" value="points.tsv" />
+            <param name="shapex" value="20" /> 
+            <param name="shapey" value="30" />
+            <param name="has_header" value="false" />
+            <param name="invert_xy" value="true" />
+            <output name="output" ftype="tiff" file="out.tiff" compare="sim_size"/> 
+        </test>
+    </tests>
+    <help>
+    **What it does**
+
+    Converts CSV point file to binary image.
+    </help>
+    <citations>
+        <citation type="doi">10.1016/j.jbiotec.2017.07.019</citation> 
+    </citations>
+</tool>
Binary file test-data/out.tiff has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/points.tsv	Sat Feb 09 14:43:25 2019 -0500
@@ -0,0 +1,9 @@
+11.7555970149	10.4048507463
+15	14
+19	2
+5	4
+5	5
+5	6
+5	7
+5	8
+5	9