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     */
022    package org.biojava3.core.sequence.io;
023    
024    import org.biojava3.core.sequence.AccessionID;
025    import org.biojava3.core.sequence.io.template.FastaHeaderFormatInterface;
026    import org.biojava3.core.sequence.template.AbstractSequence;
027    import org.biojava3.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     */
037    public class GenericFastaHeaderFormat<S extends AbstractSequence<?>, C extends Compound> implements FastaHeaderFormatInterface<S, C> {
038    
039        public String getHeader(S sequence) {
040            String header = "";
041    
042            if (sequence.getOriginalHeader() != null && sequence.getOriginalHeader().length() > 0) {
043                header = sequence.getOriginalHeader();
044            } else {
045                AccessionID accessionID = sequence.getAccession();
046                if (accessionID != null) {
047                    header = accessionID.getID();
048                }
049            }
050    
051            return header;
052        }
053    }