All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hfg.automation.platelayer.PlateReagentLayer Maven / Gradle / Ivy

package com.hfg.automation.platelayer;


import java.lang.reflect.Constructor;
import java.util.Collection;

import com.hfg.automation.AutomationXML;
import com.hfg.automation.WellRange;
import com.hfg.automation.WellRef;
import com.hfg.automation.plateop.VolumeMask;
import com.hfg.bio.HfgBioXML;
import com.hfg.units.Quantity;
import com.hfg.util.StringUtil;
import com.hfg.util.collection.OrderedMap;
import com.hfg.xml.HfgXMLSerializable;
import com.hfg.xml.XMLNode;
import com.hfg.xml.XMLTag;

//------------------------------------------------------------------------------
/**
 Plate layer for specifying per-well volumes of a reagent.
 
@author J. Alex Taylor, hairyfatguy.com
*/ //------------------------------------------------------------------------------ // com.hfg XML/HTML Coding Library // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com // [email protected] //------------------------------------------------------------------------------ public class PlateReagentLayer extends PlateLayerImpl implements ReagentLayer { private R mReagent; private VolumeMask mVolumeMask = new VolumeMask(); //########################################################################### // CONSTRUCTORS //########################################################################### //--------------------------------------------------------------------------- public PlateReagentLayer(R inValue) { setReagent(inValue); } //-------------------------------------------------------------------------- public PlateReagentLayer(XMLNode inXML) { super(inXML); // TODO: Best way to deal with the reagent? XMLNode reagentTag = inXML.getRequiredSubtagByName(AutomationXML.REAGENT); String reagentClassname = reagentTag.getAttributeValue(HfgBioXML.CLASS_ATT); if (! StringUtil.isSet(reagentClassname)) { throw new RuntimeException("No " + AutomationXML.CLASS_ATT + " specified on the layer's reagent XML tag!"); } if (reagentClassname.equals(String.class.getName())) { mReagent = (R) reagentTag.getUnescapedContent(); } else { try { Class clazz = Class.forName(reagentClassname); Constructor constructor = clazz.getConstructor(XMLNode.class); mReagent = (R) constructor.newInstance(reagentTag.getSubtags().get(0)); } catch (Exception e) { throw new RuntimeException("Error during plate instantiation from its XML tag!", e); } } XMLNode volumeMaskTag = inXML.getOptionalSubtagByName(AutomationXML.VOLUME_MASK); if (volumeMaskTag != null) { mVolumeMask = new VolumeMask(volumeMaskTag); } } //########################################################################### // PUBLIC METHODS //########################################################################### //--------------------------------------------------------------------------- public XMLNode toXMLNode() { XMLNode node = super.toXMLNode(); XMLNode reagentTag = new XMLTag(AutomationXML.REAGENT); reagentTag.setAttribute(AutomationXML.CLASS_ATT, mReagent.getClass().getName()); if (mReagent.getClass().equals(String.class)) { reagentTag.setContent(mReagent.toString()); } else { reagentTag.addSubtag(((HfgXMLSerializable) mReagent).toXMLNode()); } node.addSubtag(reagentTag); if (getVolumeMask() != null) { node.addSubtag(getVolumeMask().toXMLNode()); } return node; } //-------------------------------------------------------------------------- @Override public PlateReagentLayer clone() { PlateReagentLayer theClone = (PlateReagentLayer) super.clone(); theClone.mVolumeMask = mVolumeMask.clone(); return theClone; } //--------------------------------------------------------------------------- public PlateReagentLayer setReagent(R inValue) { mReagent = inValue; return this; } //--------------------------------------------------------------------------- public R getReagent() { return mReagent; } //--------------------------------------------------------------------------- public PlateReagentLayer setVolume(WellRange inWellRange, Quantity inQuantity) { getVolumeMask().setVolume(inWellRange, inQuantity); return this; } //--------------------------------------------------------------------------- public PlateReagentLayer setVolume(WellRef inWellRef, Quantity inQuantity) { getVolumeMask().setVolume(inWellRef, inQuantity); return this; } //--------------------------------------------------------------------------- public Quantity getVolume(WellRef inWellRef) { return getVolumeMask().getVolume(inWellRef); } //--------------------------------------------------------------------------- public VolumeMask getVolumeMask() { return mVolumeMask; } //--------------------------------------------------------------------------- @Override public Collection getOccupiedWellRefs() { return getVolumeMask().getOccupiedWellRefs(); } //--------------------------------------------------------------------------- @Override public WellLayer getWellLayer(WellRef inWellRef) { WellReagentLayer wellLayer = null; Quantity volume = getVolumeMask().getVolume(inWellRef); if (volume != null) { wellLayer = new WellReagentLayer().setReagent(getReagent()).setVolume(volume); wellLayer.setName(name()); } return wellLayer; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy