public static void main(String[] args) { DuplicationMetrics m = new DuplicationMetrics(); m.READ_PAIRS_EXAMINED = Integer.parseInt(args[0]); m.READ_PAIR_DUPLICATES = Integer.parseInt(args[1]); m.calculateDerivedFields(); System.out.println("Percent Duplication: " + m.PERCENT_DUPLICATION); System.out.println("Est. Library Size : " + m.ESTIMATED_LIBRARY_SIZE); System.out.println(); System.out.println("X Seq\tX Unique"); for (Histogram.Bin<Double> bin : m.calculateRoiHistogram().values()) { System.out.println(bin.getId() + "\t" + bin.getValue()); } } }
public static void main(String[] args) { DuplicationMetrics m = new DuplicationMetrics(); m.READ_PAIRS_EXAMINED = Integer.parseInt(args[0]); m.READ_PAIR_DUPLICATES = Integer.parseInt(args[1]); m.calculateDerivedFields(); System.out.println("Percent Duplication: " + m.PERCENT_DUPLICATION); System.out.println("Est. Library Size : " + m.ESTIMATED_LIBRARY_SIZE); System.out.println(); System.out.println("X Seq\tX Unique"); for (Histogram.Bin<Double> bin : m.calculateRoiHistogram().values()) { System.out.println(bin.getId() + "\t" + bin.getValue()); } } }
/** * Gets the bin in which the given percentile falls. * Should only be called on histograms with non-negative values and a positive sum of values. * * @param percentile a value between 0 and 1 * @return the bin value in which the percentile falls */ public double getPercentile(final double percentile) { if (percentile <= 0) throw new IllegalArgumentException("Cannot query percentiles of 0 or below"); if (percentile >= 1) throw new IllegalArgumentException("Cannot query percentiles of 1 or above"); values().stream() .filter(b -> b.getValue() < 0) .findFirst() .ifPresent(b -> { throw new IllegalStateException("Cannot calculate Percentile when negative counts are present " + "in histogram. Bin " + b.getId() + "=" + b.getValue()); }); final double total = getCount(); if (total == 0) throw new IllegalStateException("Cannot calculate percentiles when total is zero."); double soFar = 0; for (Bin<K> bin : values()) { soFar += bin.getValue(); if (soFar / total >= percentile) return bin.getIdValue(); } throw new IllegalStateException("UNPOSSIBLE! Could not find percentile: " + percentile); }
if (bin.getId() < testStatU) sumOfAllSmallerBins += bin.getValue();
/** * Gets the bin in which the given percentile falls. * Should only be called on histograms with non-negative values and a positive sum of values. * * @param percentile a value between 0 and 1 * @return the bin value in which the percentile falls */ public double getPercentile(final double percentile) { if (percentile <= 0) throw new IllegalArgumentException("Cannot query percentiles of 0 or below"); if (percentile >= 1) throw new IllegalArgumentException("Cannot query percentiles of 1 or above"); values().stream() .filter(b -> b.getValue() < 0) .findFirst() .ifPresent(b -> { throw new IllegalStateException("Cannot calculate Percentile when negative counts are present " + "in histogram. Bin " + b.getId() + "=" + b.getValue()); }); final double total = getCount(); if (total == 0) throw new IllegalStateException("Cannot calculate percentiles when total is zero."); double soFar = 0; for (Bin<K> bin : values()) { soFar += bin.getValue(); if (soFar / total >= percentile) return bin.getIdValue(); } throw new IllegalStateException("UNPOSSIBLE! Could not find percentile: " + percentile); }
/** * Outputs validation summary report to out. * * @param samReader records to validate * @param reference if null, NM tag validation is skipped * @return boolean true if there are no validation errors, otherwise false */ public boolean validateSamFileSummary(final SAMFileReader samReader, final ReferenceSequenceFile reference) { init(reference, samReader.getFileHeader()); validateSamFile(samReader, out); boolean result = errorsByType.isEmpty(); if (errorsByType.getCount() > 0) { // Convert to a histogram with String IDs so that WARNING: or ERROR: can be prepended to the error type. final Histogram<String> errorsAndWarningsByType = new Histogram<String>("Error Type", "Count"); for (final Histogram<SAMValidationError.Type>.Bin bin : errorsByType.values()) { errorsAndWarningsByType.increment(bin.getId().getHistogramString(), bin.getValue()); } final MetricsFile<ValidationMetrics, String> metricsFile = new MetricsFile<ValidationMetrics, String>(); errorsByType.setBinLabel("Error Type"); errorsByType.setValueLabel("Count"); metricsFile.setHistogram(errorsAndWarningsByType); metricsFile.write(out); } cleanup(); return result; }
/** * Outputs validation summary report to out. * * @param samReader records to validate * @param reference if null, NM tag validation is skipped * @return boolean true if there are no validation errors, otherwise false */ public boolean validateSamFileSummary(final SamReader samReader, final ReferenceSequenceFile reference) { init(reference, samReader.getFileHeader()); validateSamFile(samReader, out); boolean result = errorsByType.isEmpty(); if (errorsByType.getCount() > 0) { // Convert to a histogram with String IDs so that WARNING: or ERROR: can be prepended to the error type. final Histogram<String> errorsAndWarningsByType = new Histogram<>("Error Type", "Count"); for (final Histogram.Bin<Type> bin : errorsByType.values()) { errorsAndWarningsByType.increment(bin.getId().getHistogramString(), bin.getValue()); } final MetricsFile<ValidationMetrics, String> metricsFile = new MetricsFile<>(); errorsByType.setBinLabel("Error Type"); errorsByType.setValueLabel("Count"); metricsFile.setHistogram(errorsAndWarningsByType); metricsFile.write(out); } cleanup(); return result; }
/** * Outputs validation summary report to out. * * @param samReader records to validate * @param reference if null, NM tag validation is skipped * @return boolean true if there are no validation errors, otherwise false */ public boolean validateSamFileSummary(final SamReader samReader, final ReferenceSequenceFile reference) { init(reference, samReader.getFileHeader()); validateSamFile(samReader, out); boolean result = errorsByType.isEmpty(); if (errorsByType.getCount() > 0) { // Convert to a histogram with String IDs so that WARNING: or ERROR: can be prepended to the error type. final Histogram<String> errorsAndWarningsByType = new Histogram<>("Error Type", "Count"); for (final Histogram.Bin<Type> bin : errorsByType.values()) { errorsAndWarningsByType.increment(bin.getId().getHistogramString(), bin.getValue()); } final MetricsFile<ValidationMetrics, String> metricsFile = new MetricsFile<>(); errorsByType.setBinLabel("Error Type"); errorsByType.setValueLabel("Count"); metricsFile.setHistogram(errorsAndWarningsByType); metricsFile.write(out); } cleanup(); return result; }
@Test public void testLabelsAndComparator() { final String[] is = {"a", "B", "a"}; final Histogram<String> histo = new Histogram<>("FOO", "BAR", String.CASE_INSENSITIVE_ORDER); for (final String i : is) histo.increment(i); Assert.assertEquals(histo.get("a").getValue(), 2.0); Assert.assertEquals(histo.get("B").getValue(), 1.0); Assert.assertEquals(histo.get("a").getId(), "a"); Assert.assertEquals(histo.get("B").getId(), "B"); }