private TabixReader getTabixReader(String tabixFile) throws IOException { return new TabixReader(new File(tabixFile).getAbsolutePath()); }
public GenericTSVVariantContextProvider(GenericTSVAnnotationOptions options) { this.options = options; final String tsvPath = this.options.getTsvFile().toString(); try { this.tabixReader = new TabixReader(tsvPath, tsvPath + ".tbi"); } catch (IOException e) { throw new RuntimeException("Could not open TABIX file " + tsvPath, e); } }
/** * * @param featureFile - path to a feature file. Can be a local file, http url, or ftp url * @param codec * @throws IOException */ public TabixFeatureReader(final String featureFile, final AsciiFeatureCodec codec) throws IOException { super(featureFile, codec); tabixReader = new TabixReader(featureFile); sequenceNames = new ArrayList<String>(tabixReader.getChromosomes()); readHeader(); }
public static TabixDataSource load(Path pathToTabixGzFile) { TabixReader tabixReader; try { logger.debug("Loading TabixDataSource from {}", pathToTabixGzFile); tabixReader = new TabixReader(pathToTabixGzFile.toAbsolutePath().toString()); } catch (IOException e) { throw new ExomiserAutoConfigurationException("Failed to load/find file " + pathToTabixGzFile + ". Please check exomiser properties file points to a valid tabix .gz file.", e); } return new TabixReaderAdaptor(tabixReader); } }
/** * * @param featureFile - path to a feature file. Can be a local file, http url, or ftp url * @param indexFile - path to the index file. * @param codec * @throws IOException */ public TabixFeatureReader(final String featureFile, final String indexFile, final AsciiFeatureCodec codec) throws IOException { super(featureFile, codec); tabixReader = new TabixReader(featureFile, indexFile); sequenceNames = new ArrayList<String>(tabixReader.getChromosomes()); readHeader(); }
/** * @param featureFile path to a feature file. Can be a local file, http url, or ftp url * @param indexFile path to the index file. * @param wrapper a wrapper to apply to the byte stream from the featureResource allowing injecting features * like caching and prefetching of the stream, may be null, will only be applied if featureFile * is a uri representing a {@link java.nio.file.Path} * @param indexWrapper a wrapper to apply to the byte stream from the indexResource, may be null, will only be * applied if indexFile is a uri representing a {@link java.nio.file.Path} */ public TabixFeatureReader(final String featureFile, final String indexFile, final AsciiFeatureCodec codec, final Function<SeekableByteChannel, SeekableByteChannel> wrapper, final Function<SeekableByteChannel, SeekableByteChannel> indexWrapper) throws IOException { super(featureFile, codec, wrapper, indexWrapper); tabixReader = new TabixReader(this.path, indexFile, wrapper, indexWrapper); sequenceNames = new ArrayList<>(tabixReader.getChromosomes()); readHeader(); }
/** * @param featureFile path to a feature file. Can be a local file, http url, or ftp url * @param indexFile path to the index file. * @param wrapper a wrapper to apply to the byte stream from the featureResource allowing injecting features * like caching and prefetching of the stream, may be null, will only be applied if featureFile * is a uri representing a {@link java.nio.file.Path} * @param indexWrapper a wrapper to apply to the byte stream from the indexResource, may be null, will only be * applied if indexFile is a uri representing a {@link java.nio.file.Path} */ public TabixFeatureReader(final String featureFile, final String indexFile, final AsciiFeatureCodec codec, final Function<SeekableByteChannel, SeekableByteChannel> wrapper, final Function<SeekableByteChannel, SeekableByteChannel> indexWrapper) throws IOException { super(featureFile, codec, wrapper, indexWrapper); tabixReader = new TabixReader(this.path, indexFile, wrapper, indexWrapper); sequenceNames = new ArrayList<>(tabixReader.getChromosomes()); readHeader(); }
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) { } }
TabixReader dbsnpTabixReader = new TabixReader(dbSnpTabixFilePath.toString());
public TrackBookmark(GenomicCoords gc, String nameForBookmark) throws IOException, ClassNotFoundException, InvalidRecordException, SQLException, InvalidGenomicCoordsException{ super(gc); this.setTrackTag(trackName); // Prepare bookmark file // ===================== // First write out the current position as plain text. Then gzip and index. File bookmarkPlain= Utils.createTempFile(".asciigenome.bookmarks.", ".gff"); BufferedWriter wr = new BufferedWriter(new FileWriter(bookmarkPlain)); wr.write(this.positionToGffLine(gc, nameForBookmark) + "\n"); // gc.getChrom() + "\t" + (gc.getFrom() - 1) + "\t" + gc.getTo() + "\t" + nameForBookmark + "\n"); wr.close(); File bookmark= new File(bookmarkPlain + ".gz"); bookmark.deleteOnExit(); (new File(bookmark.getAbsolutePath() + ".tbi")).deleteOnExit(); this.setFilename(bookmark.getAbsolutePath()); this.setWorkFilename(bookmark.getAbsolutePath()); new MakeTabixIndex(bookmarkPlain.getAbsolutePath(), bookmark, TabixFormat.GFF); bookmarkPlain.delete(); this.setTabixReader(new TabixReader(bookmark.getAbsolutePath())); this.setTrackFormat(TrackFormat.GTF); this.setGc(gc); }
@BeforeClass public void setup() throws IOException { tabixReader = new TabixReader(tabixFile); sequenceNames = new ArrayList<String>(tabixReader.getChromosomes()); }
/** Return true if fileName has a valid tabix index. * @throws IOException * */ public static boolean hasTabixIndex(String fileName) throws IOException{ if((new UrlValidator()).isValid(fileName) && fileName.startsWith("ftp")){ // Because of issue #51 return false; } try{ TabixReader tabixReader= new TabixReader(fileName); tabixReader.readLine(); tabixReader.close(); return true; } catch (Exception e){ return false; } }
public void parse() { try { TabixReader inputReader = new TabixReader(caddFilePath.toString()); TabixReader.Iterator caddIterator = inputReader.query(chrName); Cadd caddVariant = null; String line; while ((line = caddIterator.next()) != null) { String[] fields = line.split("\t"); String chr = fields[0]; String ref = fields[2]; String alt = fields[4]; int pos = Integer.parseInt(fields[1]); // If the variant is the same as the last iteration variant, don't print it if (sameVariant(caddVariant, chr, pos, ref, alt)) { caddVariant.addCaddValues(Float.parseFloat(fields[88]), Float.parseFloat(fields[89]), fields[68]); } else { if (caddVariant != null) { serializer.serialize(caddVariant); } caddVariant = createCaddVariant(fields); } } serializer.serialize(caddVariant); } catch (ArrayIndexOutOfBoundsException | IOException e) { e.printStackTrace(); } }
/** * Test TabixReader.readLine * * @throws java.io.IOException */ @Test public void testTabixReaderReadLine() throws IOException { TabixReader tabixReader = new TabixReader(tabixFile); Assert.assertNotNull(tabixReader.readLine()); tabixReader.close(); } }
this.setWorkFilename(filename); this.setTrackFormat(Utils.getFileTypeFromName(new File(filename).getName())); this.tabixReader= new TabixReader(this.getWorkFilename());
@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 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 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()); }