use of uk.ac.sussex.gdsc.core.utils.BooleanArray in project GDSC-SMLM by aherbert.
the class FailCountManager method loadData.
/**
* Load the data from a file.
*/
private void loadData() {
final String filename = ImageJUtils.getFilename("Fail_count_data_filename", settings.getFilename());
if (filename == null) {
return;
}
settings.setFilename(filename);
final LocalList<FailCountData> countData = new LocalList<>();
try (BufferedReader br = Files.newBufferedReader(Paths.get(filename))) {
final Pattern pattern = Pattern.compile("[\t, ]+");
// Ignore the first line
String line = br.readLine();
final BooleanArray array = new BooleanArray(100);
int lastId = 0;
int lastCandidate = 0;
while ((line = br.readLine()) != null) {
final String[] data = pattern.split(line);
if (data.length != 3) {
throw new IOException("Require 3 fields in the data");
}
final int id = Integer.parseInt(data[0]);
if (id < 1) {
throw new IOException("ID must be strictly positive");
}
final int candidate = Integer.parseInt(data[1]);
if (candidate < 1) {
throw new IOException("Candidate must be strictly positive");
}
final boolean ok = guessStatus(data[2]);
if (lastId != id) {
if (array.size() > 0) {
countData.add(new FailCountData(lastId, array.toArray()));
array.clear();
}
if (candidate != 1) {
throw new IOException("Candidate must start at 1");
}
lastId = id;
// Ensure continuous
lastCandidate = candidate - 1;
}
// Require continuous sequence
if (candidate - lastCandidate == 1) {
array.add(ok);
lastCandidate = candidate;
} else {
// Make impossible to add any more for this ID
lastCandidate = -1;
}
}
// Final ID
if (array.size() > 0) {
countData.add(new FailCountData(lastId, array.toArray()));
}
IJ.showMessage(TITLE, "Loaded " + TextUtils.pleural(countData.size(), "sequence"));
failCountDataRef.set(countData);
} catch (final NumberFormatException | IOException ex) {
IJ.error(TITLE, "Failed to load data:\n" + ex.getMessage());
}
}
Aggregations