private String readSanitizedXML(String filename) throws IOException { String xml = DataTools.readFile(filename).trim(); if (xml.endsWith(">>")) { xml = xml.substring(0, xml.length() - 1); } return xml; }
private String readSanitizedXML(String filename) throws IOException { String xml = DataTools.readFile(filename).trim(); if (xml.endsWith(">>")) { xml = xml.substring(0, xml.length() - 1); } return xml; }
/** Return a list of scan names. */ private String[] getScanNames() throws IOException { String[] scans = null; String data = DataTools.readFile(currentId); String[] lines = data.split("\n"); for (String line : lines) { if (!line.startsWith("#")) { String key = line.substring(0, line.indexOf('=')).trim(); String value = line.substring(line.indexOf('=') + 1).trim(); addGlobalMeta(key, value); if (key.equals("ScanNames")) { scans = value.split(","); for (int i=0; i<scans.length; i++) { scans[i] = scans[i].trim(); } } } } return scans; }
/** Return a list of scan names. */ private String[] getScanNames() throws IOException { String[] scans = null; String data = DataTools.readFile(currentId); String[] lines = data.split("\n"); for (String line : lines) { if (!line.startsWith("#")) { String key = line.substring(0, line.indexOf('=')).trim(); String value = line.substring(line.indexOf('=') + 1).trim(); addGlobalMeta(key, value); if (key.equals("ScanNames")) { scans = value.split(","); for (int i=0; i<scans.length; i++) { scans[i] = scans[i].trim(); } } } } return scans; }
private void parseTimFile(String timFile) throws IOException { String[] tokens = DataTools.readFile(timFile).split("\\s"); int tNum = 0; // can ignore "Zero x" and "Extra int" String[] hashKeys = {"Number of Wavelengths/Timepoints", "Zero 1", "Zero 2", "Number of slices", "Extra int", "Calibration Unit", "Pixel Size Y", "Pixel Size X", "Image Width", "Image Length", "Origin X", "SubfileType X", "Dimension Label X", "Origin Y", "SubfileType Y", "Dimension Label Y", "Origin Z", "SubfileType Z", "Dimension Label Z"}; // there are 9 additional tokens, but I don't know what they're for for (String token : tokens) { if (token.trim().length() == 0) continue; if (tNum >= hashKeys.length) break; if (token.equals("um")) tNum = 5; while ((tNum == 1 || tNum == 2) && !token.trim().equals("0")) { tNum++; } if (tNum == 4) { try { Integer.parseInt(token); } catch (NumberFormatException e) { tNum++; } } parseKeyValue(hashKeys[tNum++], token); } }
private void parseResFile(String id) throws IOException { ResHandler handler = new ResHandler(); String resXML = DataTools.readFile(id); XMLTools.parseXML(resXML, handler); }
private void parseResFile(String id) throws IOException { ResHandler handler = new ResHandler(); String resXML = DataTools.readFile(id); XMLTools.parseXML(resXML, handler); }
private void parseZpoFile(String zpoFile) throws IOException { if (getMetadataOptions().getMetadataLevel() == MetadataLevel.MINIMUM) { return; } String[] tokens = DataTools.readFile(zpoFile).split("\\s"); for (int t=0; t<tokens.length; t++) { addGlobalMetaList("Z slice position", tokens[t]); } }
private void parseZpoFile(String zpoFile) throws IOException { if (getMetadataOptions().getMetadataLevel() == MetadataLevel.MINIMUM) { return; } String[] tokens = DataTools.readFile(zpoFile).split("\\s"); for (int t=0; t<tokens.length; t++) { addGlobalMetaList("Z slice position", tokens[t]); } }
/** * Read a configuration file with lines of the form: * * <server alias>=<real server name> * * and call mapServer(String, String) accordingly. * * @throws FormatException if configFile does not exist. * @see #mapServer(String, String) */ public static void mapServersFromConfigurationFile(String configFile) throws FormatException, IOException { LOGGER.debug("mapServersFromConfigurationFile({})", configFile); Location file = new Location(configFile); if (!file.exists()) { throw new FormatException( "Configuration file " + configFile + " does not exist."); } String[] lines = DataTools.readFile(configFile).split("[\r\n]"); for (String line : lines) { LOGGER.trace(line); int eq = line.indexOf('='); if (eq == -1 || line.startsWith("#")) continue; String alias = line.substring(0, eq).trim(); String[] servers = line.substring(eq + 1).trim().split(";"); mapServer(alias, servers); } }
/** * Read a configuration file with lines of the form: * * <server alias>=<real server name> * * and call mapServer(String, String) accordingly. * * @throws FormatException if configFile does not exist. * @see #mapServer(String, String) */ public static void mapServersFromConfigurationFile(String configFile) throws FormatException, IOException { LOGGER.debug("mapServersFromConfigurationFile({})", configFile); Location file = new Location(configFile); if (!file.exists()) { throw new FormatException( "Configuration file " + configFile + " does not exist."); } String[] lines = DataTools.readFile(configFile).split("[\r\n]"); for (String line : lines) { LOGGER.trace(line); int eq = line.indexOf('='); if (eq == -1 || line.startsWith("#")) continue; String alias = line.substring(0, eq).trim(); String[] servers = line.substring(eq + 1).trim().split(";"); mapServer(alias, servers); } }
/** Parse metadata values from the Acqusition.xml file. */ private void parseXMLFile() throws IOException { Position p = positions.get(getSeries()); String xmlData = DataTools.readFile(p.xmlFile); xmlData = XMLTools.sanitizeXML(xmlData); DefaultHandler handler = new MicromanagerHandler(); XMLTools.parseXML(xmlData, handler); }
/** Parse metadata values from the Acqusition.xml file. */ private void parseXMLFile() throws IOException { Position p = positions.get(getSeries()); String xmlData = DataTools.readFile(p.xmlFile); xmlData = XMLTools.sanitizeXML(xmlData); DefaultHandler handler = new MicromanagerHandler(); XMLTools.parseXML(xmlData, handler); }
private void parseROIs(MetadataStore store) throws IOException { if (roiFile == null) return; String roiData = DataTools.readFile(roiFile); String[] lines = roiData.split("\r\n"); int firstRow = 0; while (firstRow < lines.length && !lines[firstRow].startsWith("ROI")) { firstRow++; } firstRow += 2; if (firstRow >= lines.length) return; for (int i=firstRow; i<lines.length; i++) { String[] cols = lines[i].split("\t"); if (cols.length < 6) break; if (cols[2].trim().length() > 0) { String rectangleID = MetadataTools.createLSID("Shape", i - firstRow, 0); store.setRectangleID(rectangleID, i - firstRow, 0); store.setRectangleX(new Double(cols[2]), i - firstRow, 0); store.setRectangleY(new Double(cols[3]), i - firstRow, 0); store.setRectangleWidth(new Double(cols[4]), i - firstRow, 0); store.setRectangleHeight(new Double(cols[5]), i - firstRow, 0); String roiID = MetadataTools.createLSID("ROI", i - firstRow); store.setROIID(roiID, i - firstRow); for (int s=0; s<getSeriesCount(); s++) { store.setImageROIRef(roiID, s, i - firstRow); } } } }
private void parseROIs(MetadataStore store) throws FormatException, IOException { String roiID = MetadataTools.createLSID("ROI", 0, 0); String maskID = MetadataTools.createLSID("Shape", 0, 0); store.setROIID(roiID, 0); store.setMaskID(maskID, 0, 0); String positionData = DataTools.readFile(roiDrawFile); String[] coordinates = positionData.split("[ ,]"); double x1 = Double.parseDouble(coordinates[1]); double y1 = Double.parseDouble(coordinates[2]); double x2 = Double.parseDouble(coordinates[3]); double y2 = Double.parseDouble(coordinates[5]); store.setMaskX(x1, 0, 0); store.setMaskY(y1, 0, 0); store.setMaskWidth(x2 - x1, 0, 0); store.setMaskHeight(y2 - y1, 0, 0); store.setImageROIRef(roiID, 0, 0); ImageReader roiReader = new ImageReader(); roiReader.setId(roiFile); byte[] roiPixels = roiReader.openBytes(0); roiReader.close(); BitWriter bits = new BitWriter(roiPixels.length / 8); for (int i=0; i<roiPixels.length; i++) { bits.write(roiPixels[i] == 0 ? 0 : 1, 1); } store.setMaskBinData(bits.toByteArray(), 0, 0); }
private void parseROIs(MetadataStore store) throws FormatException, IOException { String roiID = MetadataTools.createLSID("ROI", 0, 0); String maskID = MetadataTools.createLSID("Shape", 0, 0); store.setROIID(roiID, 0); store.setMaskID(maskID, 0, 0); String positionData = DataTools.readFile(roiDrawFile); String[] coordinates = positionData.split("[ ,]"); double x1 = Double.parseDouble(coordinates[1]); double y1 = Double.parseDouble(coordinates[2]); double x2 = Double.parseDouble(coordinates[3]); double y2 = Double.parseDouble(coordinates[5]); store.setMaskX(x1, 0, 0); store.setMaskY(y1, 0, 0); store.setMaskWidth(x2 - x1, 0, 0); store.setMaskHeight(y2 - y1, 0, 0); store.setImageROIRef(roiID, 0, 0); ImageReader roiReader = new ImageReader(); roiReader.setId(roiFile); byte[] roiPixels = roiReader.openBytes(0); roiReader.close(); BitWriter bits = new BitWriter(roiPixels.length / 8); for (int i=0; i<roiPixels.length; i++) { bits.write(roiPixels[i] == 0 ? 0 : 1, 1); } store.setMaskBinData(bits.toByteArray(), 0, 0); }
@Override protected void initFile(String id) throws FormatException, IOException { // read the pattern from the file // the file should just contain a single line with the relative or // absolute file pattern currentId = new Location(id).getAbsolutePath(); String pattern = DataTools.readFile(id).trim(); String dir = new Location(id).getAbsoluteFile().getParent(); if (new Location(pattern).getParent() == null) { pattern = dir + File.separator + pattern; } helper.setUsingPatternIds(true); helper.setCanChangePattern(false); helper.setId(pattern); core = helper.getCoreMetadataList(); }
@Override protected void initFile(String id) throws FormatException, IOException { // read the pattern from the file // the file should just contain a single line with the relative or // absolute file pattern currentId = new Location(id).getAbsolutePath(); String pattern = DataTools.readFile(id).trim(); String dir = new Location(id).getAbsoluteFile().getParent(); if (new Location(pattern).getParent() == null) { pattern = dir + File.separator + pattern; } helper.setUsingPatternIds(true); helper.setCanChangePattern(false); helper.setId(pattern); core = helper.getCoreMetadataList(); }
/** Extracts the OME-XML from the current {@link #metadataFile}. */ private String readMetadataFile() throws IOException { if (checkSuffix(metadataFile, "ome.tiff") || checkSuffix(metadataFile, "ome.tif") || checkSuffix(metadataFile, "ome.tf2") || checkSuffix(metadataFile, "ome.tf8") || checkSuffix(metadataFile, "ome.btf")) { // metadata file is an OME-TIFF file; extract OME-XML comment try (RandomAccessInputStream in = new RandomAccessInputStream(metadataFile)) { TiffParser parser = new TiffParser(in); return parser.getComment(); } } // assume metadata file is an XML file return DataTools.readFile(metadataFile); }
/** Extracts the OME-XML from the current {@link #metadataFile}. */ private String readMetadataFile() throws IOException { if (checkSuffix(metadataFile, "ome.tiff") || checkSuffix(metadataFile, "ome.tif") || checkSuffix(metadataFile, "ome.tf2") || checkSuffix(metadataFile, "ome.tf8") || checkSuffix(metadataFile, "ome.btf")) { // metadata file is an OME-TIFF file; extract OME-XML comment try (RandomAccessInputStream in = new RandomAccessInputStream(metadataFile)) { TiffParser parser = new TiffParser(in); return parser.getComment(); } } // assume metadata file is an XML file return DataTools.readFile(metadataFile); }