| 0 | 1 #!/usr/bin/env python | 
|  | 2 import argparse | 
|  | 3 import shutil | 
|  | 4 import operator | 
|  | 5 | 
|  | 6 import icqsol_utils | 
|  | 7 | 
|  | 8 # Parse Command Line. | 
|  | 9 parser = argparse.ArgumentParser() | 
|  | 10 parser.add_argument('--input', dest='input', help='Shape dataset selected from history') | 
|  | 11 parser.add_argument('--input_file_format_and_type', dest='input_file_format_and_type', help='Input file format and type') | 
|  | 12 parser.add_argument('--input_dataset_type', dest='input_dataset_type', help='Input dataset_type') | 
|  | 13 parser.add_argument('--scale_x', dest='scale_x', type=float, default=1.0, help='X scaling factor') | 
|  | 14 parser.add_argument('--scale_y', dest='scale_y', type=float, default=1.0, help='Y scaling factor') | 
|  | 15 parser.add_argument('--scale_z', dest='scale_z', type=float, default=1.0, help='Z scaling factor') | 
|  | 16 parser.add_argument('--output', dest='output', help='Output file name') | 
|  | 17 parser.add_argument('--output_vtk_type', dest='output_vtk_type', default='ascii', help='Output VTK type') | 
|  | 18 | 
|  | 19 args = parser.parse_args() | 
|  | 20 | 
|  | 21 # Get the format of the input - either vtk or ply. | 
|  | 22 input_format, input_file_type = icqsol_utils.get_format_and_type(args.input_file_format_and_type) | 
|  | 23 tmp_dir = icqsol_utils.get_temp_dir() | 
|  | 24 | 
|  | 25 # Instantiate a ShapeManager for loading the input. | 
|  | 26 shape_mgr = icqsol_utils.get_shape_manager(input_format, args.input_dataset_type) | 
|  | 27 | 
|  | 28 # Get the vtk polydata from the input dataset. | 
|  | 29 vtk_poly_data = shape_mgr.loadAsVtkPolyData(args.input) | 
|  | 30 | 
|  | 31 # Scale (in place operation). | 
|  | 32 # FIXME: this should be handled in a Galaxy tool validator. | 
|  | 33 factors = (args.scale_x, args.scale_y, args.scale_z) | 
|  | 34 if reduce(operator.and_, [f > 0 for f in factors]): | 
|  | 35     # All factors must be > 0 | 
|  | 36     shape_mgr.scaleVtkPolyData(vtk_poly_data, factors=factors) | 
|  | 37 | 
|  | 38 # Save the output. | 
|  | 39 output_format, output_file_type = icqsol_utils.get_format_and_type(args.output_vtk_type) | 
|  | 40 tmp_dir = icqsol_utils.get_temp_dir() | 
|  | 41 tmp_output_path = icqsol_utils.get_temporary_file_path(tmp_dir, icqsol_utils.VTK) | 
|  | 42 shape_mgr.saveVtkPolyData(vtk_poly_data, file_name=tmp_output_path, file_type=output_file_type) | 
|  | 43 shutil.move(tmp_output_path, args.output) |