use of qupath.lib.gui.tma.TMAEntries.TMAObjectEntry in project qupath by qupath.
the class TMASummaryViewer method importScores.
private int importScores(final String text) {
Map<String, List<String>> data = TMAScoreImporter.readCSV(text);
List<String> idColumn = data.remove(TMACoreObject.KEY_UNIQUE_ID);
if (idColumn == null) {
Dialogs.showErrorMessage("Import TMA data", "No '" + TMACoreObject.KEY_UNIQUE_ID + "' column found!");
return 0;
}
// Nothing left to import...
if (data.isEmpty())
return 0;
// Get the numeric columns, if possible
Map<String, double[]> dataNumeric = new HashMap<>();
for (String key : data.keySet().toArray(new String[0])) {
double[] vals = TMAScoreImporter.parseNumeric(data.get(key), true);
if (vals != null && GeneralTools.numNaNs(vals) != vals.length) {
dataNumeric.put(key, vals);
data.remove(key);
}
}
// Loop through IDs, adding values where needed
int counter = 0;
for (int i = 0; i < idColumn.size(); i++) {
boolean matched = false;
String id = idColumn.get(i);
if (id == null) {
logger.debug("Skipping missing ID");
continue;
}
for (TMAEntry entry : entriesBase) {
if (id.equals(entry.getMetadataValue(TMACoreObject.KEY_UNIQUE_ID))) {
matched = true;
for (Entry<String, double[]> dataEntry : dataNumeric.entrySet()) {
entry.putMeasurement(dataEntry.getKey(), dataEntry.getValue()[i]);
}
for (Entry<String, List<String>> dataEntry : data.entrySet()) {
entry.putMetadata(dataEntry.getKey(), dataEntry.getValue().get(i));
}
counter++;
}
}
if (!matched)
logger.warn("No match for ID: " + id);
}
Optional<TMAEntry> objectEntry = entriesBase.stream().filter(t -> t instanceof TMAObjectEntry).findAny();
if (objectEntry.isPresent()) {
Dialogs.showInfoNotification("TMA data update", "TMA cores updated!");
}
return counter;
}
Aggregations