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 StringFIELD_FILENAMEthe field for the "filename" meta-data entry.static StringFIELD_TIMESTAMPthe field for the "timestamp" meta-data entry.protected static adams.data.container.DataPointComparator<HeatmapValue>m_Comparatorthe singleton comparator.protected Stringm_IDthe ID of the heatmap (basically the filename).protected double[][]m_Mapthe actual heat map.protected HeatmapValuem_Maxthe maximum intensity value.protected HeatmapValuem_Minthe minimum intensity value.protected adams.data.Notesm_Notesthe attached notes.protected adams.data.report.Reportm_Reportmeta-information on the heatmap.protected longm_UUIDthe unique ID.static doubleMISSING_VALUEthe missing value.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(HeatmapValue e)Adds the value specified by this value object.booleanaddAll(Collection<? extends HeatmapValue> c)Sets all the values stored in the collection in this heatmap.voidassign(adams.data.container.DataContainer<HeatmapValue> other)Obtains the stored variables from the other data point, but not the actual data points.voidclear()Sets all values to missing.intcompareTo(Object o)Compares this object with the specified object for order.intcompareToData(Object o)Compares this object with the specified object for order.intcompareToHeader(Object o)Compares this object with the specified object for order.booleancontains(Object o)Checks whether the heatmap contains the specified object.booleancontainsAll(Collection<?> c)Checks whether all of the items in the collection are stored in this heatmap.static adams.data.report.ReportcreateEmptyReport()Returns an empty report.booleanequals(Object obj)Checks whether the specified object has the same content as this one.booleanequalsData(Object obj)Indicates whether some other container's header is "equal to" this ones.booleanequalsHeader(Object obj)Indicates whether some other chromatogram's header is "equal to" this ones.static HeatmapfromIntensityString(int rows, int cols, String intensity)Creates a heatmap from the intensity string using the specified dimensions.doubleget(int pos)Returns the map value the specified position from the top left corner of the map, wlkaing through row-wise.doubleget(int row, int col)Returns the map value at the specified location.HeatmapgetClone()Returns a clone of the object.adams.data.container.DataPointComparator<HeatmapValue>getComparator()Returns the comparator in use.HeatmapgetHeader()Returns an empty container with the same meta-data as this one.HeatmapgetHeader(int height, int width)Returns an empty container with the same meta-data as this one, but with different dimensions of the map.intgetHeight()Returns the height of the map.StringgetID()Returns the ID.doublegetMax()Returns the largest value in the heatmap.HeatmapValuegetMaxValue()Returns the largest value in the heatmap.doublegetMin()Returns the smallest value in the heatmap.HeatmapValuegetMinValue()Returns the smallest value in the heatmap.adams.data.NotesgetNotes()Returns the currently stored notes.adams.data.report.ReportgetReport()Returns the report.longgetUniqueID()Returns the unique ID.intgetWidth()Returns the width of the map.intgetX(int pos)Returns the X location from the position.intgetY(int pos)Returns Y location from the position.booleanhasReport()Checks whether a report is present.booleanisEmpty()Only false if all values are missing.booleanisMissing(int pos)Sets the map value at the specified position from the top left corner of the map, walking through row-wise.booleanisMissing(int row, int col)Sets the map value at the specified location to missing.static booleanisMissingValue(double value)Checks whether the value represents a missing value.Iterator<HeatmapValue>iterator()Returns an iterator over the elements in this collection.voidmergeWith(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.HeatmapValuenewPoint()Returns a new instance of a DataContainer point.booleanremove(Object o)Sets the value at the location of the provided object to missing.booleanremoveAll(Collection<?> c)Sets all values in this heatmap to 0.0 for locations stored in the collection provided.protected voidresetMinMax()Resets the min/max values.booleanretainAll(Collection<?> c)Always throws UnsupportedOperationException.voidset(double[] values)Sets all the values, if the size of the array matches this heatmap.voidset(int pos, double value)Sets the map value at the specified position from the top left corner of the map, walking through row-wise.voidset(int row, int col, double value)Sets the map value at the specified location.voidset(Double[] values)Sets all the values, if the size of the array matches this heatmap.voidsetID(String value)Sets the ID.voidsetMissing(int pos)Sets the map value at the specified position to missing from the top left corner of the map, walking through row-wise.voidsetMissing(int row, int col)Sets the map value at the specified location.voidsetReport(adams.data.report.Report value)Sets a new report.intsize()Returns the total amount of data points in the map.Heatmapsubmap(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).StringtoIntensityString()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.SpreadSheettoSpreadSheet()Returns the content as spreadsheet.HeatmapStatistictoStatistic()Returns a statistic object for this object.StringtoString()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 voidupdateMinMax(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:
setIDin interfaceadams.data.id.MutableIDHandler- Parameters:
value- the ID
-
getID
public String getID()
Returns the ID.- Specified by:
getIDin interfaceadams.data.id.IDHandler- Returns:
- the ID
-
getUniqueID
public long getUniqueID()
Returns the unique ID.- Specified by:
getUniqueIDin interfaceadams.core.UniqueIDHandler- Returns:
- the ID
-
setReport
public void setReport(adams.data.report.Report value)
Sets a new report.- Specified by:
setReportin 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:
hasReportin 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:
getReportin 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_VALUEif only zeroes in the heatmp
-
getMinValue
public HeatmapValue getMinValue()
Returns the smallest value in the heatmap.- Returns:
- the minimum,
Double.MAX_VALUEif only zeroes in the heatmp
-
getMax
public double getMax()
Returns the largest value in the heatmap.- Returns:
- the maximum,
Double.MIN_VALUEif only zeroes in the heatmp
-
getMaxValue
public HeatmapValue getMaxValue()
Returns the largest value in the heatmap.- Returns:
- the maximum,
Double.MIN_VALUEif 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:
sizein 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:
getNotesin interfaceadams.data.NotesHandler- Returns:
- the current notes
-
getClone
public Heatmap getClone()
Returns a clone of the object.- Specified by:
getClonein interfaceadams.core.CloneHandler- Specified by:
getClonein 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:
toArrayin 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:
compareToin 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:
compareToHeaderin 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:
equalsHeaderin 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:
compareToDatain 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:
equalsDatain 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:
equalsin interfaceCollection<HeatmapValue>- Overrides:
equalsin 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:
iteratorin interfaceCollection<HeatmapValue>- Specified by:
iteratorin 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:
clearin interfaceCollection<HeatmapValue>
-
isEmpty
public boolean isEmpty()
Only false if all values are missing.- Specified by:
isEmptyin interfaceCollection<HeatmapValue>- Returns:
- true if all values are missing
-
toArray
public <HeatmapValue> HeatmapValue[] toArray(HeatmapValue[] a)
Returns the stored points as array.- Specified by:
toArrayin 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:
addin 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:
addAllin 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:
removein 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:
removeAllin 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:
containsin 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:
containsAllin 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:
retainAllin 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:
mergeWithin 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:
newComparatorin interfaceadams.data.container.DataContainer<HeatmapValue>- Returns:
- the comparator instance
-
getComparator
public adams.data.container.DataPointComparator<HeatmapValue> getComparator()
Returns the comparator in use.- Specified by:
getComparatorin interfaceadams.data.container.DataContainer<HeatmapValue>- Returns:
- the comparator in use
-
newPoint
public HeatmapValue newPoint()
Returns a new instance of a DataContainer point.- Specified by:
newPointin 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:
getHeaderin 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:
assignin 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:
toListin 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:
toListin 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:
toTreeSetin 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:
toTreeSetin 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:
toStatisticin interfaceadams.data.statistics.InformativeStatisticSupporter<HeatmapStatistic>- Returns:
- statistics for this object
-
toSpreadSheet
public adams.data.spreadsheet.SpreadSheet toSpreadSheet()
Returns the content as spreadsheet.- Specified by:
toSpreadSheetin 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
-
-