use of loci.common.Location in project bioformats by openmicroscopy.
the class CellWorxReader method getTiffFiles.
private String[] getTiffFiles(String plateName, char rowLetter, int col, int channels, int nTimepoints) {
String base = plateName + rowLetter + String.format("%02d", col + 1);
String[] files = new String[fieldCount * channels * nTimepoints];
int nextFile = 0;
for (int field = 0; field < fieldCount; field++) {
for (int channel = 0; channel < channels; channel++) {
for (int t = 0; t < nTimepoints; t++, nextFile++) {
String file = base;
if (fieldCount > 1) {
file += "_s" + (field + 1);
}
if (doChannels || channels > 1) {
file += "_w" + (channel + 1);
}
if (nTimepoints > 1) {
file += "_t" + nTimepoints;
}
files[nextFile] = file + ".tif";
if (!new Location(files[nextFile]).exists()) {
files[nextFile] = file + ".TIF";
}
}
}
}
boolean noneExist = true;
for (String file : files) {
if (new Location(file).exists()) {
noneExist = false;
break;
}
}
if (noneExist) {
nextFile = 0;
Location parent = new Location(currentId).getAbsoluteFile().getParentFile();
if (directoryList == null) {
directoryList = parent.list(true);
Arrays.sort(directoryList);
}
for (String f : directoryList) {
if (checkSuffix(f, new String[] { "tif", "tiff", "pnl" })) {
String path = new Location(parent, f).getAbsolutePath();
if (path.startsWith(base) && path.indexOf("_thumb_") < 0) {
files[nextFile++] = path;
}
}
}
}
return files;
}
use of loci.common.Location in project bioformats by openmicroscopy.
the class ColumbusReader method getSeriesUsedFiles.
/* @see loci.formats.IFormatReader#getSeriesUsedFiles(boolean) */
public String[] getSeriesUsedFiles(boolean noPixels) {
FormatTools.assertId(currentId, true, 1);
ArrayList<String> files = new ArrayList<String>();
files.add(currentId);
for (String file : metadataFiles) {
if (new Location(file).exists()) {
files.add(file);
}
}
if (!noPixels) {
for (Plane p : planes) {
if (p.series == getSeries() && !files.contains(p.file)) {
if (new Location(p.file).exists()) {
files.add(p.file);
}
}
}
}
return files.toArray(new String[files.size()]);
}
use of loci.common.Location in project bioformats by openmicroscopy.
the class ColumbusReader method findXML.
private static Location findXML(String name) {
Location parent = new Location(name).getAbsoluteFile().getParentFile();
Location xml = new Location(parent, XML_FILE);
if (xml.exists()) {
return xml;
}
if (parent.getParent() != null) {
xml = new Location(parent.getParentFile(), XML_FILE);
if (xml.exists()) {
return xml;
}
}
return null;
}
use of loci.common.Location in project bioformats by openmicroscopy.
the class ColumbusReader method initFile.
// -- Internal FormatReader API methods --
/* @see loci.formats.FormatReader#initFile(String) */
protected void initFile(String id) throws FormatException, IOException {
Location xml = findXML(id);
if (null == xml) {
throw new FormatException("Could not find " + XML_FILE);
}
id = xml.getAbsolutePath();
super.initFile(id);
Location parent = new Location(currentId).getAbsoluteFile().getParentFile();
// parse plate layout and image dimensions from the XML files
String xmlData = DataTools.readFile(id);
MeasurementHandler handler = new MeasurementHandler();
XMLTools.parseXML(xmlData, handler);
String[] parentDirectories = parent.list(true);
Arrays.sort(parentDirectories);
ArrayList<String> timepointDirs = new ArrayList<String>();
for (String file : parentDirectories) {
Location absFile = new Location(parent, file);
if (absFile.isDirectory()) {
timepointDirs.add(absFile.getAbsolutePath());
for (String f : absFile.list(true)) {
if (!checkSuffix(f, "tif")) {
if (!metadataFiles.contains(file + File.separator + f)) {
metadataFiles.add(file + File.separator + f);
}
}
}
}
}
for (int i = 0; i < metadataFiles.size(); i++) {
String metadataFile = metadataFiles.get(i);
int end = metadataFile.indexOf(File.separator);
String timepointPath = end < 0 ? "" : parent + File.separator + metadataFile.substring(0, end);
Location f = new Location(parent + File.separator + metadataFile);
if (!f.exists()) {
metadataFile = metadataFile.substring(end + 1);
f = new Location(parent, metadataFile);
}
String path = f.getAbsolutePath();
metadataFiles.set(i, path);
if (checkSuffix(path, "columbusidx.xml")) {
int timepoint = timepointDirs.indexOf(timepointPath);
if (timepointDirs.size() == 0) {
timepoint = 0;
}
parseImageXML(path, timepoint);
}
}
// process plane list to determine plate size
Comparator<Plane> planeComp = new Comparator<Plane>() {
public int compare(Plane p1, Plane p2) {
if (p1.row != p2.row) {
return p1.row - p2.row;
}
if (p1.col != p2.col) {
return p1.col - p2.col;
}
if (p1.field != p2.field) {
return p1.field - p2.field;
}
if (p1.timepoint != p2.timepoint) {
return p1.timepoint - p2.timepoint;
}
if (p1.channel != p2.channel) {
return p1.channel - p2.channel;
}
return 0;
}
};
Plane[] tmpPlanes = planes.toArray(new Plane[planes.size()]);
Arrays.sort(tmpPlanes, planeComp);
planes.clear();
reader = new MinimalTiffReader();
reader.setId(tmpPlanes[0].file);
core = reader.getCoreMetadataList();
CoreMetadata m = core.get(0);
m.sizeC = 0;
m.sizeT = 0;
ArrayList<Integer> uniqueSamples = new ArrayList<Integer>();
ArrayList<Integer> uniqueRows = new ArrayList<Integer>();
ArrayList<Integer> uniqueCols = new ArrayList<Integer>();
for (Plane p : tmpPlanes) {
planes.add(p);
int sampleIndex = p.row * handler.getPlateColumns() + p.col;
if (!uniqueSamples.contains(sampleIndex)) {
uniqueSamples.add(sampleIndex);
}
if (!uniqueRows.contains(p.row)) {
uniqueRows.add(p.row);
}
if (!uniqueCols.contains(p.col)) {
uniqueCols.add(p.col);
}
// counts are assumed to be non-sparse
if (p.field >= nFields) {
nFields = p.field + 1;
}
if (p.channel >= getSizeC()) {
m.sizeC = p.channel + 1;
}
if (p.timepoint >= getSizeT()) {
m.sizeT = p.timepoint + 1;
}
}
m.sizeZ = 1;
m.imageCount = getSizeZ() * getSizeC() * getSizeT();
m.dimensionOrder = "XYCTZ";
m.rgb = false;
int seriesCount = uniqueSamples.size() * nFields;
for (int i = 1; i < seriesCount; i++) {
core.add(m);
}
// populate the MetadataStore
MetadataStore store = makeFilterMetadata();
MetadataTools.populatePixels(store, this, true);
store.setScreenID(MetadataTools.createLSID("Screen", 0), 0);
store.setScreenName(handler.getScreenName(), 0);
store.setPlateID(MetadataTools.createLSID("Plate", 0), 0);
store.setPlateName(handler.getPlateName(), 0);
store.setPlateRows(new PositiveInteger(handler.getPlateRows()), 0);
store.setPlateColumns(new PositiveInteger(handler.getPlateColumns()), 0);
String imagePrefix = handler.getPlateName() + " Well ";
int wellSample = 0;
int nextWell = -1;
Timestamp date = new Timestamp(acquisitionDate);
long timestampSeconds = date.asInstant().getMillis() / 1000;
for (Integer row : uniqueRows) {
for (Integer col : uniqueCols) {
if (!uniqueSamples.contains(row * handler.getPlateColumns() + col)) {
continue;
}
nextWell++;
store.setWellID(MetadataTools.createLSID("Well", 0, nextWell), 0, nextWell);
store.setWellRow(new NonNegativeInteger(row), 0, nextWell);
store.setWellColumn(new NonNegativeInteger(col), 0, nextWell);
for (int field = 0; field < nFields; field++) {
Plane p = lookupPlane(row, col, field, 0, 0);
String wellSampleID = MetadataTools.createLSID("WellSample", 0, nextWell, field);
store.setWellSampleID(wellSampleID, 0, nextWell, field);
store.setWellSampleIndex(new NonNegativeInteger(wellSample), 0, nextWell, field);
if (p != null) {
store.setWellSamplePositionX(new Length(p.positionX, UNITS.REFERENCEFRAME), 0, nextWell, field);
store.setWellSamplePositionY(new Length(p.positionY, UNITS.REFERENCEFRAME), 0, nextWell, field);
}
String imageID = MetadataTools.createLSID("Image", wellSample);
store.setImageID(imageID, wellSample);
store.setWellSampleImageRef(imageID, 0, nextWell, field);
store.setImageName(imagePrefix + (char) (row + 'A') + (col + 1) + " Field #" + (field + 1), wellSample);
store.setImageAcquisitionDate(date, wellSample);
if (p != null) {
p.series = wellSample;
store.setPixelsPhysicalSizeX(FormatTools.getPhysicalSizeX(p.sizeX), p.series);
store.setPixelsPhysicalSizeY(FormatTools.getPhysicalSizeY(p.sizeY), p.series);
for (int c = 0; c < getSizeC(); c++) {
p = lookupPlane(row, col, field, 0, c);
if (p != null) {
p.series = wellSample;
store.setChannelName(p.channelName, p.series, p.channel);
if ((int) p.emWavelength > 0) {
store.setChannelEmissionWavelength(FormatTools.getEmissionWavelength(p.emWavelength), p.series, p.channel);
}
if ((int) p.exWavelength > 0) {
store.setChannelExcitationWavelength(FormatTools.getExcitationWavelength(p.exWavelength), p.series, p.channel);
}
store.setChannelColor(p.channelColor, p.series, p.channel);
}
for (int t = 0; t < getSizeT(); t++) {
p = lookupPlane(row, col, field, t, c);
if (p != null) {
p.series = wellSample;
store.setPlaneDeltaT(new Time(p.deltaT - timestampSeconds, UNITS.SECOND), p.series, getIndex(0, c, t));
}
}
}
}
wellSample++;
}
}
}
}
use of loci.common.Location in project bioformats by openmicroscopy.
the class DeltavisionReader method parseLogFile.
/**
* Extract metadata from associated log file, if it exists.
*/
private boolean parseLogFile(MetadataStore store) throws FormatException, IOException {
if (logFile == null || !new Location(logFile).exists()) {
logFile = null;
return false;
}
LOGGER.info("Parsing log file");
String[] lines = DataTools.readFile(logFile).split("[\r\n]");
String key, value = "", prefix = "";
int currentImage = 0;
List<String> channelNames = new ArrayList<String>();
List<Double> filters = new ArrayList<Double>();
for (String line : lines) {
int colon = line.indexOf(':');
if (colon >= 0 && colon < line.length() - 1 && !line.startsWith("Created")) {
key = line.substring(0, colon).trim();
value = line.substring(colon + 1).trim();
if (value.equals("") && !key.equals(""))
prefix = key;
addGlobalMeta(prefix + " " + key, value);
// Objective properties
if (key.equals("Objective")) {
// assume first word is the manufacturer's name
int space = value.indexOf(' ');
if (space != -1) {
String manufacturer = value.substring(0, space);
String extra = value.substring(space + 1);
String[] tokens = extra.split(",");
store.setObjectiveManufacturer(manufacturer, 0, 0);
String magnification = "", na = "";
if (tokens.length >= 1) {
int end = tokens[0].indexOf('X');
if (end > 0)
magnification = tokens[0].substring(0, end);
int start = tokens[0].indexOf('/');
if (start >= 0)
na = tokens[0].substring(start + 1);
}
try {
Double mag = new Double(magnification);
store.setObjectiveNominalMagnification(mag, 0, 0);
} catch (NumberFormatException e) {
LOGGER.warn("Could not parse magnification '{}'", magnification);
}
try {
store.setObjectiveLensNA(new Double(na), 0, 0);
} catch (NumberFormatException e) {
LOGGER.warn("Could not parse N.A. '{}'", na);
}
if (tokens.length >= 2) {
store.setObjectiveCorrection(getCorrection(tokens[1]), 0, 0);
}
// TODO: Token #2 is the microscope model name.
if (tokens.length > 3)
store.setObjectiveModel(tokens[3], 0, 0);
}
} else if (key.equalsIgnoreCase("Lens ID")) {
if (value.indexOf(',') != -1) {
value = value.substring(0, value.indexOf(','));
}
if (value.indexOf(' ') != -1) {
value = value.substring(value.indexOf(' ') + 1);
}
if (!value.equals("null")) {
String objectiveID = "Objective:" + value;
store.setObjectiveID(objectiveID, 0, 0);
for (int series = 0; series < getSeriesCount(); series++) {
store.setObjectiveSettingsID(objectiveID, series);
}
store.setObjectiveCorrection(getCorrection("Other"), 0, 0);
store.setObjectiveImmersion(getImmersion("Other"), 0, 0);
}
} else // Image properties
if (key.equals("Pixel Size")) {
String[] pixelSizes = value.split(" ");
for (int q = 0; q < pixelSizes.length; q++) {
Double size = null;
try {
size = new Double(pixelSizes[q].trim());
} catch (NumberFormatException e) {
LOGGER.warn("Could not parse pixel size '{}'", pixelSizes[q].trim());
}
if (q == 0) {
Length sizeX = FormatTools.getPhysicalSizeX(size);
if (sizeX != null) {
for (int series = 0; series < getSeriesCount(); series++) {
store.setPixelsPhysicalSizeX(sizeX, series);
}
}
}
if (q == 1) {
Length sizeY = FormatTools.getPhysicalSizeY(size);
if (sizeY != null) {
for (int series = 0; series < getSeriesCount(); series++) {
store.setPixelsPhysicalSizeY(sizeY, series);
}
}
}
if (q == 2) {
Length sizeZ = FormatTools.getPhysicalSizeZ(size);
if (sizeZ != null) {
for (int series = 0; series < getSeriesCount(); series++) {
store.setPixelsPhysicalSizeZ(sizeZ, series);
}
}
}
}
} else if (key.equals("Binning")) {
store.setDetectorType(getDetectorType("Other"), 0, 0);
String detectorID = MetadataTools.createLSID("Detector", 0, 0);
store.setDetectorID(detectorID, 0, 0);
for (int series = 0; series < getSeriesCount(); series++) {
for (int c = 0; c < getSizeC(); c++) {
store.setDetectorSettingsBinning(getBinning(value), series, c);
// link DetectorSettings to an actual Detector
store.setDetectorSettingsID(detectorID, series, c);
}
}
} else // Camera properties
if (key.equals("Type")) {
store.setDetectorModel(value, 0, 0);
} else if (key.equals("Gain")) {
value = value.replaceAll("X", "");
try {
String detectorID = MetadataTools.createLSID("Detector", 0, 0);
store.setDetectorID(detectorID, 0, 0);
for (int series = 0; series < getSeriesCount(); series++) {
for (int c = 0; c < getSizeC(); c++) {
store.setDetectorSettingsGain(new Double(value), series, c);
store.setDetectorSettingsID(detectorID, series, c);
}
}
} catch (NumberFormatException e) {
LOGGER.warn("Could not parse gain '{}'", value);
}
} else if (key.equals("Speed")) {
value = value.replaceAll("KHz", "");
try {
double khz = Double.parseDouble(value);
String detectorID = MetadataTools.createLSID("Detector", 0, 0);
store.setDetectorID(detectorID, 0, 0);
for (int series = 0; series < getSeriesCount(); series++) {
for (int c = 0; c < getSizeC(); c++) {
store.setDetectorSettingsReadOutRate(new Frequency(khz, UNITS.KILOHERTZ), series, c);
store.setDetectorSettingsID(detectorID, series, c);
}
}
} catch (NumberFormatException e) {
LOGGER.warn("Could not parse read-out rate '{}'", value);
}
} else if (key.equals("Temp Setting")) {
value = value.replaceAll("C", "").trim();
try {
// this is the camera temperature, not the environment temperature
// store.setImagingEnvironmentTemperature(value, 0);
} catch (NumberFormatException e) {
LOGGER.warn("Could not parse temperature '{}'", value);
}
} else // Plane properties
if (key.equals("EM filter")) {
if (!channelNames.contains(value)) {
channelNames.add(value);
}
} else if (key.equals("ND filter")) {
value = value.replaceAll("%", "");
try {
double nd = Double.parseDouble(value) / 100;
if (!filters.contains(nd)) {
filters.add(nd);
}
} catch (NumberFormatException exc) {
// so no need to log it explicitly
if (!value.equals("BLANK")) {
LOGGER.warn("Could not parse ND filter '{}'", value);
}
filters.add(null);
} catch (IllegalArgumentException e) {
LOGGER.debug("", e);
}
} else if (key.equals("Stage coordinates")) {
if (value.length() > 1) {
value = value.substring(1, value.length() - 1);
}
String[] coords = value.split(",");
for (int i = 0; i < coords.length; i++) {
Length p = null;
try {
final Double number = Double.valueOf(coords[i]);
p = new Length(number, UNITS.REFERENCEFRAME);
} catch (NumberFormatException e) {
LOGGER.warn("Could not parse stage coordinate '{}'", coords[i]);
}
if (currentImage < getImageCount() && getSeriesCount() == 1) {
// from the extended header.
if (i == 0) {
store.setPlanePositionX(p, 0, currentImage);
}
if (i == 1) {
store.setPlanePositionY(p, 0, currentImage);
}
if (i == 2) {
store.setPlanePositionZ(p, 0, currentImage);
}
}
}
currentImage++;
}
} else if (line.startsWith("Image"))
prefix = line;
else if (line.startsWith("Created")) {
if (line.length() > 8)
line = line.substring(8).trim();
String date = DateTools.formatDate(line, DATE_FORMATS);
if (date != null) {
for (int series = 0; series < getSeriesCount(); series++) {
store.setImageAcquisitionDate(new Timestamp(date), series);
}
} else {
LOGGER.warn("Could not parse date '{}'", line);
}
} else if (line.startsWith("#KEY")) {
line = line.substring(line.indexOf(" ")).trim();
int split = line.indexOf(":");
if (split < 0) {
split = line.indexOf(" ");
}
key = line.substring(0, split).trim();
value = line.substring(split + 1).trim();
addGlobalMeta(key, value);
} else if (line.endsWith(":")) {
prefix = line.substring(0, line.length() - 1);
} else if (!line.startsWith("#") && !line.replace("-", "").isEmpty() && !prefix.isEmpty()) {
addGlobalMetaList(prefix, line);
}
}
for (int series = 0; series < getSeriesCount(); series++) {
for (int c = 0; c < getEffectiveSizeC(); c++) {
if (c < channelNames.size()) {
store.setChannelName(channelNames.get(c), series, c);
}
if (c < filters.size()) {
ndFilters[c] = filters.get(c);
}
}
}
return true;
}
Aggregations