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
44 public class Alignment {
\r
46 protected AlignmentMetadata metadata;
\r
47 protected List<FastaSequence> sequences;
\r
49 protected Alignment() {
\r
50 // This has to has a default constructor for JaxB
\r
58 public Alignment(List<FastaSequence> sequences, Program program,
\r
60 this.sequences = sequences;
\r
61 this.metadata = new AlignmentMetadata(Program.CLUSTAL, gapchar);
\r
69 public Alignment(List<FastaSequence> sequences, AlignmentMetadata metadata) {
\r
70 this.sequences = sequences;
\r
71 this.metadata = metadata;
\r
76 * @return list of FastaSequence records
\r
78 public List<FastaSequence> getSequences() {
\r
84 * @return a number of sequence in the alignment
\r
86 public int getSize() {
\r
87 return this.sequences.size();
\r
92 * @return AlignmentMetadata object
\r
94 public AlignmentMetadata getMetadata() {
\r
99 public String toString() {
\r
101 for (FastaSequence fs : getSequences()) {
\r
102 sseq += fs.toString() + "\n";
\r
108 public int hashCode() {
\r
109 final int prime = 31;
\r
111 result = prime * result
\r
112 + ((metadata == null) ? 0 : metadata.hashCode());
\r
113 result = prime * result
\r
114 + ((sequences == null) ? 0 : sequences.hashCode());
\r
119 * Please note that this implementation does not take the order of sequences
\r
123 public boolean equals(Object obj) {
\r
127 if (!(obj instanceof Alignment)) {
\r
130 Alignment al = (Alignment) obj;
\r
131 if (this.getSize() != al.getSize()) {
\r
134 if (!this.getMetadata().equals(al.getMetadata())) {
\r
137 int outerCounter = 0;
\r
138 int matchCounter = 0;
\r
139 for (FastaSequence fs : getSequences()) {
\r
141 for (FastaSequence fs1 : al.getSequences()) {
\r
142 if (fs.equals(fs1)) {
\r
147 // Match for at lease one element was not found!
\r
148 if (outerCounter != matchCounter) {
\r