X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fstructure%2FStructureMapping.java;h=78634e06d0dee01b9b95f8e570a2bb2831ca2f9e;hb=37de9310bec3501cbc6381e0c3dcb282fcaad812;hp=e4749c9be07fbaec1a7cea84891ac0b55aed17e8;hpb=e7235e7d60595f9e3bec5fb65317681e594461c4;p=jalview.git diff --git a/src/jalview/structure/StructureMapping.java b/src/jalview/structure/StructureMapping.java index e4749c9..78634e0 100644 --- a/src/jalview/structure/StructureMapping.java +++ b/src/jalview/structure/StructureMapping.java @@ -1,6 +1,6 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2) - * Copyright (C) 2014 The Jalview Authors + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors * * This file is part of Jalview. * @@ -23,6 +23,8 @@ package jalview.structure; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.SequenceI; +import java.util.HashMap; + public class StructureMapping { String mappingDetails; @@ -35,11 +37,19 @@ public class StructureMapping String pdbchain; - // Mapping index 0 is resNum, index 1 is atomNo - int[][] mapping; + public static final int UNASSIGNED_VALUE = -1; + + private static final int PDB_RES_NUM_INDEX = 0; + + private static final int PDB_ATOM_NUM_INDEX = 1; + + // Mapping key is residue index while value is an array containing PDB resNum, + // and atomNo + HashMap mapping; public StructureMapping(SequenceI seq, String pdbfile, String pdbid, - String chain, int[][] mapping, String mappingDetails) + String chain, HashMap mapping, + String mappingDetails) { sequence = seq; this.pdbfile = pdbfile; @@ -64,40 +74,57 @@ public class StructureMapping return pdbid; } + /** + * + * @param seqpos + * @return 0 or corresponding atom number for the sequence position + */ public int getAtomNum(int seqpos) { - if (mapping.length > seqpos) + int[] resNumAtomMap = mapping.get(seqpos); + if (resNumAtomMap != null) { - return mapping[seqpos][1]; + return resNumAtomMap[PDB_ATOM_NUM_INDEX]; } else { - return 0; + return UNASSIGNED_VALUE; } } + /** + * + * @param seqpos + * @return 0 or the corresponding residue number for the sequence position + */ public int getPDBResNum(int seqpos) { - if (mapping.length > seqpos) + int[] resNumAtomMap = mapping.get(seqpos); + if (resNumAtomMap != null) { - return mapping[seqpos][0]; + return resNumAtomMap[PDB_RES_NUM_INDEX]; } else { - return 0; + return UNASSIGNED_VALUE; } } + /** + * + * @param pdbResNum + * @return -1 or the corresponding sequence position for a pdb residue number + */ public int getSeqPos(int pdbResNum) { - for (int i = 0; i < mapping.length; i++) + for (Integer seqPos : mapping.keySet()) { - if (mapping[i][0] == pdbResNum) + if (pdbResNum == getPDBResNum(seqPos)) { - return i; + return seqPos; } } - return -1; + return UNASSIGNED_VALUE; } /** @@ -118,7 +145,10 @@ public class StructureMapping { ds = ds.getDatasetSequence(); } - ala_copy.remap(ds, mapping, 0, -1, 1); + // need to relocate annotation from pdb coordinates to local sequence + // -1,-1 doesn't look at pdbresnum but fails to remap sequence positions... + + ala_copy.remap(ds, mapping, -1, -1, 0); ds.addAlignmentAnnotation(ala_copy); if (ds != sequence) { @@ -129,4 +159,14 @@ public class StructureMapping } return ala_copy; } + + public String getMappingDetailsOutput() + { + return mappingDetails; + } + + public HashMap getMapping() + { + return mapping; + } }