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
25 import javax.xml.bind.annotation.XmlSeeAlso;
\r
27 import compbio.util.annotation.Immutable;
\r
30 * Multiple sequence alignment.
\r
32 * Does not give any guarantees on the content of individual FastaSequece
\r
33 * records. It does not guarantee neither the uniqueness of the names of
\r
34 * sequences nor it guarantees the uniqueness of the sequences.
\r
36 * @see FastaSequence
\r
37 * @see AlignmentMetadata
\r
41 * @version 1.0 September 2009
\r
44 @XmlSeeAlso({JpredAlignment.class})
\r
45 @XmlAccessorType(XmlAccessType.FIELD)
\r
46 public class Alignment {
\r
48 protected AlignmentMetadata metadata;
\r
49 protected List<FastaSequence> sequences;
\r
51 protected Alignment() {
\r
52 // This has to has a default constructor for JaxB
\r
60 public Alignment(List<FastaSequence> sequences, Program program,
\r
62 this.sequences = sequences;
\r
63 this.metadata = new AlignmentMetadata(program, gapchar);
\r
71 public Alignment(List<FastaSequence> sequences, AlignmentMetadata metadata) {
\r
72 this.sequences = sequences;
\r
73 this.metadata = metadata;
\r
78 * @return list of FastaSequence records
\r
80 public List<FastaSequence> getSequences() {
\r
86 * @return a number of sequence in the alignment
\r
88 public int getSize() {
\r
89 return this.sequences.size();
\r
94 * @return AlignmentMetadata object
\r
96 public AlignmentMetadata getMetadata() {
\r
101 public String toString() {
\r
103 for (FastaSequence fs : getSequences()) {
\r
104 sseq += fs.toString() + "\n";
\r
110 public int hashCode() {
\r
111 final int prime = 31;
\r
113 result = prime * result
\r
114 + ((metadata == null) ? 0 : metadata.hashCode());
\r
115 result = prime * result
\r
116 + ((sequences == null) ? 0 : sequences.hashCode());
\r
121 * Please note that this implementation does not take the order of sequences
\r
125 public boolean equals(Object obj) {
\r
129 if (!(obj instanceof Alignment)) {
\r
132 Alignment al = (Alignment) obj;
\r
133 if (this.getSize() != al.getSize()) {
\r
136 if (!this.getMetadata().equals(al.getMetadata())) {
\r
139 int outerCounter = 0;
\r
140 int matchCounter = 0;
\r
141 for (FastaSequence fs : getSequences()) {
\r
143 for (FastaSequence fs1 : al.getSequences()) {
\r
144 if (fs.equals(fs1)) {
\r
149 // Match for at lease one element was not found!
\r
150 if (outerCounter != matchCounter) {
\r