/*** * Immutable method that divides the current Histogram by an input Histogram and generates a new one * Throws an exception if the bins don't match up exactly * @param divisorHistogram * @return * @throws IllegalArgumentException if the keySet of this histogram is not equal to the keySet of the given divisorHistogram */ public Histogram<K> divideByHistogram(final Histogram<K> divisorHistogram) { final Histogram<K> output = new Histogram<K>(); if (!this.keySet().equals(divisorHistogram.keySet())) throw new IllegalArgumentException("Attempting to divide Histograms with non-identical bins"); for (final K key : this.keySet()){ final Bin<K> dividend = this.get(key); final Bin<K> divisor = divisorHistogram.get(key); output.increment(key, dividend.getValue()/divisor.getValue()); } return output; }
/*** * Immutable method that divides the current Histogram by an input Histogram and generates a new one * Throws an exception if the bins don't match up exactly * @param divisorHistogram * @return * @throws IllegalArgumentException if the keySet of this histogram is not equal to the keySet of the given divisorHistogram */ public Histogram<K> divideByHistogram(final Histogram<K> divisorHistogram) { final Histogram<K> output = new Histogram<K>(); if (!this.keySet().equals(divisorHistogram.keySet())) throw new IllegalArgumentException("Attempting to divide Histograms with non-identical bins"); for (final K key : this.keySet()){ final Bin<K> dividend = this.get(key); final Bin<K> divisor = divisorHistogram.get(key); output.increment(key, dividend.getValue()/divisor.getValue()); } return output; }
/*** * Immutable method that divides the current Histogram by an input Histogram and generates a new one * Throws an exception if the bins don't match up exactly * @param divisorHistogram * @return * @throws IllegalArgumentException */ public Histogram<K> divideByHistogram(final Histogram<K> divisorHistogram) throws IllegalArgumentException{ Histogram<K> output = new Histogram<K>(); if (!this.keySet().equals(divisorHistogram.keySet())) throw new IllegalArgumentException("Attempting to divide Histograms with non-identical bins"); for (final K key : this.keySet()){ Bin dividend = this.get(key); Bin divisor = divisorHistogram.get(key); output.increment(key, dividend.getValue()/divisor.getValue()); } return output; }
/*** * Mutable method that allows the addition of a Histogram into the current one. * @param addHistogram */ public void addHistogram(final Histogram<K> addHistogram) { for (final K key : addHistogram.keySet()){ this.increment(key, addHistogram.get(key).getValue()); } }
/*** * Mutable method that allows the addition of a Histogram into the current one. * @param addHistogram */ public void addHistogram(final Histogram<K> addHistogram) { for (final K key : addHistogram.keySet()){ this.increment(key, addHistogram.get(key).getValue()); } } }
/*** * Mutable method that allows the addition of a Histogram into the current one. * @param addHistogram */ public void addHistogram(final Histogram<K> addHistogram) { for (final K key : addHistogram.keySet()){ this.increment(key, addHistogram.get(key).getValue()); } }
@Test public void testGetKeySet() { final int[] is = {4,4,5,5,5}; final Histogram<Integer> histo = new Histogram<>(); for (final int i : is) histo.increment(i); Assert.assertEquals(histo.keySet(), new HashSet<>(Arrays.asList(4,5))); }
private List<RrbsCpgDetailMetrics> buildDetailMetrics() { final List<RrbsCpgDetailMetrics> detailMetrics = new ArrayList<RrbsCpgDetailMetrics>(); for (final CpgLocation key : cpgTotal.keySet()) { final RrbsCpgDetailMetrics cpgMetric = new RrbsCpgDetailMetrics(); cpgMetric.SAMPLE = sample; cpgMetric.READ_GROUP = readGroup; cpgMetric.LIBRARY = library; cpgMetric.SEQUENCE_NAME = key.getSequence(); cpgMetric.POSITION = key.getPosition(); cpgMetric.TOTAL_SITES = (int)cpgTotal.get(key).getValue(); cpgMetric.CONVERTED_SITES = cpgConverted.containsKey(key) ? (int)cpgConverted.get(key).getValue() : 0; cpgMetric.PCT_CONVERTED = cpgMetric.CONVERTED_SITES == 0 ? 0 : cpgMetric.CONVERTED_SITES / (double)cpgMetric.TOTAL_SITES; detailMetrics.add(cpgMetric); } return detailMetrics; } }
final Object keys[] = keySet().toArray(); for (Object binId : keys) { if (!binsToKeep.contains(binId)) {
final Object keys[] = keySet().toArray(); for (Object binId : keys) { if (!binsToKeep.contains(binId)) {
private List<RrbsCpgDetailMetrics> buildDetailMetrics() { final List<RrbsCpgDetailMetrics> detailMetrics = new ArrayList<RrbsCpgDetailMetrics>(); for (final CpgLocation key : cpgTotal.keySet()) { final RrbsCpgDetailMetrics cpgMetric = new RrbsCpgDetailMetrics(); cpgMetric.SAMPLE = sample; cpgMetric.READ_GROUP = readGroup; cpgMetric.LIBRARY = library; cpgMetric.SEQUENCE_NAME = key.getSequence(); cpgMetric.POSITION = key.getPosition(); cpgMetric.TOTAL_SITES = (int)cpgTotal.get(key).getValue(); cpgMetric.CONVERTED_SITES = cpgConverted.containsKey(key) ? (int)cpgConverted.get(key).getValue() : 0; cpgMetric.PCT_CONVERTED = cpgMetric.CONVERTED_SITES == 0 ? 0 : cpgMetric.CONVERTED_SITES / (double)cpgMetric.TOTAL_SITES; detailMetrics.add(cpgMetric); } return detailMetrics; } }
final Object keys[] = keySet().toArray(); for (Object binId : keys) { if (!binsToKeep.contains((K)binId)) {
public void addMetricsToFile(final MetricsFile<GcMetrics,Integer> file) { final GcMetrics metrics = new GcMetrics(); metrics.SAMPLE = this.sample; metrics.LIBRARY = this.library; metrics.READ_GROUP = this.readGroup; double totalGc = 0; int totalReads = 0; for (Integer gcBin : histogram.keySet()) { int count = (int)histogram.get(gcBin).getValue(); totalReads += count; totalGc += gcBin * count; } metrics.MEAN_GC_CONTENT = totalGc; metrics.READ_COUNT = totalReads; file.addHistogram(histogram); file.addMetric(metrics); } }
@Override public void test() throws IOException { final MetricsFile<DuplicationMetrics, Double> metricsOutput = testMetrics(); // Check contents of set size bin against expected values if (!expectedSetSizeMap.isEmpty()) { boolean checked = false; for (final Histogram<Double> histo : metricsOutput.getAllHistograms()) { final String label = histo.getValueLabel(); for (final Double bin : histo.keySet()) { final String binStr = String.valueOf(bin); final List<String> labelBinStr = Arrays.asList(label, binStr); if (expectedSetSizeMap.containsKey(labelBinStr)) { checked = true; Histogram.Bin<Double> binValue = histo.get(bin); final double actual = binValue.getValue(); final double expected = expectedSetSizeMap.get(labelBinStr); Assert.assertEquals(actual, expected); } } } if (!checked) { Assert.fail("Could not not find matching entry for expectedSetSizeMap in metrics."); } } }
public static InsertSizeDistribution create(Histogram<Integer> insertSizeHistogram) { if (insertSizeHistogram == null) return null; int[] insertSize = new int[insertSizeHistogram.size()]; double[] count = new double[insertSizeHistogram.size()]; double total = insertSizeHistogram.getSumOfValues(); int i = 0; Set<Integer> keys = insertSizeHistogram.keySet(); for (Integer key : keys) { insertSize[i] = key; count[i] = insertSizeHistogram.get(key).getValue(); i++; } return new InsertSizeDistribution(insertSize, count, (long)total); } public InsertSizeDistribution(int[] singletons, double[] readCounts) {
public void addMetricsToFile(final MetricsFile<MapqMetrics,Integer> file) { final MapqMetrics metrics = new MapqMetrics(); metrics.SAMPLE = this.sample; metrics.LIBRARY = this.library; metrics.READ_GROUP = this.readGroup; metrics.MAPPED_READS = (long) histogram.getCount(); metrics.MIN_MAPQ = SAMRecord.UNKNOWN_MAPPING_QUALITY; metrics.MAX_MAPQ = 0; for (int key : histogram.keySet()) { if (key != SAMRecord.UNKNOWN_MAPPING_QUALITY) { if (histogram.get(key).getValue() > 0) { metrics.MIN_MAPQ = Math.min(metrics.MIN_MAPQ, key); metrics.MAX_MAPQ = Math.max(metrics.MAX_MAPQ, key); } } } if (histogram.get(SAMRecord.NO_MAPPING_QUALITY) != null) { metrics.ZERO_MAPQ = (long) histogram.get(SAMRecord.NO_MAPPING_QUALITY).getValue(); } if (histogram.get(SAMRecord.UNKNOWN_MAPPING_QUALITY) != null) { metrics.UNKNOWN_MAPQ = (long) histogram.get(SAMRecord.UNKNOWN_MAPPING_QUALITY).getValue(); } file.addHistogram(histogram); file.addMetric(metrics); } }
for (final Integer bin : duplicationHisto.keySet()) { final double duplicateGroups = duplicationHisto.get(bin).getValue(); final double opticalDuplicates = opticalHisto.get(bin) == null ? 0 : opticalHisto.get(bin).getValue();