/** * * @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(); }
@Override public void close() { lineReader.close(); }
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(); } }
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) { } }
/** 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; } }
TabixReader tabixReader= new TabixReader(fileName); try { Iterator qry= tabixReader.query(this.getGc().getChrom(), this.getGc().getFrom()-1, this.getGc().getTo()); while(true){ String q = qry.next(); System.err.println("tabix -p bed " + fileName + "\n"); } finally { tabixReader.close();
/** * 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); }
private TabixReader getTabixReader(String tabixFile) throws IOException { return new TabixReader(new File(tabixFile).getAbsolutePath()); }
@Override public TabixReader.Iterator query(String query) { return tabixReader.query(query); }
TabixReader dbsnpTabixReader = new TabixReader(dbSnpTabixFilePath.toString()); dbsnpTabixReader.close();
/** * Read one line from the data file. */ public String readLine() throws IOException { return readLine(mFp, DEFAULT_BUFFER_SIZE); }
TIndex idx = mIndex[tid]; int[] bins = new int[MAX_BIN]; int i, l, n_off, n_bins = reg2bins(beg, end, bins); if (idx.l.length > 0) min_off = (beg >> TAD_LIDX_SHIFT >= idx.l.length) ? idx.l[idx.l.length - 1] : idx.l[beg >> TAD_LIDX_SHIFT]; if ((chunks = idx.b.get(bins[i])) != null) for (int j = 0; j < chunks.length; ++j) if (less64(min_off, chunks[j].v)) off[n_off++] = new TPair64(chunks[j]); Arrays.sort(off, 0, n_off); if (less64(off[l].v, off[i].v)) { ++l; off[l].u = off[i].u; if (!less64(off[i - 1].v, off[i].u)) off[i - 1].v = off[i].u;
/** * Parse a region in the format of "chr1", "chr1:100" or "chr1:100-1000" * * @param reg Region string * @return An array where the three elements are sequence_id, * region_begin and region_end. On failure, sequence_id==-1. */ public int[] parseReg(final String reg) { // FIXME: NOT working when the sequence name contains : or -. String chr; int colon, hyphen; int[] ret = new int[3]; colon = reg.indexOf(':'); hyphen = reg.indexOf('-'); chr = colon >= 0 ? reg.substring(0, colon) : reg; ret[1] = colon >= 0 ? Integer.parseInt(reg.substring(colon + 1, hyphen >= 0 ? hyphen : reg.length())) - 1 : 0; ret[2] = hyphen >= 0 ? Integer.parseInt(reg.substring(hyphen + 1)) : 0x7fffffff; ret[0] = this.chr2tid(chr); return ret; }
@Override public String toString() { return "TabixReader: filename:"+getSource(); } }
public Set<String> getChromosomes() { if(this.tabixReader != null && this.bigBedReader == null){ return this.tabixReader.getChromosomes(); } else if(this.tabixReader == null && this.bigBedReader != null){ return new HashSet<String>(this.bigBedReader.getChromosomeNames()); } else{ System.err.println("Tabix and bigBed readers cannto be both set. One must be null."); throw new RuntimeException(); } }
@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 TabixReader.readLine * * @throws java.io.IOException */ @Test public void testTabixReaderReadLine() throws IOException { TabixReader tabixReader = new TabixReader(tabixFile); Assert.assertNotNull(tabixReader.readLine()); tabixReader.close(); } }
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); } }