public GeraldIterator() { this.chr = null; reader = new AsciiLineReader(is); readNextRecord(); }
@Override public LocationAware makeIndexableSourceFromStream(final InputStream bufferedInputStream) { final PositionalBufferedStream pbs; if (bufferedInputStream instanceof PositionalBufferedStream) { pbs = (PositionalBufferedStream) bufferedInputStream; } else { pbs = new PositionalBufferedStream(bufferedInputStream); } return new AsciiLineReaderIterator(new AsciiLineReader(pbs)); }
@Override public LocationAware makeIndexableSourceFromStream(final InputStream bufferedInputStream) { final PositionalBufferedStream pbs; if (bufferedInputStream instanceof PositionalBufferedStream) { pbs = (PositionalBufferedStream) bufferedInputStream; } else { pbs = new PositionalBufferedStream(bufferedInputStream); } return new AsciiLineReaderIterator(new AsciiLineReader(pbs)); }
public static AsciiLineReader openAsciiReader(ResourceLocator locator) throws IOException { InputStream stream = openInputStreamGZ(locator); return new AsciiLineReader(stream); }
public MUTCodec(String path, Genome genome) { super(Mutation.class); this.path = path; this.genome = genome; try { LineIterator reader = new LineIteratorImpl(new AsciiLineReader(ParsingUtils.openInputStream(path))); readActualHeader(reader); } catch (IOException e) { log.error(e.getMessage(), e); } }
public PAFCodec(String path, Genome genome) { super(PAFFeature.class); this.path = path; this.genome = genome; try { LineIterator reader = new LineIteratorImpl(new AsciiLineReader(ParsingUtils.openInputStream(path))); readActualHeader(reader); } catch (IOException e) { log.error(e.getMessage(), e); } }
public GeraldQueryIterator(String sequence, int start, int end, boolean contained) { this.chr = sequence; this.start = start; this.end = end; this.contained = contained; seekToStart(); reader = new AsciiLineReader(is); advanceToFirstRecord(); }
@Override public FeatureCodecHeader readHeader(final PositionalBufferedStream stream) throws IOException { // Construct a reader that does not read ahead (because we don't want to consume data from the stream that is not the header) final AsciiLineReader nonReadAheadLineReader = new AsciiLineReader(stream); final List<String> headerLines = new ArrayList<String>(); long headerLengthInBytes = 0; while (stream.peek() == ('#' & 0xff)) { // Look for header lines, which are prefixed by '#'. headerLines.add(nonReadAheadLineReader.readLine()); headerLengthInBytes = stream.getPosition(); } return new FeatureCodecHeader(headerLines, headerLengthInBytes); }
@Override public FeatureCodecHeader readHeader(final PositionalBufferedStream stream) throws IOException { // Construct a reader that does not read ahead (because we don't want to consume data from the stream that is not the header) final AsciiLineReader nonReadAheadLineReader = new AsciiLineReader(stream); final List<String> headerLines = new ArrayList<String>(); long headerLengthInBytes = 0; while (stream.peek() == ('#' & 0xff)) { // Look for header lines, which are prefixed by '#'. headerLines.add(nonReadAheadLineReader.readLine()); headerLengthInBytes = stream.getPosition(); } return new FeatureCodecHeader(headerLines, headerLengthInBytes); }
@Override public FeatureCodecHeader readHeader(final PositionalBufferedStream stream) throws IOException { // Construct a reader that does not read ahead (because we don't want to consume data from the stream that is not the header) final AsciiLineReader nonReadAheadLineReader = new AsciiLineReader(stream); final List<String> headerLines = new ArrayList<String>(); long headerLengthInBytes = 0; while (stream.peek() == ('#' & 0xff)) { // Look for header lines, which are prefixed by '#'. headerLines.add(nonReadAheadLineReader.readLine()); headerLengthInBytes = stream.getPosition(); } return new FeatureCodecHeader(headerLines, headerLengthInBytes); }
/** * Create an AsciiLineReader of the appropriate type for a given InputStream. * @param inputStream An InputStream-derived class that implements BlockCompressedInputStream or PositionalBufferedStream * @return AsciiLineReader that wraps inputStream */ public static AsciiLineReader from(final InputStream inputStream) { if (inputStream instanceof BlockCompressedInputStream) { // For block compressed inputs, we need to ensure that no buffering takes place above the input stream to // ensure that the correct (virtual file pointer) positions returned from this stream are preserved for // the indexer. We can't used AsciiLineReader in this case since it wraps the input stream with a // PositionalBufferedInputStream. return new BlockCompressedAsciiLineReader((BlockCompressedInputStream) inputStream); } else if (inputStream instanceof PositionalBufferedStream) { // if this is already a PositionalBufferedStream, don't let AsciiLineReader wrap it with another one... return new AsciiLineReader((PositionalBufferedStream)inputStream); } else { log.warn("Creating an indexable source for an AsciiFeatureCodec using a stream that is " + "neither a PositionalBufferedStream nor a BlockCompressedInputStream"); return new AsciiLineReader(new PositionalBufferedStream(inputStream)); // wrap the stream in a PositionalBufferedStream } }
/** * Create an AsciiLineReader of the appropriate type for a given InputStream. * @param inputStream An InputStream-derived class that implements BlockCompressedInputStream or PositionalBufferedStream * @return AsciiLineReader that wraps inputStream */ public static AsciiLineReader from(final InputStream inputStream) { if (inputStream instanceof BlockCompressedInputStream) { // For block compressed inputs, we need to ensure that no buffering takes place above the input stream to // ensure that the correct (virtual file pointer) positions returned from this stream are preserved for // the indexer. We can't used AsciiLineReader in this case since it wraps the input stream with a // PositionalBufferedInputStream. return new BlockCompressedAsciiLineReader((BlockCompressedInputStream) inputStream); } else if (inputStream instanceof PositionalBufferedStream) { // if this is already a PositionalBufferedStream, don't let AsciiLineReader wrap it with another one... return new AsciiLineReader((PositionalBufferedStream)inputStream); } else { log.warn("Creating an indexable source for an AsciiFeatureCodec using a stream that is " + "neither a PositionalBufferedStream nor a BlockCompressedInputStream"); return new AsciiLineReader(new PositionalBufferedStream(inputStream)); // wrap the stream in a PositionalBufferedStream } }
/** A VCFHeader is read from the input Path. */ public VCFRecordWriter( Path output, Path input, boolean writeHeader, TaskAttemptContext ctx) throws IOException { final AsciiLineReader r = new AsciiLineReader( input.getFileSystem(ctx.getConfiguration()).open(input)); final FeatureCodecHeader h = codec.readHeader(new AsciiLineReaderIterator(r)); if (h == null || !(h.getHeaderValue() instanceof VCFHeader)) throw new IOException("No VCF header found in "+ input); r.close(); init(output, (VCFHeader) h.getHeaderValue(), writeHeader, ctx); } public VCFRecordWriter(
/** A VCFHeader is read from the input Path. */ public VCFRecordWriter( Path output, Path input, boolean writeHeader, TaskAttemptContext ctx) throws IOException { final AsciiLineReader r = new AsciiLineReader( input.getFileSystem(ctx.getConfiguration()).open(input)); final FeatureCodecHeader h = codec.readHeader(new AsciiLineReaderIterator(r)); if (h == null || !(h.getHeaderValue() instanceof VCFHeader)) throw new IOException("No VCF header found in "+ input); r.close(); init(output, (VCFHeader) h.getHeaderValue(), writeHeader, ctx); } public VCFRecordWriter(
/** A VCFHeader is read from the input Path. */ public VCFRecordWriter( Path output, Path input, boolean writeHeader, TaskAttemptContext ctx) throws IOException { final AsciiLineReader r = new AsciiLineReader( input.getFileSystem(ctx.getConfiguration()).open(input)); final FeatureCodecHeader h = codec.readHeader(new AsciiLineReaderIterator(r)); if (h == null || !(h.getHeaderValue() instanceof VCFHeader)) throw new IOException("No VCF header found in "+ input); r.close(); init(output, (VCFHeader) h.getHeaderValue(), writeHeader, ctx); } public VCFRecordWriter(
@Test public void testContent() throws Exception { File testFile = new File(TestUtils.DATA_DIR + "igv/recombRate.ens.igv.txt"); AsciiLineReader reader = new AsciiLineReader(new FileInputStream(testFile)); BufferedReader br = new BufferedReader(new FileReader(testFile)); String arLine = null; int count = 0; while ((arLine = reader.readLine()) != null) { String brLine = br.readLine(); assertEquals(arLine, brLine); count++; } assertTrue(count > 0); }
/** returns the number of lines in the file that contain a regular expression (decorated with "MV=" and * expected to be in an INFO field in a vcf) * * @param file File to examine * @param regex String containing a regular expression to look for in the file * @return the number of lines that contain regex */ private int grep(final File file, final String regex) { int results = 0; final Pattern pattern = Pattern.compile(".*"+regex+".*"); try (final LineIteratorImpl li = new LineIteratorImpl(new AsciiLineReader(IOUtil.openFileForReading(file)))) { while (li.hasNext()) { final String line = li.next(); if (pattern.matcher(line).matches()) { results++; } } } catch (final IOException e) { e.printStackTrace(); } return results; }
/** * Returns either 1 or 2, representing the number of * bytes used to end a line. Reads only from first line of a file * * @param filePath * @return * @throws IOException */ public static int getBytesAtEnd(String filePath) throws IOException { InputStream is = new FileInputStream(filePath); AsciiLineReader reader = new AsciiLineReader(is); String line = reader.readLine(); int bytesThisLine = (int) reader.getPosition(); reader.close(); return bytesThisLine - line.length(); }
@Test(enabled = true) public void testCompressedVCFOutputWithNT() throws Exception { WalkerTestSpec spec = new WalkerTestSpec("-T UnifiedGenotyper -R " + b37KGReference + " -I " + privateTestDir + "PCRFree.2x250.Illumina.20_10_11.bam" + " -o %s -L 20:10,000,000-10,100,000 -nt 4", 1, Arrays.asList("vcf.gz"), Arrays.asList("")); final File vcf = executeTest("testCompressedVCFOutputWithNT", spec).first.get(0); final AsciiLineReader reader = new AsciiLineReader(new BlockCompressedInputStream(vcf)); int nLines = 0; while ( reader.readLine() != null ) nLines++; Assert.assertTrue(nLines > 0); }
@Test public void testSeek() throws Exception { String expectedLine = "chr22\t14000000\t15000000\trecombRate\t0.182272\t0.20444\t0.160104\t0\t0\t0\t0\t0\t0"; File testFile = new File(TestUtils.DATA_DIR + "igv/recombRate.igv.txt"); SeekableFileStream is = new SeekableFileStream(testFile); is.seek(149247); AsciiLineReader reader = new AsciiLineReader(is); String nextLine = reader.readLine(); assertEquals(expectedLine, nextLine); } }