Java Code Examples for htsjdk.samtools.util.StringUtil#repeatCharNTimes()

The following examples show how to use htsjdk.samtools.util.StringUtil#repeatCharNTimes() . 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: ContextAccumulator.java    From picard with MIT License 6 votes vote down vote up
/**
 * Fills a halfContextAccumulator by summing over the appropriate counts from a fullContextAccumulator.
 */
public void fillHalfRecords(final ContextAccumulator fullContextAccumulator, final int contextSize) {
    final String padding = StringUtil.repeatCharNTimes('N', contextSize);

    for (Map.Entry<String,AlignmentAccumulator[]> fullContext : fullContextAccumulator.artifactMap.entrySet()) {
        final String fullContextKey = fullContext.getKey();
        final char centralBase = fullContextKey.charAt(contextSize);
        final String leadingContextKey = fullContextKey.substring(0, contextSize) + centralBase + padding;
        final String trailingContextKey = padding + centralBase + fullContextKey.substring(contextSize + 1, fullContextKey.length());

        final AlignmentAccumulator[] trailingAlignmentAccumulators = this.artifactMap.get(trailingContextKey);
        final AlignmentAccumulator[] leadingAlignmentAccumulators = this.artifactMap.get(leadingContextKey);
        final AlignmentAccumulator[] fullAlignmentAccumulators = fullContext.getValue();

        for (int i=0; i < fullAlignmentAccumulators.length; i++) {
            trailingAlignmentAccumulators[i].merge(fullAlignmentAccumulators[i]);
            leadingAlignmentAccumulators[i].merge(fullAlignmentAccumulators[i]);
        }
    }
}
 
Example 2
Source File: ContextAccumulator.java    From picard with MIT License 6 votes vote down vote up
/**
 * Fills a zeroContextAccumulator by summing over the appropriate counts from a fullContextAccumulator.
 */
public void fillZeroRecords(final ContextAccumulator fullContextAccumulator, final int contextSize) {
    final String padding = StringUtil.repeatCharNTimes('N', contextSize);

    for (Map.Entry<String,AlignmentAccumulator[]> fullContext : fullContextAccumulator.artifactMap.entrySet()) {
        final String fullContextKey = fullContext.getKey();
        final char centralBase = fullContextKey.charAt(contextSize);
        final String zeroContextKey = padding + centralBase + padding;

        final AlignmentAccumulator[] zeroAlignmentAccumulators = this.artifactMap.get(zeroContextKey);
        final AlignmentAccumulator[] fullAlignmentAccumulators = fullContext.getValue();

        for (int i=0; i < fullAlignmentAccumulators.length; i++) {
            zeroAlignmentAccumulators[i].merge(fullAlignmentAccumulators[i]);
        }
    }
}
 
Example 3
Source File: ArtifactCounter.java    From picard with MIT License 4 votes vote down vote up
public ArtifactCounter(final String sampleAlias, final String library, final int contextSize, final boolean expectedTandemReads) {
    this.sampleAlias = sampleAlias;
    this.library = library;
    this.contextSize = contextSize;

    // define the contexts
    final HashSet<String> fullContexts = new HashSet<>();
    for (final byte[] kmer : SequenceUtil.generateAllKmers(2 * contextSize + 1)) {
        fullContexts.add(StringUtil.bytesToString(kmer));
    }

    final Set<String> zeroContexts = new HashSet<>();

    // the half contexts specify either leading or trailing bases. the zero context is just the center.
    // NB: we use N to represent a wildcard base, rather than an ambiguous base. It's assumed that all of the input
    // contexts are unambiguous, and that any actual N's in the data have been dealt with elsewhere.
    final String padding = StringUtil.repeatCharNTimes('N', contextSize);
    for (final String context : fullContexts) {
        final char centralBase = context.charAt(contextSize);
        final String leading = context.substring(0, contextSize) + centralBase + padding;
        final String trailing = padding + centralBase + context.substring(contextSize + 1, context.length());
        final String zero = padding + centralBase + padding;
        contextMap.put(context, new RefContext(context, leading, trailing, zero));

        leadingContexts.add(leading);
        trailingContexts.add(trailing);
        zeroContexts.add(zero);
    }

    final Set<String> halfContexts = new HashSet<>(leadingContexts);
    halfContexts.addAll(trailingContexts);

    this.fullContextAccumulator = new ContextAccumulator(fullContexts, expectedTandemReads);
    this.halfContextAccumulator = new ContextAccumulator(halfContexts, expectedTandemReads);
    this.zeroContextAccumulator = new ContextAccumulator(zeroContexts, expectedTandemReads);

    // these will get populated in the final step
    preAdapterSummaryMetricsList = new ArrayList<PreAdapterSummaryMetrics>();
    preAdapterDetailMetricsList = new ArrayList<PreAdapterDetailMetrics>();
    baitBiasSummaryMetricsList = new ArrayList<BaitBiasSummaryMetrics>();
    baitBiasDetailMetricsList = new ArrayList<BaitBiasDetailMetrics>();
}