public Iterator<SAMRecord> iterator() { // lazy initialization to prevent reads from being created until they're needed initialize(); return mergingIterator; }
private void createReadStreams() { perSampleArtificialReadStreams = new HashMap<String, ArtificialSingleSampleReadStream>(numSamples); perSampleStreamAnalyzers = new HashMap<String, ArtificialSingleSampleReadStreamAnalyzer>(numSamples); for (SAMReadGroupRecord readGroup : header.getReadGroups() ) { String readGroupID = readGroup.getReadGroupId(); String sampleName = readGroup.getSample(); int thisSampleNumContigs = MathUtils.randomIntegerInRange(minContigs, maxContigs); int thisSampleStacksPerContig = MathUtils.randomIntegerInRange(streamStacksPerContig.minStacksPerContig, streamStacksPerContig.maxStacksPerContig); int thisSampleNumUnmappedReads = Utils.getRandomGenerator().nextDouble() < unmappedReadsFraction ? unmappedReadsCount : 0; ArtificialSingleSampleReadStream thisSampleStream = new ArtificialSingleSampleReadStream(header, readGroupID, thisSampleNumContigs, thisSampleStacksPerContig, streamStackDepth.minReadsPerStack, streamStackDepth.maxReadsPerStack, streamDensity.minDistanceBetweenStacks, streamDensity.maxDistanceBetweenStacks, MIN_READ_LENGTH, MAX_READ_LENGTH, thisSampleNumUnmappedReads); perSampleArtificialReadStreams.put(sampleName, thisSampleStream); perSampleStreamAnalyzers.put(sampleName, new PositionallyDownsampledArtificialSingleSampleReadStreamAnalyzer(thisSampleStream, targetCoverage)); } mergedReadStream = new ArtificialMultiSampleReadStream(perSampleArtificialReadStreams.values()); }
public void run() { GATKSAMIterator downsamplingIter = new PerSampleDownsamplingReadsIterator(mergedReadStream.getGATKSAMIterator(), downsamplerFactory); if ( verifySortedness ) { downsamplingIter = new VerifyingSamIterator(downsamplingIter); } while ( downsamplingIter.hasNext() ) { SAMRecord read = downsamplingIter.next(); String sampleName = read.getReadGroup() != null ? read.getReadGroup().getSample() : null; ArtificialSingleSampleReadStreamAnalyzer analyzer = perSampleStreamAnalyzers.get(sampleName); if ( analyzer != null ) { analyzer.update(read); } else { throw new ReviewedGATKException("bug: stream analyzer for sample " + sampleName + " not found"); } } for ( Map.Entry<String, ArtificialSingleSampleReadStreamAnalyzer> analyzerEntry : perSampleStreamAnalyzers.entrySet() ) { ArtificialSingleSampleReadStreamAnalyzer analyzer = analyzerEntry.getValue(); analyzer.finalizeStats(); // Validate the downsampled read stream for each sample individually analyzer.validate(); } // Allow memory used by this test to be reclaimed: mergedReadStream = null; perSampleArtificialReadStreams = null; perSampleStreamAnalyzers = null; } }
public GATKSAMIterator getGATKSAMIterator() { // lazy initialization to prevent reads from being created until they're needed initialize(); return GATKSAMIteratorAdapter.adapt(mergingIterator); }