Package adams.data.heatmap
Class Heatmap
- java.lang.Object
-
- adams.data.heatmap.Heatmap
-
- All Implemented Interfaces:
adams.core.CloneHandler
,adams.core.Mergeable<adams.data.container.DataContainer>
,adams.core.UniqueIDHandler
,adams.data.container.DataContainer<HeatmapValue>
,adams.data.id.IDHandler
,adams.data.id.MutableIDHandler
,adams.data.NotesHandler
,adams.data.report.MutableReportHandler<adams.data.report.Report>
,adams.data.report.ReportHandler<adams.data.report.Report>
,adams.data.spreadsheet.SpreadSheetSupporter
,adams.data.statistics.InformativeStatisticSupporter<HeatmapStatistic>
,Serializable
,Comparable
,Iterable<HeatmapValue>
,Collection<HeatmapValue>
public class Heatmap extends Object implements Serializable, adams.data.id.MutableIDHandler, adams.data.report.MutableReportHandler<adams.data.report.Report>, adams.data.NotesHandler, adams.data.container.DataContainer<HeatmapValue>, adams.data.statistics.InformativeStatisticSupporter<HeatmapStatistic>, adams.data.spreadsheet.SpreadSheetSupporter
Simple wrapper around a 2-D array representing a heatmap.- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description 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 adams.data.container.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 HeatmapValue
m_Max
the maximum intensity value.protected HeatmapValue
m_Min
the minimum intensity value.protected adams.data.Notes
m_Notes
the attached notes.protected adams.data.report.Report
m_Report
meta-information on the heatmap.protected long
m_UUID
the unique ID.static double
MISSING_VALUE
the missing value.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description 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(adams.data.container.DataContainer<HeatmapValue> other)
Obtains the stored variables from the other data point, but not the actual data points.void
clear()
Sets all values to missing.int
compareTo(Object o)
Compares this object with the specified object for order.int
compareToData(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 adams.data.report.Report
createEmptyReport()
Returns an empty report.boolean
equals(Object obj)
Checks whether the specified object has the same content as this one.boolean
equalsData(Object obj)
Indicates whether some other container's header is "equal to" this ones.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.adams.data.container.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.HeatmapValue
getMaxValue()
Returns the largest value in the heatmap.double
getMin()
Returns the smallest value in the heatmap.HeatmapValue
getMinValue()
Returns the smallest value in the heatmap.adams.data.Notes
getNotes()
Returns the currently stored notes.adams.data.report.Report
getReport()
Returns the report.long
getUniqueID()
Returns the unique ID.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 missing.boolean
isMissing(int pos)
Sets the map value at the specified position from the top left corner of the map, walking through row-wise.boolean
isMissing(int row, int col)
Sets the map value at the specified location to missing.static boolean
isMissingValue(double value)
Checks whether the value represents a missing value.Iterator<HeatmapValue>
iterator()
Returns an iterator over the elements in this collection.void
mergeWith(adams.data.container.DataContainer other)
Merges its own data with the one provided by the specified object.adams.data.container.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 missing.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(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
set(Double[] values)
Sets all the values, if the size of the array matches this heatmap.void
setID(String value)
Sets the ID.void
setMissing(int pos)
Sets the map value at the specified position to missing from the top left corner of the map, walking through row-wise.void
setMissing(int row, int col)
Sets the map value at the specified location.void
setReport(adams.data.report.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).Double[]
toDoubleArray(boolean skipMissing)
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(adams.data.container.DataPointComparator comparator)
Returns a list with the points.adams.data.spreadsheet.SpreadSheet
toSpreadSheet()
Returns the content as spreadsheet.HeatmapStatistic
toStatistic()
Returns a statistic object for this object.String
toString()
Returns a short string representation.TreeSet<HeatmapValue>
toTreeSet()
Returns a treeset with the points.TreeSet<HeatmapValue>
toTreeSet(adams.data.container.DataPointComparator<HeatmapValue> comparator)
Returns a treeset with the points, sorted according to the given comparator.protected void
updateMinMax(int row, int col, 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, parallelStream, removeIf, spliterator, stream, toArray
-
-
-
-
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
-
MISSING_VALUE
public static final double MISSING_VALUE
the missing value.- See Also:
- Constant Field Values
-
m_Comparator
protected static adams.data.container.DataPointComparator<HeatmapValue> m_Comparator
the singleton comparator.
-
m_ID
protected String m_ID
the ID of the heatmap (basically the filename).
-
m_UUID
protected long m_UUID
the unique ID.
-
m_Map
protected double[][] m_Map
the actual heat map.
-
m_Report
protected adams.data.report.Report m_Report
meta-information on the heatmap.
-
m_Notes
protected adams.data.Notes m_Notes
the attached notes.
-
m_Min
protected HeatmapValue m_Min
the minimum intensity value.
-
m_Max
protected HeatmapValue 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 mapcols
- 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 interfaceadams.data.id.MutableIDHandler
- Parameters:
value
- the ID
-
getID
public String getID()
Returns the ID.- Specified by:
getID
in interfaceadams.data.id.IDHandler
- Returns:
- the ID
-
getUniqueID
public long getUniqueID()
Returns the unique ID.- Specified by:
getUniqueID
in interfaceadams.core.UniqueIDHandler
- Returns:
- the ID
-
setReport
public void setReport(adams.data.report.Report value)
Sets a new report.- Specified by:
setReport
in interfaceadams.data.report.MutableReportHandler<adams.data.report.Report>
- Parameters:
value
- the new report
-
hasReport
public boolean hasReport()
Checks whether a report is present.- Specified by:
hasReport
in interfaceadams.data.report.ReportHandler<adams.data.report.Report>
- Returns:
- true if a report is present
-
getReport
public adams.data.report.Report getReport()
Returns the report.- Specified by:
getReport
in interfaceadams.data.report.ReportHandler<adams.data.report.Report>
- Returns:
- the report, can be null if none available
-
resetMinMax
protected void resetMinMax()
Resets the min/max values.
-
updateMinMax
protected void updateMinMax(int row, int col, 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
-
getMinValue
public HeatmapValue getMinValue()
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
-
getMaxValue
public HeatmapValue getMaxValue()
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 interfaceCollection<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 indexcol
- 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 indexcol
- the column indexvalue
- the heat value to set (>= 0.0)
-
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 mapvalue
- the heat value to set
-
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
-
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
-
setMissing
public void setMissing(int row, int col)
Sets the map value at the specified location.- Parameters:
row
- the row indexcol
- the column index
-
setMissing
public void setMissing(int pos)
Sets the map value at the specified position to missing from the top left corner of the map, walking through row-wise.- Parameters:
pos
- the position in the map
-
isMissing
public boolean isMissing(int row, int col)
Sets the map value at the specified location to missing.- Parameters:
row
- the row indexcol
- the column index
-
isMissing
public boolean isMissing(int pos)
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
-
getNotes
public adams.data.Notes getNotes()
Returns the currently stored notes.- Specified by:
getNotes
in interfaceadams.data.NotesHandler
- Returns:
- the current notes
-
getClone
public Heatmap getClone()
Returns a clone of the object.- Specified by:
getClone
in interfaceadams.core.CloneHandler
- Specified by:
getClone
in interfaceadams.data.container.DataContainer<HeatmapValue>
- Returns:
- the clone
-
toString
public String toString()
Returns a short string representation.
-
toArray
public HeatmapValue[] toArray()
Turns the heatmap into an array (row wise).- Specified by:
toArray
in interfaceCollection<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
-
toDoubleArray
public Double[] toDoubleArray(boolean skipMissing)
Turns the heatmap into a Double array (row wise).- Parameters:
skipMissing
- whether to skip missing values- 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 interfaceComparable
- 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 interfaceadams.data.container.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 interfaceadams.data.container.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.
-
compareToData
public int compareToData(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:
compareToData
in interfaceadams.data.container.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.
-
equalsData
public boolean equalsData(Object obj)
Indicates whether some other container's header is "equal to" this ones.- Specified by:
equalsData
in interfaceadams.data.container.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 interfaceCollection<HeatmapValue>
- Overrides:
equals
in classObject
- 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 interfaceCollection<HeatmapValue>
- Specified by:
iterator
in interfaceIterable<HeatmapValue>
- Returns:
- an Iterator over the elements in this collection
-
clear
public void clear()
Sets all values to missing.
Note: the size of the collection won't be 0, as defined by the Collection interface.- Specified by:
clear
in interfaceCollection<HeatmapValue>
-
isEmpty
public boolean isEmpty()
Only false if all values are missing.- Specified by:
isEmpty
in interfaceCollection<HeatmapValue>
- Returns:
- true if all values are missing
-
toArray
public <HeatmapValue> HeatmapValue[] toArray(HeatmapValue[] a)
Returns the stored points as array.- Specified by:
toArray
in interfaceCollection<HeatmapValue>
- Parameters:
a
- ignored- Returns:
- the points as array
-
add
public boolean add(HeatmapValue e)
Adds the value specified by this value object.- Specified by:
add
in interfaceCollection<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 interfaceCollection<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 missing.- Specified by:
remove
in interfaceCollection<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 interfaceCollection<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 interfaceCollection<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 interfaceCollection<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 interfaceCollection<HeatmapValue>
- Throws:
UnsupportedOperationException
- if the clear operation is not supported by this collection
-
mergeWith
public void mergeWith(adams.data.container.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 missing value at the specified location.- Specified by:
mergeWith
in interfaceadams.core.Mergeable<adams.data.container.DataContainer>
- Parameters:
other
- the object to merge with
-
newComparator
public adams.data.container.DataPointComparator<HeatmapValue> newComparator()
Returns a new instance of the default comparator.- Specified by:
newComparator
in interfaceadams.data.container.DataContainer<HeatmapValue>
- Returns:
- the comparator instance
-
getComparator
public adams.data.container.DataPointComparator<HeatmapValue> getComparator()
Returns the comparator in use.- Specified by:
getComparator
in interfaceadams.data.container.DataContainer<HeatmapValue>
- Returns:
- the comparator in use
-
newPoint
public HeatmapValue newPoint()
Returns a new instance of a DataContainer point.- Specified by:
newPoint
in interfaceadams.data.container.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 interfaceadams.data.container.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 mapwidth
- the new width of the map- Returns:
- a clone of the payload
-
assign
public void assign(adams.data.container.DataContainer<HeatmapValue> other)
Obtains the stored variables from the other data point, but not the actual data points.- Specified by:
assign
in interfaceadams.data.container.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 interfaceadams.data.container.DataContainer<HeatmapValue>
- Returns:
- a list with all the points
-
toList
public List<HeatmapValue> toList(adams.data.container.DataPointComparator comparator)
Returns a list with the points.- Specified by:
toList
in interfaceadams.data.container.DataContainer<HeatmapValue>
- Returns:
- a list with all the points
-
toTreeSet
public TreeSet<HeatmapValue> toTreeSet()
Returns a treeset with the points.- Specified by:
toTreeSet
in interfaceadams.data.container.DataContainer<HeatmapValue>
- Returns:
- a treeset with all the points
-
toTreeSet
public TreeSet<HeatmapValue> toTreeSet(adams.data.container.DataPointComparator<HeatmapValue> comparator)
Returns a treeset with the points, sorted according to the given comparator.- Specified by:
toTreeSet
in interfaceadams.data.container.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 cornercol
- the column of the top-left cornerheight
- the height of the submapwidth
- 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
-
toStatistic
public HeatmapStatistic toStatistic()
Returns a statistic object for this object.- Specified by:
toStatistic
in interfaceadams.data.statistics.InformativeStatisticSupporter<HeatmapStatistic>
- Returns:
- statistics for this object
-
toSpreadSheet
public adams.data.spreadsheet.SpreadSheet toSpreadSheet()
Returns the content as spreadsheet.- Specified by:
toSpreadSheet
in interfaceadams.data.spreadsheet.SpreadSheetSupporter
- Returns:
- the content
-
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 heatmapcols
- the width of the heatmapintensity
- the comma-separated list of intensity values- Returns:
- the generated heatmap
-
createEmptyReport
public static adams.data.report.Report createEmptyReport()
Returns an empty report.- Returns:
- the empty report
-
isMissingValue
public static boolean isMissingValue(double value)
Checks whether the value represents a missing value.- Parameters:
value
- the value to check- Returns:
- true if missing value
-
-