htsjdk.samtools.util.Histogram.getCount()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(12.3k)|赞(0)|评价(0)|浏览(138)

本文整理了Java中htsjdk.samtools.util.Histogram.getCount()方法的一些代码示例,展示了Histogram.getCount()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Histogram.getCount()方法的具体详情如下:
包路径:htsjdk.samtools.util.Histogram
类名称:Histogram
方法名:getCount

Histogram.getCount介绍

暂无

代码示例

代码示例来源:origin: broadinstitute/picard

public double getCounterSize() {
  return this.counter.getCount();
}

代码示例来源:origin: com.github.broadinstitute/picard

public double getCounterSize() {
  return this.counter.getCount();
}

代码示例来源:origin: org.seqdoop/htsjdk

public double getMean() {
  if (mean == null) {
    mean = getSum() / getCount();
  }
  return mean;
}

代码示例来源:origin: org.seqdoop/htsjdk

/**
 * 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);
}

代码示例来源:origin: org.seqdoop/htsjdk

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();
    }
  }
}

代码示例来源:origin: com.github.samtools/htsjdk

/**
 * 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);
}

代码示例来源:origin: samtools/htsjdk

/**
 * 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);
}

代码示例来源:origin: com.github.samtools/htsjdk

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;
}

代码示例来源:origin: samtools/htsjdk

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;
}

代码示例来源:origin: org.seqdoop/htsjdk

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;
}

代码示例来源:origin: com.github.samtools/htsjdk

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();
    }
  }
}

代码示例来源:origin: samtools/htsjdk

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();
    }
  }
}

代码示例来源:origin: samtools/htsjdk

@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);
}

代码示例来源:origin: PapenfussLab/gridss

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);       
  }
}

代码示例来源:origin: broadgsa/gatk

return sumOfAllSmallerBins / histo.getCount();

代码示例来源:origin: broadinstitute/picard

public void addMetricsToFile(final MetricsFile<InsertSizeMetrics,Integer> file) {
    totalInserts += h.getCount();
    final SamPairUtil.PairOrientation pairOrientation = entry.getKey();
    final Histogram<Integer> histogram = entry.getValue();
    final double total = histogram.getCount();

代码示例来源:origin: com.github.broadinstitute/picard

public void addMetricsToFile(final MetricsFile<InsertSizeMetrics,Integer> file) {
    totalInserts += h.getCount();
    final SamPairUtil.PairOrientation pairOrientation = entry.getKey();
    final Histogram<Integer> histogram = entry.getValue();
    final double total = histogram.getCount();

代码示例来源:origin: org.seqdoop/htsjdk

/**
 * 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;
}

代码示例来源:origin: com.github.samtools/htsjdk

/**
 * 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;
}

代码示例来源:origin: samtools/htsjdk

/**
 * 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;
}

相关文章