Package htsjdk.tribble.example
Class ExampleBinaryCodec
- All Implemented Interfaces:
FeatureCodec<Feature,
PositionalBufferedStream>
An example binary codec that encodes / decodes contig / start / stop values via DataInputStreams
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
This function returns true iff the File potentialInput can be parsed by this codec.static <FEATURE_TYPE extends Feature>
voidconvertToBinaryTest
(FeatureReader<FEATURE_TYPE> reader, OutputStream out) Convenience method that creates an ExampleBinaryCodec file from another feature file.static <FEATURE_TYPE extends Feature>
voidconvertToBinaryTest
(File source, File dest, FeatureCodec<FEATURE_TYPE, LineIterator> codec) Convenience method that creates an ExampleBinaryCodec file from another feature file.decode
(PositionalBufferedStream stream) Decode a singleFeature
from theFeatureCodec
, reading no further in the underlying source than beyond that feature.decodeLoc
(PositionalBufferedStream stream) Decode a line to obtain just its FeatureLoc for indexing -- contig, start, and stop.This function returns the object the codec generates.readHeader
(PositionalBufferedStream stream) Read and return the header, or null if there is no header.Methods inherited from class htsjdk.tribble.BinaryFeatureCodec
close, getTabixFormat, isDone, makeIndexableSourceFromStream, makeSourceFromStream
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface htsjdk.tribble.FeatureCodec
getPathToDataFile
-
Field Details
-
HEADER_LINE
- See Also:
-
-
Constructor Details
-
ExampleBinaryCodec
public ExampleBinaryCodec()
-
-
Method Details
-
decodeLoc
Description copied from interface:FeatureCodec
Decode a line to obtain just its FeatureLoc for indexing -- contig, start, and stop.- Parameters:
stream
- the input stream from which to decode the next record- Returns:
- Return the FeatureLoc encoded by the line, or null if the line does not represent a feature (e.g. is a comment)
- Throws:
IOException
-
decode
Description copied from interface:FeatureCodec
Decode a singleFeature
from theFeatureCodec
, reading no further in the underlying source than beyond that feature.- Parameters:
stream
- the input stream from which to decode the next record- Returns:
- Return the Feature encoded by the line, or null if the line does not represent a feature (e.g. is a comment)
- Throws:
IOException
-
readHeader
Description copied from interface:FeatureCodec
Read and return the header, or null if there is no header. Note: Implementers of this method must be careful to read exactly as much fromFeatureCodec
as needed to parse the header, and no more. Otherwise, data that might otherwise be fed into parsing aFeature
may be lost.- Parameters:
stream
- the source from which to decode the header- Returns:
- header object
- Throws:
IOException
-
getFeatureType
Description copied from interface:FeatureCodec
This function returns the object the codec generates. This is allowed to be Feature in the case where conditionally different types are generated. Be as specific as you can though.
This function is used by reflections based tools, so we can know the underlying type
- Returns:
- the feature type this codec generates.
-
canDecode
Description copied from interface:FeatureCodec
This function returns true iff the File potentialInput can be parsed by this codec. Note that checking the file's extension is a perfectly acceptable implementation of this method and file contents only rarely need to be checked.
There is an assumption that there's never a situation where two different Codecs return true for the same file. If this occurs, the recommendation would be to error out.
Note this function must never throw an error. All errors should be trapped and false returned.- Parameters:
path
- the file to test for parsability with this codec- Returns:
- true if potentialInput can be parsed, false otherwise
-
convertToBinaryTest
public static <FEATURE_TYPE extends Feature> void convertToBinaryTest(File source, File dest, FeatureCodec<FEATURE_TYPE, LineIterator> codec) throws IOExceptionConvenience method that creates an ExampleBinaryCodec file from another feature file. For testing purposes really- Parameters:
source
- file containing the featuresdest
- the place to write the binary featurescodec
- of the source file features- Throws:
IOException
-
convertToBinaryTest
public static <FEATURE_TYPE extends Feature> void convertToBinaryTest(FeatureReader<FEATURE_TYPE> reader, OutputStream out) throws IOException Convenience method that creates an ExampleBinaryCodec file from another feature file. For testing purposes really- Throws:
IOException
-