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