    001    package calhoun.seq;
    002
    003    import java.io.Serializable;
    004
    005    import calhoun.util.Assert;
    006
    007    public class SimpleFastaSequence implements FastaSequence, Serializable {
    008            private static final long serialVersionUID = 3541355741077645447L;
    009            String header;
    010            private String sequence;
    011            private byte [] quality = null;
    012
    013            public SimpleFastaSequence() {
    014
    015            }
    016
    017            public SimpleFastaSequence(String header, String sequence) {
    018                    this.header = header;
    019                    this.sequence = sequence;
    020            }
    021
    022            public void setHeader(String s) {
    023                    header = s;
    024            }
    025
    026            public void setSequence(String s) {
    027                    if(quality != null && s != null) {
    028                            Integer sl = new Integer(s.length());
    029                            Integer ql = new Integer(quality.length);
    030                            Assert.a(sl.equals(ql), "Quality (",ql,") and sequence (",sl,") for ",header==null?"":header," are not the same size.");
    031                    }
    032                    sequence = s;
    033            }
    034
    035            public String getHeader() {
    036                    return header;
    037            }
    038
    039            public boolean hasSequence() {
    040                    return sequence != null;
    041            }
    042
    043            public boolean hasQuality() {
    044                    return quality != null;
    045            }
    046
    047            public String getSequence() {
    048                    return sequence;
    049            }
    050
    051            public String getSequence(int start, int stop) {
    052                    Assert.a(sequence != null, "No sequence available for ", header);
    053                    return sequence.substring(start-1, stop);
    054            }
    055
    056            public int getLength() {
    057                    if(sequence != null) {
    058                            return sequence.length();
    059                    }
    060                    else {
    061                            Assert.a(quality != null, "No sequence or quality available for ", header);
    062                            return quality.length;
    063                    }
    064            }
    065
    066            public byte[] getQuality() {
    067                    return quality;
    068            }
    069
    070            public void setQuality(byte [] q) {
    071                    if(q != null && sequence != null) {
    072                            Assert.a(sequence.length() == q.length, header, ": Quality (",new Integer(q.length),") and sequence (",new Integer(sequence.length()),") for ",header," are not the same size.");
    073                    }
    074                    quality = q;
    075            }
    076    }