Merge branch 'releases/Release_2_11_3_Branch'
[jalview.git] / src / jalview / datamodel / SeqDistanceContactMatrix.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
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.
11  *  
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.
16  * 
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.
20  */
21 package jalview.datamodel;
22
23 import java.awt.Color;
24 import java.util.BitSet;
25 import java.util.HashMap;
26 import java.util.List;
27
28 import jalview.util.MapList;
29 import jalview.ws.datamodel.alphafold.MappableContactMatrix;
30
31 /**
32  * Dummy contact matrix based on sequence distance
33  * 
34  * @author jprocter
35  *
36  */
37 public class SeqDistanceContactMatrix
38         extends MappableContactMatrix<SeqDistanceContactMatrix>
39         implements ContactMatrixI
40 {
41   private static final String SEQUENCE_DISTANCE = "SEQUENCE_DISTANCE";
42
43   private int width = 0;
44
45   public SeqDistanceContactMatrix(int width)
46   {
47     this.width = width;
48   }
49
50   @Override
51   public float getMin()
52   {
53     return 0f;
54   }
55
56   @Override
57   public float getMax()
58   {
59     return width;
60   }
61
62   @Override
63   public ContactListI getContactList(final int column)
64   {
65     if (column < 0 || column >= width)
66     {
67       return null;
68     }
69     return new ContactListImpl(new ContactListProviderI()
70     {
71
72       int p = column;
73
74       // @Override
75       // public Color getColorForScore(int column)
76       // {
77       // return jalview.util.ColorUtils.getGraduatedColour(Math.abs(column-p),
78       // 0, Color.white, width, Color.magenta);
79       // }
80       // @Override
81       // public Color getColorForRange(int from_column, int to_column)
82       // {
83       // return jalview.util.ColorUtils.getGraduatedColour(
84       // Math.abs(to_column + from_column - 2 * p) / 2, 0, Color.white, width,
85       // Color.magenta);
86       // }
87
88       @Override
89       public int getContactHeight()
90       {
91         return width;
92
93       }
94
95       @Override
96       public int getPosition()
97       {
98         return p;
99       }
100
101       @Override
102       public double getContactAt(int column)
103       {
104         return Math.abs(column - p);
105       }
106     });
107   }
108
109   @Override
110   public String getAnnotDescr()
111   {
112     return "Sequence distance matrix";
113   }
114
115   @Override
116   public String getAnnotLabel()
117   {
118     return "Sequence Distance";
119   }
120
121   @Override
122   public String getType()
123   {
124     return SEQUENCE_DISTANCE;
125   }
126
127   @Override
128   public int getWidth()
129   {
130     return width;
131   }
132
133   @Override
134   public int getHeight()
135   {
136     return width;
137   }
138
139   @Override
140   public double getElementAt(int _column, int i)
141   {
142     return Math.abs(_column - i);
143   }
144
145   @Override
146   protected SeqDistanceContactMatrix newMappableContactMatrix(
147           SequenceI newRefSeq, MapList newFromMapList)
148   {
149
150     return new SeqDistanceContactMatrix(width);
151   }
152 }