1 package jalview.datamodel;
3 import jalview.ws.params.InvalidArgumentException;
6 import java.util.ArrayList;
9 public class ContactMatrix implements ContactMatrixI
12 * are contacts reflexive ?
14 boolean symmetric = true;
16 public ContactMatrix(boolean symmetric)
18 this.symmetric = symmetric;
21 List<List<Float>> contacts = null;
23 int width = 0, numcontacts = 0;
25 float min = 0f, max = 0f;
27 public void addContact(int left, int right, float strength)
29 if (left < 0 || right < 0)
31 throw new Error(new InvalidArgumentException(
32 "Cannot have negative indices for contact left=" + left
33 + " right=" + right + " strength=" + strength));
47 // TODO: use sparse list for efficiency ?
48 contacts = new ArrayList<List<Float>>();
50 List<Float> clist = contacts.get(left);
53 clist = new ArrayList<Float>();
54 contacts.set(left, clist);
56 Float last = clist.set(right, strength);
57 // TODO: if last is non null, may need to recompute range
58 checkBounds(strength);
65 private void checkBounds(float strength)
77 Color minColor = Color.white, maxColor = Color.magenta;
79 Color shadeFor(float value)
81 return jalview.util.ColorUtils.getGraduatedColour(value, 0,
82 Color.white, max, Color.magenta);
85 public ContactListI getContactList(final int column)
87 if (column < 0 || column >= width)
91 return new ContactListI()
96 public Color getColorForScore(int column)
99 return shadeFor((float) getContactAt(column));
103 public Color getColorForRange(int i, int j)
107 for (int r=i;r<j;r++)
109 contc = getContactAt(r);
115 // average for moment - probably more interested in maxIntProj though
116 return shadeFor(((float) v) / (j - i + 1));
120 public int getColumnWidth()
126 public int getContactHeight()
133 public double getContactAt(int column)
141 clist = contacts.get(p);
142 cl = clist.get(column);
146 clist = contacts.get(column);
152 clist = contacts.get(p);
153 cl = clist.get(column);
157 // return 0 not NaN ?
160 return cl.doubleValue();