001/*
002 *                    PDB web development code
003 *
004 * This code may be freely distributed and modified under the
005 * terms of the GNU Lesser General Public Licence.  This should
006 * be distributed with the code.  If you do not have a copy,
007 * see:
008 *
009 *      http://www.gnu.org/copyleft/lesser.html
010 *
011 * Copyright for this code is held jointly by the individual
012 * authors.  These should be listed in @author doc comments.
013 *
014 *
015 * Created on May 24, 2009
016 * Created by Andreas Prlic
017 *
018 */
019
020package org.biojava.nbio.structure.align.pairwise;
021
022import java.io.*;
023
024/** A class to track the alignment results in a flat file
025 *
026 * @author andreas
027 *
028 */
029public class AlignmentResult implements Serializable
030{
031
032        /**
033         *
034         */
035        private static final long serialVersionUID = -4132105905712445473L;
036        AlternativeAlignment[] alignments;
037        String pdb1;
038        String pdb2;
039
040        String chain1;
041        String chain2;
042
043        int length1;
044        int length2;
045
046        long calculationTime;
047        long ioTime;
048
049        @Override
050public String toString(){
051                StringBuffer buf = new StringBuffer();
052                buf.append(pdb1);
053                buf.append("_");
054                buf.append(chain1);
055                buf.append(" vs. ");
056                buf.append(pdb2);
057                buf.append("_");
058                buf.append(chain2);
059                buf.append(" : ");
060                buf.append(" l1: ");
061                buf.append(length1);
062                buf.append(" l2: ");
063                buf.append(length2);
064                buf.append(" ");
065                if ( alignments != null)
066                        if ( alignments.length > 0) {
067                                AlternativeAlignment a = alignments[0];
068                                buf.append(a.toString());
069                                int eqr = a.getEqr();
070                                buf.append(" %res1: ");
071                                buf.append(Math.round((eqr/(float)length2)*100));
072                                buf.append(" %res2: ");
073                                buf.append(Math.round((eqr/(float)length1)*100));
074                                buf.append(" ");
075
076                        }
077                buf.append(" ioTime: ");
078                buf.append(ioTime);
079                buf.append(" compTime: ");
080                buf.append(calculationTime);
081                return buf.toString();
082
083        }
084
085        public AlternativeAlignment[] getAlignments()
086        {
087                return alignments;
088        }
089
090        /** we only keep the first alternative...
091         *
092         * @param alignments
093         */
094        public void setAlignments(AlternativeAlignment[] alignments)
095        {
096                if ( alignments.length > 0){
097                        this.alignments = new AlternativeAlignment[1];
098                        this.alignments[0]=alignments[0];
099                }
100
101        }
102        public String getPdb1()
103        {
104                return pdb1;
105        }
106        public void setPdb1(String pdb1)
107        {
108                this.pdb1 = pdb1;
109        }
110        public String getPdb2()
111        {
112                return pdb2;
113        }
114        public void setPdb2(String pdb2)
115        {
116                this.pdb2 = pdb2;
117        }
118        public String getChain1()
119        {
120                return chain1;
121        }
122        public void setChain1(String chain1)
123        {
124                this.chain1 = chain1;
125        }
126        public String getChain2()
127        {
128                return chain2;
129        }
130        public void setChain2(String chain2)
131        {
132                this.chain2 = chain2;
133        }
134        public int getLength1()
135        {
136                return length1;
137        }
138        public void setLength1(int length1)
139        {
140                this.length1 = length1;
141        }
142        public int getLength2()
143        {
144                return length2;
145        }
146        public void setLength2(int length2)
147        {
148                this.length2 = length2;
149        }
150
151
152        public long getCalculationTime()
153        {
154                return calculationTime;
155        }
156        public void setCalculationTime(long calculationTime)
157        {
158                this.calculationTime = calculationTime;
159        }
160        public long getIoTime()
161        {
162                return ioTime;
163        }
164        public void setIoTime(long ioTime)
165        {
166                this.ioTime = ioTime;
167        }
168        public void serialize (File output)
169        throws FileNotFoundException, IOException{
170                // save alignment result:
171
172                FileOutputStream outStream = new FileOutputStream(output);
173                ObjectOutputStream objStream = new ObjectOutputStream(outStream);
174                objStream.writeObject(this);
175                objStream.close();
176
177        }
178
179        public static AlignmentResult deserialize(File output)
180        throws FileNotFoundException, IOException, ClassNotFoundException{
181                FileInputStream fin = new FileInputStream(output);
182                ObjectInputStream objIn = new ObjectInputStream(fin);
183                AlignmentResult result = (AlignmentResult) objIn.readObject();
184                objIn.close();
185                return result;
186        }
187
188
189}