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.FastaHeaderFormatInterface;
026import org.biojava.nbio.core.sequence.template.AbstractSequence;
027import org.biojava.nbio.core.sequence.template.Compound;
028
029/**
030 * We store the original header if the sequence is parsed from a fasta file and will use that exact
031 * sequence if we write out the sequences to a fasta file. If we don't have an orginal header then
032 * use the accession id. This allows the implementation by the user to write out complex header
033 * with id notes etc without rewriting the fasta writer
034 *
035 * @author Scooter Willis <willishf at gmail dot com>
036 */
037public class GenericFastaHeaderFormat<S extends AbstractSequence<?>, C extends Compound> implements FastaHeaderFormatInterface<S, C> {
038
039        @Override
040        public String getHeader(S sequence) {
041                String header = "";
042
043                if (sequence.getOriginalHeader() != null && sequence.getOriginalHeader().length() > 0) {
044                        header = sequence.getOriginalHeader();
045                } else {
046                        AccessionID accessionID = sequence.getAccession();
047                        if (accessionID != null) {
048                                header = accessionID.getID();
049                        }
050                }
051
052                return header;
053        }
054}