Skip to content
Snippets Groups Projects
Commit 34e3b5fd authored by brinn's avatar brinn
Browse files

Add methods getCamera, getEmissionTag, getExitationTag, getExpCam,...

Add methods getCamera, getEmissionTag, getExitationTag, getExpCam, getFilterRef, getLightSRef, getWaveLength, getChannelDescription from Matt.

SVN: 24786
parent 46d2a2f1
No related branches found
No related tags found
No related merge requests found
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package ch.systemsx.cisd.imagereaders.bioformats; package ch.systemsx.cisd.imagereaders.bioformats;
import java.io.StringReader; import java.io.StringReader;
...@@ -44,9 +43,9 @@ import ch.systemsx.cisd.common.geometry.SpatialPoint; ...@@ -44,9 +43,9 @@ import ch.systemsx.cisd.common.geometry.SpatialPoint;
/** /**
* A helper class with utility methods that parse metadata from FLEX files. * A helper class with utility methods that parse metadata from FLEX files.
* <p> * <p>
* Clients can implement their own utility methods on the top of FlexHelper, by parsing the * Clients can implement their own utility methods on the top of FlexHelper, by parsing the metadata
* metadata XML as returned by {@link #getMetadata()} or by directly executing XPath query * XML as returned by {@link #getMetadata()} or by directly executing XPath query via
* via {@link #selectByXpathQuery(String)}. * {@link #selectByXpathQuery(String)}.
* *
* @author Kaloyan Enimanev * @author Kaloyan Enimanev
*/ */
...@@ -61,6 +60,21 @@ public class FlexHelper ...@@ -61,6 +60,21 @@ public class FlexHelper
private static final String SELECT_TILE_FOR_IMAGE = private static final String SELECT_TILE_FOR_IMAGE =
"//Images/Image[@BufferNo='%s']/Sublayout/text()"; "//Images/Image[@BufferNo='%s']/Sublayout/text()";
private static final String SELECT_FILTER_REF_FOR_IMAGE =
"//Images/Image[@BufferNo='%s']/FilterCombinationRef/text()";
private static final String SELECT_LIGHTS_REF_FOR_IMAGE =
"//Images/Image[@BufferNo='%s']/LightSourceCombinationRef/text()";
private static final String SELECT_EMISSION_FOR_IMAGE =
"//FilterCombinations/FilterCombination[@ID='%s']/SliderRef[@ID='%s']";
private static final String SELECT_LASER_FOR_IMAGE =
"//LightSourceCombinations/LightSourceCombination[@ID='%s']/LightSourceRef/@ID";
private static final String SELECT_EXCITATION_FOR_IMAGE =
"//LightSources/LightSource[@ID='%s']/Wavelength/text()";
private static final String SELECT_TILE_XCOORDS = "//Sublayouts/Sublayout/Field/OffsetX/text()"; private static final String SELECT_TILE_XCOORDS = "//Sublayouts/Sublayout/Field/OffsetX/text()";
private static final String SELECT_TILE_YCOORDS = "//Sublayouts/Sublayout/Field/OffsetY/text()"; private static final String SELECT_TILE_YCOORDS = "//Sublayouts/Sublayout/Field/OffsetY/text()";
...@@ -95,7 +109,7 @@ public class FlexHelper ...@@ -95,7 +109,7 @@ public class FlexHelper
String tile = nodeList.item(0).getNodeValue(); String tile = nodeList.item(0).getNodeValue();
return Integer.parseInt(tile.trim()); return Integer.parseInt(tile.trim());
} }
public String getChannelCode(int imageIdx) public String getChannelCode(int imageIdx)
{ {
NodeList nodeList = selectByXpathQuery(SELECT_CHANNELS); NodeList nodeList = selectByXpathQuery(SELECT_CHANNELS);
...@@ -106,6 +120,100 @@ public class FlexHelper ...@@ -106,6 +120,100 @@ public class FlexHelper
return nodeList.item(imageIdx).getNodeValue(); return nodeList.item(imageIdx).getNodeValue();
} }
public String getChannelDescription(int imageIdx)
{
String out =
getChannelCode(imageIdx) + " - Ex:" + getExcitationTag(imageIdx) + "nm Em:"
+ getEmissionTag(imageIdx) + "nm";
return out;
}
public String getExpCam(int imageIdx)
{
NodeList nodeList = selectByXpathQuery(SELECT_CHANNELS);
if (imageIdx < 0 || nodeList.getLength() <= imageIdx)
{
throw new IllegalArgumentException("No image can be matched to idx=" + imageIdx);
}
return nodeList.item(imageIdx).getNodeValue();
}
public String getFilterRef(int imageIdx)
{
String query = String.format(SELECT_FILTER_REF_FOR_IMAGE, imageIdx);
NodeList nodeList = selectByXpathQuery(query);
if (nodeList.getLength() == 0)
{
throw new IllegalArgumentException("No image can be matched to idx=" + imageIdx);
}
String filterRef = nodeList.item(0).getNodeValue();
return filterRef.trim();
}
public String getLightSRef(int imageIdx)
{
String query = String.format(SELECT_LIGHTS_REF_FOR_IMAGE, imageIdx);
NodeList nodeList = selectByXpathQuery(query);
if (nodeList.getLength() == 0)
{
throw new IllegalArgumentException("No image can be matched to idx=" + imageIdx);
}
String filterRef = nodeList.item(0).getNodeValue();
return filterRef.trim();
}
public String getCamera(int imageIdx)
{
String expCam = getExpCam(imageIdx);
String cam = "Camera" + expCam.split("Cam")[1];
return cam.trim();
}
public String getEmissionTag(int imageIdx)
{
String query =
String.format(SELECT_EMISSION_FOR_IMAGE, getFilterRef(imageIdx),
getCamera(imageIdx));
NodeList nodeList = selectByXpathQuery(query);
if (nodeList.getLength() == 0)
{
throw new IllegalArgumentException("No image can be matched to idx=" + imageIdx);
}
String emissionTag = nodeList.item(0).getAttributes().getNamedItem("Filter").getNodeValue();
return emissionTag.trim();
}
public String getExcitationTag(int imageIdx)
{
String query = String.format(SELECT_LASER_FOR_IMAGE, getLightSRef(imageIdx));
NodeList nodeList = selectByXpathQuery(query);
if (nodeList.getLength() == 0)
{
throw new IllegalArgumentException("No image can be matched to idx=" + imageIdx);
}
String out = "";
for (int i = 0; i < nodeList.getLength(); i++)
{
out = out + getWaveLength(nodeList.item(i).getNodeValue()) + ",";
}
out = out.substring(0, out.length() - 1);
return out;
}
public String getWaveLength(String laser)
{
String query = String.format(SELECT_EXCITATION_FOR_IMAGE, laser);
NodeList nodeList = selectByXpathQuery(query);
if (nodeList.getLength() == 0)
{
throw new IllegalArgumentException("No image can be matched to idx=" + laser);
}
String waveLength = nodeList.item(0).getNodeValue();
return waveLength.trim();
}
public Map<Integer, SpatialPoint> getTileCoordinates() public Map<Integer, SpatialPoint> getTileCoordinates()
{ {
Map<Integer, SpatialPoint> points = new HashMap<Integer, SpatialPoint>(); Map<Integer, SpatialPoint> points = new HashMap<Integer, SpatialPoint>();
...@@ -193,11 +301,11 @@ public class FlexHelper ...@@ -193,11 +301,11 @@ public class FlexHelper
return dBF.newDocumentBuilder().parse(is); return dBF.newDocumentBuilder().parse(is);
} catch (Exception e) } catch (Exception e)
{ {
final String errorMessage = String.format( final String errorMessage =
"Failed to parse FLEX metadata :\n\n%s\n\nisn't a well formed XML document. %s", String.format(
value, e.getMessage()); "Failed to parse FLEX metadata :\n\n%s\n\nisn't a well formed XML document. %s",
value, e.getMessage());
throw new IllegalArgumentException(errorMessage); throw new IllegalArgumentException(errorMessage);
} }
} }
} }
...@@ -39,6 +39,8 @@ public class FlexHelperTest extends ImageReaderTestCase ...@@ -39,6 +39,8 @@ public class FlexHelperTest extends ImageReaderTestCase
assertEquals(1, helper.getTileNumber(0)); assertEquals(1, helper.getTileNumber(0));
assertEquals("Exp1Cam1", helper.getChannelCode(0)); assertEquals("Exp1Cam1", helper.getChannelCode(0));
assertEquals("488", helper.getExcitationTag(0));
assertEquals("565/40", helper.getEmissionTag(0));
Map<Integer, SpatialPoint> tileCoordinates = helper.getTileCoordinates(); Map<Integer, SpatialPoint> tileCoordinates = helper.getTileCoordinates();
assertEquals(1, tileCoordinates.size()); assertEquals(1, tileCoordinates.size());
...@@ -59,16 +61,21 @@ public class FlexHelperTest extends ImageReaderTestCase ...@@ -59,16 +61,21 @@ public class FlexHelperTest extends ImageReaderTestCase
{ "Exp1", "Exp1", "Exp2" }; { "Exp1", "Exp1", "Exp2" };
final String[] CAMS = new String[] final String[] CAMS = new String[]
{ "Cam1", "Cam3", "Cam2" }; { "Cam1", "Cam3", "Cam2" };
final String[] EXCITATION = new String[]
{ "561,405", "561,405", "488" };
final String[] EMISSION = new String[]
{ "450/50", "690/70", "565/40" };
for (int i = 0; i < 12; i++) for (int i = 0; i < 12; i++)
{ {
int parsedTile = helper.getTileNumber(i); int parsedTile = helper.getTileNumber(i);
String parsedChannelName = helper.getChannelCode(i);
assertEquals((i / 3) + 1, parsedTile); assertEquals((i / 3) + 1, parsedTile);
String channelName = EXPOSURES[ i % 3 ] + CAMS[ i % 3 ]; String channelName = EXPOSURES[i % 3] + CAMS[i % 3];
assertEquals(channelName, parsedChannelName); assertEquals(channelName, helper.getChannelCode(i));
assertEquals(EXCITATION[i % 3], helper.getExcitationTag(i));
assertEquals(EMISSION[i % 3], helper.getEmissionTag(i));
} }
Map<Integer, SpatialPoint> tileCoordinates = helper.getTileCoordinates(); Map<Integer, SpatialPoint> tileCoordinates = helper.getTileCoordinates();
assertEquals(4, tileCoordinates.size()); assertEquals(4, tileCoordinates.size());
assertEquals(new SpatialPoint(4.44E-4, 6.61E-4), tileCoordinates.get(1)); assertEquals(new SpatialPoint(4.44E-4, 6.61E-4), tileCoordinates.get(1));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment