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;
}
}
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);
}
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);
}
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()]);
}
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;
}
Aggregations