1 /* Copyright (c) 2009 Peter Troshin
\r
2 * Copyright (c) 2013 Alexander Sherstnev
\r
4 * JAva Bioinformatics Analysis Web Services (JABAWS) @version: 1.0
\r
6 * This library is free software; you can redistribute it and/or modify it under the terms of the
\r
7 * Apache License version 2 as published by the Apache Software Foundation
\r
9 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
\r
10 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Apache
\r
11 * License for more details.
\r
13 * A copy of the license is in apache_license.txt. It is also available here:
\r
14 * @see: http://www.apache.org/licenses/LICENSE-2.0.txt
\r
16 * Any republication or derived work distributed in source code form
\r
17 * must include this copyright and license notice.
\r
20 package compbio.data.sequence;
\r
22 import java.util.List;
\r
23 import java.util.ArrayList;
\r
25 import javax.xml.bind.annotation.XmlAccessType;
\r
26 import javax.xml.bind.annotation.XmlAccessorType;
\r
28 import compbio.util.annotation.Immutable;
\r
29 import compbio.data.sequence.Alignment;
\r
31 * Multiple sequence alignment and Jpred prediction.
\r
33 * Does not give any guarantees on the content of individual FastaSequece
\r
34 * records. It does not guarantee neither the uniqueness of the names of
\r
35 * sequences nor it guarantees the uniqueness of the sequences.
\r
37 * @see FastaSequence
\r
38 * @see AlignmentMetadata
\r
42 * @version 1.0 September 2009
\r
45 @XmlAccessorType(XmlAccessType.FIELD)
\r
47 public final class JpredAlignment extends Alignment{
\r
49 private AlignmentMetadata metadata;
\r
50 private List<FastaSequence> sequences;
\r
52 FastaSequence jnetpred;
\r
53 FastaSequence JNETCONF;
\r
54 FastaSequence JNETSOL25;
\r
55 FastaSequence JNETSOL5;
\r
56 FastaSequence JNETSOL0;
\r
57 FastaSequence JNETHMM;
\r
58 FastaSequence JNETPSSM;
\r
59 FastaSequence JNETJURY;
\r
61 private JpredAlignment() {
\r
62 // This has to has a default constructor for JaxB
\r
70 public JpredAlignment(List<FastaSequence> sequences, Program program,
\r
72 DecomposeInitalJpredSeq(sequences);
\r
73 this.metadata = new AlignmentMetadata(Program.CLUSTAL, gapchar);
\r
81 public JpredAlignment(List<FastaSequence> sequences, AlignmentMetadata metadata) {
\r
82 DecomposeInitalJpredSeq(sequences);
\r
83 this.metadata = metadata;
\r
90 private void DecomposeInitalJpredSeq(List<FastaSequence> sequences) {
\r
91 List<FastaSequence> realsequences = new ArrayList<FastaSequence>();
\r
92 for (FastaSequence s : sequences) {
\r
93 if (s.getId().equals("jnetpred")) {
\r
95 } else if (s.getId().equals("JNETCONF")) {
\r
97 } else if (s.getId().equals("JNETSOL25")) {
\r
99 } else if (s.getId().equals("JNETSOL5")) {
\r
101 } else if (s.getId().equals("JNETSOL0")) {
\r
103 } else if (s.getId().equals("JNETHMM")) {
\r
105 } else if (s.getId().equals("JNETHMM")) {
\r
107 } else if (s.getId().equals("JNETSOL0")) {
\r
109 } else if (s.getId().equals("JNETHMM")) {
\r
112 realsequences.add(s);
\r
115 this.sequences = realsequences;
\r
120 * @return Jpred prediction
\r
122 public String getJpredPrediction() {
\r
123 return this.jnetpred.getSequence();
\r
128 * @return Jpred JNETSOL25 line
\r
130 public String getJpredSOL25() {
\r
131 return this.JNETSOL25.getSequence();
\r
136 * @return Jpred JNETSOL5 line
\r
138 public String getJpredSOL5() {
\r
139 return this.JNETSOL5.getSequence();
\r
143 * @return Jpred JNETSOL0 line
\r
145 public String getJpredSOL0() {
\r
146 return this.JNETSOL0.getSequence();
\r
150 * @return Jpred JNETCONF line
\r
152 public String getJpredJNETCONF() {
\r
153 return this.JNETCONF.getSequence();
\r
157 * @return list of FastaSequence records
\r
159 public List<FastaSequence> getSequences() {
\r
165 * @return a number of sequence in the alignment
\r
167 public int getSize() {
\r
168 return this.sequences.size();
\r
173 * @return AlignmentMetadata object
\r
175 public AlignmentMetadata getMetadata() {
\r
180 public String toString() {
\r
182 for (FastaSequence fs : getSequences()) {
\r
183 sseq += fs.toString() + "\n";
\r
189 public int hashCode() {
\r
190 final int prime = 31;
\r
192 result = prime * result
\r
193 + ((metadata == null) ? 0 : metadata.hashCode());
\r
194 result = prime * result
\r
195 + ((sequences == null) ? 0 : sequences.hashCode());
\r
200 * Please note that this implementation does not take the order of sequences
\r
204 public boolean equals(Object obj) {
\r
208 if (!(obj instanceof Alignment)) {
\r
211 Alignment al = (Alignment) obj;
\r
212 if (this.getSize() != al.getSize()) {
\r
215 if (!this.getMetadata().equals(al.getMetadata())) {
\r
218 int outerCounter = 0;
\r
219 int matchCounter = 0;
\r
220 for (FastaSequence fs : getSequences()) {
\r
222 for (FastaSequence fs1 : al.getSequences()) {
\r
223 if (fs.equals(fs1)) {
\r
228 // Match for at lease one element was not found!
\r
229 if (outerCounter != matchCounter) {
\r