2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.structure;
23 import jalview.datamodel.AlignmentAnnotation;
24 import jalview.datamodel.SequenceI;
26 import java.util.HashMap;
28 public class StructureMapping
30 String mappingDetails;
40 public static final int UNASSIGNED_VALUE = -1;
42 private static final int PDB_RES_NUM_INDEX = 0;
44 private static final int PDB_ATOM_NUM_INDEX = 1;
46 // Mapping key is residue index while value is an array containing PDB resNum,
48 HashMap<Integer, int[]> mapping;
50 public StructureMapping(SequenceI seq, String pdbfile, String pdbid,
51 String chain, HashMap<Integer, int[]> mapping,
52 String mappingDetails)
55 this.pdbfile = pdbfile;
57 this.pdbchain = chain;
58 this.mapping = mapping;
59 this.mappingDetails = mappingDetails;
62 public SequenceI getSequence()
67 public String getChain()
72 public String getPdbId()
80 * @return 0 or corresponding atom number for the sequence position
82 public int getAtomNum(int seqpos)
84 int[] resNumAtomMap = mapping.get(seqpos);
85 if (resNumAtomMap != null)
87 return resNumAtomMap[PDB_ATOM_NUM_INDEX];
91 return UNASSIGNED_VALUE;
98 * @return 0 or the corresponding residue number for the sequence position
100 public int getPDBResNum(int seqpos)
102 int[] resNumAtomMap = mapping.get(seqpos);
103 if (resNumAtomMap != null)
105 return resNumAtomMap[PDB_RES_NUM_INDEX];
109 return UNASSIGNED_VALUE;
116 * @return -1 or the corresponding sequence position for a pdb residue number
118 public int getSeqPos(int pdbResNum)
120 for (Integer seqPos : mapping.keySet())
122 if (pdbResNum == getPDBResNum(seqPos))
127 return UNASSIGNED_VALUE;
131 * transfer a copy of an alignment annotation row in the PDB chain coordinate
132 * system onto the mapped sequence
135 * @return the copy that was remapped to the mapped sequence
136 * @note this method will create a copy and add it to the dataset sequence for
137 * the mapped sequence as well as the mapped sequence (if it is not a
140 public AlignmentAnnotation transfer(AlignmentAnnotation ana)
142 AlignmentAnnotation ala_copy = new AlignmentAnnotation(ana);
143 SequenceI ds = sequence;
144 while (ds.getDatasetSequence() != null)
146 ds = ds.getDatasetSequence();
148 // need to relocate annotation from pdb coordinates to local sequence
149 // -1,-1 doesn't look at pdbresnum but fails to remap sequence positions...
151 ala_copy.remap(ds, mapping, -1, -1, 0);
152 ds.addAlignmentAnnotation(ala_copy);
155 // mapping wasn't to an original dataset sequence, so we make a copy on
156 // the mapped sequence too
157 ala_copy = new AlignmentAnnotation(ala_copy);
158 sequence.addAlignmentAnnotation(ala_copy);