@Override public TabixReader.Iterator query(String query) { return tabixReader.query(query); }
protected TabixBigBedIterator(TabixReader reader, String chrom, int start, int end){ this.tabixIterator= reader.query(chrom, start, end); }
@Override public TabixReader.Iterator query(String chromosome, int start, int end) { return tabixReader.query(chromosome, start, end); }
/** * * @see #parseReg(String) * @param reg A region string of the form acceptable by {@link #parseReg(String)} * @return */ public Iterator query(final String reg) { int[] x = parseReg(reg); if(x[0]<0) return EOF_ITERATOR; return query(x[0], x[1], x[2]); }
/** * * @see #parseReg(String) * @param reg a chromosome * @param start start interval * @param end end interval * @return a tabix iterator */ public Iterator query(final String reg,int start,int end) { int tid=this.chr2tid(reg); if(tid==-1) return EOF_ITERATOR; return query(tid, start, end); }
/** * * @see #parseReg(String) * @param reg A region string of the form acceptable by {@link #parseReg(String)} * @return */ public Iterator query(final String reg) { int[] x = parseReg(reg); if(x[0]<0) return EOF_ITERATOR; return query(x[0], x[1], x[2]); }
@Override public CloseableIterator<VariantContext> query(String contig, int beginPos, int endPos) { return new TabixIteratorWrapper(tabixReader.query(contig, beginPos, endPos)); }
/** * * @see #parseReg(String) * @param reg A region string of the form acceptable by {@link #parseReg(String)} * @return */ public Iterator query(final String reg) { int[] x = parseReg(reg); if(x[0]<0) return EOF_ITERATOR; return query(x[0], x[1], x[2]); }
/** * * @see #parseReg(String) * @param reg a chromosome * @param start start interval * @param end end interval * @return a tabix iterator */ public Iterator query(final String reg,int start,int end) { int tid=this.chr2tid(reg); if(tid==-1) return EOF_ITERATOR; return query(tid, start, end); }
/** * * @see #parseReg(String) * @param reg a chromosome * @param start start interval * @param end end interval * @return a tabix iterator */ public Iterator query(final String reg,int start,int end) { int tid=this.chr2tid(reg); if(tid==-1) return EOF_ITERATOR; return query(tid, start, end); }
public static void main(String[] args) { if (args.length < 1) { System.out.println("Usage: java -cp .:sam.jar TabixReader <in.gz> [region]"); System.exit(1); } try { TabixReader tr = new TabixReader(args[0]); String s; if (args.length == 1) { // no region is specified; print the whole file while ((s = tr.readLine()) != null) System.out.println(s); } else { // a region is specified; random access TabixReader.Iterator iter = tr.query(args[1]); // get the iterator while ((s = iter.next()) != null) System.out.println(s); } } catch (IOException e) { } }
/** * Test reading a local tabix file * * @throws java.io.IOException */ @Test public void testLocalQuery() throws IOException { TabixIteratorLineReader lineReader = new TabixIteratorLineReader( tabixReader.query(tabixReader.chr2tid("4"), 320, 330)); int nRecords = 0; String nextLine; while ((nextLine = lineReader.readLine()) != null) { Assert.assertTrue(nextLine.startsWith("4")); nRecords++; } Assert.assertTrue(nRecords > 0); }
/** * Return iterator over all features overlapping the given interval * * @param chr * @param start * @param end * @return * @throws IOException */ @Override public CloseableTribbleIterator<T> query(final String chr, final int start, final int end) throws IOException { final List<String> mp = getSequenceNames(); if (mp == null) throw new TribbleException.TabixReaderFailure("Unable to find sequence named " + chr + " in the tabix index. ", path); if (!mp.contains(chr)) { return new EmptyIterator<T>(); } final TabixIteratorLineReader lineReader = new TabixIteratorLineReader(tabixReader.query(tabixReader.chr2tid(chr), start - 1, end)); return new FeatureIterator<T>(lineReader, start - 1, end); }
/** * Return iterator over all features overlapping the given interval * * @param chr * @param start * @param end * @return * @throws IOException */ public CloseableTribbleIterator<T> query(final String chr, final int start, final int end) throws IOException { final List<String> mp = getSequenceNames(); if (mp == null) throw new TribbleException.TabixReaderFailure("Unable to find sequence named " + chr + " in the tabix index. ", path); if (!mp.contains(chr)) { return new EmptyIterator<T>(); } final TabixIteratorLineReader lineReader = new TabixIteratorLineReader(tabixReader.query(tabixReader.chr2tid(chr), start - 1, end)); return new FeatureIterator<T>(lineReader, start - 1, end); }
/** * Return iterator over all features overlapping the given interval * * @param chr * @param start * @param end * @return * @throws IOException */ @Override public CloseableTribbleIterator<T> query(final String chr, final int start, final int end) throws IOException { final List<String> mp = getSequenceNames(); if (mp == null) throw new TribbleException.TabixReaderFailure("Unable to find sequence named " + chr + " in the tabix index. ", path); if (!mp.contains(chr)) { return new EmptyIterator<T>(); } final TabixIteratorLineReader lineReader = new TabixIteratorLineReader(tabixReader.query(tabixReader.chr2tid(chr), start - 1, end)); return new FeatureIterator<T>(lineReader, start - 1, end); }
@Test public void canCompressAndIndexSortedGzipFile() throws IOException, InvalidRecordException, ClassNotFoundException, SQLException { String infile= "test_data/hg19_genes.gtf.gz"; File outfile= new File("test_data/tmp2.bed.gz"); outfile.deleteOnExit(); File expectedTbi= new File(outfile.getAbsolutePath() + TabixUtils.STANDARD_INDEX_EXTENSION); expectedTbi.deleteOnExit(); new MakeTabixIndex(infile, outfile, TabixFormat.GFF); assertTrue(outfile.exists()); assertTrue(outfile.length() > 7000000); assertTrue(expectedTbi.exists()); assertTrue(expectedTbi.length() > 500000); TabixReader tbx = new TabixReader(outfile.getAbsolutePath()); Iterator x = tbx.query("chr1", 1, 1000000); assertTrue(x.next().startsWith("chr1")); }
@Test public void canCompressAndIndexHeaderlessVCF() throws ClassNotFoundException, IOException, InvalidRecordException, SQLException{ String infile= "test_data/noheader.vcf"; File outfile= new File("test_data/noheader.vcf.gz"); outfile.deleteOnExit(); File expectedTbi= new File(outfile.getAbsolutePath() + TabixUtils.STANDARD_INDEX_EXTENSION); expectedTbi.deleteOnExit(); new MakeTabixIndex(infile, outfile, TabixFormat.VCF); assertTrue(outfile.exists()); assertTrue(outfile.length() > 200); assertTrue(expectedTbi.exists()); assertTrue(expectedTbi.length() > 100); TabixReader tbx = new TabixReader(outfile.getAbsolutePath()); Iterator x = tbx.query("1", 1, 10000000); assertTrue(x.next().startsWith("1")); }
/** * Test reading a tabix file over http * * @throws java.io.IOException */ @Test public void testRemoteQuery() throws IOException { String tabixFile = TestUtil.BASE_URL_FOR_HTTP_TESTS +"igvdata/tabix/trioDup.vcf.gz"; TabixReader tabixReader = new TabixReader(tabixFile); TabixIteratorLineReader lineReader = new TabixIteratorLineReader( tabixReader.query(tabixReader.chr2tid("4"), 320, 330)); int nRecords = 0; String nextLine; while ((nextLine = lineReader.readLine()) != null) { Assert.assertTrue(nextLine.startsWith("4")); nRecords++; } Assert.assertTrue(nRecords > 0); }
@Test public void canCompressAndIndexSortedFile() throws IOException, InvalidRecordException, ClassNotFoundException, SQLException { String infile= "test_data/overlapped.bed"; File outfile= new File("test_data/tmp.bed.gz"); outfile.deleteOnExit(); File expectedTbi= new File(outfile.getAbsolutePath() + TabixUtils.STANDARD_INDEX_EXTENSION); expectedTbi.deleteOnExit(); new MakeTabixIndex(infile, outfile, TabixFormat.BED); assertTrue(outfile.exists()); assertTrue(outfile.length() > 80); assertTrue(expectedTbi.exists()); assertTrue(expectedTbi.length() > 80); TabixReader tbx = new TabixReader(outfile.getAbsolutePath()); Iterator x = tbx.query("chr1", 1, 1000000); assertTrue(x.next().startsWith("chr1")); }
@Test public void canCompressAndIndexVCF() throws ClassNotFoundException, IOException, InvalidRecordException, SQLException{ String infile= "test_data/CHD.exon.2010_03.sites.unsorted.vcf"; File outfile= new File("test_data/tmp6.bed.gz"); outfile.deleteOnExit(); File expectedTbi= new File(outfile.getAbsolutePath() + TabixUtils.STANDARD_INDEX_EXTENSION); expectedTbi.deleteOnExit(); new MakeTabixIndex(infile, outfile, TabixFormat.VCF); assertTrue(outfile.exists()); assertTrue(outfile.length() > 1000); assertTrue(expectedTbi.exists()); assertTrue(expectedTbi.length() > 1000); TabixReader tbx = new TabixReader(outfile.getAbsolutePath()); Iterator x = tbx.query("1", 20000000, 30000000); assertTrue(x.next().startsWith("1")); // Check you can read ok this.vcfTester(outfile.getAbsolutePath()); }