Mercurial > repos > greg > icqsol_scale_shape
comparison icqsol_utils.py @ 0:c8b87f2bb2e8 draft
Uploaded
| author | greg |
|---|---|
| date | Sat, 05 Dec 2015 10:36:31 -0500 |
| parents | |
| children | d7c8a1ad787d |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:c8b87f2bb2e8 |
|---|---|
| 1 import os | |
| 2 import sys | |
| 3 import tempfile | |
| 4 | |
| 5 PLY = 'ply' | |
| 6 POLYDATA = 'POLYDATA' | |
| 7 VTK = 'vtk' | |
| 8 | |
| 9 | |
| 10 def asbool(val): | |
| 11 return str(val).lower() in ['yes', 'true'] | |
| 12 | |
| 13 | |
| 14 def get_format_and_type(galaxy_ext): | |
| 15 # Define the output file format and type. | |
| 16 format = None | |
| 17 datatype = None | |
| 18 if galaxy_ext in ['vtkascii', 'vtkbinary']: | |
| 19 format = VTK | |
| 20 elif galaxy_ext in ['plyascii', 'plybinary']: | |
| 21 format = PLY | |
| 22 if galaxy_ext in ['vtkascii', 'plyascii']: | |
| 23 datatype = 'ascii' | |
| 24 elif galaxy_ext in ['vtkbinary', 'plybinary']: | |
| 25 datatype = 'binary' | |
| 26 return format, datatype | |
| 27 | |
| 28 | |
| 29 def get_input_file_path(tmp_dir, input_file, format): | |
| 30 """ | |
| 31 iCqSol uses file extensions (e.g., .ply, .vtk) when reading and | |
| 32 writing files, so the Galaxy dataset naming convention of | |
| 33 setting all file extensions as .dat must be handled. | |
| 34 """ | |
| 35 file_path = get_temporary_file_path(tmp_dir, format) | |
| 36 # Remove the file so we can create a symlink. | |
| 37 os.remove(file_path) | |
| 38 os.symlink(input_file, file_path) | |
| 39 return file_path | |
| 40 | |
| 41 | |
| 42 def get_temp_dir(prefix='tmp-vtk-', dir=None): | |
| 43 """ | |
| 44 Return a temporary directory. | |
| 45 """ | |
| 46 return tempfile.mkdtemp(prefix=prefix, dir=dir) | |
| 47 | |
| 48 | |
| 49 def get_tempfilename(dir=None, suffix=None): | |
| 50 """ | |
| 51 Return a temporary file name. | |
| 52 """ | |
| 53 fd, name = tempfile.mkstemp(suffix=suffix, dir=dir) | |
| 54 os.close(fd) | |
| 55 return name | |
| 56 | |
| 57 | |
| 58 def get_temporary_file_path(tmp_dir, file_extension): | |
| 59 """ | |
| 60 Return the path to a temporary file with a valid VTK format | |
| 61 file extension. | |
| 62 """ | |
| 63 return get_tempfilename(tmp_dir, file_extension) | |
| 64 | |
| 65 | |
| 66 def stop_err(msg): | |
| 67 sys.stderr.write("%s\n" % msg) | |
| 68 sys.exit() |
