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 java.lang.ObjectEmblCDROMRandomAccessis 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 suppliedRecordParserand calling the appropriate method on it.- Since:
- 1.2
- Author:
- Keith James
-
-
Field Summary
Fields Modifier and Type Field Description protected java.io.RandomAccessFileraIndexFileprotected byte[]recBytesprotected org.biojava.bio.seq.db.emblcd.RecordParserrecParserArecParserfor implementingreadRecord()specific to each concrete subclass.
-
Constructor Summary
Constructors Constructor Description EmblCDROMRandomAccess(java.io.File indexFile, int headerLength, int recordLength, long recordCount)Creates a newEmblCDROMRandomAccessobject.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidclose()closecloses the underlyingRandomAccessFile.java.lang.Object[]findRecord(java.lang.String identifier)findRecordperforms a binary search within the file for a record specified by an identifier String.java.io.FilegetFile()getFilereturns theFilewrapped.protected abstract java.lang.StringgetRecordKey(java.lang.Object[] record)getRecordKeyreturns the field from the record on which the records were sorted in the index.protected abstract java.lang.Object[]readRecord()readRecordreturns an array of objects parsed from a single record.
-
-
-
Constructor Detail
-
EmblCDROMRandomAccess
public EmblCDROMRandomAccess(java.io.File indexFile, int headerLength, int recordLength, long recordCount) throws java.io.FileNotFoundExceptionCreates a newEmblCDROMRandomAccessobject.- Parameters:
indexFile- aFileto wrap.headerLength- anint(normally 300 bytes).recordLength- anintindicating the length of a single record.recordCount- anlongindicating the total number of records.- Throws:
java.io.FileNotFoundException- if indexFile cannot be found.
-
-
Method Detail
-
getFile
public java.io.File getFile()
getFilereturns theFilewrapped.- Returns:
- a
File.
-
findRecord
public java.lang.Object[] findRecord(java.lang.String identifier) throws java.io.IOExceptionfindRecordperforms a binary search within the file for a record specified by an identifier String.- Parameters:
identifier- aStringidentifier (sequence ID or accession number).- Returns:
- an
Object []array containing the record. If there is no such record an empty array is returned. - Throws:
java.io.IOException- if an error occurs.
-
close
public void close() throws java.io.IOExceptionclosecloses the underlyingRandomAccessFile.- Throws:
java.io.IOException- if an error occurs.
-
readRecord
protected abstract java.lang.Object[] readRecord() throws java.io.IOExceptionreadRecordreturns 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:
java.io.IOException- if an error occurs.
-
getRecordKey
protected abstract java.lang.String getRecordKey(java.lang.Object[] record)
getRecordKeyreturns the field from the record on which the records were sorted in the index. (i.e. sequence ID or accession number).- Returns:
- a
String.
-
-