changeset 0:ed8a71e13f7b draft

planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
author imgteam
date Sat, 09 Feb 2019 14:45:19 -0500
parents
children f1744c5654b9
files projective_transformation_points.py projective_transformation_points.xml test-data/out.tsv test-data/out2.tsv test-data/points_tsv.tsv test-data/warp_matrix.tsv
diffstat 6 files changed, 97 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/projective_transformation_points.py	Sat Feb 09 14:45:19 2019 -0500
@@ -0,0 +1,35 @@
+from skimage.transform import ProjectiveTransform
+import numpy as np
+import pandas as pd
+import argparse
+
+
+def warp_coords_batch(coord_map, coords, dtype=np.float64, batch_size=1000000):
+    tf_coords = coords.astype(np.float32)
+
+    for i in range(0, (tf_coords.shape[0]//batch_size+1)):
+        tf_coords[batch_size*i:batch_size*(i+1)] = coord_map(tf_coords[batch_size*i:batch_size*(i+1)])
+
+    return np.unique(np.round(tf_coords).astype(coords.dtype),axis=0)
+
+
+def transform(coords, warp_matrix, out):
+    indices = np.array(pd.read_csv(coords, delimiter="\t"))
+    a_matrix = np.array(pd.read_csv(warp_matrix, delimiter="\t", header=None))
+    
+    trans = ProjectiveTransform(matrix=a_matrix)
+    warped_coords = warp_coords_batch(trans, indices)
+
+    df = pd.DataFrame()
+    df['x'] = warped_coords[:,0]
+    df['y'] = warped_coords[:,1]
+    df.to_csv(out, index = False, sep="\t")
+
+
+if __name__ == "__main__":
+    parser = argparse.ArgumentParser(description="Transform coordinates")
+    parser.add_argument("coords", help="Paste path to .csv with coordinates to transform (tab separated)")
+    parser.add_argument("warp_matrix", help="Paste path to .csv that should be used for transformation (, separated)")
+    parser.add_argument("out", help="Paste path to file in which transformed coords should be saved (tab separated)")
+    args = parser.parse_args()
+    transform(args.coords, args.warp_matrix, args.out)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/projective_transformation_points.xml	Sat Feb 09 14:45:19 2019 -0500
@@ -0,0 +1,38 @@
+<tool id="ip_projective_transformation_points" name="Projective Transformation" version="0.0.2">
+    <description>of input points</description>
+    <requirements>
+        <requirement type="package" version="0.14.2">scikit-image</requirement>
+        <requirement type="package" version="0.23.4">pandas</requirement>
+        <requirement type="package" version="1.15.2">numpy</requirement><!--conflict of 1.15.4 with mkl_fft!?-->
+    </requirements>
+    <command>
+    <![CDATA[
+        python '$__tool_directory__/projective_transformation_points.py'
+            '$moving_points'
+            '$warp_matrix'
+            '$out'
+    ]]>
+    </command>
+    <inputs>
+        <param name="moving_points" type="data" format="tabular" label="Moving Points" />
+        <param name="warp_matrix" type= "data" format="tabular" label="Warp Matrix" />
+    </inputs>
+    <outputs>
+       <data format="tabular" name="out" />
+    </outputs>
+    <tests>
+      <test>
+        <param name="moving_points" value="points_tsv.tsv" />
+        <param name="warp_matrix" value="warp_matrix.tsv" />
+        <output name="out" value="out.tsv" ftype="tabular" />
+      </test>
+    </tests>
+    <help>
+    **What it does**
+
+    This tool performs a projective transformation of the input (moving) points.
+    </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/out.tsv	Sat Feb 09 14:45:19 2019 -0500
@@ -0,0 +1,7 @@
+x	y
+18	24
+18	25
+18	26
+18	27
+20	22
+25	35
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/out2.tsv	Sat Feb 09 14:45:19 2019 -0500
@@ -0,0 +1,7 @@
+x	y
+18	24
+18	25
+18	26
+18	27
+20	22
+25	35
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/points_tsv.tsv	Sat Feb 09 14:45:19 2019 -0500
@@ -0,0 +1,7 @@
+5	3
+10	2
+8	4
+15	15
+8	5
+8	6
+8	7
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/warp_matrix.tsv	Sat Feb 09 14:45:19 2019 -0500
@@ -0,0 +1,3 @@
+1	0	10
+0	1	20
+0	0	1