Last update: 2011-06-23

org.proteios.util.jep
Class ChannelFunction

java.lang.Object
  extended by org.proteios.util.jep.ChannelFunction
All Implemented Interfaces:
org.nfunk.jep.function.PostfixMathCommandI, JepExpressionFunction, JepFunction

public class ChannelFunction
extends Object
implements JepExpressionFunction

A JEP function class that adds a ch(int) function to a JEP expression parser. The function will look up the intensity value for the given channel. For example: ch(1) / ch(2)

To be able to use this function it must be registered with the JEP parser and, before the expression is evaluated, a SqlResult object must be set. For example we can evaluate an expression for every position in a bioassay:

DbControl dc = ...
BioAssay assay = ...
String expression = "ch(1) / ch(2)";
ChannelFunction ch = new ChannelFunction({3, 4});
JEP jep = JepUtil.newJep(expression, ch);
DynamicResultIterator result = 
   assay.getSpotData().iterate(dc);
while (result.hasNext())
{
   ch.setSqlResult(result.next());
   double value = jep.getValue();
   // Do something with the value
}
result.close();

Version:
2.0
Author:
Nicklas
See Also:
Jep
Last modified
$Date: 2009-04-09 08:48:11 +0200 (Thu, 09 Apr 2009) $

Constructor Summary
ChannelFunction()
          Create a new instance of this function.
ChannelFunction(int[] channelToIndex)
          Create a new instance of this function which can be used to dynamically evaluate expressions.
 
Method Summary
 Object channel(int channel)
          Get the value of the specified channel of the current sql result.
 String getFunctionName()
          Get the name of this function.
 int getNumberOfParameters()
           
 void run(Stack stack)
           
 void setCurNumberOfParameters(int n)
           
 void setSqlResult(SqlResult result)
          Set a new SqlResult object that will be used the next time the JEP expression is evaluated.
 Expression toExpression(Node node)
          Create an expression referencing a channel intensity.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ChannelFunction

public ChannelFunction()
Create a new instance of this function. The new instance cannot be used to dynamically evaluate expressions. It should only be used for converting JEP formulas to Expression:s.

See Also:
Jep.formulaToExpression(String, JepFunction[])

ChannelFunction

public ChannelFunction(int[] channelToIndex)
Create a new instance of this function which can be used to dynamically evaluate expressions.

Parameters:
channelToIndex - An array that maps channel numbers to column indexes in the SqlResult, array position 0 maps the index of channel number 1, etc.
See Also:
setSqlResult(SqlResult)
Method Detail

getFunctionName

public String getFunctionName()
Description copied from interface: JepFunction
Get the name of this function. It is used when registering the function with a JEP parser.

Specified by:
getFunctionName in interface JepFunction
Returns:
The string "ch"
See Also:
JEP.addFunction(String, PostfixMathCommandI)

toExpression

public Expression toExpression(Node node)
Create an expression referencing a channel intensity.

Specified by:
toExpression in interface JepExpressionFunction
Parameters:
node - The node representing this function
Returns:
An Expression object

getNumberOfParameters

public int getNumberOfParameters()
Specified by:
getNumberOfParameters in interface org.nfunk.jep.function.PostfixMathCommandI
Returns:
Always 1

setCurNumberOfParameters

public void setCurNumberOfParameters(int n)
Specified by:
setCurNumberOfParameters in interface org.nfunk.jep.function.PostfixMathCommandI

run

public void run(Stack stack)
         throws ParseException
Specified by:
run in interface org.nfunk.jep.function.PostfixMathCommandI
Throws:
ParseException

setSqlResult

public void setSqlResult(SqlResult result)
Set a new SqlResult object that will be used the next time the JEP expression is evaluated.

Parameters:
result - The result object

channel

public Object channel(int channel)
               throws ParseException
Get the value of the specified channel of the current sql result.

Parameters:
channel - The channel number
Throws:
ParseException

Last update: 2011-06-23