Search in sources :

Example 1 with SAMRecordCoordinateComparator

use of htsjdk.samtools.SAMRecordCoordinateComparator in project gridss by PapenfussLab.

the class TestHelper method sorted.

public static List<SAMRecord> sorted(List<SAMRecord> list) {
    List<SAMRecord> out = Lists.newArrayList(list);
    Collections.sort(out, new SAMRecordCoordinateComparator());
    return out;
}
Also used : SAMRecordCoordinateComparator(htsjdk.samtools.SAMRecordCoordinateComparator) SAMRecord(htsjdk.samtools.SAMRecord)

Example 2 with SAMRecordCoordinateComparator

use of htsjdk.samtools.SAMRecordCoordinateComparator in project gridss by PapenfussLab.

the class VcfBreakendToReadPairTest method should_write_sorted_read_per_breakend.

@Test
public void should_write_sorted_read_per_breakend() throws IOException {
    ProcessingContext pc = getCommandlineContext();
    List<IdsvVariantContext> in = new ArrayList<IdsvVariantContext>();
    in.add(new IdsvVariantContextBuilder(pc, BP("ao", new BreakpointSummary(0, FWD, 1, 1, 2, 3, BWD, 4, 4, 5))).phredScore(6).make());
    in.add(new IdsvVariantContextBuilder(pc, BP("ah", new BreakpointSummary(3, BWD, 4, 4, 5, 0, FWD, 1, 1, 2))).phredScore(6).make());
    in.add(new IdsvVariantContextBuilder(pc, BP("bo", new BreakpointSummary(1, BWD, 10, 10, 20, 2, FWD, 40, 40, 50))).phredScore(100).make());
    in.add(new IdsvVariantContextBuilder(pc, BP("bh", new BreakpointSummary(2, FWD, 40, 40, 50, 1, BWD, 10, 10, 20))).phredScore(100).make());
    List<SAMRecord> list = go(pc, in).get(0);
    assertEquals(4, list.size());
    assertTrue(Ordering.from(new SAMRecordCoordinateComparator()).isOrdered(list));
    assertEquals(0, (int) list.get(0).getReferenceIndex());
    assertEquals(1, list.get(0).getAlignmentStart());
    assertEquals(2, list.get(0).getAlignmentEnd());
    assertFalse(list.get(0).getReadNegativeStrandFlag());
    assertTrue(list.get(0).getReadPairedFlag());
    assertEquals(4, list.get(0).getMateAlignmentStart());
    assertEquals(3, (int) list.get(0).getMateReferenceIndex());
    assertTrue(list.get(0).getMateNegativeStrandFlag());
    assertTrue(list.get(1).getReadNegativeStrandFlag());
}
Also used : SAMRecordCoordinateComparator(htsjdk.samtools.SAMRecordCoordinateComparator) SAMRecord(htsjdk.samtools.SAMRecord) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 3 with SAMRecordCoordinateComparator

use of htsjdk.samtools.SAMRecordCoordinateComparator in project jvarkit by lindenb.

the class MergingIteratorTest method test3.

@Test
public void test3() {
    SAMSequenceDictionary dict = new SAMSequenceDictionary();
    dict.addSequence(new SAMSequenceRecord("1", 10000));
    SAMFileHeader header = new SAMFileHeader();
    header.setSequenceDictionary(dict);
    final List<SAMRecord> L = new ArrayList<>();
    DefaultSAMRecordFactory srf = new DefaultSAMRecordFactory();
    SAMRecord r1 = srf.createSAMRecord(header);
    r1.setReadName("R1");
    r1.setReferenceName("1");
    r1.setAlignmentStart(1);
    r1.setFlags(99);
    r1.setReadString("GAATTC");
    r1.setBaseQualityString("222222");
    r1.setCigarString("6M");
    L.add(r1);
    r1 = srf.createSAMRecord(header);
    r1.setReadName("R2");
    r1.setReferenceName("1");
    r1.setAlignmentStart(83);
    r1.setFlags(83);
    r1.setReadString("GAATTC");
    r1.setBaseQualityString("222222");
    r1.setCigarString("6M");
    L.add(r1);
    final MergingIterator<SAMRecord> iter = new MergingIterator<>(new SAMRecordCoordinateComparator(), Collections.singletonList(L.iterator()));
    while (iter.hasNext()) iter.next();
    iter.close();
}
Also used : SAMRecordCoordinateComparator(htsjdk.samtools.SAMRecordCoordinateComparator) SAMRecord(htsjdk.samtools.SAMRecord) ArrayList(java.util.ArrayList) SAMSequenceRecord(htsjdk.samtools.SAMSequenceRecord) SAMFileHeader(htsjdk.samtools.SAMFileHeader) SAMSequenceDictionary(htsjdk.samtools.SAMSequenceDictionary) DefaultSAMRecordFactory(htsjdk.samtools.DefaultSAMRecordFactory) Test(org.testng.annotations.Test)

Example 4 with SAMRecordCoordinateComparator

use of htsjdk.samtools.SAMRecordCoordinateComparator in project gatk by broadinstitute.

the class ReadsSparkSinkUnitTest method assertReadsAreSorted.

private static void assertReadsAreSorted(SAMFileHeader header, List<GATKRead> writtenReads) {
    final SAMRecordCoordinateComparator comparator = new SAMRecordCoordinateComparator();
    // Assert that the reads are sorted.
    final int size = writtenReads.size();
    for (int i = 0; i < size - 1; ++i) {
        final SAMRecord smaller = writtenReads.get(i).convertToSAMRecord(header);
        final SAMRecord larger = writtenReads.get(i + 1).convertToSAMRecord(header);
        final int compare = comparator.compare(smaller, larger);
        Assert.assertTrue(compare < 0, "Reads are out of order (compare=" + compare + "): " + smaller.getSAMString() + " and " + larger.getSAMString());
    }
}
Also used : SAMRecordCoordinateComparator(htsjdk.samtools.SAMRecordCoordinateComparator) SAMRecord(htsjdk.samtools.SAMRecord)

Example 5 with SAMRecordCoordinateComparator

use of htsjdk.samtools.SAMRecordCoordinateComparator in project gridss by PapenfussLab.

the class IntermediateFilesTest method createBAM.

public void createBAM(File file, SAMFileHeader header, SAMRecord... data) {
    SAMFileWriter writer = new SAMFileWriterFactory().setCreateIndex(true).makeSAMOrBAMWriter(header, true, file);
    if (header.getSortOrder() == SortOrder.coordinate) {
        SortingCollection<SAMRecord> presort = SortingCollection.newInstance(SAMRecord.class, new BAMRecordCodec(header), new SAMRecordCoordinateComparator(), 100000000, testFolder.getRoot());
        for (SAMRecord r : data) {
            presort.add(r);
        }
        presort.doneAdding();
        for (SAMRecord r : presort) {
            writer.addAlignment(r);
        }
    } else {
        for (SAMRecord r : data) {
            writer.addAlignment(r);
        }
    }
    writer.close();
}
Also used : SAMRecordCoordinateComparator(htsjdk.samtools.SAMRecordCoordinateComparator) BAMRecordCodec(htsjdk.samtools.BAMRecordCodec) SAMFileWriter(htsjdk.samtools.SAMFileWriter) SAMRecord(htsjdk.samtools.SAMRecord) SAMFileWriterFactory(htsjdk.samtools.SAMFileWriterFactory)

Aggregations

SAMRecord (htsjdk.samtools.SAMRecord)8 SAMRecordCoordinateComparator (htsjdk.samtools.SAMRecordCoordinateComparator)8 ArrayList (java.util.ArrayList)4 SAMFileHeader (htsjdk.samtools.SAMFileHeader)3 SAMSequenceDictionary (htsjdk.samtools.SAMSequenceDictionary)3 SAMSequenceRecord (htsjdk.samtools.SAMSequenceRecord)3 Parameter (com.beust.jcommander.Parameter)2 IOUtils (com.github.lindenb.jvarkit.io.IOUtils)2 JvarkitException (com.github.lindenb.jvarkit.lang.JvarkitException)2 BedLineCodec (com.github.lindenb.jvarkit.util.bio.bed.BedLineCodec)2 Launcher (com.github.lindenb.jvarkit.util.jcommander.Launcher)2 Program (com.github.lindenb.jvarkit.util.jcommander.Program)2 Logger (com.github.lindenb.jvarkit.util.log.Logger)2 SAMSequenceDictionaryProgress (com.github.lindenb.jvarkit.util.picard.SAMSequenceDictionaryProgress)2 SAMRecordPartition (com.github.lindenb.jvarkit.util.samtools.SAMRecordPartition)2 SamRecordJEXLFilter (com.github.lindenb.jvarkit.util.samtools.SamRecordJEXLFilter)2 Cigar (htsjdk.samtools.Cigar)2 CigarElement (htsjdk.samtools.CigarElement)2 CigarOperator (htsjdk.samtools.CigarOperator)2 SamReader (htsjdk.samtools.SamReader)2