+/* Copyright (c) 2009 Peter Troshin\r
+ * Copyright (c) 2013 Alexander Sherstnev\r
+ * \r
+ * JAva Bioinformatics Analysis Web Services (JABAWS) @version: 1.0\r
+ * \r
+ * This library is free software; you can redistribute it and/or modify it under the terms of the\r
+ * Apache License version 2 as published by the Apache Software Foundation\r
+ * \r
+ * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without\r
+ * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Apache \r
+ * License for more details.\r
+ * \r
+ * A copy of the license is in apache_license.txt. It is also available here:\r
+ * @see: http://www.apache.org/licenses/LICENSE-2.0.txt\r
+ * \r
+ * Any republication or derived work distributed in source code form\r
+ * must include this copyright and license notice.\r
+ */\r
+\r
+package compbio.data.sequence;\r
+\r
+import java.util.List;\r
+import java.util.ArrayList;\r
+\r
+import javax.xml.bind.annotation.XmlAccessType;\r
+import javax.xml.bind.annotation.XmlAccessorType;\r
+\r
+import compbio.util.annotation.Immutable;\r
+import compbio.data.sequence.Alignment;\r
+/**\r
+ * Multiple sequence alignment and Jpred prediction.\r
+ * \r
+ * Does not give any guarantees on the content of individual FastaSequece\r
+ * records. It does not guarantee neither the uniqueness of the names of\r
+ * sequences nor it guarantees the uniqueness of the sequences.\r
+ * \r
+ * @see FastaSequence\r
+ * @see AlignmentMetadata\r
+ * \r
+ * @author pvtroshin\r
+ * \r
+ * @version 1.0 September 2009\r
+ * \r
+ */\r
+@XmlAccessorType(XmlAccessType.FIELD)\r
+@Immutable\r
+public final class JpredAlignment extends Alignment{\r
+\r
+ private AlignmentMetadata metadata;\r
+ private List<FastaSequence> sequences;\r
+ \r
+ FastaSequence jnetpred;\r
+ FastaSequence JNETCONF;\r
+ FastaSequence JNETSOL25;\r
+ FastaSequence JNETSOL5;\r
+ FastaSequence JNETSOL0;\r
+ FastaSequence JNETHMM;\r
+ FastaSequence JNETPSSM;\r
+ FastaSequence JNETJURY;\r
+\r
+ private JpredAlignment() {\r
+ // This has to has a default constructor for JaxB\r
+ }\r
+\r
+ /**\r
+ * @param sequences\r
+ * @param program\r
+ * @param gapchar\r
+ */\r
+ public JpredAlignment(List<FastaSequence> sequences, Program program,\r
+ char gapchar) {\r
+ DecomposeInitalJpredSeq(sequences);\r
+ this.metadata = new AlignmentMetadata(Program.CLUSTAL, gapchar);\r
+ }\r
+\r
+ /**\r
+ * \r
+ * @param sequences\r
+ * @param metadata\r
+ */\r
+ public JpredAlignment(List<FastaSequence> sequences, AlignmentMetadata metadata) {\r
+ DecomposeInitalJpredSeq(sequences);\r
+ this.metadata = metadata;\r
+ }\r
+\r
+ /**\r
+ * \r
+ * @param sequences\r
+ */\r
+ private void DecomposeInitalJpredSeq(List<FastaSequence> sequences) {\r
+ List<FastaSequence> realsequences = new ArrayList<FastaSequence>();\r
+ for (FastaSequence s : sequences) {\r
+ if (s.getId().equals("jnetpred")) {\r
+ this.jnetpred = s;\r
+ } else if (s.getId().equals("JNETCONF")) {\r
+ this.JNETCONF = s;\r
+ } else if (s.getId().equals("JNETSOL25")) {\r
+ this.JNETSOL25 = s;\r
+ } else if (s.getId().equals("JNETSOL5")) {\r
+ this.JNETSOL5 = s;\r
+ } else if (s.getId().equals("JNETSOL0")) {\r
+ this.JNETSOL0 = s;\r
+ } else if (s.getId().equals("JNETHMM")) {\r
+ this.JNETSOL0 = s;\r
+ } else if (s.getId().equals("JNETHMM")) {\r
+ this.JNETHMM = s;\r
+ } else if (s.getId().equals("JNETSOL0")) {\r
+ this.JNETPSSM = s;\r
+ } else if (s.getId().equals("JNETHMM")) {\r
+ this.JNETJURY = s;\r
+ } else {\r
+ realsequences.add(s);\r
+ }\r
+ }\r
+ this.sequences = realsequences;\r
+ }\r
+\r
+ /**\r
+ * \r
+ * @return Jpred prediction \r
+ */\r
+ public String getJpredPrediction() {\r
+ return this.jnetpred.getSequence();\r
+ }\r
+\r
+ /**\r
+ * \r
+ * @return Jpred JNETSOL25 line\r
+ */\r
+ public String getJpredSOL25() {\r
+ return this.JNETSOL25.getSequence();\r
+ }\r
+\r
+ /**\r
+ * \r
+ * @return Jpred JNETSOL5 line\r
+ */\r
+ public String getJpredSOL5() {\r
+ return this.JNETSOL5.getSequence();\r
+ }\r
+ /**\r
+ * \r
+ * @return Jpred JNETSOL0 line\r
+ */\r
+ public String getJpredSOL0() {\r
+ return this.JNETSOL0.getSequence();\r
+ }\r
+ /**\r
+ * \r
+ * @return Jpred JNETCONF line\r
+ */\r
+ public String getJpredJNETCONF() {\r
+ return this.JNETCONF.getSequence();\r
+ }\r
+ /**\r
+ * \r
+ * @return list of FastaSequence records\r
+ */\r
+ public List<FastaSequence> getSequences() {\r
+ return sequences;\r
+ }\r
+\r
+ /**\r
+ * \r
+ * @return a number of sequence in the alignment\r
+ */\r
+ public int getSize() {\r
+ return this.sequences.size();\r
+ }\r
+\r
+ /**\r
+ * \r
+ * @return AlignmentMetadata object\r
+ */\r
+ public AlignmentMetadata getMetadata() {\r
+ return metadata;\r
+ }\r
+\r
+ @Override\r
+ public String toString() {\r
+ String sseq = "";\r
+ for (FastaSequence fs : getSequences()) {\r
+ sseq += fs.toString() + "\n";\r
+ }\r
+ return sseq;\r
+ }\r
+\r
+ @Override\r
+ public int hashCode() {\r
+ final int prime = 31;\r
+ int result = 1;\r
+ result = prime * result\r
+ + ((metadata == null) ? 0 : metadata.hashCode());\r
+ result = prime * result\r
+ + ((sequences == null) ? 0 : sequences.hashCode());\r
+ return result;\r
+ }\r
+\r
+ /**\r
+ * Please note that this implementation does not take the order of sequences\r
+ * into account!\r
+ */\r
+ @Override\r
+ public boolean equals(Object obj) {\r
+ if (obj == null) {\r
+ return false;\r
+ }\r
+ if (!(obj instanceof Alignment)) {\r
+ return false;\r
+ }\r
+ Alignment al = (Alignment) obj;\r
+ if (this.getSize() != al.getSize()) {\r
+ return false;\r
+ }\r
+ if (!this.getMetadata().equals(al.getMetadata())) {\r
+ return false;\r
+ }\r
+ int outerCounter = 0;\r
+ int matchCounter = 0;\r
+ for (FastaSequence fs : getSequences()) {\r
+ outerCounter++;\r
+ for (FastaSequence fs1 : al.getSequences()) {\r
+ if (fs.equals(fs1)) {\r
+ matchCounter++;\r
+ continue;\r
+ }\r
+ }\r
+ // Match for at lease one element was not found!\r
+ if (outerCounter != matchCounter) {\r
+ return false;\r
+ }\r
+ }\r
+\r
+ return true;\r
+ }\r
+\r
+}\r