adams.data.heatmap
Class Heatmap

java.lang.Object
  extended by adams.data.heatmap.Heatmap
All Implemented Interfaces:
CloneHandler, Mergeable<DataContainer>, DataContainer<HeatmapValue>, IDHandler, MutableIDHandler, NotesHandler, MutableReportHandler<Report>, ReportHandler<Report>, Serializable, Comparable, Iterable<HeatmapValue>, Collection<HeatmapValue>

public class Heatmap
extends Object
implements Serializable, MutableIDHandler, MutableReportHandler<Report>, NotesHandler, DataContainer<HeatmapValue>

Simple wrapper around a 2-D array representing a heatmap.

Version:
$Revision: 6975 $
Author:
fracpete (fracpete at waikato dot ac dot nz)
See Also:
Serialized Form

Field Summary
static String FIELD_FILENAME
          the field for the "filename" meta-data entry.
static String FIELD_TIMESTAMP
          the field for the "timestamp" meta-data entry.
protected static DataPointComparator<HeatmapValue> m_Comparator
          the singleton comparator.
protected  String m_ID
          the ID of the heatmap (basically the filename).
protected  double[][] m_Map
          the actual heat map.
protected  double m_Max
          the maximum intensity value.
protected  double m_Min
          the minimum intensity value.
protected  Notes m_Notes
          the attached notes.
protected  Report m_Report
          meta-information on the heatmap.
 
Constructor Summary
Heatmap(double[][] map)
          Initializes the heatmap with the 2-D data.
Heatmap(int rows, int cols)
          Initializes an empty heatmap with a given size.
 
Method Summary
 boolean add(HeatmapValue e)
          Adds the value specified by this value object.
 boolean addAll(Collection<? extends HeatmapValue> c)
          Sets all the values stored in the collection in this heatmap.
 void assign(DataContainer<HeatmapValue> other)
          Obtains the stored variables from the other data point, but not the actual data points.
 void clear()
          Sets all values to 0.0.
 int compareTo(Object o)
          Compares this object with the specified object for order.
 int compareToHeader(Object o)
          Compares this object with the specified object for order.
 boolean contains(Object o)
          Checks whether the heatmap contains the specified object.
 boolean containsAll(Collection<?> c)
          Checks whether all of the items in the collection are stored in this heatmap.
static Report createEmptyReport()
          Returns an empty report.
 boolean equals(Object obj)
          Checks whether the specified object has the same content as this one.
 boolean equalsHeader(Object obj)
          Indicates whether some other chromatogram's header is "equal to" this ones.
static Heatmap fromIntensityString(int rows, int cols, String intensity)
          Creates a heatmap from the intensity string using the specified dimensions.
 double get(int pos)
          Returns the map value the specified position from the top left corner of the map, wlkaing through row-wise.
 double get(int row, int col)
          Returns the map value at the specified location.
 Heatmap getClone()
          Returns a clone of the object.
 DataPointComparator<HeatmapValue> getComparator()
          Returns the comparator in use.
 Heatmap getHeader()
          Returns an empty container with the same meta-data as this one.
 Heatmap getHeader(int height, int width)
          Returns an empty container with the same meta-data as this one, but with different dimensions of the map.
 int getHeight()
          Returns the height of the map.
 String getID()
          Returns the ID.
 double getMax()
          Returns the largest value in the heatmap.
 double getMin()
          Returns the smallest value in the heatmap.
 Notes getNotes()
          Returns the currently stored notes.
 Report getReport()
          Returns the report.
 int getWidth()
          Returns the width of the map.
 int getX(int pos)
          Returns the X location from the position.
 int getY(int pos)
          Returns Y location from the position.
 boolean hasReport()
          Checks whether a report is present.
 boolean isEmpty()
          Only false if all values are 0.0.
 Iterator<HeatmapValue> iterator()
          Returns an iterator over the elements in this collection.
 void mergeWith(DataContainer other)
          Merges its own data with the one provided by the specified object.
 DataPointComparator<HeatmapValue> newComparator()
          Returns a new instance of the default comparator.
 HeatmapValue newPoint()
          Returns a new instance of a DataContainer point.
 boolean remove(Object o)
          Sets the value at the location of the provided object to 0.0.
 boolean removeAll(Collection<?> c)
          Sets all values in this heatmap to 0.0 for locations stored in the collection provided.
protected  void resetMinMax()
          Resets the min/max values.
 boolean retainAll(Collection<?> c)
          Always throws UnsupportedOperationException.
 void set(double[] values)
          Sets all the values, if the size of the array matches this heatmap.
 void set(Double[] values)
          Sets all the values, if the size of the array matches this heatmap.
 void set(int pos, double value)
          Sets the map value at the specified position from the top left corner of the map, walking through row-wise.
 void set(int row, int col, double value)
          Sets the map value at the specified location.
 void setID(String value)
          Sets the ID.
 void setReport(Report value)
          Sets a new report.
 int size()
          Returns the total amount of data points in the map.
 Heatmap submap(int row, int col, int height, int width)
          Returns the specified submap.
 HeatmapValue[] toArray()
          Turns the heatmap into an array (row wise).
<HeatmapValue>
HeatmapValue[]
toArray(HeatmapValue[] a)
          Returns the stored points as array.
 Double[] toDoubleArray()
          Turns the heatmap into a Double array (row wise).
 String toIntensityString()
          Returns a comma-separated string of all the intensity values.
 List<HeatmapValue> toList()
          Returns a list with the points.
 List<HeatmapValue> toList(DataPointComparator comparator)
          Returns a list with the points.
 String toString()
          Returns a short string representation.
 TreeSet<HeatmapValue> toTreeSet()
          Returns a treeset with the points.
 TreeSet<HeatmapValue> toTreeSet(DataPointComparator<HeatmapValue> comparator)
          Returns a treeset with the points, sorted according to the given comparator.
protected  void updateMinMax(double value)
          Updates the min/max values.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Collection
hashCode
 

Field Detail

FIELD_FILENAME

public static final String FIELD_FILENAME
the field for the "filename" meta-data entry.

See Also:
Constant Field Values

FIELD_TIMESTAMP

public static final String FIELD_TIMESTAMP
the field for the "timestamp" meta-data entry.

See Also:
Constant Field Values

m_Comparator

protected static DataPointComparator<HeatmapValue> m_Comparator
the singleton comparator.


m_ID

protected String m_ID
the ID of the heatmap (basically the filename).


m_Map

protected double[][] m_Map
the actual heat map.


m_Report

protected Report m_Report
meta-information on the heatmap.


m_Notes

protected Notes m_Notes
the attached notes.


m_Min

protected double m_Min
the minimum intensity value.


m_Max

protected double m_Max
the maximum intensity value.

Constructor Detail

Heatmap

public Heatmap(int rows,
               int cols)
Initializes an empty heatmap with a given size.

Parameters:
rows - the number of rows in the map
cols - the number of cols in the map

Heatmap

public Heatmap(double[][] map)
Initializes the heatmap with the 2-D data.

Parameters:
map - the map data
Method Detail

setID

public void setID(String value)
Sets the ID.

Specified by:
setID in interface MutableIDHandler
Parameters:
value - the ID

getID

public String getID()
Returns the ID.

Specified by:
getID in interface IDHandler
Returns:
the ID

setReport

public void setReport(Report value)
Sets a new report.

Specified by:
setReport in interface MutableReportHandler<Report>
Parameters:
value - the new report

hasReport

public boolean hasReport()
Checks whether a report is present.

Specified by:
hasReport in interface ReportHandler<Report>
Returns:
true if a report is present

getReport

public Report getReport()
Returns the report.

Specified by:
getReport in interface ReportHandler<Report>
Returns:
the report, can be null if none available

resetMinMax

protected void resetMinMax()
Resets the min/max values.


updateMinMax

protected void updateMinMax(double value)
Updates the min/max values.

Parameters:
value - the new value

getMin

public double getMin()
Returns the smallest value in the heatmap.

Returns:
the minimum, Double.MAX_VALUE if only zeroes in the heatmp

getMax

public double getMax()
Returns the largest value in the heatmap.

Returns:
the maximum, Double.MIN_VALUE if only zeroes in the heatmp

getHeight

public int getHeight()
Returns the height of the map.

Returns:
the height

getWidth

public int getWidth()
Returns the width of the map.

Returns:
the width

size

public int size()
Returns the total amount of data points in the map.

Specified by:
size in interface Collection<HeatmapValue>
Returns:
the total size

getX

public int getX(int pos)
Returns the X location from the position.

Parameters:
pos - the position to get the X location for
Returns:
the X location

getY

public int getY(int pos)
Returns Y location from the position.

Parameters:
pos - the position to retrieve the Y location for
Returns:
the Y location

get

public double get(int row,
                  int col)
Returns the map value at the specified location.

Parameters:
row - the row index
col - the column index
Returns:
the heat value at the location

get

public double get(int pos)
Returns the map value the specified position from the top left corner of the map, wlkaing through row-wise.

Parameters:
pos - the position to retrieve
Returns:
the heat value at the position

set

public void set(int row,
                int col,
                double value)
Sets the map value at the specified location.

Parameters:
row - the row index
col - the column index
value - the heat value to set (>= 0.0)
Throws:
IllegalArgumentException - if negative value encountered

set

public void set(int pos,
                double value)
Sets the map value at the specified position from the top left corner of the map, walking through row-wise.

Parameters:
pos - the position in the map
value - the heat value to set
Throws:
IllegalArgumentException - if negative value encountered

set

public void set(double[] values)
Sets all the values, if the size of the array matches this heatmap. The array is assumed to have the values stored row-wise.

Parameters:
values - the values to set
Throws:
IllegalArgumentException - if array length and size of heatmap don't match
IllegalArgumentException - if negative values encountered

set

public void set(Double[] values)
Sets all the values, if the size of the array matches this heatmap. The array is assumed to have the values stored row-wise.

Parameters:
values - the values to set
Throws:
IllegalArgumentException - if array length and size of heatmap don't match
IllegalArgumentException - if negative values encountered

getNotes

public Notes getNotes()
Returns the currently stored notes.

Specified by:
getNotes in interface NotesHandler
Returns:
the current notes

getClone

public Heatmap getClone()
Returns a clone of the object.

Specified by:
getClone in interface CloneHandler
Specified by:
getClone in interface DataContainer<HeatmapValue>
Returns:
the clone

toString

public String toString()
Returns a short string representation.

Overrides:
toString in class Object
Returns:
the string representation

toArray

public HeatmapValue[] toArray()
Turns the heatmap into an array (row wise).

Specified by:
toArray in interface Collection<HeatmapValue>
Returns:
the heat values as array

toDoubleArray

public Double[] toDoubleArray()
Turns the heatmap into a Double array (row wise).

Returns:
the heat values as Double array

compareTo

public int compareTo(Object o)
Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

Specified by:
compareTo in interface Comparable
Parameters:
o - the object to be compared.
Returns:
a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
Throws:
ClassCastException - if the specified object's type prevents it from being compared to this object.

compareToHeader

public int compareToHeader(Object o)
Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

Specified by:
compareToHeader in interface DataContainer<HeatmapValue>
Parameters:
o - the object to be compared.
Returns:
a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
Throws:
ClassCastException - if the specified object's type prevents it from being compared to this object.

equalsHeader

public boolean equalsHeader(Object obj)
Indicates whether some other chromatogram's header is "equal to" this ones.

Specified by:
equalsHeader in interface DataContainer<HeatmapValue>
Parameters:
obj - the reference object with which to compare.
Returns:
true if this object is the same as the obj argument; false otherwise.

equals

public boolean equals(Object obj)
Checks whether the specified object has the same content as this one.

Specified by:
equals in interface Collection<HeatmapValue>
Overrides:
equals in class Object
Parameters:
obj - the object to compare
Returns:
true if the same content
See Also:
compareTo(Object)

iterator

public Iterator<HeatmapValue> iterator()
Returns an iterator over the elements in this collection. There are no guarantees concerning the order in which the elements are returned (unless this collection is an instance of some class that provides a guarantee).

Specified by:
iterator in interface Iterable<HeatmapValue>
Specified by:
iterator in interface Collection<HeatmapValue>
Returns:
an Iterator over the elements in this collection

clear

public void clear()
Sets all values to 0.0.

Note: the size of the collection won't be 0, as defined by the Collection interface.

Specified by:
clear in interface Collection<HeatmapValue>

isEmpty

public boolean isEmpty()
Only false if all values are 0.0.

Specified by:
isEmpty in interface Collection<HeatmapValue>
Returns:
true if all values are 0.0

toArray

public <HeatmapValue> HeatmapValue[] toArray(HeatmapValue[] a)
Returns the stored points as array.

Specified by:
toArray in interface Collection<HeatmapValue>
Parameters:
array - ignored
Returns:
the points as array

add

public boolean add(HeatmapValue e)
Adds the value specified by this value object.

Specified by:
add in interface Collection<HeatmapValue>
Parameters:
e - the value to add
Returns:
true if the value was different from the previous one

addAll

public boolean addAll(Collection<? extends HeatmapValue> c)
Sets all the values stored in the collection in this heatmap.

Specified by:
addAll in interface Collection<HeatmapValue>
Parameters:
c - the collection to use
Returns:
true if heatmap was modified

remove

public boolean remove(Object o)
Sets the value at the location of the provided object to 0.0.

Specified by:
remove in interface Collection<HeatmapValue>
Parameters:
o - the heatmap value with the coordinates to remove
Returns:
true if the value changed

removeAll

public boolean removeAll(Collection<?> c)
Sets all values in this heatmap to 0.0 for locations stored in the collection provided.

Specified by:
removeAll in interface Collection<HeatmapValue>
Parameters:
c - the collection of heatmap values, which locations should be set to 0.0 in this heatmap
Returns:
true if collection modified

contains

public boolean contains(Object o)
Checks whether the heatmap contains the specified object. For a heatmap value, the exact same value must be stored in the heatmap.

Specified by:
contains in interface Collection<HeatmapValue>
Parameters:
o - the object to look for
Returns:
true if object stored

containsAll

public boolean containsAll(Collection<?> c)
Checks whether all of the items in the collection are stored in this heatmap.

Specified by:
containsAll in interface Collection<HeatmapValue>
Parameters:
c - the collection to check
Returns:
true if all items are present

retainAll

public boolean retainAll(Collection<?> c)
Always throws UnsupportedOperationException.

Specified by:
retainAll in interface Collection<HeatmapValue>
Throws:
UnsupportedOperationException - if the clear operation is not supported by this collection

mergeWith

public void mergeWith(DataContainer other)
Merges its own data with the one provided by the specified object. Only adds a value from the other heatmap, if this one has a value of 0.0 at the specified location.

Specified by:
mergeWith in interface Mergeable<DataContainer>
Parameters:
other - the object to merge with

newComparator

public DataPointComparator<HeatmapValue> newComparator()
Returns a new instance of the default comparator.

Specified by:
newComparator in interface DataContainer<HeatmapValue>
Returns:
the comparator instance

getComparator

public DataPointComparator<HeatmapValue> getComparator()
Returns the comparator in use.

Specified by:
getComparator in interface DataContainer<HeatmapValue>
Returns:
the comparator in use

newPoint

public HeatmapValue newPoint()
Returns a new instance of a DataContainer point.

Specified by:
newPoint in interface DataContainer<HeatmapValue>
Returns:
the new DataContainer point

getHeader

public Heatmap getHeader()
Returns an empty container with the same meta-data as this one.

Specified by:
getHeader in interface DataContainer<HeatmapValue>
Returns:
a clone of the payload

getHeader

public Heatmap getHeader(int height,
                         int width)
Returns an empty container with the same meta-data as this one, but with different dimensions of the map.

Parameters:
height - the new height of the map
width - the new width of the map
Returns:
a clone of the payload

assign

public void assign(DataContainer<HeatmapValue> other)
Obtains the stored variables from the other data point, but not the actual data points.

Specified by:
assign in interface DataContainer<HeatmapValue>
Parameters:
other - the data point to get the values from

toList

public List<HeatmapValue> toList()
Returns a list with the points.

Specified by:
toList in interface DataContainer<HeatmapValue>
Returns:
a list with all the points

toList

public List<HeatmapValue> toList(DataPointComparator comparator)
Returns a list with the points.

Specified by:
toList in interface DataContainer<HeatmapValue>
Returns:
a list with all the points

toTreeSet

public TreeSet<HeatmapValue> toTreeSet()
Returns a treeset with the points.

Specified by:
toTreeSet in interface DataContainer<HeatmapValue>
Returns:
a treeset with all the points

toTreeSet

public TreeSet<HeatmapValue> toTreeSet(DataPointComparator<HeatmapValue> comparator)
Returns a treeset with the points, sorted according to the given comparator.

Specified by:
toTreeSet in interface DataContainer<HeatmapValue>
Parameters:
comparator - the comparator to use
Returns:
a treeset with all the points

submap

public Heatmap submap(int row,
                      int col,
                      int height,
                      int width)
Returns the specified submap.

Parameters:
row - the row of the top-left corner
col - the column of the top-left corner
height - the height of the submap
width - the width of the submap

toIntensityString

public String toIntensityString()
Returns a comma-separated string of all the intensity values.

Returns:
the intensity values as string

fromIntensityString

public static Heatmap fromIntensityString(int rows,
                                          int cols,
                                          String intensity)
Creates a heatmap from the intensity string using the specified dimensions.

Parameters:
rows - the height of the heatmap
cols - the width of the heatmap
intensity - the comma-separated list of intensity values
Returns:
the generated heatmap

createEmptyReport

public static Report createEmptyReport()
Returns an empty report.

Returns:
the empty report


Copyright © 2013 University of Waikato, Hamilton, NZ. All Rights Reserved.