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 * Created on 01-21-2010
021 */
022package org.biojava.nbio.core.sequence.io;
023
024import org.biojava.nbio.core.sequence.AccessionID;
025import org.biojava.nbio.core.sequence.io.template.SequenceHeaderParserInterface;
026import org.biojava.nbio.core.sequence.template.AbstractSequence;
027import org.biojava.nbio.core.sequence.template.Compound;
028
029/**
030 * The plain fasta header takes everything in the header as a single entity. It
031 * is useful for non-standard header formats that don't follow a single rule.<br>
032 * If the user has a custom header with local data that is kept constant all
033 * over the data then they can create their own implementation of a
034 * FastaHeaderParserInterface
035 *
036 * @author Amr ALHOSSARY
037 * @since 3.0.6
038 */
039public class PlainFastaHeaderParser<S extends AbstractSequence<C>, C extends Compound>
040                implements SequenceHeaderParserInterface<S, C> {
041
042        /**
043         * Parse out the all header as one entity
044         *
045         * @param header
046         * @return
047         */
048        private String[] getHeaderValues(String header) {
049                return new String[] { header };
050        }
051
052        /**
053         * Parse the header and set the values in the sequence
054         *
055         * @param header
056         * @param sequence
057         */
058        @Override
059        public void parseHeader(String header, S sequence) {
060                sequence.setOriginalHeader(header);
061                String[] data = getHeaderValues(header);
062
063                if (data.length == 1) {
064                        sequence.setAccession(new AccessionID(data[0]));
065                } else {
066                        throw new RuntimeException(
067                                        "No header or Some Error Occurred while reading header");
068                }
069        }
070}