1 /* Copyright (c) 2009 Peter Troshin
\r
3 * JAva Bioinformatics Analysis Web Services (JABAWS) @version: 1.0
\r
5 * This library is free software; you can redistribute it and/or modify it under the terms of the
\r
6 * Apache License version 2 as published by the Apache Software Foundation
\r
8 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
\r
9 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Apache
\r
10 * License for more details.
\r
12 * A copy of the license is in apache_license.txt. It is also available here:
\r
13 * @see: http://www.apache.org/licenses/LICENSE-2.0.txt
\r
15 * Any republication or derived work distributed in source code form
\r
16 * must include this copyright and license notice.
\r
19 package compbio.data.sequence;
\r
21 import java.util.List;
\r
23 import javax.xml.bind.annotation.XmlAccessType;
\r
24 import javax.xml.bind.annotation.XmlAccessorType;
\r
26 import compbio.util.annotation.Immutable;
\r
29 * Multiple sequence alignment.
\r
31 * Does not give any guarantees on the content of individual FastaSequece
\r
32 * records. It does not guarantee neither the uniqueness of the names of
\r
33 * sequences nor it guarantees the uniqueness of the sequences.
\r
35 * @see FastaSequence
\r
36 * @see AlignmentMetadata
\r
40 * @version 1.0 September 2009
\r
43 @XmlAccessorType(XmlAccessType.FIELD)
\r
45 public final class Alignment {
\r
47 private AlignmentMetadata metadata;
\r
48 private List<FastaSequence> sequences;
\r
50 private Alignment() {
\r
51 // This has to has a default constructor for JaxB
\r
59 public Alignment(List<FastaSequence> sequences, Program program,
\r
61 this.sequences = sequences;
\r
62 this.metadata = new AlignmentMetadata(Program.CLUSTAL, gapchar);
\r
70 public Alignment(List<FastaSequence> sequences, AlignmentMetadata metadata) {
\r
71 this.sequences = sequences;
\r
72 this.metadata = metadata;
\r
77 * @return list of FastaSequence records
\r
79 public List<FastaSequence> getSequences() {
\r
85 * @return a number of sequence in the alignment
\r
87 public int getSize() {
\r
88 return this.sequences.size();
\r
93 * @return AlignmentMetadata object
\r
95 public AlignmentMetadata getMetadata() {
\r
100 public String toString() {
\r
102 for (FastaSequence fs : getSequences()) {
\r
103 sseq += fs.toString() + "\n";
\r
109 public int hashCode() {
\r
110 final int prime = 31;
\r
112 result = prime * result
\r
113 + ((metadata == null) ? 0 : metadata.hashCode());
\r
114 result = prime * result
\r
115 + ((sequences == null) ? 0 : sequences.hashCode());
\r
120 * Please note that this implementation does not take the order of sequences
\r
124 public boolean equals(Object obj) {
\r
128 if (!(obj instanceof Alignment)) {
\r
131 Alignment al = (Alignment) obj;
\r
132 if (this.getSize() != al.getSize()) {
\r
135 if (!this.getMetadata().equals(al.getMetadata())) {
\r
138 int outerCounter = 0;
\r
139 int matchCounter = 0;
\r
140 for (FastaSequence fs : getSequences()) {
\r
142 for (FastaSequence fs1 : al.getSequences()) {
\r
143 if (fs.equals(fs1)) {
\r
148 // Match for at lease one element was not found!
\r
149 if (outerCounter != matchCounter) {
\r