All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.broadinstitute.hellbender.tools.readersplitters.ReadGroupSplitter Maven / Gradle / Ivy

The newest version!
package org.broadinstitute.hellbender.tools.readersplitters;

import htsjdk.samtools.SAMFileHeader;
import htsjdk.samtools.SAMReadGroupRecord;
import org.broadinstitute.hellbender.utils.read.GATKRead;
import org.broadinstitute.hellbender.utils.read.ReadUtils;

import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * Splits a reader based on a value from a read group.
 * @param  The type of the value from the read group.
 */
public abstract class ReadGroupSplitter extends ReaderSplitter {
    @Override
    public T getSplitBy(final GATKRead record, final SAMFileHeader header) {
        return getSplitByFunction().apply(ReadUtils.getSAMReadGroupRecord(record, header));
    }

    @Override
    public List getSplitsBy(final SAMFileHeader header) {
        return header.getReadGroups().stream().map(getSplitByFunction()).collect(Collectors.toList());
    }

    /**
     * @return A function that selects a value from a read group record.
     */
    protected abstract Function getSplitByFunction();
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy