Package pyforms :: Package Utils :: Module BioradWriter |
[hide private]
[frames] | no frames]

# Source Code for Module pyforms.Utils.BioradWriter

     1  #!/usr/bin/python
     2  # -*- coding: utf-8 -*-
     3
     4  __author__      = "Ricardo Ribeiro"
     5  __credits__     = ["Ricardo Ribeiro"]
     6  __license__     = "MIT"
     7  __version__     = "0.0"
     8  __maintainer__  = "Ricardo Ribeiro"
     9  __email__       = "ricardojvr@gmail.com"
    10  __status__      = "Development"
    11
    12
    13  import os
    14  import subprocess
    15
    16
    17
    18 -class BioradWriter:
    19
    20          """
    21                  Encapsulation of ImageJ's (http://rsb.info.nih.gov/ij/) 'Biorad Writer' plugin to enable
    22                  the transformation of TIFF images into PIC format directly from the command line.
    23          """
    24
    25          # Configuration parameters
    26          # NB: Keep the trailing slashes
    27          imageJDir = '/home/admin/imagej/'
    28          javaDir = imageJDir + 'jdk/bin/'
    29          bioradWriterConfigFile = 'biorad_writer_config.txt'
    30
    31          @staticmethod
    32 -        def __update_config_file(outputFileName):
    33                  try:
    34                          with open(BioradWriter.imageJDir + BioradWriter.bioradWriterConfigFile, 'w') as f:
    35                                  f.write(os.getcwd() + "/output/\n");
    36                                  f.write(outputFileName);
    37                  except (IOError) as e:
    38                          raise e
    39
    40          @staticmethod
    41 -        def convert(inputFileName, outputFileName='',
    42                  imageJDir='/home/admin/imagej/',
    43                  javaDir='/home/admin/imagej/jdk/bin/',
    44                  bioradWriterConfigFile='biorad_writer_config.txt' ):
    45
    46                  if not outputFileName:
    47                          outputFileName = os.path.splitext(inputFileName)[0] + '.PIC'
    48
    49                  BioradWriter.__update_config_file(outputFileName)
    50                  execStr = 'cd ' + BioradWriter.imageJDir + ";"
    51                  execStr += BioradWriter.javaDir + 'java -cp ' + BioradWriter.imageJDir + 'ij.jar ij.ImageJ -batch ' + BioradWriter.imageJDir + 'macro.ijm ' + inputFileName + ';'
    52                  execStr += 'cd -'
    53                  subprocess.call(execStr, shell=True)
    54