use of htsjdk.samtools.SAMReadGroupRecord in project gatk by broadinstitute.
the class ReadGroupBlackListReadFilterUnitTest method testFilterOutByFile.
@Test
public void testFilterOutByFile() throws IOException {
int recordsPerGroup = 3;
List<GATKRead> records = new ArrayList<>();
int alignmentStart = 0;
for (int x = 0; x < GROUP_COUNT; x++) {
SAMReadGroupRecord groupRecord = header.getReadGroup(getReadGroupId(x));
for (int y = 1; y <= recordsPerGroup; y++) {
GATKRead record = ArtificialReadUtils.createArtificialRead(header, "readUno", 0, ++alignmentStart, 20);
record.setReadGroup(groupRecord.getReadGroupId());
records.add(record);
}
}
List<String> filterList = new ArrayList<>();
filterList.add(publicTestDir + "readgroupblacklisttest.txt");
ReadGroupBlackListReadFilter filter = new ReadGroupBlackListReadFilter(filterList, header);
int filtered = 0;
int unfiltered = 0;
for (GATKRead record : records) {
String readGroup = record.getReadGroup();
if (!filter.test(record)) {
if (!("ReadGroup3".equals(readGroup) || "ReadGroup4".equals(readGroup)))
Assert.fail("Read group " + readGroup + " was filtered");
filtered++;
} else {
if ("ReadGroup3".equals(readGroup) || "ReadGroup4".equals(readGroup))
Assert.fail("Read group " + readGroup + " was not filtered");
unfiltered++;
}
}
int filteredExpected = recordsPerGroup * 2;
int unfilteredExpected = recordsPerGroup * (GROUP_COUNT - 2);
Assert.assertEquals(filtered, filteredExpected, "Filtered");
Assert.assertEquals(unfiltered, unfilteredExpected, "Uniltered");
}
use of htsjdk.samtools.SAMReadGroupRecord in project gatk by broadinstitute.
the class RecalUtils method parsePlatformForRead.
/**
* Section of code shared between the two recalibration walkers which uses the command line arguments to adjust attributes of the read such as quals or platform string
*
* @param read The read to adjust
* @param RAC The list of shared command line arguments
*/
public static void parsePlatformForRead(final GATKRead read, final SAMFileHeader header, final RecalibrationArgumentCollection RAC) {
final SAMReadGroupRecord readGroup = ReadUtils.getSAMReadGroupRecord(read, header);
if (RAC.FORCE_PLATFORM != null && (readGroup.getPlatform() == null || !readGroup.getPlatform().equals(RAC.FORCE_PLATFORM))) {
readGroup.setPlatform(RAC.FORCE_PLATFORM);
}
if (readGroup.getPlatform() == null) {
if (RAC.DEFAULT_PLATFORM != null) {
if (!warnUserNullPlatform) {
Utils.warnUser("The input .bam file contains reads with no platform information. " + "Defaulting to platform = " + RAC.DEFAULT_PLATFORM + ". " + "First observed at read with name = " + read.getName());
warnUserNullPlatform = true;
}
readGroup.setPlatform(RAC.DEFAULT_PLATFORM);
} else {
throw new UserException.MalformedRead(read, "The input .bam file contains reads with no platform information. First observed at read with name = " + read.getName());
}
}
}
use of htsjdk.samtools.SAMReadGroupRecord in project gatk by broadinstitute.
the class ReadGroupCovariate method recordValues.
@Override
public void recordValues(final GATKRead read, final SAMFileHeader header, final ReadCovariates values, final boolean recordIndelValues) {
final SAMReadGroupRecord rg = ReadUtils.getSAMReadGroupRecord(read, header);
final String readGroupId = getID(rg);
final int key = keyForReadGroup(readGroupId);
final int readLength = read.getLength();
for (int i = 0; i < readLength; i++) {
values.addCovariate(key, key, key, i);
}
}
use of htsjdk.samtools.SAMReadGroupRecord in project gatk by broadinstitute.
the class AlignmentContextUnitTest method testNoSample.
@Test(expectedExceptions = UserException.ReadMissingReadGroup.class)
public void testNoSample() throws Exception {
final SAMReadGroupRecord readGroupOne = new SAMReadGroupRecord("rg1");
final SAMFileHeader header = ArtificialReadUtils.createArtificialSamHeader(1, 1, 1000);
header.addReadGroup(readGroupOne);
final Locatable loc = new SimpleInterval("chr1", 1, 1);
final GATKRead read1 = ArtificialReadUtils.createArtificialRead(header, "read1", 0, 1, 10);
read1.setReadGroup(readGroupOne.getId());
final ReadPileup pileup = new ReadPileup(loc, Arrays.asList(read1), 1);
final AlignmentContext ac = new AlignmentContext(loc, pileup);
ac.splitContextBySampleName(header);
}
use of htsjdk.samtools.SAMReadGroupRecord in project gatk by broadinstitute.
the class LocusWalkerSpark method getAlignmentsFunction.
/**
* Return a function that maps a {@link Shard} of reads into a tuple of alignments and their corresponding reference and features.
* @param bReferenceSource the reference source broadcast
* @param bFeatureManager the feature manager broadcast
* @param sequenceDictionary the sequence dictionary for the reads
* @param header the reads header
* @param downsamplingInfo the downsampling method for the reads
* @return a function that maps a {@link Shard} of reads into a tuple of alignments and their corresponding reference and features.
*/
private static FlatMapFunction<Shard<GATKRead>, LocusWalkerContext> getAlignmentsFunction(Broadcast<ReferenceMultiSource> bReferenceSource, Broadcast<FeatureManager> bFeatureManager, SAMSequenceDictionary sequenceDictionary, SAMFileHeader header, LIBSDownsamplingInfo downsamplingInfo) {
return (FlatMapFunction<Shard<GATKRead>, LocusWalkerContext>) shardedRead -> {
SimpleInterval interval = shardedRead.getInterval();
SimpleInterval paddedInterval = shardedRead.getPaddedInterval();
Iterator<GATKRead> readIterator = shardedRead.iterator();
ReferenceDataSource reference = bReferenceSource == null ? null : new ReferenceMemorySource(bReferenceSource.getValue().getReferenceBases(null, paddedInterval), sequenceDictionary);
FeatureManager fm = bFeatureManager == null ? null : bFeatureManager.getValue();
final Set<String> samples = header.getReadGroups().stream().map(SAMReadGroupRecord::getSample).collect(Collectors.toSet());
LocusIteratorByState libs = new LocusIteratorByState(readIterator, downsamplingInfo, false, samples, header, true, false);
IntervalOverlappingIterator<AlignmentContext> alignmentContexts = new IntervalOverlappingIterator<>(libs, ImmutableList.of(interval), sequenceDictionary);
final Spliterator<AlignmentContext> alignmentContextSpliterator = Spliterators.spliteratorUnknownSize(alignmentContexts, 0);
return StreamSupport.stream(alignmentContextSpliterator, false).map(alignmentContext -> {
final SimpleInterval alignmentInterval = new SimpleInterval(alignmentContext);
return new LocusWalkerContext(alignmentContext, new ReferenceContext(reference, alignmentInterval), new FeatureContext(fm, alignmentInterval));
}).iterator();
};
}
Aggregations