001/*
002 *                    BioJava 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 * For more information on the BioJava project and its aims,
015 * or to join the biojava-l mailing list, visit the home page
016 * at:
017 *
018 *      http://www.biojava.org/
019 *
020 * Created on Jun 21, 2010
021 * Author: Jianjiong Gao
022 *
023 */
024
025package org.biojava.nbio.protmod;
026
027import java.util.Collections;
028import java.util.List;
029
030public class ModificationLinkage {
031        private final List<Component> components;
032        private final int indexOfComponent1;
033        private final int indexOfComponent2;
034        private final List<String> pdbNameOfPotentialAtomsOnComponent1;
035        private final List<String> pdbNameOfPotentialAtomsOnComponent2;
036        private final String labelOfAtomOnComponent1;
037        private final String labelOfAtomOnComponent2;
038
039        /**
040         *
041         * @param components {@link Component}s involved in a modification.
042         * @param indexOfComponent1 index of the first component.
043         * @param indexOfComponent2 index of the second component.
044         */
045        public ModificationLinkage(
046                        final List<Component> components,
047                        final int indexOfComponent1,
048                        final int indexOfComponent2) {
049                this(components, indexOfComponent1, null,
050                                null, indexOfComponent2, null, null);
051        }
052
053        /**
054         *
055         * @param components {@link Component}s involved in a modification.
056         * @param indexOfComponent1 index of the first component.
057         * @param labelOfAtomOnComponent1 label of the atom on the first
058         *  component.
059         * @param indexOfComponent2 index of the second component.
060         * @param labelOfAtomOnComponent2 label of the atom on the second
061         *  component.
062         */
063        public ModificationLinkage(
064                        final List<Component> components,
065                        final int indexOfComponent1,
066                        final String pdbNameOfAtomsOnComponent1,
067                        final int indexOfComponent2,
068                        final String pdbNameOfAtomsOnComponent2) {
069                this(components, indexOfComponent1,
070                                Collections.singletonList(pdbNameOfAtomsOnComponent1),
071                                null, indexOfComponent2,
072                                Collections.singletonList(pdbNameOfAtomsOnComponent2),
073                                null);
074        }
075
076        /**
077         *
078         * @param components {@link Component}s involved in a modification.
079         * @param indexOfComponent1 index of the first component.
080         * @param labelOfAtomOnComponent1 label of the atom on the first
081         *  component.
082         * @param indexOfComponent2 index of the second component.
083         * @param labelOfAtomOnComponent2 label of the atom on the second
084         *  component.
085         */
086        public ModificationLinkage(
087                        final List<Component> components,
088                        final int indexOfComponent1,
089                        final List<String> pdbNameOfPotentialAtomsOnComponent1,
090                        final int indexOfComponent2,
091                        final List<String> pdbNameOfPotentialAtomsOnComponent2) {
092                this(components, indexOfComponent1, pdbNameOfPotentialAtomsOnComponent1,
093                                null, indexOfComponent2, pdbNameOfPotentialAtomsOnComponent2, null);
094        }
095
096        /**
097         *
098         * @param components {@link Component}s involved in a modification.
099         * @param indexOfComponent1 index of the first component.
100         * @param pdbNameOfPotentialAtomsOnComponent1 a list of PDB names of
101         *  potential atoms on the first component.
102         * @param labelOfAtomOnComponent1 label of the atom on the first
103         *  component.
104         * @param indexOfComponent2 index of the second component.
105         * @param pdbNameOfPotentialAtomsOnComponent2 a list of PDB names of
106         *  potential atoms on the second component.
107         * @param labelOfAtomOnComponent2 label of the atom on the second
108         *  component.
109         */
110        public ModificationLinkage(
111                        final List<Component> components,
112                        final int indexOfComponent1,
113                        final List<String> pdbNameOfPotentialAtomsOnComponent1,
114                        final String labelOfAtomOnComponent1,
115                        final int indexOfComponent2,
116                        final List<String> pdbNameOfPotentialAtomsOnComponent2,
117                        final String labelOfAtomOnComponent2) {
118                if (components == null) {
119                        throw new IllegalArgumentException("Null components");
120                }
121
122                if ( indexOfComponent1 < 0)
123                        throw new IllegalArgumentException("indexOfComponent1 has to be >= 0");
124                if ( indexOfComponent1 >= components.size())
125                        throw new IllegalArgumentException("indexOfComponent1 has to be <= components.size()");
126
127                if ( indexOfComponent2 < 0)
128                        throw new IllegalArgumentException("indexOfComponent2 has to be >= 0");
129                if ( indexOfComponent2 >= components.size())
130                        throw new IllegalArgumentException("indexOfComponent2 [" + indexOfComponent2 + "] has to be <= components.size() [" + components.size()+"]");
131
132
133
134                if (indexOfComponent1 == indexOfComponent2) {
135                        throw new IllegalArgumentException("No linkage is allowed for an" +
136                                        " identical component.");
137                }
138
139                this.components = components;
140                this.indexOfComponent1 = indexOfComponent1;
141                this.indexOfComponent2 = indexOfComponent2;
142                this.pdbNameOfPotentialAtomsOnComponent1 = pdbNameOfPotentialAtomsOnComponent1;
143                this.pdbNameOfPotentialAtomsOnComponent2 = pdbNameOfPotentialAtomsOnComponent2;
144                this.labelOfAtomOnComponent1 = labelOfAtomOnComponent1;
145                this.labelOfAtomOnComponent2 = labelOfAtomOnComponent2;
146        }
147
148        /**
149         *
150         * @return index of the first component.
151         */
152        public int getIndexOfComponent1() {
153                return indexOfComponent1;
154        }
155
156        /**
157         *
158         * @return index of the second component.
159         */
160        public int getIndexOfComponent2() {
161                return indexOfComponent2;
162        }
163
164        /**
165         *
166         * @return the first component.
167         */
168        public Component getComponent1() {
169                return components.get(indexOfComponent1);
170        }
171
172        /**
173         *
174         * @return the second component.
175         */
176        public Component getComponent2() {
177                return components.get(indexOfComponent2);
178        }
179
180        /**
181         *
182         * @return a list of PDB names of potential atoms on the first component.
183         */
184        public List<String> getPDBNameOfPotentialAtomsOnComponent1() {
185                return pdbNameOfPotentialAtomsOnComponent1;
186        }
187
188        /**
189         *
190         * @return a list of PDB names of potential atoms on the second component.
191         */
192        public List<String> getPDBNameOfPotentialAtomsOnComponent2() {
193                return pdbNameOfPotentialAtomsOnComponent2;
194        }
195
196        /**
197         *
198         * @return label of the atom on the first component.
199         */
200        public String getLabelOfAtomOnComponent1() {
201                return labelOfAtomOnComponent1;
202        }
203
204        /**
205         *
206         * @return label of the atom on the second component.
207         */
208        public String getLabelOfAtomOnComponent2() {
209                return labelOfAtomOnComponent2;
210        }
211
212        /**
213         *
214         */
215        @Override
216        public String toString() {
217                Component comp1 = getComponent1();
218                Component comp2 = getComponent2();
219                List<String> atom1 = getPDBNameOfPotentialAtomsOnComponent1();
220                List<String> atom2 = getPDBNameOfPotentialAtomsOnComponent2();
221                if ( comp1 == null || comp2 == null) {
222                        return "ModificationLinkage: empty";
223                }
224                if ( comp1.getPdbccIds() != null && comp2.getPdbccIds() != null) {
225                        return "ModificationLinkage: " + comp1.getPdbccIds().toString()+":"+atom1+"<=>" + comp2.getPdbccIds()+atom2;
226                } else {
227                        return "ModificationLinkage :"+atom1+"<=>" + atom2;
228                }
229        }
230}