Java Code Examples for htsjdk.samtools.util.CollectionUtil#getSoleElement()

The following examples show how to use htsjdk.samtools.util.CollectionUtil#getSoleElement() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TileMetricsUtil.java    From picard with MIT License 6 votes vote down vote up
private static Collection<Tile> getTileClusterRecordsV3(
        final Map<String, ? extends Collection<IlluminaTileMetrics>> locationToMetricsMap,
        final Map<Integer, Map<Integer, Collection<TilePhasingValue>>> phasingValues,
        final float density) {

    final Collection<Tile> tiles = new LinkedList<>();
    for (final Map.Entry<String, ? extends Collection<IlluminaTileMetrics>> entry : locationToMetricsMap.entrySet()) {
        final Collection<IlluminaTileMetrics> tileRecords = entry.getValue();

        final IlluminaTileMetrics record = CollectionUtil.getSoleElement(tileRecords);

        //only create for cluster records
        if (record.isClusterRecord()) {
            final Collection<TilePhasingValue> tilePhasingValues = phasingValues.get(record.getLaneNumber()).get(record.getTileNumber());
            tiles.add(new Tile(record.getLaneNumber(), record.getTileNumber(), density, record.getMetricValue(),
                    tilePhasingValues.toArray(new TilePhasingValue[tilePhasingValues.size()])));
        }
    }
    return Collections.unmodifiableCollection(tiles);
}
 
Example 2
Source File: TileMetricsUtil.java    From picard with MIT License 5 votes vote down vote up
/**
 * Returns an unmodifiable collection of tile data read from the provided file. For each tile we will extract:
 * - lane number
 * - tile number
 * - density
 * - cluster ID
 * - Phasing & Prephasing for first template read (if available)
 * - Phasing & Prephasing for second template read (if available)
 */
public static Collection<Tile> parseTileMetrics(final File tileMetricsOutFile, final ReadStructure readStructure,
                                                final ValidationStringency validationStringency) throws FileNotFoundException {
    // Get the tile metrics lines from TileMetricsOut, keeping only the last value for any Lane/Tile/Code combination
    final Collection<IlluminaTileMetrics> tileMetrics = determineLastValueForLaneTileMetricsCode(new TileMetricsOutReader
            (tileMetricsOutFile, TileMetricsOutReader.TileMetricsVersion.TWO));

    // Collect the tiles by lane & tile, and then collect the metrics by lane
    final Map<String, ? extends Collection<IlluminaTileMetrics>> locationToMetricsMap = partitionTileMetricsByLocation(tileMetrics);
    final Collection<Tile> tiles = new LinkedList<>();
    for (final Map.Entry<String, ? extends Collection<IlluminaTileMetrics>> entry : locationToMetricsMap.entrySet()) {
        final Collection<IlluminaTileMetrics> tileRecords = entry.getValue();

        // Get a mapping from metric code number to the corresponding IlluminaTileMetrics
        final Map<Integer, ? extends Collection<IlluminaTileMetrics>> codeMetricsMap = partitionTileMetricsByCode(tileRecords);

        final Set<Integer> observedCodes = codeMetricsMap.keySet();
        if (!(observedCodes.contains(IlluminaMetricsCode.DENSITY_ID.getMetricsCode()) && observedCodes.contains(IlluminaMetricsCode.CLUSTER_ID.getMetricsCode())))
            throw new PicardException(String.format("Expected to find cluster and density record codes (%s and %s) in records read for tile location %s (lane:tile), but found only %s.",
                    IlluminaMetricsCode.CLUSTER_ID.getMetricsCode(), IlluminaMetricsCode.DENSITY_ID.getMetricsCode(), entry.getKey(), observedCodes));

        final IlluminaTileMetrics densityRecord = CollectionUtil.getSoleElement(codeMetricsMap.get(IlluminaMetricsCode.DENSITY_ID.getMetricsCode()));
        final IlluminaTileMetrics clusterRecord = CollectionUtil.getSoleElement(codeMetricsMap.get(IlluminaMetricsCode.CLUSTER_ID.getMetricsCode()));

        // Snag the phasing data for each read in the read structure. For both types of phasing values, this is the median of all of the individual values seen
        final Collection<TilePhasingValue> tilePhasingValues = getTilePhasingValues(codeMetricsMap, readStructure, validationStringency);

        tiles.add(new Tile(densityRecord.getLaneNumber(), densityRecord.getTileNumber(), densityRecord.getMetricValue(), clusterRecord.getMetricValue(),
                tilePhasingValues.toArray(new TilePhasingValue[tilePhasingValues.size()])));
    }

    return Collections.unmodifiableCollection(tiles);
}