diff imagej2_convert_format.py @ 0:312e8ce708b1 draft

planemo upload commit 4bf97847c35c4dcf9638008b9b4b6c4e10015f19
author iuc
date Tue, 09 Jun 2015 12:21:40 -0400
parents
children 14d09b0ab9e1
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/imagej2_convert_format.py	Tue Jun 09 12:21:40 2015 -0400
@@ -0,0 +1,36 @@
+#!/usr/bin/env python
+# Galaxy wrapper for use with Imagej2 via bioformats and javabridge by Greg Von Kuster
+"""
+A wrapper script for running ImageJ2 commands via bioformats and javabridge.
+"""
+import argparse
+import imagej2_base_utils
+import imagej2_utils
+
+if __name__=="__main__":
+    # Parse Command Line.
+    parser = argparse.ArgumentParser()
+    parser.add_argument( '--in_fname', dest='in_fname', help='Path to the input file' )
+    parser.add_argument( '--input_datatype', dest='input_datatype', help='Input image datatype' )
+    parser.add_argument( '--max_heap_size_type', dest='max_heap_size_type', help='Type (default or megabytes) of max_heap_size value' )
+    parser.add_argument( '--max_heap_size', dest='max_heap_size', help='Maximum size of the memory allocation pool used by the JVM.' )
+    parser.add_argument( '--output_datatype', dest='output_datatype', help='Output image datatype' )
+    parser.add_argument( '--out_fname', help='Path to the output file' )
+    args = parser.parse_args()
+    # Set the size of the memory allocation pool used by the JVM.
+    max_heap_size = imagej2_base_utils.get_max_heap_size_value( args.max_heap_size_type, args.max_heap_size )
+    # Start the JVM via the Javabridge.
+    imagej2_utils.start_vm( args=None, class_path=None, max_heap_size=max_heap_size, run_headless=True )
+    try:
+        tmp_dir = imagej2_base_utils.get_temp_dir()
+        in_image_path = imagej2_base_utils.get_input_image_path( tmp_dir, args.in_fname, args.input_datatype )
+        # Load the input image.
+        image, scale = imagej2_utils.load_image( in_image_path, rescale=False, wants_max_intensity=True )
+        # Write the output image.
+        out_image_path = imagej2_base_utils.get_temporary_image_path( tmp_dir, args.output_datatype )
+        imagej2_utils.write_image( image_path=out_image_path, pixels=image, pixel_type=str( image.dtype ), move_to=args.out_fname )
+    except Exception, e:
+        imagej2_base_utils.stop_err( str( e ) )
+    finally:
+        imagej2_utils.kill_vm()
+        imagej2_base_utils.cleanup_before_exit( tmp_dir )