AFLPcore
Class Gel

java.lang.Object
  |
  +--AFLPcore.Data
        |
        +--AFLPcore.Gel

public class Gel
extends Data

A gel contains most of the information needed by the program. It contains a set of lanes and a set of bins. Additionally, the gel contains methods to convert the lanes into an array which can be converted into an image. The image can be controlled by setting the size range, borders, and intensity. Note: the gel will NOT check to see if the size ranges specified are valid. The image can also be written out in a PPM image format. This format is not widely used, but it is easy to code. More formats may be added in the future. Finally, the gel can be written to an output stream as well as read in from an input stream. As mentioned before, this effectively writes all of the critical data for the program.

See Also:
Bin, Lane

Constructor Summary
Gel()
          Create a new Gel.
 
Method Summary
 void addBin(Bin bin)
          Adds the specified bin to the gel.
 void addLane(Lane ln)
          Adds a lane to this gel.
 Bin binAtSize(double size)
          Gives the bin at the specified location.
 java.lang.Object clone()
          Clones the gel Not Implemented.
 int getBackGroundColor()
          Gives the color of the background for the gel.
 DataList getBins()
          Gives a list of all the bins in the gel.
 int getGelTopBorder()
          Gives the height of the border on the top and bottom of the gel image.
 double getGlobalMaxIntensity()
          Gives the maximum intensity of the gel.
 double getIntensity()
          Gives the height to which all values will be scaled to transform them into colors.
 int getLaneBorder()
          Gives the spacing between two lanes in the gel image.
 DataList getLanes()
          Gives a list of all of the lanes in the gel.
 int getLaneWidth()
          Gives the width of a lane, in pixels.
 double getMaxIntensity(double minSize, double maxSize)
          Gives the maximum intensity in the gel between the two specified sizes.
 double getMaxSize()
          Gives the largest size that will be included in the gel image when it is produced.
 double getMinSize()
          Gives the smallest size that will be included in the gel image when it is produced.
 int getNumLanes()
          Gives the number of lanes stored in this gel.
 int[] getPixels(double minSize, double maxSize, int length, double maxHeight)
          Gives an array of pixels that represents the gel as an image.
 int[] getPixels(int length)
          Gives an array of pixels that represents the gel as an image.
 DataList getSelectedLanes()
          Gives a list of all of the selected lanes in the gel.
 double getSizeInc()
          Gives the size in bp represented by each pixel in the pixel array.
 Lane laneAt(int index)
          Gives the lane at the specified index.
 void read(java.io.DataInputStream in)
          Reads in the properties of this class from the specified input stream.
 void removeBin(Bin bin)
          Removes the specified bin from the list of bins for this gel.
 void removeLane(Lane ln)
           
 void setBackGroundColor(int color)
          Set the background color to the specified value.
 void setGelTopBorder(int value)
          Sets the border on the top and bottom of the gel image to the specified value.
 void setIntensity(double intensity)
          Sets the intensity to the specified value.
 void setLaneBorder(int value)
          Sets the spacing between lanes as well as the left and right border on the gel image.
 void setLaneWidth(int value)
          Sets the width of a lane in the gel image.
 void setMaxSize(double maxSize)
          Sets the largest size that will be included in the gel image when it is produced.
 void setMinSize(double minSize)
          Sets the smallest size that will be included in the gel image when it is produced.
 void toggleSelectedLane(Lane ln)
          Changes the selection state of the specified lane.
 void write(java.io.DataOutputStream out)
          Writes all of the information this class needs to store in order to be recreated.
protected  void writeLane(int[] pix, int length, Lane lane, int horzIndex, int width, double scaleFactor, double maxSize)
          Writes the specified lane data into the specified pixel array at the given location.
 void writePNG(java.io.DataOutputStream out)
          Writes the gel image in a PNG format to the specified output stream.
 void writePPM(java.io.DataOutputStream out)
          Writes the gel image in a PPM format to the specified output stream.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Gel

public Gel()
Create a new Gel.
Method Detail

addLane

public void addLane(Lane ln)
Adds a lane to this gel.
Parameters:
ln - the lane to add

removeLane

public void removeLane(Lane ln)

laneAt

public Lane laneAt(int index)
Gives the lane at the specified index.

getLanes

public DataList getLanes()
Gives a list of all of the lanes in the gel. The list is not sorted and is in the same order as the lanes appear in the gel, left from right.
Returns:
the lanes in the gel. Empty if there are none.

getSelectedLanes

public DataList getSelectedLanes()
Gives a list of all of the selected lanes in the gel. The list is not sorted and is in the same order as the lanes appear in the gel, left from right, except not every lane is included in this list.
Returns:
the lanes in that are selected. Empty if there are none.

toggleSelectedLane

public void toggleSelectedLane(Lane ln)
Changes the selection state of the specified lane. If the lane is already selected, it is removed from the list of selected lanes. If it is not selected, it is added to the list. The order of the selected lanes is identical to the the ordering of the lanes in the gel.

The list is updated when a lane is added by moving through every lane in the gel, seeing if it should be selected, and then adding it to a new list if it should. Finally, the new list becomes the list of selected lanes.

Parameters:
ln - the lane to toggle

addBin

public void addBin(Bin bin)
Adds the specified bin to the gel.
Parameters:
bin - the new bin, complete with size and width set.

removeBin

public void removeBin(Bin bin)
Removes the specified bin from the list of bins for this gel.
Parameters:
bin - the bin to remove

getBins

public DataList getBins()
Gives a list of all the bins in the gel.
Returns:
the bins in the gel. If there are none, the list will be empty.

binAtSize

public Bin binAtSize(double size)
Gives the bin at the specified location. It works be searching the bin list for the specified size. If the size is found, that bin is returned. Otherwise, it retrieves the bin smaller than size and checks to see if size is within that range. If it is not, the first bin larger than size is checked in s similar manner.
Parameters:
size - the location to look for bins at
Returns:
the bin that contains the given size. null if no such bin exists.

getPixels

public int[] getPixels(int length)
Gives an array of pixels that represents the gel as an image. This can easily be converted into an Image using the MemoryImageSource. The array is one dimensional, with the form value(x,y) = pix[y*width + x] The data in the lanes of the gel are converted from heights to color values. The image will represent the data from minSize to maxSize which where set for this gel with setMinSize and setMaxSize. The color scaling is contolled by the intensity with setIntensity.
Parameters:
length - the length in pixels of the image in the array

getPixels

public int[] getPixels(double minSize,
                       double maxSize,
                       int length,
                       double maxHeight)
Gives an array of pixels that represents the gel as an image. This can easily be converted into an Image using the MemoryImageSource. The array is one dimensional, with the form value(x,y) = pix[y*width + x] The data in the lanes of the gel are converted from heights to color values. The image will represent the data from minSize to maxSize.
Parameters:
minSize - the size of the smallest fragement to display
maxSize - the size of the largest tragement to display
length - the length, in pixels, of the gel image.
maxHeight - the value which will give the brightest color Used to determine the color for the lane.
See Also:
writeLane(int[], int, AFLPcore.Lane, int, int, double, double), MemoryImageSource

writeLane

protected void writeLane(int[] pix,
                         int length,
                         Lane lane,
                         int horzIndex,
                         int width,
                         double scaleFactor,
                         double maxSize)
Writes the specified lane data into the specified pixel array at the given location. Since the destination is not the same size as the source, some points from the lane will be skipped or used multiple times. The former is more likely since lanes usually consist of several thousand points. The height at the point in a lane is converted to a color, where the height of the point determines the brightness of the color. For color values that exceed 255, they will be clipped to 255.
Parameters:
pix - the array representing the image
length - the length in pixels of the lane on the image
lane - the lane with the data of interest
horzIndex - determines the horizontal position in the image to write the lane to. It uses the laneWidth and laneBorder as well.
width - the width of the image in the pixel array
scaleFactor - the value to multiply the height by to get the color value, which maxes out at 255.
maxSize - the maximum size, in bp, for the lane. This size will be the first value shown in the lane.

getLaneWidth

public int getLaneWidth()
Gives the width of a lane, in pixels. This value is used to determine how wide to make the lanes in the gel image.
Returns:
the width

setLaneWidth

public void setLaneWidth(int value)
Sets the width of a lane in the gel image.
Parameters:
value - the width in pixels
See Also:
getPixels(int)

getLaneBorder

public int getLaneBorder()
Gives the spacing between two lanes in the gel image.
Returns:
the width in pixels between two lanes in the gel image, also the left and right borders.
See Also:
getPixels(int)

setLaneBorder

public void setLaneBorder(int value)
Sets the spacing between lanes as well as the left and right border on the gel image.
Parameters:
value - the width of the spacing, in pixels
See Also:
getPixels(int)

getGelTopBorder

public int getGelTopBorder()
Gives the height of the border on the top and bottom of the gel image.
Returns:
the height in pixels.
See Also:
getPixels(int)

setGelTopBorder

public void setGelTopBorder(int value)
Sets the border on the top and bottom of the gel image to the specified value.
Parameters:
value - the height of the border in pixels
See Also:
getPixels(int)

getMaxIntensity

public double getMaxIntensity(double minSize,
                              double maxSize)
Gives the maximum intensity in the gel between the two specified sizes.
Parameters:
minSize - the lower bound for searching, in bp
maxSize - the upper bound for searching, in bp
Returns:
the maximum intensity in the gel, -1 if the sizes are invalid or if the max < min.

getGlobalMaxIntensity

public double getGlobalMaxIntensity()
Gives the maximum intensity of the gel. This method will execute considerable faster than getMaxIntensity(double, double) because this value is stored in the gel and updated only when lanes are added. However, the slower method will scan for the maximum in the current lanes and in a limited range.
Returns:
the maximum intensity

getNumLanes

public int getNumLanes()
Gives the number of lanes stored in this gel.
Returns:
the number of lanes

getSizeInc

public double getSizeInc()
Gives the size in bp represented by each pixel in the pixel array.
Returns:
the scale of the image, bps per pixel.

getMinSize

public double getMinSize()
Gives the smallest size that will be included in the gel image when it is produced.
Returns:
the size in bp
See Also:
getPixels(int)

setMinSize

public void setMinSize(double minSize)
Sets the smallest size that will be included in the gel image when it is produced. This method will not check to see if the specified value is valid for this gel.
Parameters:
minSize - the size in bp
See Also:
getPixels(int)

getMaxSize

public double getMaxSize()
Gives the largest size that will be included in the gel image when it is produced.
Returns:
the size in bp
See Also:
getPixels(int)

setMaxSize

public void setMaxSize(double maxSize)
Sets the largest size that will be included in the gel image when it is produced. This method will not check to see if the specified value is valid for this gel.
Parameters:
maxSize - the size in bp
See Also:
getPixels(int)

getIntensity

public double getIntensity()
Gives the height to which all values will be scaled to transform them into colors. The smaller this number is, the brighter a gel will appear. Remember that anything above this value will simply be clipped to the maximum color value.
Returns:
the maximum expected height of a trace.
See Also:
getPixels(int)

setIntensity

public void setIntensity(double intensity)
Sets the intensity to the specified value. The intensity is used when the pixel array is assebled. It is the value which corresponds to the brightest color on the gel. Any value below it will be dimmer, and any value above it will have the same intensity.
Parameters:
intensity - the new value
See Also:
getPixels(int)

getBackGroundColor

public int getBackGroundColor()
Gives the color of the background for the gel.
Returns:
an integer representing the color, in the form 0xAARRGGBB, in hex, where 'A' represents the alpha value, 'R' the red, 'G', the green, and 'B' the blue.

setBackGroundColor

public void setBackGroundColor(int color)
Set the background color to the specified value.
Parameters:
color - the color as a 32-bit value, in the form 0xAARRGGBB, for alpha, red, green, and blue components.

clone

public java.lang.Object clone()
Clones the gel Not Implemented.
Overrides:
clone in class Data

writePPM

public void writePPM(java.io.DataOutputStream out)
              throws java.io.IOException
Writes the gel image in a PPM format to the specified output stream. If the pixels have been created using getPixels then that will be used to write the PPM. Otherwise, an image of length 500 will be created.
Parameters:
out - the stream to write the PPM to
Throws:
java.io.IOException - occurs if problems writing to the stream are incountered.

writePNG

public void writePNG(java.io.DataOutputStream out)
              throws java.io.IOException
Writes the gel image in a PNG format to the specified output stream. If the pixels have been created using getPixels then that will be used to write the PNG. Otherwise, an image of length 500 will be created.

To do the actual writing, the method uses a library produced by VisualTek. The library is specified in full here, as well as the java.awt.Image class. My thanks to them.

Java PNG by VisualTek Solutions Inc.
http://www.visualtek.com/PNG/

An image is created from the pixels and it is then passed to the libaray.

Parameters:
out - the stream to write the PPM to
Throws:
java.io.IOException - occurs if problems writing to the stream are incountered.

write

public void write(java.io.DataOutputStream out)
           throws java.io.IOException
Writes all of the information this class needs to store in order to be recreated. This will be used for things like storing the class in a file. Therefore, the write should output enough information so that read can recreate the essential properties of this class.
Parameters:
out - the destination to write the data to.
Throws:
java.io.IOException - occurs when a problem is encountered when writing to the stream.

read

public void read(java.io.DataInputStream in)
          throws java.io.IOException
Reads in the properties of this class from the specified input stream. The stream data should have been created by write. This will retrieve this classes state from the input stream. All of the current data in this class will be replaced by the data from the stream.
Parameters:
in - the input stream with the data for the class.
Throws:
java.io.IOException - occurs when a problem is encountered when writing to the stream.