public class SimpleDistanceMatrixData extends uno.informatics.data.pojo.DataPojo implements DistanceMatrixData
Constructor and Description |
---|
SimpleDistanceMatrixData(uno.informatics.data.SimpleEntity[] headers,
double[][] distances)
Create distance matrix data given the item headers and distances.
|
SimpleDistanceMatrixData(String name,
uno.informatics.data.SimpleEntity[] headers,
double[][] distances)
Create distance matrix data given the dataset name, item headers and
distances.
|
Modifier and Type | Method and Description |
---|---|
double |
getDistance(int idX,
int idY)
Get the distance between two entries.
|
static SimpleDistanceMatrixData |
readData(Path filePath,
uno.informatics.data.io.FileType type)
Read distance matrix data from file.
|
void |
writeData(Path filePath,
uno.informatics.data.io.FileType fileType)
Write distance matrix to file.
|
void |
writeData(Path filePath,
uno.informatics.data.io.FileType fileType,
org.jamesframework.core.subset.SubsetSolution solution,
boolean includeId,
boolean includeSelected,
boolean includeUnselected)
Write subset of the distance matrix to file and in the order of ids in
the solution.
|
checkHeaders, getDataset, getHeader, getIDs, getSize, indexOf, indexOf, setDataset, updateOrCreateHeaders, updateOrCreateHeaders
equals, getName, getUniqueIdentifier, hashCode, initialise, setName, setUniqueIdentifier, toString
addPropertyChangeListener, getPropertyChangeSupport, removePropertyChangeListener
public SimpleDistanceMatrixData(uno.informatics.data.SimpleEntity[] headers, double[][] distances)
All values should be positive and the diagonal values equal to zero. The distance matrix should be symmetric with all rows of equal length. Violating any of these requirements will produce an exception.
Item headers are required. Each item should at least have a unique identifier (names are optional).
headers
- item headers; its length should be the same as the dimension
of the given distance matrix and each item should at least
have a unique identifier (names are optional)distances
- distance matrix (symmetric)IllegalArgumentException
- if an illegal distance matrix is given or the number of
headers does not match the dimension of the distance matrixpublic SimpleDistanceMatrixData(String name, uno.informatics.data.SimpleEntity[] headers, double[][] distances)
All values should be positive and the diagonal values equal to zero. The distance matrix should be symmetric with all rows of equal length. Violating any of these requirements will produce an exception.
Item headers are required. Each item should at least have a unique identifier (names are optional).
name
- dataset nameheaders
- item headers; its length should be the same as the dimension
of the given distance matrix and each item should at least
have a unique identifier (names are optional)distances
- distance matrix (symmetric)IllegalArgumentException
- if an illegal distance matrix is given, if the number of
headers does not match the dimension of the distance matrix,
or if unique identifiers are missing in one or more headerspublic double getDistance(int idX, int idY)
DistanceMatrixData
getDistance
in interface DistanceMatrixData
idX
- the id of the first entryidY
- the id of the second entrypublic static SimpleDistanceMatrixData readData(Path filePath, uno.informatics.data.io.FileType type) throws IOException
FileType.TXT
and FileType.CSV
are allowed. Values are separated with a single
tab (txt) or comma (csv) character and should all be positive. Matrix
entries are included row-wise and rows can be truncated at or after the
diagonal. If included, diagonal values should always be zero. Any
provided values after the diagonal (upper triangular part) are validated
based on the compulsory lower triangular part, verifying that the
distance matrix is symmetric.
The file includes one required and one optional header column specifying unique identifiers and item names, respectively. The first, required header column is identified with column header "ID". The second, optional header column is identified with column header "NAME", when included. If no explicit names are provided, the unique identifiers are used as names as well. Optionally, the same item identifiers from the first header column may also be included on the first row (in the same order).
Leading and trailing whitespace is removed from names and unique identifiers and they are unquoted if wrapped in single or double quotes after whitespace removal. If it is intended to start or end a name/identifier with whitespace this whitespace should be contained within the quotes, as it will then not be removed.
The dataset name is set to the name of the file from which the data is read.
filePath
- path to file that contains the datatype
- FileType.TXT
or FileType.CSV
IOException
- if the file can not be read or is not correctly formattedpublic void writeData(Path filePath, uno.informatics.data.io.FileType fileType) throws IOException
filePath
- path to filefileType
- FileType.TXT
or FileType.CSV
IOException
- if the file can not be writtenpublic void writeData(Path filePath, uno.informatics.data.io.FileType fileType, org.jamesframework.core.subset.SubsetSolution solution, boolean includeId, boolean includeSelected, boolean includeUnselected) throws IOException
filePath
- path to filefileType
- FileType.TXT
or FileType.CSV
solution
- the solution to subset the dataincludeId
- includes the integer id used by the solutionincludeSelected
- includes selected accessionsincludeUnselected
- includes unselected accessionsIOException
- if the file can not be writtenCopyright © 2017. All rights reserved.