/*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.9.0b2)
- * Copyright (C) 2015 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.
*
package jalview.structure;
import jalview.datamodel.AlignmentAnnotation;
+import jalview.datamodel.Mapping;
import jalview.datamodel.SequenceI;
+import java.util.ArrayList;
import java.util.HashMap;
+import java.util.List;
public class StructureMapping
{
String pdbchain;
- public static final int UNASSIGNED_VALUE = -1;
+ public static final int UNASSIGNED_VALUE = Integer.MIN_VALUE;
private static final int PDB_RES_NUM_INDEX = 0;
// and atomNo
HashMap<Integer, int[]> mapping;
+ jalview.datamodel.Mapping seqToPdbMapping = null;
+ /**
+ * Constructor
+ *
+ * @param seq
+ * @param pdbfile
+ * @param pdbid
+ * @param chain
+ * @param mapping
+ * a map from sequence to two values, { resNo, atomNo } in the
+ * structure
+ * @param mappingDetails
+ */
public StructureMapping(SequenceI seq, String pdbfile, String pdbid,
String chain, HashMap<Integer, int[]> mapping,
String mappingDetails)
this.mappingDetails = mappingDetails;
}
+ public StructureMapping(SequenceI seq, String pdbFile2, String pdbId2,
+ String chain, HashMap<Integer, int[]> mapping2,
+ String mappingOutput, Mapping seqToPdbMapping)
+ {
+ this(seq, pdbFile2, pdbId2, chain, mapping2, mappingOutput);
+ this.seqToPdbMapping = seqToPdbMapping;
+ }
+
public SequenceI getSequence()
{
return sequence;
/**
*
* @param seqpos
- * @return 0 or the corresponding residue number for the sequence position
+ * @return UNASSIGNED_VALUE or the corresponding residue number for the
+ * sequence position
*/
public int getPDBResNum(int seqpos)
{
}
/**
+ * Returns a (possibly empty) list of [start, end] residue positions in the
+ * mapped structure, corresponding to the given range of sequence positions
+ *
+ * @param fromSeqPos
+ * @param toSeqPos
+ * @return
+ */
+ public List<int[]> getPDBResNumRanges(int fromSeqPos, int toSeqPos)
+ {
+ List<int[]> result = new ArrayList<int[]>();
+ int startRes = -1;
+ int endRes = -1;
+
+ for (int i = fromSeqPos; i <= toSeqPos; i++)
+ {
+ int resNo = getPDBResNum(i);
+ if (resNo == UNASSIGNED_VALUE)
+ {
+ continue; // no mapping from this sequence position
+ }
+ if (startRes == -1)
+ {
+ startRes = resNo;
+ endRes = resNo;
+ }
+ if (resNo >= startRes && resNo <= endRes)
+ {
+ // within the current range - no change
+ continue;
+ }
+ if (resNo == startRes - 1)
+ {
+ // extend beginning of current range
+ startRes--;
+ continue;
+ }
+ if (resNo == endRes + 1)
+ {
+ // extend end of current range
+ endRes++;
+ continue;
+ }
+
+ /*
+ * resNo is not within or contiguous with last range,
+ * so write out the last range
+ */
+ result.add(new int[] { startRes, endRes });
+ startRes = resNo;
+ endRes = resNo;
+ }
+
+ /*
+ * and add the last range
+ */
+ if (startRes != -1)
+ {
+ result.add(new int[] { startRes, endRes });
+ }
+
+ return result;
+ }
+
+ /**
*
* @param pdbResNum
* @return -1 or the corresponding sequence position for a pdb residue number
{
return mapping;
}
+
+ public Mapping getSeqToPdbMapping()
+ {
+ return seqToPdbMapping;
+ }
}