Commit ab714727 authored by danyfel80's avatar danyfel80
Browse files

added new code

parent f9f0737c
...@@ -21,6 +21,7 @@ import plugins.adufour.hcs.data.WellPlate; ...@@ -21,6 +21,7 @@ import plugins.adufour.hcs.data.WellPlate;
import plugins.adufour.hcs.gui.WellPlateViewer; import plugins.adufour.hcs.gui.WellPlateViewer;
import plugins.adufour.hcs.io.WellPlateReader; import plugins.adufour.hcs.io.WellPlateReader;
import plugins.adufour.hcs.io.WellPlateReader_Opera; import plugins.adufour.hcs.io.WellPlateReader_Opera;
import plugins.adufour.hcs.io.WellPlateReader_OperaColumbusNew;
public class WellPlateImporter extends PluginActionable { public class WellPlateImporter extends PluginActionable {
private static final Set<WellPlateReader> availableReaders = new HashSet<WellPlateReader>(); private static final Set<WellPlateReader> availableReaders = new HashSet<WellPlateReader>();
...@@ -36,6 +37,7 @@ public class WellPlateImporter extends PluginActionable { ...@@ -36,6 +37,7 @@ public class WellPlateImporter extends PluginActionable {
if (importers.isEmpty()) { if (importers.isEmpty()) {
// Probably debugging within Eclipse => add one (known) entry manually // Probably debugging within Eclipse => add one (known) entry manually
importers.add((Class<WellPlateReader>) WellPlateReader_Opera.class.asSubclass(WellPlateReader.class)); importers.add((Class<WellPlateReader>) WellPlateReader_Opera.class.asSubclass(WellPlateReader.class));
importers.add((Class<WellPlateReader>) WellPlateReader_OperaColumbusNew.class.asSubclass(WellPlateReader.class));
} }
// Add available file filters // Add available file filters
...@@ -83,7 +85,8 @@ public class WellPlateImporter extends PluginActionable { ...@@ -83,7 +85,8 @@ public class WellPlateImporter extends PluginActionable {
try { try {
File selection = jfc.getSelectedFile(); File selection = jfc.getSelectedFile();
CancelableProgressFrame loadingProgress = new CancelableProgressFrame("Loading plate " + selection.getName()); CancelableProgressFrame loadingProgress = new CancelableProgressFrame(
"Loading plate " + selection.getName());
getPreferencesRoot().put("lastUsedDirectory", selection.getPath()); getPreferencesRoot().put("lastUsedDirectory", selection.getPath());
...@@ -106,8 +109,7 @@ public class WellPlateImporter extends PluginActionable { ...@@ -106,8 +109,7 @@ public class WellPlateImporter extends PluginActionable {
} }
/** /**
* @param path * @param path Path to check.
* Path to check.
* @return <code>true</code> if at least one reader accepts the given file * @return <code>true</code> if at least one reader accepts the given file
*/ */
public static boolean isValid(File path) { public static boolean isValid(File path) {
...@@ -121,11 +123,9 @@ public class WellPlateImporter extends PluginActionable { ...@@ -121,11 +123,9 @@ public class WellPlateImporter extends PluginActionable {
} }
/** /**
* Looks for an appropriate readed of the files contained in the provided * Looks for an appropriate readed of the files contained in the provided path.
* path.
* *
* @param file * @param file Path of the folder containing the files to read.
* Path of the folder containing the files to read.
* @return The appropriate reader for the files. * @return The appropriate reader for the files.
*/ */
public static WellPlateReader getReaderFor(File file) { public static WellPlateReader getReaderFor(File file) {
......
package plugins.adufour.hcs.data;
import java.awt.Color;
public interface IChannel {
long getId();
String getName();
Color getColor();
double getExcitationWavelength();
double getEmissionWavelength();
IImage getImage();
}
package plugins.adufour.hcs.data;
import java.awt.geom.Point2D;
import java.util.Map;
public interface IField {
long getId();
Point2D getPosition();
Map<Long, ? extends IPlane> getPlanes();
}
package plugins.adufour.hcs.data;
import java.awt.Color;
import java.util.Date;
public interface IImage {
public String getVersion();
public String getId();
public String getState();
public long getBufferNumber();
public String getUrl();
public long getRow();
public long getColumn();
public long getFieldId();
public long getPlaneId();
public long getTimepointId();
public long getChannelId();
public Color getChannelColor();
public String getChannelType();
public String getAcquisitionType();
public double getResolutionX();
public double getResolutionY();
public long getSizeX();
public long getSizeY();
public double getPositionX();
public double getPositionY();
public double getAbsPositionZ();
public double getPositionZ();
public double getTime();
public Date getDate();
public double getExcitationWavelength();
public double getEmissionWavelength();
}
package plugins.adufour.hcs.data;
import java.util.Map;
public interface IPlane {
long getId();
double getPositionZ();
public Map<Long, ? extends ITimepoint> getTimepoints();
}
package plugins.adufour.hcs.data;
import java.awt.Dimension;
import java.util.Map;
public interface IPlate {
String getId();
String getName();
String getType();
Dimension getDimension();
Map<Long, ? extends IWell> getWells();
}
package plugins.adufour.hcs.data;
import java.util.Map;
public interface ITimepoint {
long getId();
public Map<Long, ? extends IChannel> getChannels();
}
package plugins.adufour.hcs.data;
import java.awt.Point;
import java.util.Map;
public interface IWell {
long getId();
Point getPositionInPlate();
Map<Long, ? extends IField> getFields();
}
...@@ -8,25 +8,57 @@ import java.util.Iterator; ...@@ -8,25 +8,57 @@ import java.util.Iterator;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
import icy.type.dimension.Dimension2D;
import icy.util.StringUtil; import icy.util.StringUtil;
public class Well { public class Well {
public enum Shape { public static class Shape {
Circle(new Ellipse2D.Double()),
Square(new Rectangle2D.Double()), public static Shape newCircle() {
Rectangle(new Rectangle2D.Double()); return new Shape(new Ellipse2D.Double(0, 0, 1, 1));
}
public static Shape newSquare() {
return new Shape(new Rectangle2D.Double(0, 0, 1, 1));
}
public static Shape newRectangle() {
return new Shape(new Rectangle2D.Double(0, 0, 2, 1));
}
public final RectangularShape wellShape; public final RectangularShape wellShape;
private Shape(RectangularShape shape) { private Shape(RectangularShape shape) {
this.wellShape = shape; this.wellShape = shape;
// Assign default values in case none are available
shape.setFrame(0, 0, 5000, 5000);
} }
public void setDimension(double width, double height) { public void setDimension(double width, double height) {
wellShape.setFrame(0, 0, width, height); wellShape.setFrame(0, 0, width, height);
} }
public RectangularShape getShape() {
return wellShape;
}
public Dimension2D getDimension() {
return new Dimension2D.Double(wellShape.getWidth(), wellShape.getHeight());
}
public static Shape valueOf(String shape) {
Shape s;
switch (shape.toLowerCase()) {
case "circle":
s = newCircle();
break;
case "square":
s = newSquare();
break;
default: // rectangle
s = newRectangle();
break;
}
return s;
}
} }
/** /**
......
...@@ -5,207 +5,208 @@ import java.util.Iterator; ...@@ -5,207 +5,208 @@ import java.util.Iterator;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import com.drew.imaging.tiff.TiffProcessingException;
import icy.sequence.Sequence; import icy.sequence.Sequence;
import ome.xml.meta.OMEXMLMetadata; import ome.xml.meta.OMEXMLMetadata;
import plugins.adufour.hcs.io.WellPlateReader; import plugins.adufour.hcs.io.WellPlateReader;
public class WellPlate public class WellPlate {
{ private final WellPlateReader wellPlateReader;
private final WellPlateReader wellPlateReader;
private final OMEXMLMetadata metadata;
private final OMEXMLMetadata metadata;
private final Sequence sequence;
private final Sequence sequence;
/**
/** * Linearized 2D array containing all wells
* Linearized 2D array containing all wells */
*/ private final Well[] wells;
private final Well[] wells;
/**
/** * @param reader the reader that creates this well plate (will be used to load
* @param reader * individual fields)
* the reader that creates this well plate (will be used to load individual fields) * @param metadata the well plate metadata containing the plate layout
* @param metadata * @param shape the shape of the wells in this plate
* the well plate metadata containing the plate layout */
* @param shape public WellPlate(WellPlateReader reader, OMEXMLMetadata metadata, Well.Shape shape) {
* the shape of the wells in this plate this.wellPlateReader = reader;
*/ this.metadata = metadata;
public WellPlate(WellPlateReader reader, OMEXMLMetadata metadata, Well.Shape shape) this.sequence = new Sequence(metadata);
{
this.wellPlateReader = reader; // Initialize the wells (even if they contain no image)
this.metadata = metadata; int nbRows = getNbRows();
this.sequence = new Sequence(metadata); int nbCols = getNbCols();
wells = new Well[nbRows * nbCols];
// Initialize the wells (even if they contain no image) for (int row = 0; row < nbRows; row++)
int nbRows = getNbRows(); for (int col = 0; col < nbCols; col++)
int nbCols = getNbCols(); wells[row * nbCols + col] = new Well(shape, row, col);
wells = new Well[nbRows * nbCols]; }
for (int row = 0; row < nbRows; row++)
for (int col = 0; col < nbCols; col++) /**
wells[row * nbCols + col] = new Well(shape, row, col); * Builds a well plate considering the metadata and the array of wells (already
} * prepared before calling this constructor).
*
/** * @param reader the reader that creates this well plate (will be used to load
* @return The number of rows in this well plate * @param metadata the well plate metadata containing the plate layout
*/ * @param wells The wells contained in the plate. Make sure to use the same
public int getNbRows() * size as in the metadata.
{ * @throws IllegalArgumentException If the size of the wells array is not
return metadata.getPlateRows(0).getValue(); * equivalent to the size specified in the
} * metadata.
*/
/** public WellPlate(WellPlateReader reader, OMEXMLMetadata metadata, Well[] wells) {
* @return The number of columns in this well plate this.wellPlateReader = reader;
*/ this.metadata = metadata;
public int getNbCols() this.sequence = new Sequence(metadata);
{
return metadata.getPlateColumns(0).getValue(); // Initialize the wells with parameter
} int nbRows = getNbRows();
int nbCols = getNbCols();
public Well getWellAt(int row, int col) if (nbRows * nbCols == wells.length)
{ this.wells = wells;
return wells[row * getNbCols() + col]; else
} throw new IllegalArgumentException("The size of the wells array (" + wells.length
+ ") is not compatible with the metadata (" + nbRows + ", " + nbCols + ")");
public OMEXMLMetadata getMetaData() }
{
return metadata; /**
} * @return The number of rows in this well plate
*/
@Override public int getNbRows() {
public String toString() return metadata.getPlateRows(0).getValue();
{ }
String plateID = metadata.getPlateID(0);
String plateType = metadata.getPlateName(0); /**
* @return The number of columns in this well plate
return plateID + " (" + plateType + ")"; */
} public int getNbCols() {
return metadata.getPlateColumns(0).getValue();
public Sequence loadField(Field field) throws IOException, SAXException, TiffProcessingException }
{
wellPlateReader.loadField(field, sequence); public Well getWellAt(int row, int col) {
if (field != null) sequence.setName(field.getWell().getAlphanumericID()); return wells[row * getNbCols() + col];
return sequence; }
}
public OMEXMLMetadata getMetaData() {
/** return metadata;
* @return A well iterator that automatically skips empty wells }
*/
public Iterator<Well> wellIterator() @Override
{ public String toString() {
return wellIterator(null); String plateID = metadata.getPlateID(0);
} String plateType = metadata.getPlateName(0);
/** return plateID + " (" + plateType + ")";
* @return A well iterator that automatically skips empty wells }
* @param filters
* one or more templates (separated by spaces) used to select only a subset of wells, public Sequence loadField(Field field) throws IOException, SAXException {
* e.g.: wellPlateReader.loadField(field, sequence);
* <ul> if (field != null)
* <li><code>"A"</code> will select all wells in row A</li> sequence.setName(field.getWell().getAlphanumericID());
* <li><code>"A 03 B12"</code> will select all wells in row A, column 03, and well return sequence;
* B12</li> }
* <li>etc.</li>
* </ul> /**
*/ * @return A well iterator that automatically skips empty wells
public Iterator<Well> wellIterator(final String filters) */
{ public Iterator<Well> wellIterator() {
return new Iterator<Well>() return wellIterator(null);
{ }
int currentWellIndex = -1;
int nextWellIndex = 0; /**
Well nextWell = null; * @return A well iterator that automatically skips empty wells
* @param filters one or more templates (separated by spaces) used to select
@Override * only a subset of wells, e.g.:
public Well next() * <ul>
{ * <li><code>"A"</code> will select all wells in row A</li>
currentWellIndex = nextWellIndex; * <li><code>"A 03 B12"</code> will select all wells in row A,
return nextWell; * column 03, and well B12</li>
} * <li>etc.</li>
* </ul>
@Override */
public boolean hasNext() public Iterator<Well> wellIterator(final String filters) {
{ return new Iterator<Well>() {
for (int newWell = currentWellIndex + 1; newWell < wells.length; newWell++) int currentWellIndex = -1;
{ int nextWellIndex = 0;
Well candidateWell = wells[newWell]; Well nextWell = null;
if (candidateWell.isEmpty()) continue; @Override
public Well next() {
// the well is automatically valid if there are no filters currentWellIndex = nextWellIndex;
boolean isValidWell = (filters == null); return nextWell;
}
if (filters != null)
{ @Override
for (String filter : filters.split("\\s+")) public boolean hasNext() {
if (candidateWell.getAlphanumericID().contains(filter)) for (int newWell = currentWellIndex + 1; newWell < wells.length; newWell++) {
{ Well candidateWell = wells[newWell];
isValidWell = true;
break; if (candidateWell.isEmpty())
} continue;
}
// the well is automatically valid if there are no filters
if (isValidWell) boolean isValidWell = (filters == null);
{
nextWell = wells[newWell]; if (filters != null) {
nextWellIndex = newWell; for (String filter : filters.split("\\s+"))
return true; if (candidateWell.getAlphanumericID().contains(filter)) {
} isValidWell = true;
} break;
return false; }
} }
};
} if (isValidWell) {
nextWell = wells[newWell];
/** nextWellIndex = newWell;
* @return A field iterator that automatically skips empty wells return true;
*/ }
public Iterator<Field> fieldIterator() }