Exemplo n.º 1
0
  private void parseChannelData(Location dir) throws IOException {
    emWave = new int[channelNames.size()];
    exWave = new int[channelNames.size()];
    exposure = new double[channelNames.size()];
    gain = new double[channelNames.size()];
    offset = new double[channelNames.size()];

    for (int c = 0; c < channelNames.size(); c++) {
      Location dyeFile = new Location(dir, channelNames.get(c) + ".dye");
      FileInputStream stream = new FileInputStream(dyeFile.getAbsolutePath());
      IniList dye =
          new IniParser()
              .parseINI(new BufferedReader(new InputStreamReader(stream, Constants.ENCODING)));

      IniTable numerator = dye.getTable("Numerator");
      String em = numerator.get("Emission");
      em = em.substring(0, em.indexOf(" "));
      emWave[c] = Integer.parseInt(em);

      String ex = numerator.get("Excitation");
      ex = ex.substring(0, ex.lastIndexOf(" "));
      if (ex.indexOf(" ") != -1) {
        ex = ex.substring(ex.lastIndexOf(" ") + 1);
      }
      exWave[c] = Integer.parseInt(ex);

      exposure[c] = Double.parseDouble(numerator.get("Exposure"));
      gain[c] = Double.parseDouble(numerator.get("Gain"));
      offset[c] = Double.parseDouble(numerator.get("Offset"));
    }
  }
Exemplo n.º 2
0
  /* @see BaseTiffReader#initStandardMetadata() */
  protected void initStandardMetadata() throws FormatException, IOException {
    super.initStandardMetadata();

    delegate = new MinimalTiffReader();
    delegate.setId(currentId);

    exposureTimes = new ArrayList<Double>();

    String data = ifds.get(0).getComment();

    // remove magic string
    data = data.substring(data.indexOf("\n") + 1);

    date = data.substring(0, data.indexOf("\n"));
    data = data.substring(data.indexOf("\n") + 1);
    data = data.replaceAll("ReadFromDoc", "");

    IniParser parser = new IniParser();
    parser.setCommentDelimiter(";");

    IniList ini = parser.parseINI(new BufferedReader(new StringReader(data)));

    String objective = ini.getTable(" MICROSCOPE ").get("Objective");
    int space = objective.indexOf(" ");
    if (space != -1) {
      magnification = new Integer(objective.substring(0, space - 1));
      immersion = objective.substring(space + 1);
    }

    IniTable cameraTable = ini.getTable(" CAPTURE DEVICE ");
    binning = cameraTable.get("Binning") + "x" + cameraTable.get("Binning");
    cameraType = cameraTable.get("Camera Type");
    cameraName = cameraTable.get("Camera Name");
    core[0].bitsPerPixel = Integer.parseInt(cameraTable.get("Display Depth"));

    IniTable captureTable = ini.getTable(" CAPTURE ");
    int index = 1;
    for (int i = 0; i < getSizeC(); i++) {
      if (captureTable.get("c_Filter" + index) != null) {
        exposureTimes.add(new Double(captureTable.get("c_Expos" + index)));
      } else i--;
      index++;
    }

    IniTable calibrationTable = ini.getTable(" CALIBRATION ");
    String units = calibrationTable.get("units");
    scaling = Double.parseDouble(calibrationTable.get("factor"));

    core[0].imageCount *= getSizeC();
    core[0].rgb = false;

    if (ifds.get(0).containsKey(CUSTOM_BITS)) {
      core[0].bitsPerPixel = ifds.get(0).getIFDIntValue(CUSTOM_BITS);
    }

    if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
      HashMap<String, String> iniMap = ini.flattenIntoHashMap();
      metadata.putAll(iniMap);
    }
  }
Exemplo n.º 3
0
  /* @see loci.formats.FormatReader#initFile(String) */
  protected void initFile(String id) throws FormatException, IOException {
    // make sure we have the experiment file
    id = locateExperimentFile(id);
    super.initFile(id);
    Location dir = new Location(id).getAbsoluteFile().getParentFile();

    for (String file : dir.list(true)) {
      Location f = new Location(dir, file);
      if (!f.isDirectory()) {
        if (checkSuffix(file, META_EXT)) {
          metadataFiles.add(f.getAbsolutePath());
        }
      }
    }

    // parse Experiment metadata
    IniList experiment = readMetaData(id);

    if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
      objective = experiment.getTable("Geometry").get("Name");
      IniTable camera = experiment.getTable("Camera");
      binning = camera.get("BinX") + "x" + camera.get("BinY");

      parseChannelData(dir);

      addGlobalMeta("Objective", objective);
      addGlobalMeta("Camera binning", binning);
    }

    Vector<String> uniqueRows = new Vector<String>();
    Vector<String> uniqueColumns = new Vector<String>();

    for (String well : wellLabels) {
      String row = well.substring(0, 1).trim();
      String column = well.substring(1).trim();

      if (!uniqueRows.contains(row) && row.length() > 0) uniqueRows.add(row);
      if (!uniqueColumns.contains(column) && column.length() > 0) {
        uniqueColumns.add(column);
      }
    }

    int nSlices = getSizeZ() == 0 ? 1 : getSizeZ();
    int nTimepoints = getSizeT();
    int nWells = wellLabels.size();
    int nChannels = getSizeC() == 0 ? channelNames.size() : getSizeC();
    if (nChannels == 0) nChannels = 1;

    tiffs = getTiffs(dir.getAbsolutePath());

    reader = new MinimalTiffReader();
    reader.setId(tiffs[0][0]);

    int sizeX = reader.getSizeX();
    int sizeY = reader.getSizeY();
    int pixelType = reader.getPixelType();
    boolean rgb = reader.isRGB();
    boolean interleaved = reader.isInterleaved();
    boolean indexed = reader.isIndexed();
    boolean littleEndian = reader.isLittleEndian();

    if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
      IniParser parser = new IniParser();
      for (String metadataFile : metadataFiles) {
        String filename = new Location(metadataFile).getName();
        if (!checkSuffix(metadataFile, "txt")) {
          String data = DataTools.readFile(metadataFile);
          IniList ini = parser.parseINI(new BufferedReader(new StringReader(data)));
          HashMap<String, String> h = ini.flattenIntoHashMap();
          for (String key : h.keySet()) {
            addGlobalMeta(filename + " " + key, h.get(key));
          }
        }
      }
    }

    for (int i = 0; i < getSeriesCount(); i++) {
      core[i] = new CoreMetadata();
      core[i].sizeC = nChannels;
      core[i].sizeZ = nSlices;
      core[i].sizeT = nTimepoints;
      core[i].sizeX = sizeX / fieldCols;
      core[i].sizeY = sizeY / fieldRows;
      core[i].pixelType = pixelType;
      core[i].rgb = rgb;
      core[i].interleaved = interleaved;
      core[i].indexed = indexed;
      core[i].littleEndian = littleEndian;
      core[i].dimensionOrder = "XYZTC";
      core[i].imageCount = nSlices * nTimepoints * nChannels;
    }

    MetadataStore store = makeFilterMetadata();
    boolean populatePlanes = getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM;
    MetadataTools.populatePixels(store, this, populatePlanes);

    String plateAcqID = MetadataTools.createLSID("PlateAcquisition", 0, 0);
    store.setPlateAcquisitionID(plateAcqID, 0, 0);
    if (fieldRows * fieldCols > 0) {
      store.setPlateAcquisitionMaximumFieldCount(new PositiveInteger(fieldRows * fieldCols), 0, 0);
    } else {
      LOGGER.warn("Expected positive value for MaximumFieldCount; got {}", fieldRows * fieldCols);
    }

    for (int row = 0; row < wellRows; row++) {
      for (int col = 0; col < wellCols; col++) {
        int index = row * wellCols + col;

        store.setWellID(MetadataTools.createLSID("Well", 0, index), 0, index);
        store.setWellRow(new NonNegativeInteger(row), 0, index);
        store.setWellColumn(new NonNegativeInteger(col), 0, index);
      }
    }

    for (int i = 0; i < getSeriesCount(); i++) {
      int well = i / (fieldRows * fieldCols);
      int field = i % (fieldRows * fieldCols);

      MetadataTools.setDefaultCreationDate(store, tiffs[well][0], i);

      String name = wellLabels.get(well);
      String row = name.substring(0, 1);
      Integer col = Integer.parseInt(name.substring(1));

      int index = (row.charAt(0) - 'A') * wellCols + col - 1;

      String wellSampleID = MetadataTools.createLSID("WellSample", 0, index, field);
      store.setWellSampleID(wellSampleID, 0, index, field);
      store.setWellSampleIndex(new NonNegativeInteger(i), 0, index, field);

      String imageID = MetadataTools.createLSID("Image", i);
      store.setWellSampleImageRef(imageID, 0, index, field);
      store.setImageID(imageID, i);
      store.setImageName(name + " Field #" + (field + 1), i);

      store.setPlateAcquisitionWellSampleRef(wellSampleID, 0, 0, i);
    }

    MetadataLevel level = getMetadataOptions().getMetadataLevel();
    if (level != MetadataLevel.MINIMUM) {
      String instrumentID = MetadataTools.createLSID("Instrument", 0);
      store.setInstrumentID(instrumentID, 0);

      String objectiveID = MetadataTools.createLSID("Objective", 0, 0);
      store.setObjectiveID(objectiveID, 0, 0);
      if (objective != null) {
        String[] tokens = objective.split(" ");
        String mag = tokens[0].replaceAll("[xX]", "");
        String na = null;
        int naIndex = 0;
        for (int i = 0; i < tokens.length; i++) {
          if (tokens[i].equals("NA")) {
            naIndex = i + 1;
            na = tokens[naIndex];
            break;
          }
        }

        Integer magnification = new Integer(mag);
        if (magnification > 0) {
          store.setObjectiveNominalMagnification(new PositiveInteger(magnification), 0, 0);
        } else {
          LOGGER.warn("Expected positive value for NominalMagnification; got {}", magnification);
        }
        if (na != null) {
          na = na.substring(0, 1) + "." + na.substring(1);
          store.setObjectiveLensNA(new Double(na), 0, 0);
        }
        if (naIndex + 1 < tokens.length) {
          store.setObjectiveManufacturer(tokens[naIndex + 1], 0, 0);
        }
      }

      // populate LogicalChannel data
      for (int i = 0; i < getSeriesCount(); i++) {
        store.setImageInstrumentRef(instrumentID, i);
        store.setObjectiveSettingsID(objectiveID, i);

        for (int c = 0; c < getSizeC(); c++) {
          store.setChannelName(channelNames.get(c), i, c);
          if (emWave[c] > 0) {
            store.setChannelEmissionWavelength(new PositiveInteger(emWave[c]), i, c);
          } else {
            LOGGER.warn("Expected positive value for EmissionWavelength; got {}", emWave[c]);
          }
          if (exWave[c] > 0) {
            store.setChannelExcitationWavelength(new PositiveInteger(exWave[c]), i, c);
          } else {
            LOGGER.warn("Expected positive value for ExcitationWavelength; got {}", exWave[c]);
          }

          String detectorID = MetadataTools.createLSID("Detector", 0, c);
          store.setDetectorID(detectorID, 0, c);
          store.setDetectorSettingsID(detectorID, i, c);
          store.setDetectorSettingsGain(gain[c], i, c);
          store.setDetectorSettingsOffset(offset[c], i, c);
          store.setDetectorSettingsBinning(getBinning(binning), i, c);
        }

        long firstPlane = 0;
        for (int p = 0; p < getImageCount(); p++) {
          int[] zct = getZCTCoords(p);
          store.setPlaneExposureTime(exposure[zct[1]], i, p);
          String file = getFilename(i, p);
          if (file != null) {
            long plane = getTimestamp(file);
            if (p == 0) {
              firstPlane = plane;
            }
            double timestamp = (plane - firstPlane) / 1000.0;
            store.setPlaneDeltaT(timestamp, i, p);
          }
        }
      }

      store.setPlateID(MetadataTools.createLSID("Plate", 0), 0);
      store.setPlateRowNamingConvention(getNamingConvention("Letter"), 0);
      store.setPlateColumnNamingConvention(getNamingConvention("Number"), 0);
      store.setPlateName(plateName, 0);
      store.setPlateDescription(plateDescription, 0);

      if (level != MetadataLevel.NO_OVERLAYS) {
        parseROIs(store);
      }
    }
  }
Exemplo n.º 4
0
  private IniList readMetaData(String id) throws IOException {
    IniParser parser = new IniParser();
    IniList exp =
        parser.parseINI(
            new BufferedReader(new InputStreamReader(new FileInputStream(id), Constants.ENCODING)));
    IniList plate = null;
    // Read Plate File
    for (String filename : metadataFiles) {
      if (checkSuffix(filename, "plt")) {
        plate =
            parser.parseINI(
                new BufferedReader(
                    new InputStreamReader(new FileInputStream(filename), Constants.ENCODING)));
      } else if (filename.endsWith("RoiSummary.txt")) {
        roiFile = filename;
        if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
          RandomAccessInputStream s = new RandomAccessInputStream(filename);
          String line = s.readLine().trim();
          while (!line.endsWith(".adf\"")) {
            line = s.readLine().trim();
          }
          plateName = line.substring(line.indexOf(":")).trim();
          plateName = plateName.replace('/', File.separatorChar);
          plateName = plateName.replace('\\', File.separatorChar);
          for (int i = 0; i < 3; i++) {
            plateName = plateName.substring(0, plateName.lastIndexOf(File.separator));
          }
          plateName = plateName.substring(plateName.lastIndexOf(File.separator) + 1);

          s.close();
        }
      }
    }
    if (plate == null) throw new IOException("No Plate File");

    IniTable plateType = plate.getTable("PlateType");

    if (plateName == null) {
      plateName = plateType.get("Brand");
    }
    plateDescription = plateType.get("Brand") + " " + plateType.get("Description");

    int nWells = Integer.parseInt(plateType.get("Wells"));
    if (nWells == 96) {
      wellRows = 8;
      wellCols = 12;
    } else if (nWells == 384) {
      wellRows = 16;
      wellCols = 24;
    }

    Location dir = new Location(id).getAbsoluteFile().getParentFile();
    String[] wellList = dir.list();
    Arrays.sort(wellList);
    for (String filename : wellList) {
      if (filename.startsWith("Well ")) {
        wellLabels.add(filename.split("\\s|\\.")[1]);
      }
    }

    IniTable imageTable = exp.getTable("Image");
    boolean montage = imageTable.get("Montaged").equals("1");
    if (montage) {
      fieldRows = Integer.parseInt(imageTable.get("TilesY"));
      fieldCols = Integer.parseInt(imageTable.get("TilesX"));
    } else {
      fieldRows = 1;
      fieldCols = 1;
    }

    core = new CoreMetadata[wellLabels.size() * fieldRows * fieldCols];

    core[0] = new CoreMetadata();

    // Hack for current testing/development purposes
    // Not all channels have the same Z!!! How to handle???
    // FIXME FIXME FIXME
    core[0].sizeZ = 1;
    // FIXME FIXME FIXME
    // END OF HACK

    core[0].sizeC = Integer.parseInt(exp.getTable("General").get("Dyes"));
    core[0].bitsPerPixel = Integer.parseInt(exp.getTable("Camera").get("BitdepthUsed"));

    IniTable dyeTable = exp.getTable("Dyes");
    for (int i = 1; i <= getSizeC(); i++) {
      channelNames.add(dyeTable.get(Integer.toString(i)));
    }

    // Count Images
    core[0].sizeT = 0;
    Location well = new Location(dir.getAbsolutePath(), "Well " + wellLabels.get(1));
    for (String channelName : channelNames) {
      int timepoints = 0;
      for (String filename : well.list()) {
        if (filename.startsWith(channelName) && filename.endsWith(".tif")) {
          timepoints++;
        }
      }
      if (timepoints > getSizeT()) {
        core[0].sizeT = timepoints;
      }
    }

    return exp;
  }
Exemplo n.º 5
0
  /* @see BaseTiffReader#initStandardMetadata() */
  @Override
  protected void initStandardMetadata() throws FormatException, IOException {
    super.initStandardMetadata();

    boolean helios = ifds.get(0).containsKey(HELIOS_TAG);
    boolean titan = ifds.get(0).containsKey(TITAN_TAG);

    // Helios etc data might have a stray Titan tag
    if (titan && ifds.get(0).getIFDTextValue(TITAN_TAG).trim().isEmpty()) {
      titan = false;
    }

    // Titan data (always?) has an empty Helios tag as well, so the Titan tag is checked first
    String software = "S-FEG";
    if (titan) {
      software = "Titan";
    } else if (helios) {
      software = "Helios NanoLab";
    }
    addGlobalMeta("Software", software);

    int tagKey = SFEG_TAG;
    if (titan) {
      tagKey = TITAN_TAG;
    } else if (helios) {
      tagKey = HELIOS_TAG;
    }

    String tag = ifds.get(0).getIFDTextValue(tagKey);
    if (tag == null) {
      return;
    }
    tag = tag.trim();
    if (tag.isEmpty()) {
      return; // fall back to regular reader
    }
    // store metadata for later conversion to OME-XML
    if (tag.startsWith("<")) {
      XMLTools.parseXML(tag, new FEIHandler());
    } else {
      IniParser parser = new IniParser();
      IniList ini = parser.parseINI(new BufferedReader(new StringReader(tag)));
      detectors = new ArrayList<String>();

      if (helios) {
        IniTable userTable = ini.getTable("User");
        date = userTable.get("Date") + " " + userTable.get("Time");

        if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
          userName = userTable.get("User");

          IniTable systemTable = ini.getTable("System");
          if (systemTable == null) {
            systemTable = ini.getTable("SYSTEM");
          }
          if (systemTable != null) {
            microscopeModel = systemTable.get("SystemType");
          }

          IniTable beamTable = ini.getTable("Beam");
          if (beamTable != null) {
            String beamTableName = beamTable.get("Beam");
            if (beamTableName != null) {
              beamTable = ini.getTable(beamTableName);
            }
          }

          if (beamTable != null) {
            String beamX = beamTable.get("StageX");
            String beamY = beamTable.get("StageY");
            String beamZ = beamTable.get("StageZ");
            IniTable stageTable = ini.getTable("Stage");

            if (beamX != null) {
              final Double number = Double.valueOf(beamX);
              stageX = new Length(number, UNITS.REFERENCEFRAME);
            } else if (stageTable != null) {
              final Double number = Double.valueOf(stageTable.get("StageX"));
              stageX = new Length(number, UNITS.REFERENCEFRAME);
            }

            if (beamY != null) {
              final Double number = Double.valueOf(beamY);
              stageY = new Length(number, UNITS.REFERENCEFRAME);
            } else if (stageTable != null) {
              final Double number = Double.valueOf(stageTable.get("StageY"));
              stageY = new Length(number, UNITS.REFERENCEFRAME);
            }

            if (beamZ != null) {
              final Double number = Double.valueOf(beamZ);
              stageZ = new Length(number, UNITS.REFERENCEFRAME);
            } else if (stageTable != null) {
              final Double number = Double.valueOf(stageTable.get("StageZ"));
              stageZ = new Length(number, UNITS.REFERENCEFRAME);
            }
          }

          IniTable scanTable = ini.getTable("Scan");
          // physical sizes are stored in meters
          sizeX = new Double(scanTable.get("PixelWidth")) * 1000000;
          sizeY = new Double(scanTable.get("PixelHeight")) * 1000000;
          timeIncrement = new Double(scanTable.get("FrameTime"));
        }
      } else {
        IniTable dataTable = ini.getTable("DatabarData");
        imageName = dataTable.get("ImageName");
        imageDescription = dataTable.get("szUserText");

        String magnification = ini.getTable("Vector").get("Magnification");
        sizeX = new Double(magnification) * MAG_MULTIPLIER;
        sizeY = new Double(magnification) * MAG_MULTIPLIER;

        IniTable scanTable = ini.getTable("Vector.Sysscan");
        final Double posX = Double.valueOf(scanTable.get("PositionX"));
        final Double posY = Double.valueOf(scanTable.get("PositionY"));
        stageX = new Length(posX, UNITS.REFERENCEFRAME);
        stageY = new Length(posY, UNITS.REFERENCEFRAME);

        IniTable detectorTable = ini.getTable("Vector.Video.Detectors");
        int detectorCount = Integer.parseInt(detectorTable.get("NrDetectorsConnected"));
        for (int i = 0; i < detectorCount; i++) {
          detectors.add(detectorTable.get("Detector_" + i + "_Name"));
        }
      }

      // store everything else in the metadata hashtable

      if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
        HashMap<String, String> iniMap = ini.flattenIntoHashMap();
        metadata.putAll(iniMap);
      }
    }
  }