Vector sequences;\r
int start;\r
int end;\r
-\r
- Vector total = new Vector();\r
-\r
- String consString = "";\r
-\r
- Sequence consSequence;\r
- Hashtable propHash;\r
- int threshold;\r
+ Vector seqNums; // vector of int vectors where first is sequence checksum\r
+ int maxLength=0; // used by quality calcs\r
+ boolean seqNumsChanged = false; // updated after any change via calcSeqNum;\r
+ private void calcSeqNums() {\r
+ for (int i=0; i<sequences.size(); i++) {\r
+ calcSeqNum(i);\r
+ }\r
+ }\r
+ private void calcSeqNum(int i) {\r
+ String sq=null; // for dumb jbuilder not-inited exception warning\r
+ int[] sqnum = null;\r
+ if (i>-1 && i<sequences.size()) {\r
+ sq = ((SequenceI)sequences.elementAt(i)).getSequence();\r
+ if (seqNums.size()<=i) {\r
+ seqNums.add(new int[sq.length()+1]);\r
+ }\r
+ if (sq.hashCode()!=((int[])seqNums.elementAt(i))[0])\r
+ {\r
+ int j, len;\r
+ seqNumsChanged = true;\r
+ sq = ((SequenceI) sequences.elementAt(i)).getSequence();\r
+ len = sq.length();\r
+ if (maxLength < len)\r
+ maxLength = len;\r
+ sqnum = new int[len + 1]; // better to always make a new array - sequence can change its length\r
+ sqnum[0] = sq.hashCode();\r
+ for (j = 1; j <= len; j++)\r
+ {\r
+ sqnum[j] = ( (Integer) jalview.schemes.ResidueProperties.aaHash.get(new\r
+ String(sq.substring(j - 1, j)))).intValue(); // yuk\r
+ }\r
+ seqNums.set(i, sqnum);\r
+ }\r
+ } else {\r
+ // JBPNote INFO level debug\r
+ System.out.println("calcSeqNum called with out of range sequence index for Alignment\n");\r
+ }\r
+ }\r
+ Vector total = new Vector();\r
+ public Vector quality;\r
+ public Double[] qualityRange = new Double[2];\r
+ String consString = "";\r
+\r
+ Sequence consSequence;\r
+ Hashtable propHash;\r
+ int threshold;\r
\r
String name = "";\r
\r
this.sequences = sequences;\r
this.start = start;\r
this.end = end;\r
+ seqNums = new Vector(sequences.size());\r
+ calcSeqNums();\r
}\r
\r
\r
return consSequence;\r
}\r
\r
+ // From Alignment.java in jalview118\r
+\r
+ public void findQuality() {\r
+ findQuality(0,maxLength-1);\r
+ }\r
+\r
+ int[][] cons2;\r
+\r
+ private void percentIdentity2() {\r
+ calcSeqNums(); // updates maxLength, too.\r
+ if (cons2==null || seqNumsChanged) {\r
+ cons2 = new int[maxLength][24];\r
+ // Initialize the array\r
+ for (int j=0;j<24;j++) {\r
+ for (int i=0; i < maxLength;i++) {\r
+ cons2[i][j] = 0;\r
+ }\r
+ }\r
+\r
+ int sqnum[];\r
+ int j = 0;\r
+ while(j < sequences.size()) {\r
+ sqnum=(int[])seqNums.elementAt(j);\r
+ for (int i = 1; i < sqnum.length; i++) {\r
+ cons2[i-1][sqnum[i]]++;\r
+ }\r
+ j++;\r
+ }\r
+\r
+ // unnecessary ?\r
+ /* for (int i=start; i <= end; i++) {\r
+ int max = -1000;\r
+ int maxi = -1;\r
+ int maxj = -1;\r
+\r
+ for (int j=0;j<24;j++) {\r
+ if (cons2[i][j] > max) {\r
+ max = cons2[i][j];\r
+ maxi = i;\r
+ maxj = j;\r
+ }\r
+\r
+ }\r
+ } */\r
+ }\r
+\r
+}\r
+\r
+\r
+public void findQuality(int start, int end) {\r
+ quality = new Vector();\r
+ double max = -10000;\r
+ String s = "";\r
+ int[][] BLOSUM62 = jalview.schemes.ResidueProperties.getBLOSUM62();\r
+ //Loop over columns // JBPNote Profiling info\r
+ // long ts = System.currentTimeMillis();\r
+ //long te = System.currentTimeMillis();\r
+ percentIdentity2();\r
+\r
+ int size = seqNums.size();\r
+ int[] lengths = new int[size];\r
+\r
+ for (int l = 0; l < size; l++)\r
+ lengths[l] = ((int[]) seqNums.get(l)).length;\r
+\r
+ for (int j=start; j <= end; j++) {\r
+ double bigtot = 0;\r
+\r
+ // First Xr = depends on column only\r
+ double x[] = new double[24];\r
+\r
+ for (int ii=0; ii < 24; ii++) {\r
+ x[ii] = 0;\r
+ try {\r
+ for (int i2=0; i2 < 24; i2++) {\r
+ x[ii] += (double)cons2[j][i2] * BLOSUM62[ii][i2]+4;\r
+ }\r
+ } catch (Exception e) {\r
+ System.out.println("Exception : " + e);\r
+ }\r
+ //System.out.println("X " + ii + " " + x[ii]);\r
+ x[ii] /= (size);\r
+ //System.out.println("X " + ii + " " + x[ii]);\r
+ }\r
+ // Now calculate D for each position and sum\r
+ for (int k=0; k < size; k++) {\r
+ double tot = 0;\r
+ double[] xx = new double[24];\r
+ int seqNum =\r
+ ((j+1)<lengths[size])\r
+ ? ((int[]) seqNums.get(k))[j+1]\r
+ : 23; // Sequence, or gap at the end\r
+\r
+ // This is a loop over r\r
+ for (int i=0; i < 23; i++) {\r
+ double sr = 0;\r
+ try {\r
+ sr = (double)BLOSUM62[i][seqNum]+4;\r
+ } catch (Exception e) {\r
+ System.out.println("Exception in sr " + e);\r
+ }\r
+ //Calculate X with another loop over residues\r
+\r
+ // System.out.println("Xi " + i + " " + x[i] + " " + sr);\r
+ xx[i] = x[i] - sr;\r
+\r
+ tot += xx[i]*xx[i];\r
+ }\r
+ bigtot += Math.sqrt(tot);\r
+ }\r
+ // This is the quality for one column\r
+ if (max < bigtot) {max = bigtot;}\r
+ // bigtot = bigtot * (size-cons2[j][23])/size;\r
+\r
+ quality.addElement(new Double(bigtot));\r
+\r
+ s += "-";\r
+\r
+ // Need to normalize by gaps\r
+ }\r
+ double newmax=-10000;\r
+ for (int j=start; j <= end; j++) {\r
+ double tmp = ((Double)quality.elementAt(j)).doubleValue();\r
+ tmp = (max - tmp)*(size-cons2[j][23])/size;\r
+ // System.out.println(tmp+ " " + j);\r
+ quality.setElementAt(new Double(tmp),j);\r
+ if (tmp>newmax)\r
+ newmax = tmp;\r
+ }\r
+ // System.out.println("Quality " + s);\r
+ qualityRange[0] = new Double(0);\r
+ qualityRange[1] = new Double(newmax);\r
+ }\r
+\r
+\r
}\r
alignment.getWidth());\r
cons.calculate();\r
cons.verdict(false, 100);\r
-\r
+ cons.findQuality();\r
String sequence = cons.getConsSequence().getSequence();\r
+ float minR,minG,minB, maxR,maxG,maxB;\r
+ minR = 0.3f;\r
+ minG = 0f;\r
+ minB = 0f;\r
+ maxR = 1.0f-minR; maxG=0.9f-minG; maxB=0f-minB; // scalable range for colouring\r
+ float min = cons.qualityRange[0].floatValue();\r
+ float max = cons.qualityRange[1].floatValue();\r
+\r
for (int i = 0; i < alignment.getWidth(); i++)\r
{\r
- int value = 0;\r
+ float value = 0;\r
try\r
{\r
- value = Integer.parseInt(sequence.charAt(i) + "");\r
+ //value = Integer.parseInt(sequence.charAt(i) + "");\r
+ value = ((Double) cons.quality.get(i)).floatValue();\r
}\r
catch (Exception ex)\r
{\r
if (sequence.charAt(i) == '*') value = 10;\r
}\r
-\r
+ float vprop = value-min;\r
+ vprop/=max;\r
annotations[i] = new Annotation(sequence.charAt(i) + "",\r
- "Conservation graph", ' ', value);\r
+ "Conservation graph", ' ', value, new Color(minR+maxR*vprop, minB+maxB*vprop, minB+maxB*vprop));\r
}\r
\r
if(conservation==null)\r
{\r
conservation = new AlignmentAnnotation("Conservation",\r
"Conservation of total alignment",\r
- annotations, 0, 10, 1);\r
+ annotations,\r
+ cons.qualityRange[0].floatValue(),\r
+ cons.qualityRange[1].floatValue(), 1);\r
alignment.addAnnotation(conservation);\r
}\r
else\r