htsjdk.samtools.SAMRecordQueryNameComparator Java Examples

The following examples show how to use htsjdk.samtools.SAMRecordQueryNameComparator. 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: RevertSam.java    From picard with MIT License 6 votes vote down vote up
RevertSamSorter(
        final boolean outputByReadGroup,
        final Map<String, SAMFileHeader> headerMap,
        final SAMFileHeader singleOutHeader,
        final int maxRecordsInRam) {

    this.outputByReadGroup = outputByReadGroup;
    if (outputByReadGroup) {
        for (final Map.Entry<String, SAMFileHeader> entry : headerMap.entrySet()) {
            final String readGroupId = entry.getKey();
            final SAMFileHeader outHeader = entry.getValue();
            final SortingCollection<SAMRecord> sorter = SortingCollection.newInstance(SAMRecord.class, new BAMRecordCodec(outHeader), new SAMRecordQueryNameComparator(), maxRecordsInRam);
            sorterMap.put(readGroupId, sorter);
        }
        singleSorter = null;
    } else {
        singleSorter = SortingCollection.newInstance(SAMRecord.class, new BAMRecordCodec(singleOutHeader), new SAMRecordQueryNameComparator(), maxRecordsInRam);
    }
}
 
Example #2
Source File: ReadQueryNameComparatorUnitTest.java    From gatk with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Tests that the ordering produced by {@link ReadQueryNameComparator} matches queryname ordering
 * as produced by htsjdk's {@link SAMRecordQueryNameComparator} for a representative selection of reads. Ignores
 * differences in tie-breaking done for reads with the same position -- just asserts that the reads are
 * queryname-sorted according to htsjdk, including unmapped reads with and without an assigned position.
 */
@Test
public void testComparatorOrderingMatchesHtsjdkFileOrdering() throws IOException {
    final String inputBam = publicTestDir + "org/broadinstitute/hellbender/utils/read/comparator_test_with_unmapped.bam";
    final List<GATKRead> reads = new ArrayList<>();
    SAMFileHeader header;

    try ( final ReadsDataSource readsSource = new ReadsPathDataSource(IOUtils.getPath(inputBam)) ) {
        header = readsSource.getHeader();

        for ( GATKRead read : readsSource ) {
            reads.add(read);
        }
    }

    // Randomize ordering and then re-sort
    Collections.shuffle(reads);
    reads.sort(new ReadQueryNameComparator());

    final SAMRecordQueryNameComparator samComparator = new SAMRecordQueryNameComparator();
    GATKRead previousRead = null;
    for ( final GATKRead currentRead : reads ) {
        if ( previousRead != null ) {
            Assert.assertTrue(samComparator.compare(previousRead.convertToSAMRecord(header), currentRead.convertToSAMRecord(header)) <= 0,
                              "Reads are out of order: " + previousRead + " and " + currentRead);
        }
        previousRead = currentRead;
    }
}
 
Example #3
Source File: SVUtilsUnitTest.java    From gatk with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@DataProvider
private Object[][] forGetSamRecordComparator() {
    final List<Object[]> data = new ArrayList<>(2);
    data.add(new Object[]{SAMFileHeader.SortOrder.coordinate, SAMRecordCoordinateComparator.class});
    data.add(new Object[]{SAMFileHeader.SortOrder.queryname, SAMRecordQueryNameComparator.class});
    return data.toArray(new Object[data.size()][]);
}
 
Example #4
Source File: QueryNameJointIterator.java    From Drop-seq with MIT License 4 votes vote down vote up
public QueryNameJointIterator(final PeekableIterator<List<SAMRecord>> iterOne, final PeekableIterator<List<SAMRecord>> iterTwo) {
	this.comp = new SAMRecordQueryNameComparator();
	this.iterOne = iterOne;
	this.iterTwo = iterTwo;
	getNextSet();
}
 
Example #5
Source File: SortingSAMRecordCollection.java    From abra2 with MIT License 4 votes vote down vote up
public static SortingSAMRecordCollection newSortByNameInstance(SAMRecord[] recordArray, SAMFileHeader header, int maxRecordsInRAM, String tempDir) {
	return new SortingSAMRecordCollection(recordArray, header, new SAMRecordQueryNameComparator(), maxRecordsInRAM, tempDir);
}
 
Example #6
Source File: ReadQueryNameComparatorUnitTest.java    From gatk with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Test(dataProvider = "getReads")
public void testTieBreakers(GATKRead left, GATKRead right){
    ReadQueryNameComparator readComparator = new ReadQueryNameComparator();
    SAMRecordQueryNameComparator samComparator = new SAMRecordQueryNameComparator();
    Assert.assertEquals(readComparator.compare(left, right), samComparator.compare(left.convertToSAMRecord(HEADER), right.convertToSAMRecord(HEADER)));
}