001/*
002 *                    BioJava development code
003 *
004 * This code may be freely distributed and modified under the
005 * terms of the GNU Lesser General Public Licence.  This should
006 * be distributed with the code.  If you do not have a copy,
007 * see:
008 *
009 *      http://www.gnu.org/copyleft/lesser.html
010 *
011 * Copyright for this code is held jointly by the individual
012 * authors.  These should be listed in @author doc comments.
013 *
014 * For more information on the BioJava project and its aims,
015 * or to join the biojava-l mailing list, visit the home page
016 * at:
017 *
018 *      http://www.biojava.org/
019 *
020 */
021
022package org.biojava.bio.seq.db.emblcd;
023
024import java.io.File;
025import java.io.FileNotFoundException;
026import java.io.IOException;
027
028/**
029 * <code>EntryNamRandomAccess</code> objects provide random access to
030 * records within the "entrynam.idx" file of an EMBL CD-ROM format
031 * binary index. Records are retrieved by their sequence ID.
032 *
033 * @author Keith James
034 * @since 1.2
035 */
036public class EntryNamRandomAccess extends EmblCDROMRandomAccess
037{
038    public EntryNamRandomAccess(File indexFile,
039                                int  headerLength,
040                                int  recordLength,
041                                long recordCount)
042        throws FileNotFoundException
043    {
044        super(indexFile, headerLength, recordLength, recordCount);
045    }
046
047    /**
048     * <code>readRecord</code> creates an array of Objects from the
049     * raw byte array of a single record. For this file type the array
050     * contains <code>String seqID, Long rPosition, Long sPosition,
051     * Integer fileNumber</code>. See EMBOSS documentation for a full
052     * description.
053     *
054     * @return an <code>Object []</code> array.
055     *
056     * @exception IOException if an error occurs.
057     */
058    protected Object [] readRecord() throws IOException
059    {
060        int eof = raIndexFile.read(recBytes);
061        if (eof == -1)
062            raIndexFile.close();
063
064        return recParser.parseEntryNamRecord(recBytes);
065    }
066
067    /**
068     * <code>getRecordKey</code> returns the field from the record on
069     * which the records were sorted in the index. (i.e. sequence ID
070     * or accession number).
071     *
072     * @return a <code>String</code>.
073     */
074    protected String getRecordKey(Object [] record)
075    {
076        return (String) record[0];
077    }
078}