public void query( String contig, int start, int stop, boolean contained ) { if (contained) queryContained(contig, start, stop); else queryOverlapping(contig, start, stop); }
/** * query containing - get reads contained by the specified interval * * @param contig the contig index string * @param start the start position * @param stop the stop position */ public void queryContained( String contig, int start, int stop ) { this.overlapping = false; initialize(contig, start, stop); }
public void queryUnmappedReads() { initializeUnmapped(); }
@Test public void testWholeChromosomeQuery() { ArtificialSAMQueryIterator iter = ArtificialSAMUtils.queryReadIterator(1, 2, 100); iter.queryContained("chr1", 1, -1); int count = 0; while (iter.hasNext()) { SAMRecord rec = iter.next(); count++; } assertEquals(count, 100); }
@Test public void testOverlappingQueryStart() { ArtificialSAMQueryIterator iter = ArtificialSAMUtils.queryReadIterator(1, 2, 100); iter.queryOverlapping("chr1", 1, 50); int count = 0; while (iter.hasNext()) { SAMRecord rec = iter.next(); count++; } assertEquals(count, 50); }
ensureUntouched(); reset(); while (super.hasNext() && this.peek().getReferenceIndex() < contigIndex) { super.next(); throw new ReviewedGATKException("Unable to find the target chromosome"); while (super.hasNext() && this.peek().getAlignmentStart() < start) { super.next(); SAMRecord rec = this.peek(); if (!matches(rec)) { throw new ReviewedGATKException("The next read doesn't match");
/** * initialize the iterator to an unmapped read position */ public void initializeUnmapped() { // throw away data from the previous invocation, if one exists. ensureUntouched(); reset(); while (super.hasNext() && this.peek().getReferenceIndex() >= 0) { super.next(); } // sanity check that we have an actual matching read next SAMRecord rec = this.peek(); if (rec == null) { throw new ReviewedGATKException("The next read doesn't match"); } // set the seeked variable to true seeked = true; }
@Test(expectedExceptions=IllegalArgumentException.class) public void testUnknownChromosome() { ArtificialSAMQueryIterator iter = ArtificialSAMUtils.queryReadIterator(1, 2, 100); iter.queryOverlapping("chr621", 25, 74); } }
/** * create an ArtificialSAMQueryIterator containing the specified read piles * * @param startingChr the chromosome (reference ID) to start from * @param endingChr the id to end with * @param readCount the number of reads per chromosome * @param unmappedReadCount the count of unmapped reads to place at the end of the iterator, like in a sorted bam file * @return GATKSAMIterator representing the specified amount of fake data */ public static GATKSAMIterator queryReadIterator(int startingChr, int endingChr, int readCount, int unmappedReadCount) { SAMFileHeader header = createArtificialSamHeader((endingChr - startingChr) + 1, startingChr, readCount + DEFAULT_READ_LENGTH); return new ArtificialSAMQueryIterator(startingChr, endingChr, readCount, unmappedReadCount, header); }
/** * override the hasNext, to incorportate our limiting factor * * @return */ public boolean hasNext() { boolean res = super.hasNext(); if (!seeked) { return res; } if (res && matches(this.next)) { return true; } return false; }
@Test public void testContainedQueryStart() { ArtificialSAMQueryIterator iter = ArtificialSAMUtils.queryReadIterator(1, 2, 100); iter.queryContained("chr1", 1, 50); int count = 0; while (iter.hasNext()) { SAMRecord rec = iter.next(); count++; } assertEquals(count, 1); }
@Test public void testOverlappingQueryMiddle() { ArtificialSAMQueryIterator iter = ArtificialSAMUtils.queryReadIterator(1, 2, 100); iter.queryOverlapping("chr1", 25, 74); int count = 0; while (iter.hasNext()) { SAMRecord rec = iter.next(); count++; } assertEquals(count, 50); }
/** * create an iterator containing the specified read piles * * @param startingChr the chromosome (reference ID) to start from * @param endingChr the id to end with * @param readCount the number of reads per chromosome * @param unmappedReadCount the count of unmapped reads to place at the end of the iterator, like in a sorted bam file * @return GATKSAMIterator representing the specified amount of fake data */ public static GATKSAMIterator mappedAndUnmappedReadIterator(int startingChr, int endingChr, int readCount, int unmappedReadCount) { SAMFileHeader header = createArtificialSamHeader((endingChr - startingChr) + 1, startingChr, readCount + DEFAULT_READ_LENGTH); return new ArtificialSAMQueryIterator(startingChr, endingChr, readCount, unmappedReadCount, header); }
@Test public void testContainedQueryMiddle() { ArtificialSAMQueryIterator iter = ArtificialSAMUtils.queryReadIterator(1, 2, 100); iter.queryContained("chr1", 25, 74); int count = 0; while (iter.hasNext()) { SAMRecord rec = iter.next(); count++; } assertEquals(count, 1); }
/** * create an iterator containing the specified read piles * * @param startingChr the chromosome (reference ID) to start from * @param endingChr the id to end with * @param readCount the number of reads per chromosome * @return GATKSAMIterator representing the specified amount of fake data */ public static GATKSAMIterator mappedReadIterator(int startingChr, int endingChr, int readCount) { SAMFileHeader header = createArtificialSamHeader((endingChr - startingChr) + 1, startingChr, readCount + DEFAULT_READ_LENGTH); return new ArtificialSAMQueryIterator(startingChr, endingChr, readCount, 0, header); }
/** * query containing - get reads contained by the specified interval * * @param contig the contig index string * @param start the start position * @param stop the stop position */ public void queryOverlapping( String contig, int start, int stop ) { this.overlapping = true; initialize(contig, start, stop); }
/** * create an ArtificialSAMQueryIterator containing the specified read piles * * @param startingChr the chromosome (reference ID) to start from * @param endingChr the id to end with * @param readCount the number of reads per chromosome * @return GATKSAMIterator representing the specified amount of fake data */ public static ArtificialSAMQueryIterator queryReadIterator(int startingChr, int endingChr, int readCount) { SAMFileHeader header = createArtificialSamHeader((endingChr - startingChr) + 1, startingChr, readCount + DEFAULT_READ_LENGTH); return new ArtificialSAMQueryIterator(startingChr, endingChr, readCount, 0, header); }