use of org.apache.commons.lang3.tuple.MutablePair in project disunity by ata4.
the class BundleWriter method write.
public void write(Bundle bundle, Progress progress) throws IOException {
this.bundle = bundle;
// add offset placeholders
levelOffsetMap.clear();
bundle.entries().stream().filter(entry -> {
if (bundle.entries().size() == 1) {
return true;
}
String name = entry.name();
return name.equals("mainData") || name.startsWith("level");
}).forEach(entry -> levelOffsetMap.put(entry, new MutablePair<>(0L, 0L)));
BundleHeader header = bundle.header();
header.levelByteEnd().clear();
header.levelByteEnd().addAll(levelOffsetMap.values());
header.numberOfLevelsToDownload(levelOffsetMap.size());
// write header
out.writeStruct(header);
header.headerSize((int) out.position());
// write bundle data
if (header.compressed()) {
// write data to temporary file
try (DataWriter outData = DataWriters.forFile(dataFile, CREATE, WRITE, TRUNCATE_EXISTING)) {
writeData(outData, progress);
}
// configure LZMA encoder
LzmaEncoderProps props = new LzmaEncoderProps();
// 8 MiB
props.setDictionarySize(1 << 23);
// maximum
props.setNumFastBytes(273);
props.setUncompressedSize(Files.size(dataFile));
props.setEndMarkerMode(true);
// stream the temporary bundle data compressed into the bundle file
try (OutputStream os = new LzmaOutputStream(new BufferedOutputStream(out.stream()), props)) {
Files.copy(dataFile, os);
}
for (MutablePair<Long, Long> levelOffset : levelOffsetMap.values()) {
levelOffset.setLeft(out.size());
}
} else {
// write data directly to file
writeData(out, progress);
}
// update header
int fileSize = (int) out.size();
header.completeFileSize(fileSize);
header.minimumStreamedBytes(fileSize);
out.position(0);
out.writeStruct(header);
}
use of org.apache.commons.lang3.tuple.MutablePair in project gatk by broadinstitute.
the class RecalUtils method generateReportTables.
public static List<GATKReportTable> generateReportTables(final RecalibrationTables recalibrationTables, final StandardCovariateList covariates) {
final List<GATKReportTable> result = new LinkedList<>();
int rowIndex = 0;
GATKReportTable allCovsReportTable = null;
for (NestedIntegerArray<RecalDatum> table : recalibrationTables) {
// initialize the array to hold the column names
final ArrayList<Pair<String, String>> columnNames = new ArrayList<>();
// save the required covariate name so we can reference it in the future
columnNames.add(new MutablePair<>(covariates.getReadGroupCovariate().parseNameForReport(), "%s"));
if (!recalibrationTables.isReadGroupTable(table)) {
// save the required covariate name so we can reference it in the future
columnNames.add(new MutablePair<>(covariates.getQualityScoreCovariate().parseNameForReport(), "%d"));
if (recalibrationTables.isAdditionalCovariateTable(table)) {
columnNames.add(covariateValue);
columnNames.add(covariateName);
}
}
// the order of these column names is important here
columnNames.add(eventType);
columnNames.add(empiricalQuality);
if (recalibrationTables.isReadGroupTable(table)) {
// only the read group table needs the estimated Q reported
columnNames.add(estimatedQReported);
}
columnNames.add(nObservations);
columnNames.add(nErrors);
final String reportTableName = getReportTableName(recalibrationTables, table);
final GATKReportTable.Sorting sort = GATKReportTable.Sorting.SORT_BY_COLUMN;
final GATKReportTable reportTable;
final boolean addToList;
//XXX this "if" implicitly uses the knowledge about the ordering of tables.
if (!recalibrationTables.isAdditionalCovariateTable(table)) {
reportTable = makeNewTableWithColumns(columnNames, reportTableName, sort);
// reset the row index since we're starting with a new table
rowIndex = 0;
addToList = true;
} else if (allCovsReportTable == null && recalibrationTables.isAdditionalCovariateTable(table)) {
reportTable = makeNewTableWithColumns(columnNames, reportTableName, sort);
// reset the row index since we're starting with a new table
rowIndex = 0;
allCovsReportTable = reportTable;
addToList = true;
} else {
reportTable = allCovsReportTable;
addToList = false;
}
for (final NestedIntegerArray.Leaf<RecalDatum> row : table.getAllLeaves()) {
final RecalDatum datum = row.value;
final int[] keys = row.keys;
int columnIndex = 0;
int keyIndex = 0;
reportTable.set(rowIndex, columnNames.get(columnIndex++).getLeft(), covariates.getReadGroupCovariate().formatKey(keys[keyIndex++]));
if (!recalibrationTables.isReadGroupTable(table)) {
reportTable.set(rowIndex, columnNames.get(columnIndex++).getLeft(), covariates.getQualityScoreCovariate().formatKey(keys[keyIndex++]));
if (recalibrationTables.isAdditionalCovariateTable(table)) {
final Covariate covariate = recalibrationTables.getCovariateForTable(table);
reportTable.set(rowIndex, columnNames.get(columnIndex++).getLeft(), covariate.formatKey(keys[keyIndex++]));
reportTable.set(rowIndex, columnNames.get(columnIndex++).getLeft(), covariate.parseNameForReport());
}
}
final EventType event = EventType.eventFrom(keys[keyIndex]);
reportTable.set(rowIndex, columnNames.get(columnIndex++).getLeft(), event.toString());
reportTable.set(rowIndex, columnNames.get(columnIndex++).getLeft(), datum.getEmpiricalQuality());
if (recalibrationTables.isReadGroupTable(table)) {
// we only add the estimated Q reported in the RG table
reportTable.set(rowIndex, columnNames.get(columnIndex++).getLeft(), datum.getEstimatedQReported());
}
reportTable.set(rowIndex, columnNames.get(columnIndex++).getLeft(), datum.getNumObservations());
reportTable.set(rowIndex, columnNames.get(columnIndex).getLeft(), datum.getNumMismatches());
rowIndex++;
}
if (addToList) {
//XXX using a set would be slow because the equals method on GATKReportTable is expensive.
result.add(reportTable);
}
}
return result;
}
use of org.apache.commons.lang3.tuple.MutablePair in project apex-malhar by apache.
the class AbstractKinesisInputOperator method replay.
protected void replay(long windowId) {
try {
@SuppressWarnings("unchecked") Map<String, MutablePair<String, Integer>> recoveredData = (Map<String, MutablePair<String, Integer>>) windowDataManager.retrieve(windowId);
if (recoveredData == null) {
return;
}
for (Map.Entry<String, MutablePair<String, Integer>> rc : recoveredData.entrySet()) {
logger.debug("Replaying the windowId: {}", windowId);
logger.debug("ShardId: " + rc.getKey() + " , Start Sequence Id: " + rc.getValue().getLeft() + " , No Of Records: " + rc.getValue().getRight());
try {
List<Record> records = KinesisUtil.getInstance().getRecords(consumer.streamName, rc.getValue().getRight(), rc.getKey(), ShardIteratorType.AT_SEQUENCE_NUMBER, rc.getValue().getLeft());
for (Record record : records) {
emitTuple(new Pair<String, Record>(rc.getKey(), record));
shardPosition.put(rc.getKey(), record.getSequenceNumber());
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
/*
* Set the shard positions and start the consumer if last recovery windowid
* match with current completed windowid.
*/
if (windowId == windowDataManager.getLargestCompletedWindow()) {
// Set the shard positions to the consumer
Map<String, String> statsData = new HashMap<String, String>(getConsumer().getShardPosition());
statsData.putAll(shardPosition);
getConsumer().resetShardPositions(statsData);
consumer.start();
}
} catch (IOException e) {
throw new RuntimeException("replay", e);
}
}
use of org.apache.commons.lang3.tuple.MutablePair in project apex-malhar by apache.
the class Application method populateDAG.
@Override
public void populateDAG(DAG dag, Configuration configuration) {
RandomNumberPairGenerator inputOperator = new RandomNumberPairGenerator();
WindowedOperatorImpl<MutablePair<Double, Double>, MutablePair<MutableLong, MutableLong>, Double> windowedOperator = new WindowedOperatorImpl<>();
Accumulation<MutablePair<Double, Double>, MutablePair<MutableLong, MutableLong>, Double> piAccumulation = new PiAccumulation();
windowedOperator.setAccumulation(piAccumulation);
windowedOperator.setDataStorage(new InMemoryWindowedStorage<MutablePair<MutableLong, MutableLong>>());
windowedOperator.setWindowStateStorage(new InMemoryWindowedStorage<WindowState>());
windowedOperator.setWindowOption(new WindowOption.GlobalWindow());
windowedOperator.setTriggerOption(TriggerOption.AtWatermark().withEarlyFiringsAtEvery(Duration.millis(1000)).accumulatingFiredPanes());
ConsoleOutputOperator outputOperator = new ConsoleOutputOperator();
dag.addOperator("inputOperator", inputOperator);
dag.addOperator("windowedOperator", windowedOperator);
dag.addOperator("outputOperator", outputOperator);
dag.addStream("input_windowed", inputOperator.output, windowedOperator.input);
dag.addStream("windowed_output", windowedOperator.output, outputOperator.input);
}
use of org.apache.commons.lang3.tuple.MutablePair in project BWAPI4J by OpenBW.
the class MapImpl method findNeighboringAreas.
public MutablePair<AreaId, AreaId> findNeighboringAreas(final WalkPosition p) {
final MutablePair<AreaId, AreaId> result = new MutablePair<>(null, null);
final WalkPosition[] deltas = { new WalkPosition(0, -1), new WalkPosition(-1, 0), new WalkPosition(+1, 0), new WalkPosition(0, +1) };
for (final WalkPosition delta : deltas) {
if (getData().getMapData().isValid(p.add(delta))) {
final AreaId areaId = getData().getMiniTile(p.add(delta), CheckMode.NO_CHECK).getAreaId();
if (areaId.intValue() > 0) {
if (result.getLeft() == null) {
result.setLeft(areaId);
} else if (!result.getLeft().equals(areaId)) {
if (result.getRight() == null || ((areaId.intValue() < result.getRight().intValue()))) {
result.setRight(areaId);
}
}
}
}
}
return result;
}
Aggregations