X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fstructure%2FStructureMapping.java;h=cbc2c0070952de38a27c2357fe712d74b9327982;hb=9a47b82e8b3b647773c1c0df94b6ce6b477587e4;hp=06e6bc3507f528ac69d7430b6552bd81f773a78d;hpb=6905363d02254a557f93f66a2b69d85aa0b23696;p=jalview.git diff --git a/src/jalview/structure/StructureMapping.java b/src/jalview/structure/StructureMapping.java index 06e6bc3..cbc2c00 100644 --- a/src/jalview/structure/StructureMapping.java +++ b/src/jalview/structure/StructureMapping.java @@ -1,100 +1,147 @@ -/* - * Jalview - A Sequence Alignment Editor and Viewer - * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA - */ - -package jalview.structure; - -import jalview.datamodel.*; - -public class StructureMapping -{ - String mappingDetails; - SequenceI sequence; - String pdbfile; - String pdbid; - String pdbchain; - - //Mapping index 0 is resNum, index 1 is atomNo - int[][] mapping; - - public StructureMapping(SequenceI seq, - String pdbfile, - String pdbid, - String chain, - int[][] mapping, - String mappingDetails) - { - sequence = seq; - this.pdbfile = pdbfile; - this.pdbid = pdbid; - this.pdbchain = chain; - this.mapping = mapping; - this.mappingDetails = mappingDetails; - } - - public SequenceI getSequence() - { - return sequence; - } - - public String getChain() - { - return pdbchain; - } - - public String getPdbId() - { - return pdbid; - } - - public int getAtomNum(int seqpos) - { - if (mapping.length > seqpos) - { - return mapping[seqpos][1]; - } - else - { - return 0; - } - } - - public int getPDBResNum(int seqpos) - { - if (mapping.length > seqpos) - { - return mapping[seqpos][0]; - } - else - { - return 0; - } - } - - public int getSeqPos(int pdbResNum) - { - for (int i = 0; i < mapping.length; i++) - { - if (mapping[i][0] == pdbResNum) - { - return i; - } - } - return -1; - } -} +/* + * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2) + * Copyright (C) 2014 The Jalview Authors + * + * This file is part of Jalview. + * + * Jalview is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 + * of the License, or (at your option) any later version. + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. + */ +package jalview.structure; + +import jalview.datamodel.AlignmentAnnotation; +import jalview.datamodel.SequenceI; + +public class StructureMapping +{ + String mappingDetails; + + SequenceI sequence; + + String pdbfile; + + String pdbid; + + String pdbchain; + + // Mapping index 0 is resNum, index 1 is atomNo + int[][] mapping; + + public StructureMapping(SequenceI seq, String pdbfile, String pdbid, + String chain, int[][] mapping, String mappingDetails) + { + sequence = seq; + this.pdbfile = pdbfile; + this.pdbid = pdbid; + this.pdbchain = chain; + this.mapping = mapping; + this.mappingDetails = mappingDetails; + } + + public SequenceI getSequence() + { + return sequence; + } + + public String getChain() + { + return pdbchain; + } + + public String getPdbId() + { + return pdbid; + } + + /** + * + * @param seqpos + * @return 0 or corresponding atom number for the sequence position + */ + public int getAtomNum(int seqpos) + { + if (mapping.length > seqpos) + { + return mapping[seqpos][1]; + } + else + { + return 0; + } + } + + /** + * + * @param seqpos + * @return 0 or the corresponding residue number for the sequence position + */ + public int getPDBResNum(int seqpos) + { + if (mapping.length > seqpos) + { + return mapping[seqpos][0]; + } + else + { + return 0; + } + } + + /** + * + * @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++) + { + if (mapping[i][0] == pdbResNum) + { + return i; + } + } + return -1; + } + + /** + * transfer a copy of an alignment annotation row in the PDB chain coordinate + * system onto the mapped sequence + * + * @param ana + * @return the copy that was remapped to the mapped sequence + * @note this method will create a copy and add it to the dataset sequence for + * the mapped sequence as well as the mapped sequence (if it is not a + * dataset sequence). + */ + public AlignmentAnnotation transfer(AlignmentAnnotation ana) + { + AlignmentAnnotation ala_copy = new AlignmentAnnotation(ana); + SequenceI ds = sequence; + while (ds.getDatasetSequence() != null) + { + ds = ds.getDatasetSequence(); + } + ala_copy.remap(ds, mapping, 0, -1, 1); + ds.addAlignmentAnnotation(ala_copy); + if (ds != sequence) + { + // mapping wasn't to an original dataset sequence, so we make a copy on + // the mapped sequence too + ala_copy = new AlignmentAnnotation(ala_copy); + sequence.addAlignmentAnnotation(ala_copy); + } + return ala_copy; + } +}