Package htsjdk.tribble.index
Class AbstractIndex
- java.lang.Object
-
- htsjdk.tribble.index.AbstractIndex
-
- All Implemented Interfaces:
Index
,MutableIndex
- Direct Known Subclasses:
IntervalTreeIndex
,LinearIndex
public abstract class AbstractIndex extends Object implements MutableIndex
An abstract implementation of the index class. This class takes care of the basics that are common to all of the current indexing classes; including the version information, common header properties, and reading and writing the header to disk.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
AbstractIndex.BlockStats
static class
AbstractIndex.IndexType
-
Field Summary
Fields Modifier and Type Field Description protected LinkedHashMap<String,ChrIndex>
chrIndices
the map of our chromosome binsprotected int
flags
protected String
indexedFileMD5
protected long
indexedFileSize
protected long
indexedFileTS
protected Path
indexedPath
protected Log
logger
static int
MAGIC_NUMBER
protected int
version
static int
VERSION
-
Constructor Summary
Constructors Constructor Description AbstractIndex()
create an abstract index, with defaults for the version value, and empty properties and chromosome listsAbstractIndex(AbstractIndex parent)
AbstractIndex(File featureFile)
AbstractIndex(String featureFile)
create an index file from the target feature fileAbstractIndex(Path featurePath)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addProperties(Map<String,String> properties)
void
addProperty(String key, String value)
boolean
containsChromosome(String chr)
boolean
equalsIgnoreProperties(Object obj)
Returns true if this and obj are 'effectively' equivalent indices.void
finalizeIndex()
List<Block>
getBlocks(String chr)
List<Block>
getBlocks(String chr, int start, int end)
Query the index.protected AbstractIndex.BlockStats
getBlockStats(boolean logDetails)
abstract Class
getChrIndexClass()
returns the class for the index typeint
getFlags()
File
getIndexedFile()
Deprecated.on 03/2017.String
getIndexedFileMD5()
long
getIndexedFileSize()
long
getIndexedFileTS()
Path
getIndexedPath()
Map<String,String>
getProperties()
return a mapping of name to property valueList<String>
getSequenceNames()
protected abstract int
getType()
get the index typeint
getVersion()
boolean
hasFileSize()
boolean
hasMD5()
boolean
hasTimestamp()
boolean
isCurrentVersion()
check the current version against the version we read inprotected void
printIndexInfo()
void
read(LittleEndianInputStream dis)
void
setMD5(String md5)
protected String
statsSummary()
protected void
validateIndexHeader(int indexType, LittleEndianInputStream dis)
void
write(LittleEndianOutputStream stream)
all indexes are writable to diskvoid
write(Path idxPath)
Writes the index into a path.void
writeBasedOnFeaturePath(Path featurePath)
Write an appropriately named and located Index file based on the name and location of the featureFile.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface htsjdk.tribble.index.Index
write, writeBasedOnFeatureFile
-
-
-
-
Field Detail
-
VERSION
public static final int VERSION
- See Also:
- Constant Field Values
-
MAGIC_NUMBER
public static final int MAGIC_NUMBER
- See Also:
- Constant Field Values
-
version
protected int version
-
indexedPath
protected Path indexedPath
-
indexedFileSize
protected long indexedFileSize
-
indexedFileTS
protected long indexedFileTS
-
indexedFileMD5
protected String indexedFileMD5
-
flags
protected int flags
-
logger
protected final Log logger
-
chrIndices
protected LinkedHashMap<String,ChrIndex> chrIndices
the map of our chromosome bins
-
-
Constructor Detail
-
AbstractIndex
public AbstractIndex()
create an abstract index, with defaults for the version value, and empty properties and chromosome lists
-
AbstractIndex
public AbstractIndex(String featureFile)
create an index file from the target feature file- Parameters:
featureFile
- the feature file to create an index from
-
AbstractIndex
public AbstractIndex(File featureFile)
-
AbstractIndex
public AbstractIndex(Path featurePath)
-
AbstractIndex
public AbstractIndex(AbstractIndex parent)
-
-
Method Detail
-
hasFileSize
public boolean hasFileSize()
-
hasTimestamp
public boolean hasTimestamp()
-
hasMD5
public boolean hasMD5()
-
equalsIgnoreProperties
public boolean equalsIgnoreProperties(Object obj)
Description copied from interface:Index
Returns true if this and obj are 'effectively' equivalent indices. Ignores the time stamp on the file, as this may not be the same for even identical indices- Specified by:
equalsIgnoreProperties
in interfaceIndex
- Parameters:
obj
-- Returns:
- true if this and obj are 'effectively' equivalent data structures.
-
validateIndexHeader
protected void validateIndexHeader(int indexType, LittleEndianInputStream dis) throws IOException
- Throws:
IOException
-
isCurrentVersion
public boolean isCurrentVersion()
check the current version against the version we read in- Specified by:
isCurrentVersion
in interfaceIndex
- Returns:
- true if we're up to date, false otherwise
-
getIndexedFile
@Deprecated public File getIndexedFile()
Deprecated.on 03/2017. UsegetIndexedPath()
instead.Gets the indexed file.- Throws:
UnsupportedOperationException
- if the path cannot be represented as a file.
-
getIndexedPath
public Path getIndexedPath()
-
getIndexedFileSize
public long getIndexedFileSize()
-
getIndexedFileTS
public long getIndexedFileTS()
-
getIndexedFileMD5
public String getIndexedFileMD5()
-
getFlags
public int getFlags()
-
getVersion
public int getVersion()
-
setMD5
public void setMD5(String md5)
-
containsChromosome
public boolean containsChromosome(String chr)
- Specified by:
containsChromosome
in interfaceIndex
- Parameters:
chr
- the chromosome (or contig) name- Returns:
- true if we have an entry; false otherwise
-
finalizeIndex
public void finalizeIndex()
-
getSequenceNames
public List<String> getSequenceNames()
- Specified by:
getSequenceNames
in interfaceIndex
- Returns:
- a list of the sequence names we've seen during indexing, in order
-
getBlocks
public List<Block> getBlocks(String chr, int start, int end)
Description copied from interface:Index
Query the index.
-
write
public void write(LittleEndianOutputStream stream) throws IOException
Description copied from interface:Index
all indexes are writable to disk- Specified by:
write
in interfaceIndex
- Parameters:
stream
- the stream to write the index to. Caller must close after invocation.- Throws:
IOException
- if the index is unable to write to the specified location
-
write
public void write(Path idxPath) throws IOException
Description copied from interface:Index
Writes the index into a path.- Specified by:
write
in interfaceIndex
- Parameters:
idxPath
- Where to write the index.- Throws:
IOException
- if the index is unable to write to the specified path.
-
writeBasedOnFeaturePath
public void writeBasedOnFeaturePath(Path featurePath) throws IOException
Description copied from interface:Index
Write an appropriately named and located Index file based on the name and location of the featureFile. If featureFile is not a normal file, the index will silently not be written.- Specified by:
writeBasedOnFeaturePath
in interfaceIndex
- Throws:
IOException
- if featureFile is not a normal file.
-
read
public void read(LittleEndianInputStream dis) throws IOException
- Throws:
IOException
-
printIndexInfo
protected void printIndexInfo()
-
getBlockStats
protected AbstractIndex.BlockStats getBlockStats(boolean logDetails)
-
statsSummary
protected String statsSummary()
-
addProperty
public void addProperty(String key, String value)
- Specified by:
addProperty
in interfaceMutableIndex
-
addProperties
public void addProperties(Map<String,String> properties)
- Specified by:
addProperties
in interfaceMutableIndex
-
getProperties
public Map<String,String> getProperties()
return a mapping of name to property value- Specified by:
getProperties
in interfaceIndex
- Returns:
- the mapping of values as an unmodifiable map
-
getType
protected abstract int getType()
get the index type- Returns:
- The index type
-
getChrIndexClass
public abstract Class getChrIndexClass()
returns the class for the index type- Returns:
- a Class, from which a new instance can be created
-
-