public double getCounterSize() { return this.counter.getCount(); }
public double getCounterSize() { return this.counter.getCount(); }
public double getMean() { if (mean == null) { mean = getSum() / getCount(); } return mean; }
/** * Gets the bin in which the given percentile falls. * * @param percentile a value between 0 and 1 * @return the bin value in which the percentile falls */ public double getPercentile(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"); double total = getCount(); double sofar = 0; for (Bin bin : values()) { sofar += bin.getValue(); if (sofar / total >= percentile) return bin.getIdValue(); } throw new IllegalStateException("Could not find percentile: " + percentile); }
private void addError(final SAMValidationError error) { // Just ignore an error if it's of a type we're not interested in if (this.errorsToIgnore.contains(error.getType())) return; if (this.ignoreWarnings && error.getType().severity == SAMValidationError.Severity.WARNING) return; this.errorsByType.increment(error.getType()); if (verbose) { out.println(error); out.flush(); if (this.errorsByType.getCount() >= maxVerboseOutput) { throw new MaxOutputExceededException(); } } }
/** * 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); }
/** * 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); }
public double getMedian() { double total = 0; double count = getCount(); // Base cases if (count == 0) return 0; if (count == 1) return values().iterator().next().getIdValue(); final double midLow, midHigh; if (count % 2 == 0) { midLow = count / 2; midHigh = midLow + 1; } else { midLow = Math.ceil(count / 2); midHigh = midLow; } Double midLowValue = null; Double midHighValue = null; for (final Bin<K> bin : values()) { total += bin.getValue(); if (midLowValue == null && total >= midLow) midLowValue = bin.getIdValue(); if (midHighValue == null && total >= midHigh) midHighValue = bin.getIdValue(); if (midLowValue != null && midHighValue != null) break; } return (midLowValue + midHighValue) / 2; }
public double getMedian() { double total = 0; double count = getCount(); // Base cases if (count == 0) return 0; if (count == 1) return values().iterator().next().getIdValue(); final double midLow, midHigh; if (count % 2 == 0) { midLow = count / 2; midHigh = midLow + 1; } else { midLow = Math.ceil(count / 2); midHigh = midLow; } Double midLowValue = null; Double midHighValue = null; for (final Bin<K> bin : values()) { total += bin.getValue(); if (midLowValue == null && total >= midLow) midLowValue = bin.getIdValue(); if (midHighValue == null && total >= midHigh) midHighValue = bin.getIdValue(); if (midLowValue != null && midHighValue != null) break; } return (midLowValue + midHighValue) / 2; }
public double getMedian() { double total = 0; double count = getCount(); // Base cases if (count == 0) return 0; if (count == 1) return values().iterator().next().getIdValue(); final double midLow, midHigh; if (count % 2 == 0) { midLow = count / 2; midHigh = midLow + 1; } else { midLow = Math.ceil(count / 2); midHigh = midLow; } Double midLowValue = null; Double midHighValue = null; for (final Bin bin : values()) { total += bin.getValue(); if (midLowValue == null && total >= midLow) midLowValue = bin.getIdValue(); if (midHighValue == null && total >= midHigh) midHighValue = bin.getIdValue(); if (midLowValue != null && midHighValue != null) break; } return (midLowValue + midHighValue) / 2; }
private void addError(final SAMValidationError error) { // Just ignore an error if it's of a type we're not interested in if (this.errorsToIgnore.contains(error.getType())) return; switch (error.getType().severity) { case WARNING: if (this.ignoreWarnings) { return; } this.numWarnings++; break; case ERROR: this.numErrors++; break; default: throw new SAMException("Unknown SAM validation error severity: " + error.getType().severity); } this.errorsByType.increment(error.getType()); if (verbose) { out.println(error); out.flush(); if (this.errorsByType.getCount() >= maxVerboseOutput) { throw new MaxOutputExceededException(); } } }
private void addError(final SAMValidationError error) { // Just ignore an error if it's of a type we're not interested in if (this.errorsToIgnore.contains(error.getType())) return; switch (error.getType().severity) { case WARNING: if (this.ignoreWarnings) { return; } this.numWarnings++; break; case ERROR: this.numErrors++; break; default: throw new SAMException("Unknown SAM validation error severity: " + error.getType().severity); } this.errorsByType.increment(error.getType()); if (verbose) { out.println(error); out.flush(); if (this.errorsByType.getCount() >= maxVerboseOutput) { throw new MaxOutputExceededException(); } } }
@Test public void testSamFileVersion1pt5() throws Exception { final SamReader samReader = SamReaderFactory.makeDefault().validationStringency(ValidationStringency.SILENT).open(new File(TEST_DATA_DIR, "test_samfile_version_1pt5.bam")); final Histogram<String> results = executeValidation(samReader, null, IndexValidationStringency.EXHAUSTIVE); Assert.assertEquals(results.getCount(),2.0); }
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); } }
return sumOfAllSmallerBins / histo.getCount();
/** * 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; }