Package org.biojava.bio.seq.db.emblcd
Class EmblCDROMRandomAccess
- java.lang.Object
-
- org.biojava.bio.seq.db.emblcd.EmblCDROMRandomAccess
-
- Direct Known Subclasses:
EntryNamRandomAccess
public abstract class EmblCDROMRandomAccess extends Object
EmblCDROMRandomAccess
is an abstract class whose concrete subclasses can perform fast lookups in EMBL CD-ROM format index files. As the format of the records varies between file types, subclasses should implement two methods;readRecord()
, which should parse the record into an array of objects andgetRecordKey()
which should retrieve the the field from the parsed record on which the records were sorted in the index. This is used during the binary search in thefindRecord()
method.Implementing
readRecord()
is easy because it simply means delegating to the suppliedRecordParser
and calling the appropriate method on it.- Since:
- 1.2
- Author:
- Keith James
-
-
Field Summary
Fields Modifier and Type Field Description protected RandomAccessFile
raIndexFile
protected byte[]
recBytes
protected org.biojava.bio.seq.db.emblcd.RecordParser
recParser
ArecParser
for implementingreadRecord()
specific to each concrete subclass.
-
Constructor Summary
Constructors Constructor Description EmblCDROMRandomAccess(File indexFile, int headerLength, int recordLength, long recordCount)
Creates a newEmblCDROMRandomAccess
object.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
close()
close
closes the underlyingRandomAccessFile
.Object[]
findRecord(String identifier)
findRecord
performs a binary search within the file for a record specified by an identifier String.File
getFile()
getFile
returns theFile
wrapped.protected abstract String
getRecordKey(Object[] record)
getRecordKey
returns the field from the record on which the records were sorted in the index.protected abstract Object[]
readRecord()
readRecord
returns an array of objects parsed from a single record.
-
-
-
Field Detail
-
raIndexFile
protected RandomAccessFile raIndexFile
-
recParser
protected org.biojava.bio.seq.db.emblcd.RecordParser recParser
ArecParser
for implementingreadRecord()
specific to each concrete subclass.
-
recBytes
protected byte[] recBytes
-
-
Constructor Detail
-
EmblCDROMRandomAccess
public EmblCDROMRandomAccess(File indexFile, int headerLength, int recordLength, long recordCount) throws FileNotFoundException
Creates a newEmblCDROMRandomAccess
object.- Parameters:
indexFile
- aFile
to wrap.headerLength
- anint
(normally 300 bytes).recordLength
- anint
indicating the length of a single record.recordCount
- anlong
indicating the total number of records.- Throws:
FileNotFoundException
- if indexFile cannot be found.
-
-
Method Detail
-
findRecord
public Object[] findRecord(String identifier) throws IOException
findRecord
performs a binary search within the file for a record specified by an identifier String.- Parameters:
identifier
- aString
identifier (sequence ID or accession number).- Returns:
- an
Object []
array containing the record. If there is no such record an empty array is returned. - Throws:
IOException
- if an error occurs.
-
close
public void close() throws IOException
close
closes the underlyingRandomAccessFile
.- Throws:
IOException
- if an error occurs.
-
readRecord
protected abstract Object[] readRecord() throws IOException
readRecord
returns an array of objects parsed from a single record. Its content will depend on the type of index file. Concrete subclasses must provide an implementation of this method.- Returns:
- an
Object []
array. - Throws:
IOException
- if an error occurs.
-
getRecordKey
protected abstract String getRecordKey(Object[] record)
getRecordKey
returns the field from the record on which the records were sorted in the index. (i.e. sequence ID or accession number).- Returns:
- a
String
.
-
-