Search in sources :

Example 6 with IniParser

use of loci.common.IniParser in project bioformats by openmicroscopy.

the class SimplePCITiffReader method initStandardMetadata.

// -- Internal BaseTiffReader API methods --
/* @see BaseTiffReader#initStandardMetadata() */
@Override
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)));
    IniTable microscopeTable = ini.getTable(" MICROSCOPE ");
    if (microscopeTable != null) {
        String objective = microscopeTable.get("Objective");
        int space = objective.indexOf(' ');
        if (space != -1) {
            magnification = new Double(objective.substring(0, space - 1));
            immersion = objective.substring(space + 1);
        }
    }
    CoreMetadata m = core.get(0);
    IniTable cameraTable = ini.getTable(" CAPTURE DEVICE ");
    binning = cameraTable.get("Binning") + "x" + cameraTable.get("Binning");
    cameraType = cameraTable.get("Camera Type");
    cameraName = cameraTable.get("Camera Name");
    String displayDepth = cameraTable.get("Display Depth");
    if (displayDepth != null) {
        m.bitsPerPixel = Integer.parseInt(displayDepth);
    } else {
        String bitDepth = cameraTable.get("Bit Depth");
        if (bitDepth != null && bitDepth.length() > "-bit".length()) {
            bitDepth = bitDepth.substring(0, bitDepth.length() - "-bit".length());
            m.bitsPerPixel = Integer.parseInt(bitDepth);
        } else {
            throw new FormatException("Could not find bits per pixels");
        }
    }
    IniTable captureTable = ini.getTable(" CAPTURE ");
    if (captureTable != null) {
        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)));
            }
            index++;
        }
    }
    IniTable calibrationTable = ini.getTable(" CALIBRATION ");
    String units = calibrationTable.get("units");
    scaling = Double.parseDouble(calibrationTable.get("factor"));
    m.imageCount *= getSizeC();
    m.rgb = false;
    if (ifds.get(0).containsKey(CUSTOM_BITS)) {
        m.bitsPerPixel = ifds.get(0).getIFDIntValue(CUSTOM_BITS);
    }
    if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
        HashMap<String, String> iniMap = ini.flattenIntoHashMap();
        metadata.putAll(iniMap);
    }
}
Also used : IniParser(loci.common.IniParser) IniList(loci.common.IniList) CoreMetadata(loci.formats.CoreMetadata) FormatException(loci.formats.FormatException) IniTable(loci.common.IniTable) BufferedReader(java.io.BufferedReader) StringReader(java.io.StringReader)

Example 7 with IniParser

use of loci.common.IniParser in project bioformats by openmicroscopy.

the class BDReader method readMetaData.

private IniList readMetaData(String id) throws IOException {
    IniParser parser = new IniParser();
    RandomAccessInputStream idStream = new RandomAccessInputStream(id);
    IniList exp = parser.parseINI(new BufferedReader(new InputStreamReader(idStream, Constants.ENCODING)));
    IniList plate = null;
    IniList xyz = null;
    // Read Plate File
    for (String filename : metadataFiles) {
        if (checkSuffix(filename, "plt")) {
            RandomAccessInputStream stream = new RandomAccessInputStream(filename);
            plate = parser.parseINI(new BufferedReader(new InputStreamReader(stream, Constants.ENCODING)));
            stream.close();
        } else if (checkSuffix(filename, "xyz")) {
            RandomAccessInputStream stream = new RandomAccessInputStream(filename);
            xyz = parser.parseINI(new BufferedReader(new InputStreamReader(stream, Constants.ENCODING)));
            stream.close();
        } 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;
    }
    for (String filename : rootList) {
        String name = new Location(filename).getName();
        if (name.startsWith("Well ")) {
            wellLabels.add(name.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.clear();
    int coresize = wellLabels.size() * fieldRows * fieldCols;
    CoreMetadata ms0 = new CoreMetadata();
    core.add(ms0);
    for (int i = 1; i < coresize; i++) {
        core.add(new CoreMetadata());
    }
    ms0.sizeC = Integer.parseInt(exp.getTable("General").get("Dyes"));
    ms0.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)));
    }
    if (xyz != null) {
        IniTable zTable = xyz.getTable("Z1Axis");
        boolean zEnabled = "1".equals(zTable.get("Z1AxisEnabled")) && "1".equals(zTable.get("Z1AxisMode"));
        if (zEnabled) {
            ms0.sizeZ = (int) Double.parseDouble(zTable.get("Z1AxisValue")) + 1;
        } else {
            ms0.sizeZ = 1;
        }
    } else {
        ms0.sizeZ = 1;
    }
    // Count Images
    ms0.sizeT = 0;
    for (String channelName : channelNames) {
        int images = 0;
        for (String filename : wellList.get(1)) {
            if (filename.startsWith(channelName) && filename.endsWith(".tif")) {
                images++;
            }
        }
        if (images > getImageCount()) {
            ms0.sizeT = images / getSizeZ();
            ms0.imageCount = getSizeZ() * getSizeT() * channelNames.size();
        }
    }
    idStream.close();
    return exp;
}
Also used : IniParser(loci.common.IniParser) InputStreamReader(java.io.InputStreamReader) IniList(loci.common.IniList) IniTable(loci.common.IniTable) BufferedReader(java.io.BufferedReader) RandomAccessInputStream(loci.common.RandomAccessInputStream) IOException(java.io.IOException) CoreMetadata(loci.formats.CoreMetadata) Location(loci.common.Location)

Example 8 with IniParser

use of loci.common.IniParser in project bioformats by openmicroscopy.

the class BDReader method initFile.

// -- Internal FormatReader API methods --
/* @see loci.formats.FormatReader#initFile(String) */
@Override
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();
    rootList = dir.list(true);
    Arrays.sort(rootList);
    for (int i = 0; i < rootList.length; i++) {
        String file = rootList[i];
        Location f = new Location(dir, file);
        rootList[i] = f.getAbsolutePath();
        if (!f.isDirectory()) {
            if (checkSuffix(file, META_EXT) && !f.isDirectory()) {
                metadataFiles.add(f.getAbsolutePath());
            }
        } else {
            String[] wells = f.list(true);
            Arrays.sort(wells);
            wellList.add(wells);
            for (String well : wells) {
                Location wellFile = new Location(f, well);
                if (!wellFile.isDirectory()) {
                    if (checkSuffix(well, META_EXT)) {
                        metadataFiles.add(wellFile.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);
    }
    final List<String> uniqueRows = new ArrayList<String>();
    final List<String> uniqueColumns = new ArrayList<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();
    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, new String[] { "txt", "bmp", "adf", "roi" })) {
                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));
                }
            }
        }
    }
    int coresize = core.size();
    core.clear();
    for (int i = 0; i < coresize; i++) {
        CoreMetadata ms = new CoreMetadata();
        core.add(ms);
        ms.sizeC = nChannels;
        ms.sizeZ = nSlices;
        ms.sizeT = nTimepoints;
        ms.sizeX = sizeX / fieldCols;
        ms.sizeY = sizeY / fieldRows;
        ms.pixelType = pixelType;
        ms.rgb = rgb;
        ms.interleaved = interleaved;
        ms.indexed = indexed;
        ms.littleEndian = littleEndian;
        ms.dimensionOrder = "XYZTC";
        ms.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);
    PositiveInteger fieldCount = FormatTools.getMaxFieldCount(fieldRows * fieldCols);
    if (fieldCount != null) {
        store.setPlateAcquisitionMaximumFieldCount(fieldCount, 0, 0);
    }
    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;
                }
            }
            Double magnification = new Double(mag);
            store.setObjectiveNominalMagnification(magnification, 0, 0);
            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);
                Length emission = FormatTools.getEmissionWavelength(emWave[c]);
                Length excitation = FormatTools.getExcitationWavelength(exWave[c]);
                if (emission != null) {
                    store.setChannelEmissionWavelength(emission, i, c);
                }
                if (excitation != null) {
                    store.setChannelExcitationWavelength(excitation, i, 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(new Time(exposure[zct[1]], UNITS.SECOND), 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(new Time(timestamp, UNITS.SECOND), 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);
        }
    }
}
Also used : IniParser(loci.common.IniParser) IniList(loci.common.IniList) ArrayList(java.util.ArrayList) Time(ome.units.quantity.Time) StringReader(java.io.StringReader) PositiveInteger(ome.xml.model.primitives.PositiveInteger) NonNegativeInteger(ome.xml.model.primitives.NonNegativeInteger) CoreMetadata(loci.formats.CoreMetadata) MetadataStore(loci.formats.meta.MetadataStore) PositiveInteger(ome.xml.model.primitives.PositiveInteger) NonNegativeInteger(ome.xml.model.primitives.NonNegativeInteger) Length(ome.units.quantity.Length) IniTable(loci.common.IniTable) BufferedReader(java.io.BufferedReader) Location(loci.common.Location)

Example 9 with IniParser

use of loci.common.IniParser in project bioformats by openmicroscopy.

the class ConfigurationTree method parseConfigFile.

public void parseConfigFile(String configFile) throws IOException {
    File file = new File(configFile);
    if (file.isDirectory()) {
        return;
    }
    String parent = file.getParent();
    if (configDir != null) {
        parent = relocateToRoot(parent);
    }
    configFile = file.getAbsolutePath();
    String dir = file.getParentFile().getAbsolutePath();
    IniParser parser = new IniParser();
    parser.setCommentDelimiter(null);
    FileInputStream stream = new FileInputStream(configFile);
    IniList iniList = parser.parseINI(new BufferedReader(new InputStreamReader(stream, Constants.ENCODING)));
    for (IniTable table : iniList) {
        String id = table.get(IniTable.HEADER_KEY);
        id = id.substring(0, id.lastIndexOf(" "));
        id = new File(parent, id).getAbsolutePath();
        DefaultMutableTreeNode node = findNode(id, true, configFile);
        if (node == null) {
            LOGGER.warn("config file '{}' has invalid filename '{}'", configFile, id);
            continue;
        }
    }
}
Also used : IniParser(loci.common.IniParser) InputStreamReader(java.io.InputStreamReader) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) IniList(loci.common.IniList) IniTable(loci.common.IniTable) BufferedReader(java.io.BufferedReader) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 10 with IniParser

use of loci.common.IniParser in project bioformats by openmicroscopy.

the class BDReader method parseChannelData.

private void parseChannelData(Location dir) throws IOException {
    emWave = new double[channelNames.size()];
    exWave = new double[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");
        RandomAccessInputStream stream = new RandomAccessInputStream(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] = Double.parseDouble(em);
        String ex = numerator.get("Excitation");
        ex = ex.substring(0, ex.lastIndexOf(" "));
        if (ex.indexOf(' ') != -1) {
            ex = ex.substring(ex.lastIndexOf(" ") + 1);
        }
        exWave[c] = Double.parseDouble(ex);
        exposure[c] = Double.parseDouble(numerator.get("Exposure"));
        gain[c] = Double.parseDouble(numerator.get("Gain"));
        offset[c] = Double.parseDouble(numerator.get("Offset"));
        stream.close();
    }
}
Also used : IniParser(loci.common.IniParser) InputStreamReader(java.io.InputStreamReader) IniList(loci.common.IniList) IniTable(loci.common.IniTable) BufferedReader(java.io.BufferedReader) RandomAccessInputStream(loci.common.RandomAccessInputStream) Location(loci.common.Location)

Aggregations

IniParser (loci.common.IniParser)13 IniList (loci.common.IniList)12 BufferedReader (java.io.BufferedReader)11 IniTable (loci.common.IniTable)11 CoreMetadata (loci.formats.CoreMetadata)8 Location (loci.common.Location)7 StringReader (java.io.StringReader)6 InputStreamReader (java.io.InputStreamReader)5 RandomAccessInputStream (loci.common.RandomAccessInputStream)4 FormatException (loci.formats.FormatException)4 MetadataStore (loci.formats.meta.MetadataStore)4 File (java.io.File)3 Length (ome.units.quantity.Length)3 FileInputStream (java.io.FileInputStream)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Time (ome.units.quantity.Time)2 Hashtable (java.util.Hashtable)1 Map (java.util.Map)1 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)1