/** * @see org.broad.tribble.index.linear.LinearIndex#optimize(double) * @param featureInput File containing features * @param codec Codec used to read the features * @param optimizeThreshold Threshold used to optimize the linear index * @return */ public static long runWithIndex(File featureInput, FeatureCodec codec, int optimizeThreshold) { // get an index Index index = loadIndex(featureInput, codec); if (optimizeThreshold != -1) ((LinearIndex) index).optimize(optimizeThreshold); // get a reader AbstractFeatureReader reader = null; try { reader = AbstractFeatureReader.getFeatureReader(featureInput.getAbsolutePath(), codec, index); // now read iterate over the file long recordCount = 0l; // this call could be replaced with a query Iterator<Feature> iter = reader.iterator(); // cycle through the iterators while (iter.hasNext()) { Feature feat = iter.next(); ++recordCount; } System.err.println("We saw " + recordCount + " record in file " + featureInput); return recordCount; } catch (IOException e) { throw new RuntimeException( "Something went wrong while reading feature file " + featureInput, e); } }
public void mergeInto(VariantContextWriterStorage target) { try { if (!closed) throw new ReviewedStingException("Writer not closed, but we are merging into the file!"); final String targetFilePath = target.file != null ? target.file.getAbsolutePath() : "/dev/stdin"; logger.debug( String.format( "Merging VariantContextWriterStorage from %s into %s", file.getAbsolutePath(), targetFilePath)); // use the feature manager to determine the right codec for the tmp file // that way we don't assume it's a specific type final FeatureManager.FeatureDescriptor fd = new FeatureManager().getByFiletype(file); if (fd == null) throw new UserException.LocalParallelizationProblem(file); final FeatureCodec codec = fd.getCodec(); final AbstractFeatureReader<Feature, ?> source = AbstractFeatureReader.getFeatureReader(file.getAbsolutePath(), codec, false); for (final Feature vc : source.iterator()) { target.writer.add((VariantContext) vc); } source.close(); file.delete(); // this should be last to aid in debugging when the process fails } catch (IOException e) { throw new UserException.CouldNotReadInputFile( file, "Error reading file in VCFWriterStorage: ", e); } }