Search in sources :

Example 46 with Location

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

the class TCSReader method isThisType.

/* @see loci.formats.IFormatReader#isThisType(String, boolean) */
@Override
public boolean isThisType(String name, boolean open) {
    // not allowed to touch the file system
    if (!open)
        return false;
    // check that there is no LEI file
    String prefix = name;
    if (prefix.indexOf('.') != -1) {
        prefix = prefix.substring(0, prefix.lastIndexOf("."));
    }
    Location lei = new Location(prefix + ".lei");
    if (!lei.exists()) {
        lei = new Location(prefix + ".LEI");
        while (!lei.exists() && prefix.indexOf('_') != -1) {
            prefix = prefix.substring(0, prefix.lastIndexOf("_"));
            lei = new Location(prefix + ".lei");
            if (!lei.exists())
                lei = new Location(prefix + ".LEI");
        }
    }
    if (lei.exists())
        return false;
    try {
        RandomAccessInputStream s = new RandomAccessInputStream(name);
        boolean isThisType = isThisType(s);
        s.close();
        return isThisType;
    } catch (IOException e) {
        LOGGER.debug("", e);
        return false;
    }
}
Also used : RandomAccessInputStream(loci.common.RandomAccessInputStream) IOException(java.io.IOException) Location(loci.common.Location)

Example 47 with Location

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

the class CellVoyagerReader method initFile.

@Override
protected void initFile(final String id) throws FormatException, IOException {
    super.initFile(id);
    measurementFolder = new Location(id).getAbsoluteFile();
    if (!measurementFolder.exists()) {
        throw new IOException("File " + id + " does not exist.");
    }
    if (!measurementFolder.isDirectory()) {
        measurementFolder = measurementFolder.getParentFile();
        if (measurementFolder.getName().equals("Image")) {
            measurementFolder = measurementFolder.getParentFile();
        }
    }
    imageFolder = new Location(measurementFolder, "Image");
    measurementResultFile = new Location(measurementFolder, "MeasurementResult.xml");
    if (!measurementResultFile.exists()) {
        throw new IOException("Could not find " + measurementResultFile + " in folder.");
    }
    omeMeasurementFile = new Location(measurementFolder, "MeasurementResult.ome.xml");
    if (!omeMeasurementFile.exists()) {
        throw new IOException("Could not find " + omeMeasurementFile + " in folder.");
    }
    /*
     * Open MeasurementSettings file
     */
    RandomAccessInputStream result = new RandomAccessInputStream(measurementResultFile.getAbsolutePath());
    Document msDocument = null;
    try {
        msDocument = XMLTools.parseDOM(result);
    } catch (ParserConfigurationException e) {
        throw new IOException(e);
    } catch (SAXException e) {
        throw new IOException(e);
    } finally {
        result.close();
    }
    msDocument.getDocumentElement().normalize();
    /*
     * Check file version
     */
    final String fileVersionMajor = getChildText(msDocument.getDocumentElement(), new String[] { "FileVersion", "Major" });
    // Note the typo here.
    final String fileVersionMinor = getChildText(msDocument.getDocumentElement(), new String[] { "FileVersion", "Miner" });
    if (!fileVersionMajor.equals("1") || !fileVersionMinor.equals("0")) {
        LOGGER.warn("Detected a file version " + fileVersionMajor + "." + fileVersionMinor + ". This reader was built by reverse-engineering v1.0 files only. Errors might occur.");
    }
    /*
     * Open OME metadata file
     */
    RandomAccessInputStream measurement = new RandomAccessInputStream(omeMeasurementFile.getAbsolutePath());
    Document omeDocument = null;
    try {
        omeDocument = XMLTools.parseDOM(measurement);
    } catch (ParserConfigurationException e) {
        throw new IOException(e);
    } catch (SAXException e) {
        throw new IOException(e);
    } finally {
        measurement.close();
    }
    omeDocument.getDocumentElement().normalize();
    /*
     * Extract metadata from MeasurementSetting.xml & OME xml file. This is
     * where the core of parsing and fetching useful info happens
     */
    readInfo(msDocument, omeDocument);
}
Also used : IOException(java.io.IOException) RandomAccessInputStream(loci.common.RandomAccessInputStream) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) Document(org.w3c.dom.Document) Location(loci.common.Location) SAXException(org.xml.sax.SAXException)

Example 48 with Location

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

the class CellVoyagerReader method isThisType.

@Override
public boolean isThisType(final String name, final boolean open) {
    /*
     * We want to be pointed to any file in the directory that contains
     * 'MeasurementResult.xml'.
     */
    final String localName = new Location(name).getName();
    if (localName.equals("MeasurementResult.xml")) {
        return true;
    }
    final Location parent = new Location(name).getAbsoluteFile().getParentFile();
    Location xml = new Location(parent, "MeasurementResult.xml");
    if (!xml.exists() && parent != null) {
        if (parent.getParent() == null) {
            return false;
        }
        xml = new Location(parent.getParentFile(), "MeasurementResult.xml");
        if (!xml.exists()) {
            return false;
        }
    }
    return super.isThisType(name, open);
}
Also used : Location(loci.common.Location)

Example 49 with Location

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

the class CellWorxReader method getSeriesUsedFiles.

/* @see loci.formats.IFormatReader#getSeriesUsedFiles(boolean) */
@Override
public String[] getSeriesUsedFiles(boolean noPixels) {
    FormatTools.assertId(currentId, true, 1);
    final List<String> files = new ArrayList<String>();
    files.add(currentId);
    if (plateLogFile != null && new Location(plateLogFile).exists()) {
        files.add(plateLogFile);
    }
    if (zMapFile != null)
        files.add(zMapFile);
    int row = getWellRow(getSeries());
    int col = getWellColumn(getSeries());
    if (new Location(logFiles[row][col]).exists()) {
        files.add(logFiles[row][col]);
    }
    if (!noPixels) {
        if (checkSuffix(wellFiles[row][col][0], "pnl")) {
            if (new Location(wellFiles[row][col][0]).exists()) {
                files.add(wellFiles[row][col][0]);
            }
        } else {
            for (String f : wellFiles[row][col]) {
                if (new Location(f).exists()) {
                    files.add(f);
                }
            }
        }
    }
    return files.toArray(new String[files.size()]);
}
Also used : ArrayList(java.util.ArrayList) Location(loci.common.Location)

Example 50 with Location

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

the class CellWorxReader method isThisType.

// -- IFormatReader API methods --
/* @see loci.formats.IFormatReader#isThisType(String, boolean) */
@Override
public boolean isThisType(String name, boolean open) {
    if (checkSuffix(name, "pnl") || checkSuffix(name, "htd")) {
        return super.isThisType(name, open);
    }
    if (!open)
        return false;
    Location current = new Location(name).getAbsoluteFile();
    Location parent = current.getParentFile();
    String htdName = current.getName();
    while (htdName.indexOf('_') > 0) {
        htdName = htdName.substring(0, htdName.lastIndexOf("_"));
        if (new Location(parent, htdName + ".htd").exists() || new Location(parent, htdName + ".HTD").exists()) {
            return checkSuffix(name, "log") || isGroupFiles();
        }
    }
    return false;
}
Also used : Location(loci.common.Location)

Aggregations

Location (loci.common.Location)185 CoreMetadata (loci.formats.CoreMetadata)55 MetadataStore (loci.formats.meta.MetadataStore)51 FormatException (loci.formats.FormatException)49 ArrayList (java.util.ArrayList)47 RandomAccessInputStream (loci.common.RandomAccessInputStream)47 Length (ome.units.quantity.Length)34 IOException (java.io.IOException)28 Timestamp (ome.xml.model.primitives.Timestamp)28 Time (ome.units.quantity.Time)20 IFD (loci.formats.tiff.IFD)15 TiffParser (loci.formats.tiff.TiffParser)15 NonNegativeInteger (ome.xml.model.primitives.NonNegativeInteger)15 PositiveInteger (ome.xml.model.primitives.PositiveInteger)15 DependencyException (loci.common.services.DependencyException)13 ServiceException (loci.common.services.ServiceException)12 File (java.io.File)11 ServiceFactory (loci.common.services.ServiceFactory)11 IniList (loci.common.IniList)10 FilePattern (loci.formats.FilePattern)10