3 import jalview.datamodel.*;
\r
4 import jalview.schemes.*;
\r
8 public class SequenceRenderer implements RendererI
\r
12 boolean renderGaps = true;
\r
13 SequenceGroup currentSequenceGroup = null;
\r
16 public SequenceRenderer(AlignViewport av)
\r
22 public void renderGaps(boolean b)
\r
27 public Color getResidueBoxColour(ColourSchemeI cs, SequenceI seq, int i)
\r
29 Color c = Color.white;
\r
31 c = cs.findColour(seq, seq.getSequence(i, i + 1), i, null);
\r
32 }catch(Exception ex){}
\r
37 public void drawSequence(Graphics g,SequenceI seq,SequenceGroup sg, int start, int end, int x1, int y1, int width, int height, Vector pid, int seqnum)
\r
39 currentSequenceGroup = sg;
\r
41 drawBoxes(g, seq, start, end, x1, y1, (int) width, height, pid);
\r
43 fm = g.getFontMetrics();
\r
44 drawText(g,seq,start,end,x1,y1,(int)width,height);
\r
48 public void drawBoxes(Graphics g, SequenceI seq,int start, int end, int x1, int y1, int width, int height,Vector freq) {
\r
50 int length = seq.getLength();
\r
52 Color currentColor = Color.WHITE;
\r
55 int curWidth = width;
\r
57 if(currentSequenceGroup!=null && currentSequenceGroup.getDisplayBoxes())
\r
59 curStart = currentSequenceGroup.getStartRes();
\r
60 curWidth = currentSequenceGroup.getEndRes();
\r
63 // int threshold = 80;
\r
65 while (i <= end && i < length)
\r
67 if(inCurrentSequenceGroup(i))
\r
69 color = getResidueBoxColour(currentSequenceGroup.cs, seq, i);
\r
72 color = getResidueBoxColour(av.getGlobalColourScheme(), seq, i);
\r
74 // Hashtable hash = (Hashtable)freq.elementAt(i-start);
\r
75 // String s = (String)hash.get("maxResidue");
\r
76 // int count = ((Integer)hash.get("maxCount")).intValue();
\r
77 // int max = ((Integer)hash.get("size")).intValue();
\r
78 // int nongap = ((Integer)hash.get("nongap")).intValue();
\r
79 // float frac = (float)(count*1.0/(1.0*nongap));
\r
81 //System.out.println("Frac/count/nongap " + frac + " " + count + " " + nongap);
\r
82 /* if (!seq.getSequence().substring(i,i+1).equals(s) ||
\r
91 } else if (frac > 0.8) {
\r
93 } else if (frac > 0.7) {
\r
95 } else if (frac > 0.5) {
\r
97 } else if (frac> 0.3) {
\r
98 c = Color.lightGray;
\r
102 if (color != currentColor || color != null)
\r
104 g.fillRect(x1+width*(curStart-start),y1,curWidth,height);
\r
106 currentColor = color;
\r
117 g.fillRect(x1+width*(curStart-start),y1,curWidth,height);
\r
120 public void drawText(Graphics g, SequenceI seq,int start, int end, int x1, int y1, int width, int height)
\r
122 int pady = height/5;
\r
124 g.setColor(Color.black);
\r
127 // Need to find the sequence position here.
\r
128 for (int i = start; i <= end; i++)
\r
130 if(i<seq.getLength())
\r
131 s = seq.getSequence().charAt(i);
\r
135 if(!renderGaps && (s=='-' || s=='.' || s==' '))
\r
139 if (inCurrentSequenceGroup(i))
\r
141 if(!currentSequenceGroup.getDisplayText())
\r
144 if(currentSequenceGroup.getColourText())
\r
145 g.setColor(getResidueBoxColour(currentSequenceGroup.cs, seq, i).darker());
\r
148 g.setColor(Color.black);
\r
150 charOffset = (width - fm.charWidth(s))/2;
\r
151 g.drawString(String.valueOf(s), charOffset + x1 + width * (i - start), y1 + height - pady);
\r
157 boolean inCurrentSequenceGroup(int res)
\r
159 if(currentSequenceGroup==null)
\r
162 return (currentSequenceGroup.getStartRes()<=res && currentSequenceGroup.getEndRes()>=res)?true:false;
\r
165 public void drawHighlightedText(Graphics g, SequenceI seq,int start, int end, int x1, int y1, int width, int height)
\r
167 int pady = height/5;
\r
169 g.setColor(Color.BLACK);
\r
170 g.fillRect(x1,y1,width*(end-start+1),height);
\r
171 g.setColor(Color.white);
\r
174 // Need to find the sequence position here.
\r
175 for (int i = start; i <= end; i++)
\r
177 if(i<seq.getLength())
\r
178 s = seq.getSequence().charAt(i);
\r
180 charOffset = (width - fm.charWidth(s))/2;
\r
181 g.drawString(String.valueOf(s), charOffset + x1 + width * (i - start), y1 + height - pady);
\r