use of htsjdk.samtools.SAMReadGroupRecord in project gatk by broadinstitute.
the class AlignmentContextUnitTest method test1Sample2Readgroups.
@Test
public void test1Sample2Readgroups() throws Exception {
final SAMReadGroupRecord readGroupOne = new SAMReadGroupRecord("rg1");
readGroupOne.setSample("sample1");
final SAMReadGroupRecord readGroupTwo = new SAMReadGroupRecord("rg2");
readGroupTwo.setSample("sample1");
final SAMFileHeader header = ArtificialReadUtils.createArtificialSamHeader(1, 1, 1000);
header.addReadGroup(readGroupOne);
header.addReadGroup(readGroupTwo);
final Locatable loc = new SimpleInterval("chr1", 1, 1);
final GATKRead read1 = ArtificialReadUtils.createArtificialRead(header, "read1", 0, 1, 10);
read1.setReadGroup(readGroupOne.getId());
final GATKRead read2 = ArtificialReadUtils.createArtificialRead(header, "read2", 0, 1, 10);
read2.setReadGroup(readGroupTwo.getId());
final GATKRead read3 = ArtificialReadUtils.createArtificialRead(header, "read3", 0, 1, 10);
read3.setReadGroup(readGroupOne.getId());
final GATKRead read4 = ArtificialReadUtils.createArtificialRead(header, "read4", 0, 1, 10);
read4.setReadGroup(readGroupTwo.getId());
final GATKRead read5 = ArtificialReadUtils.createArtificialRead(header, "read5", 0, 1, 10);
read5.setReadGroup(readGroupTwo.getId());
final GATKRead read6 = ArtificialReadUtils.createArtificialRead(header, "read6", 0, 1, 10);
read6.setReadGroup(readGroupOne.getId());
final GATKRead read7 = ArtificialReadUtils.createArtificialRead(header, "read7", 0, 1, 10);
read7.setReadGroup(readGroupOne.getId());
final ReadPileup pileup = new ReadPileup(loc, Arrays.asList(read1, read2, read3, read4, read5, read6, read7), 1);
final AlignmentContext ac = new AlignmentContext(loc, pileup);
Assert.assertSame(ac.getBasePileup(), pileup);
Assert.assertEquals(ac.getContig(), loc.getContig());
Assert.assertEquals(ac.getEnd(), loc.getEnd());
Assert.assertEquals(ac.getLocation(), loc);
Assert.assertEquals(ac.getPosition(), loc.getStart());
Assert.assertEquals(ac.getStart(), loc.getStart());
Assert.assertEquals(ac.hasPileupBeenDownsampled(), false);
Assert.assertEquals(ac.size(), pileup.size());
Assert.assertSame(ac.stratify(AlignmentContext.ReadOrientation.COMPLETE), ac, "Complete");
final AlignmentContext acFWD = ac.stratify(AlignmentContext.ReadOrientation.FORWARD);
Assert.assertEquals(acFWD.getLocation(), loc, "Forward Loc");
Assert.assertEquals((Iterable<?>) acFWD.getBasePileup(), (Iterable<?>) pileup, "Forward Pileup");
final AlignmentContext acREV = ac.stratify(AlignmentContext.ReadOrientation.REVERSE);
AlignmentContext emptyAC = new AlignmentContext(loc, new ReadPileup(loc));
Assert.assertEquals(acREV.getLocation(), loc, "Reverse Loc");
Assert.assertEquals((Iterable<?>) acREV.getBasePileup(), (Iterable<?>) emptyAC.getBasePileup(), "Reverse pileup");
Assert.assertNotNull(ac.toString());
final Map<String, AlignmentContext> bySample = ac.splitContextBySampleName(header);
Assert.assertEquals(bySample.size(), 1);
Assert.assertEquals(bySample.keySet(), ReadUtils.getSamplesFromHeader(header));
final AlignmentContext firstAC = bySample.values().iterator().next();
Assert.assertEquals(firstAC.getLocation(), ac.getLocation());
Assert.assertEquals(firstAC.getBasePileup(), ac.getBasePileup());
final Map<String, AlignmentContext> bySampleAssume1 = ac.splitContextBySampleName("sample1", header);
Assert.assertEquals(bySampleAssume1.size(), 1);
Assert.assertEquals(bySampleAssume1.keySet(), ReadUtils.getSamplesFromHeader(header));
final AlignmentContext firstACAssume1 = bySampleAssume1.values().iterator().next();
Assert.assertEquals(firstACAssume1.getLocation(), ac.getLocation());
Assert.assertEquals(firstACAssume1.getBasePileup(), ac.getBasePileup());
final Map<String, AlignmentContext> stringAlignmentContextMap = AlignmentContext.splitContextBySampleName(pileup, header);
Assert.assertEquals(stringAlignmentContextMap.keySet(), Collections.singleton("sample1"));
Assert.assertEquals(stringAlignmentContextMap.get("sample1").getLocation(), loc);
Assert.assertEquals(stringAlignmentContextMap.get("sample1").getBasePileup(), pileup);
}
use of htsjdk.samtools.SAMReadGroupRecord in project gatk by broadinstitute.
the class SampleCollectionUnitTest method setUp.
@BeforeClass
public void setUp() {
final Random rnd = new Random(randomSeed);
emptyHeader = ArtificialReadUtils.createArtificialSamHeader();
final SAMReadGroupRecord rg1_1 = new SAMReadGroupRecord("RG1");
rg1_1.setSample("SM1");
final SAMReadGroupRecord rg1_0 = new SAMReadGroupRecord("RG0");
singleSampleReadGroupHeader = ArtificialReadUtils.createArtificialSamHeader();
singleSampleReadGroupHeader.addReadGroup(rg1_1);
singleSampleLessReadGroupHeader = ArtificialReadUtils.createArtificialSamHeader();
singleSampleLessReadGroupHeader.addReadGroup(rg1_0);
multiSampleHeaders = new SAMFileHeader[multiSampleWithOrphanReadGroupCount + multiSampleWithoutOrphanReadGroupCount];
for (int i = 0; i < multiSampleWithOrphanReadGroupCount; i++) {
final int orphanCount = rnd.nextInt(maxOrphanReadGroupCount - minOrphanReadGroupCount) + minOrphanReadGroupCount;
final SAMFileHeader header = ArtificialReadUtils.createArtificialSamHeader();
for (int j = 0; j < orphanCount; j++) {
header.addReadGroup(new SAMReadGroupRecord("RG0_" + j));
}
addSampleReadGroups(rnd, header);
multiSampleHeaders[i] = header;
}
for (int i = 0; i < multiSampleWithoutOrphanReadGroupCount; i++) {
final SAMFileHeader header = ArtificialReadUtils.createArtificialSamHeader();
addSampleReadGroups(rnd, header);
multiSampleHeaders[i + multiSampleWithOrphanReadGroupCount] = header;
}
}
use of htsjdk.samtools.SAMReadGroupRecord in project gatk by broadinstitute.
the class SampleCollectionUnitTest method testSampleIndexByGroupId.
@Test(dataProvider = "samFileHeaderData", dependsOnMethods = { "testSampleIds" })
public void testSampleIndexByGroupId(final SAMFileHeader header) {
final SampleCollection sampleCollection = new SampleCollection(header);
final List<String> sampleIds = sampleCollection.sampleIds();
for (final SAMReadGroupRecord rg : header.getReadGroups()) {
final String sampleId = rg.getSample();
if (sampleId == null) {
Assert.assertEquals(sampleCollection.sampleIndexByGroupId(rg.getId()), -1);
} else {
Assert.assertEquals(sampleCollection.sampleIndexByGroupId(rg.getId()), sampleIds.indexOf(sampleId));
}
Assert.assertEquals(sampleCollection.sampleIndexByGroupId(rg.getId() + "random_extension"), -1);
}
}
use of htsjdk.samtools.SAMReadGroupRecord in project gatk by broadinstitute.
the class SampleCollectionUnitTest method testReadGroupIndexByGroupId.
@Test(dataProvider = "samFileHeaderData", dependsOnMethods = { "testReadGroupIds" })
public void testReadGroupIndexByGroupId(final SAMFileHeader header) {
final SampleCollection sampleCollection = new SampleCollection(header);
final List<String> readGroupIds = sampleCollection.readGroups();
for (final SAMReadGroupRecord rg : header.getReadGroups()) {
Assert.assertTrue(readGroupIds.indexOf(rg.getId()) >= 0);
Assert.assertEquals(sampleCollection.readGroupIndexById(rg.getId()), readGroupIds.indexOf(rg.getId()));
Assert.assertEquals(sampleCollection.readGroupIndexById(rg.getId() + "_random_extension"), -1);
}
}
use of htsjdk.samtools.SAMReadGroupRecord in project gatk by broadinstitute.
the class SampleCollectionUnitTest method addSampleReadGroups.
private void addSampleReadGroups(Random rnd, SAMFileHeader header) {
final int sampleCount = rnd.nextInt(maxMultiSampleCount - minMultiSampleCount) + minMultiSampleCount;
for (int j = 0; j < sampleCount; j++) {
final int readGroupCount = rnd.nextInt(maxReadGroupPerSample - minReadGroupPerSample) + minReadGroupPerSample;
for (int k = 0; k < readGroupCount; k++) {
final SAMReadGroupRecord rg = new SAMReadGroupRecord("RG" + (j + 1) + "_" + (k + 1));
rg.setSample("SM" + (j + 1));
header.addReadGroup(rg);
}
}
}
Aggregations