Search in sources :

Example 1 with MutablePair

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);
}
Also used : DataWriters(info.ata4.io.DataWriters) OutputStream(java.io.OutputStream) LzmaOutputStream(net.contrapunctus.lzma.LzmaOutputStream) Progress(info.ata4.junity.progress.Progress) DataWriter(info.ata4.io.DataWriter) Files(java.nio.file.Files) StandardOpenOption(java.nio.file.StandardOpenOption) IOException(java.io.IOException) BufferedOutputStream(java.io.BufferedOutputStream) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) MutablePair(org.apache.commons.lang3.tuple.MutablePair) Closeable(java.io.Closeable) Map(java.util.Map) Optional(java.util.Optional) LzmaEncoderProps(info.ata4.io.lzma.LzmaEncoderProps) Path(java.nio.file.Path) InputStream(java.io.InputStream) MutablePair(org.apache.commons.lang3.tuple.MutablePair) OutputStream(java.io.OutputStream) LzmaOutputStream(net.contrapunctus.lzma.LzmaOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) LzmaEncoderProps(info.ata4.io.lzma.LzmaEncoderProps) LzmaOutputStream(net.contrapunctus.lzma.LzmaOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) DataWriter(info.ata4.io.DataWriter)

Example 2 with MutablePair

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;
}
Also used : Covariate(org.broadinstitute.hellbender.utils.recalibration.covariates.Covariate) GATKReportTable(org.broadinstitute.hellbender.utils.report.GATKReportTable) MutablePair(org.apache.commons.lang3.tuple.MutablePair) Pair(org.apache.commons.lang3.tuple.Pair) NestedIntegerArray(org.broadinstitute.hellbender.utils.collections.NestedIntegerArray)

Example 3 with MutablePair

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);
    }
}
Also used : HashMap(java.util.HashMap) IOException(java.io.IOException) IOException(java.io.IOException) MutablePair(org.apache.commons.lang3.tuple.MutablePair) Record(com.amazonaws.services.kinesis.model.Record) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with MutablePair

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);
}
Also used : WindowState(org.apache.apex.malhar.lib.window.WindowState) WindowOption(org.apache.apex.malhar.lib.window.WindowOption) WindowedOperatorImpl(org.apache.apex.malhar.lib.window.impl.WindowedOperatorImpl) ConsoleOutputOperator(org.apache.apex.malhar.lib.io.ConsoleOutputOperator) MutablePair(org.apache.commons.lang3.tuple.MutablePair)

Example 5 with MutablePair

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;
}
Also used : MutablePair(org.apache.commons.lang3.tuple.MutablePair) AreaId(bwem.area.typedef.AreaId)

Aggregations

MutablePair (org.apache.commons.lang3.tuple.MutablePair)67 Pair (org.apache.commons.lang3.tuple.Pair)33 Test (org.junit.Test)28 Message (com.microsoft.azure.sdk.iot.device.Message)27 IotHubTransportMessage (com.microsoft.azure.sdk.iot.device.transport.IotHubTransportMessage)27 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)23 HashMap (java.util.HashMap)18 MqttDeviceTwin (com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceTwin)17 ArrayList (java.util.ArrayList)17 IOException (java.io.IOException)9 DeviceOperations (com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceOperations)8 AreaId (bwem.area.typedef.AreaId)7 List (java.util.List)7 Map (java.util.Map)6 MqttDeviceMethod (com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceMethod)5 MiniTile (bwem.tile.MiniTile)4 Altitude (bwem.typedef.Altitude)4 ContainerStartRequest (com.datatorrent.stram.StreamingContainerAgent.ContainerStartRequest)4 ContainerRequest (org.apache.hadoop.yarn.client.api.AMRMClient.ContainerRequest)4 WalkPosition (org.openbw.bwapi4j.WalkPosition)4