Changeset 7883 for trunk/projects


Ignore:
Timestamp:
02/03/12 11:58:45 (8 years ago)
Author:
curtis
Message:

Add initial version of Prairie OME injection logic

Code is still in progress, not yet tested or working.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/projects/prairie-ome-tiff/src/main/java/loci/apps/prairie/PrairieInjector.java

    r7881 r7883  
    3535package loci.apps.prairie; 
    3636 
     37import java.util.HashMap; 
     38import java.util.Map; 
     39import java.util.UUID; 
     40 
     41import loci.common.RandomAccessInputStream; 
     42import loci.common.services.ServiceFactory; 
     43import loci.common.xml.XMLTools; 
     44import loci.formats.ImageReader; 
     45import loci.formats.meta.IMetadata; 
     46import loci.formats.services.OMEXMLService; 
     47import loci.formats.tiff.TiffSaver; 
     48import ome.xml.model.primitives.NonNegativeInteger; 
     49 
    3750/** 
    3851 * Command line tool to inject OME-XML into Prairie TIFF files. 
     
    4760public class PrairieInjector { 
    4861 
    49   public static void main(String[] args) { 
    50     System.out.println("Hello world!"); 
     62  public static void main(String[] args) throws Exception { 
     63//    System.setProperty("plugins.dir", "C:\\Program Files (x86)\\ImageJ\\plugins"); 
     64//    new ImageJ(); 
     65//    System.out.println("Instance = " + IJ.getInstance()); 
     66 
     67//    String infile; 
     68//    String outfile; 
     69 
     70//    BufferedReader reader; 
     71//    reader = new BufferedReader(new InputStreamReader(System.in)); 
     72// 
     73//    System.out.println("What is name of input file? "); 
     74//    infile = reader.readLine(); 
     75// 
     76//    System.out.println("What is name of output file? "); 
     77//    outfile = reader.readLine(); 
     78 
     79        //String[] myArgs = {infile, outfile}; 
     80//      "C:\\users\\Kristin\\Documents\\Dropbox\\LOCI\\DataFromJoe\\TIFF-001\\TIFF-001_Cycle001_CurrentSettings_Ch1_000001.tif", 
     81//      "C:\\users\\Kristin\\Documents\\Dropbox\\LOCI\\DataFromJoe\\TIFF-001\\TestConvert.ome.tif"}; 
     82//    ImageInfo.main(myArgs); 
     83 
     84 
     85    // LAUNCH PROGRAM WITH: 
     86    // java -cp loci_tools.jar;prairie-injector.jar loci.apps.prairie.Injector myPrairieData.xml 
     87 
     88//    JFileChooser chooser = new JFileChooser(); 
     89    ImageReader reader = new ImageReader(); 
     90 
     91    ServiceFactory serviceFactory = new ServiceFactory(); 
     92    OMEXMLService omexmlService = serviceFactory.getInstance(OMEXMLService.class); 
     93 
     94    // create a metadata store, where info is placed 
     95    IMetadata meta = omexmlService.createOMEXMLMetadata(); 
     96 
     97    // associate that store with the reader 
     98    reader.setMetadataStore(meta); 
     99 
     100    // parse the Prairie dataset, populating the metadata store 
     101    // does not read actual image planes 
     102    String pathToPrairieXMLFile = args[0]; 
     103    reader.setId(pathToPrairieXMLFile); 
     104 
     105    String[] files = reader.getUsedFiles(); 
     106 
     107    // free resources and close any open files 
     108    // does not wipe out the metadata store 
     109    reader.close(); 
     110 
     111    // set the TiffData elements to describe the planar ordering 
     112    int tiffDataIndex = 0; 
     113    Map<String, String> uuids = new HashMap<String, String>(); 
     114    for (String file : files) { 
     115      if (!isTiff(file)) continue; 
     116 
     117      // TODO: populate these values from the current filename 
     118      int c = 0, z = 0, t = 0; 
     119 
     120      meta.setTiffDataFirstC(new NonNegativeInteger(c), 0, tiffDataIndex); 
     121      meta.setTiffDataFirstZ(new NonNegativeInteger(z), 0, tiffDataIndex); 
     122      meta.setTiffDataFirstT(new NonNegativeInteger(t), 0, tiffDataIndex); 
     123      meta.setUUIDFileName(file, 0, tiffDataIndex); 
     124      String uuid = UUID.randomUUID().toString(); 
     125      meta.setUUIDValue(uuid, 0, tiffDataIndex); 
     126      uuids.put(file, uuid); 
     127      tiffDataIndex++; 
     128    } 
     129 
     130    for (String file : files) { 
     131      if (!isTiff(file)) continue; 
     132 
     133      // set this TIFF file's UUID to the correct one 
     134      meta.setUUID(uuids.get(file)); 
     135 
     136      // write out the XML to the TIFF 
     137      String xml = omexmlService.getOMEXML(meta); 
     138      XMLTools.validateXML(xml); // TEMPORARY to make sure it is correct 
     139      RandomAccessInputStream in = new RandomAccessInputStream(file); 
     140      TiffSaver tiffSaver = new TiffSaver(file); 
     141      tiffSaver.overwriteComment(in, xml); 
     142      in.close(); 
     143    } 
     144 
     145 
     146//    JFileChooser chooser = GUITools.buildFileChooser(reader, true); 
     147//    int returnVal = chooser.showOpenDialog(null); 
     148 
     149//    ImageConverter.main(myArgs); 
     150 
     151//    PrairieReader r = new PrairieReader(); 
     152//    r.setId(myFile); 
     153  } 
     154 
     155  private static boolean isTiff(String file) { 
     156    return file.toLowerCase().endsWith(".tif") || 
     157      file.toLowerCase().endsWith(".tiff"); 
    51158  } 
    52159 
    53160} 
     161 
Note: See TracChangeset for help on using the changeset viewer.