*/\r
public class AAFrequency\r
{\r
- /** Takes in a vector of sequences and column start and column end\r
- * and returns a vector of size (end-start+1). Each element of the\r
+ /** Takes in a !!ARRAY!! of sequences and column start and column end\r
+ * and fills given Vector of size (end-start+1). Each element of the\r
* vector contains a hashtable with the keys being residues and\r
* the values being the count of each residue in that column.\r
* This class is used extensively in calculating alignment colourschemes\r
* that depend on the amount of conservation in each alignment column. */\r
- public static final Vector calculate(Vector sequences, int start, int end)\r
+\r
+ public static final Hashtable [] calculate(Vector sequences, int start, int end)\r
+ {\r
+ SequenceI [] seqs = new SequenceI[sequences.size()];\r
+ int width = 0;\r
+ for(int i=0; i<sequences.size(); i++)\r
+ {\r
+ seqs[i] = (SequenceI) sequences.elementAt(i);\r
+ if(seqs[i].getLength()>width)\r
+ width = seqs[i].getLength();\r
+ }\r
+\r
+ Hashtable [] reply = new Hashtable[width];\r
+\r
+ calculate(seqs, start, end, reply);\r
+\r
+ return reply;\r
+ }\r
+\r
+public static final void calculate(SequenceI[] sequences,\r
+ int start, int end,\r
+ Hashtable [] result)\r
+{\r
+ Hashtable residueHash;\r
+ int maxCount, nongap, i, j, v, jSize = sequences.length;\r
+ String maxResidue;\r
+ char c;\r
+ float percentage;\r
+\r
+ int[] values = new int[132];\r
+\r
+ for (i = start; i < end; i++)\r
+ {\r
+ residueHash = new Hashtable();\r
+ maxCount = 0;\r
+ maxResidue = "-";\r
+ nongap = 0;\r
+ values = new int[132];\r
+\r
+ for (j = 0; j < jSize; j++)\r
{\r
- Vector result = new Vector();\r
- Hashtable residueHash;\r
- int count, maxCount, nongap, i, j, jSize = sequences.size();\r
- String maxResidue, sequence, res;\r
- float percentage;\r
+ if (sequences[j].getLength() > i)\r
+ {\r
+ c = sequences[j].getCharAt(i);\r
\r
- for (i = start; i <= end; i++)\r
+ if ('a' <= c && c <= 'z')\r
+ {\r
+ c -= ('a' - 'A');\r
+ }\r
+\r
+ if (jalview.util.Comparison.isGap(c))\r
+ {\r
+ c = '-'; // we always use this for gaps in the property vectors\r
+ }\r
+ else\r
{\r
- residueHash = new Hashtable();\r
- maxCount = 0;\r
- maxResidue = "-";\r
- nongap = 0;\r
-\r
- for (j = 0; j < jSize; j++)\r
- {\r
- if (sequences.elementAt(j) instanceof Sequence)\r
- {\r
- sequence = ((Sequence) sequences.elementAt(j)).getSequence();\r
-\r
- if (sequence.length() > i)\r
- {\r
- res = String.valueOf(Character.toUpperCase(sequence.charAt(i)));\r
-\r
- if (jalview.util.Comparison.isGap(res.charAt(0)))\r
- {\r
- res = "-"; // we always use this for gaps in the property vectors\r
- }\r
- else\r
- { nongap++; }\r
-\r
- if (residueHash.containsKey(res))\r
- {\r
- count = ((Integer) residueHash.get(res)).intValue();\r
- count++;\r
-\r
- if (!jalview.util.Comparison.isGap(res.charAt(0)) &&\r
- (count >= maxCount))\r
- {\r
- if (count > maxCount)\r
- {\r
- maxResidue = res;\r
- }\r
- else if (maxResidue.indexOf(res) == -1)\r
- {\r
- maxResidue += res;\r
- }\r
-\r
- maxCount = count;\r
- }\r
-\r
- residueHash.put(res, new Integer(count));\r
- }\r
- else\r
- {\r
- residueHash.put(res, new Integer(1));\r
- }\r
- }\r
- else\r
- {\r
- if (residueHash.containsKey("-"))\r
- {\r
- count = ((Integer) residueHash.get("-")).intValue();\r
- count++;\r
- residueHash.put("-", new Integer(count));\r
- }\r
- else\r
- {\r
- residueHash.put("-", new Integer(1));\r
- }\r
- }\r
- }\r
- }\r
-\r
- residueHash.put("maxCount", new Integer(maxCount));\r
- residueHash.put("maxResidue", maxResidue);\r
-\r
-\r
- //Size is redundant at present if we calculate percentage here\r
- //residueHash.put("size", new Integer(jSize));\r
- //residueHash.put("nogaps", new Integer(nongap));\r
-\r
- percentage = ((float)maxCount*100) / (float)jSize;\r
- residueHash.put("pid_gaps", new Float(percentage) );\r
-\r
- percentage = ((float)maxCount*100) / (float)nongap;\r
- residueHash.put("pid_nogaps", new Float(percentage) );\r
- result.addElement(residueHash);\r
+ nongap++;\r
}\r
\r
+ values[c]++;\r
\r
+ }\r
+ else\r
+ {\r
+ values['-']++;\r
+ }\r
+ }\r
\r
- return result;\r
+ for (v = 'A'; v < 'Z'; v++)\r
+ {\r
+ if (values[v] == 0 || values[v] < maxCount)\r
+ continue;\r
+\r
+ if (values[v] > maxCount)\r
+ {\r
+ maxResidue = String.valueOf( (char) v);\r
+ }\r
+ else if (values[v] == maxCount)\r
+ {\r
+ maxResidue += String.valueOf( (char) v);\r
+ }\r
+ maxCount = values[v];\r
}\r
+\r
+\r
+ residueHash.put("maxCount", new Integer(maxCount));\r
+ residueHash.put("maxResidue", maxResidue);\r
+\r
+ percentage = ( (float) maxCount * 100) / (float) jSize;\r
+ residueHash.put("pid_gaps", new Float(percentage));\r
+\r
+ percentage = ( (float) maxCount * 100) / (float) nongap;\r
+ residueHash.put("pid_nogaps", new Float(percentage));\r
+ result[i] = residueHash;\r
+ }\r
+}\r
}\r
+\r
+\r
viewport.alignment.getWidth());\r
}\r
\r
- cs.setConsensus(viewport.vconsensus);\r
+ cs.setConsensus(viewport.hconsensus);\r
if (cs.conservationApplied())\r
{\r
Alignment al = (Alignment) viewport.alignment;\r
cs.setConservation(null);\r
}\r
\r
- cs.setConsensus(viewport.vconsensus);\r
+ cs.setConsensus(viewport.hconsensus);\r
\r
}\r
viewport.setGlobalColourScheme(cs);\r
boolean showHiddenMarkers = true;\r
\r
\r
- public Vector vconsensus;\r
+ public Hashtable [] hconsensus;\r
AlignmentAnnotation consensus;\r
AlignmentAnnotation conservation;\r
AlignmentAnnotation quality;\r
globalColourScheme = ColourSchemeProperty.getColour(alignment, colour);\r
if (globalColourScheme != null)\r
{\r
- globalColourScheme.setConsensus(vconsensus);\r
+ globalColourScheme.setConsensus(hconsensus);\r
}\r
}\r
\r
\r
public void updateConsensus()\r
{\r
- Annotation[] annotations = new Annotation[alignment.getWidth()];\r
-\r
// this routine prevents vconsensus becoming a new object each time\r
// consenus is calculated. Important for speed of Blosum62\r
// and PID colouring of alignment\r
- if (vconsensus == null)\r
- {\r
- vconsensus = alignment.getAAFrequency();\r
- }\r
- else\r
- {\r
- Vector temp = alignment.getAAFrequency();\r
- vconsensus.removeAllElements();\r
- Enumeration e = temp.elements();\r
- while (e.hasMoreElements())\r
- {\r
- vconsensus.addElement(e.nextElement());\r
- }\r
- }\r
- Hashtable hash = null;\r
- for (int i = 0; i < alignment.getWidth(); i++)\r
+ int aWidth = alignment.getWidth();\r
+\r
+ Annotation[] annotations = new Annotation[aWidth];\r
+\r
+ hconsensus = new Hashtable[aWidth];\r
+ AAFrequency.calculate(alignment.getSequencesArray(),\r
+ 0, aWidth,\r
+ hconsensus);\r
+\r
+ for (int i = 0; i < aWidth; i++)\r
{\r
- hash = (Hashtable) vconsensus.elementAt(i);\r
float value = 0;\r
if(ignoreGapsInConsensusCalculation)\r
- value = ((Float)hash.get("pid_nogaps")).floatValue();\r
+ value = ((Float)hconsensus[i].get("pid_nogaps")).floatValue();\r
else\r
- value = ((Float)hash.get("pid_gaps")).floatValue();\r
+ value = ((Float)hconsensus[i].get("pid_gaps")).floatValue();\r
\r
- String maxRes = hash.get("maxResidue").toString();\r
- String mouseOver = hash.get("maxResidue") + " ";\r
+ String maxRes = hconsensus[i].get("maxResidue").toString();\r
+ String mouseOver = hconsensus[i].get("maxResidue") + " ";\r
if (maxRes.length() > 1)\r
{\r
mouseOver = "[" + maxRes + "] ";\r
}\r
\r
if(globalColourScheme!=null)\r
- globalColourScheme.setConsensus(vconsensus);\r
+ globalColourScheme.setConsensus(hconsensus);\r
\r
}\r
/**\r
float initialScale = (float) av.alignment.getWidth() /\r
(float) av.alignment.getHeight();\r
\r
- if(av.vconsensus==null)\r
+ if(av.hconsensus==null)\r
graphHeight = 0;\r
\r
if (av.alignment.getWidth() > av.alignment.getHeight())\r
return gapCharacter;
}
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public Vector getAAFrequency()
- {
- return AAFrequency.calculate(sequences, 0, getWidth());
- }
/**
* DOCUMENT ME!
*/
public char getGapCharacter();
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public Vector getAAFrequency();
/**
* Returns true if alignment is nucleotide sequence
{
this.setDropTarget(new java.awt.dnd.DropTarget(this, this));
- if (viewport.vconsensus == null)
+ if (viewport.hconsensus == null)
{
//Out of memory calculating consensus.
BLOSUM62Colour.setEnabled(false);
*/
void updateEditMenuBar()
{
- if (historyList.size() > 0)
+ /* if (historyList.size() > 0)
{
undoMenuItem.setEnabled(true);
{
redoMenuItem.setEnabled(false);
redoMenuItem.setText("Redo");
- }
+ }*/
}
/**
if (av.padGaps)
av.getAlignment().padGaps();
- if (av.vconsensus != null && av.autoCalculateConsensus)
+ if (av.hconsensus != null && av.autoCalculateConsensus)
{
av.updateConsensus();
av.updateConservation();
viewport.alignment.getWidth());
}
- cs.setConsensus(viewport.vconsensus);
+ cs.setConsensus(viewport.hconsensus);
if (cs.conservationApplied())
{
Alignment al = (Alignment) viewport.alignment;
cs.setConservation(null);
}
- cs.setConsensus(viewport.vconsensus);
+ cs.setConsensus(viewport.hconsensus);
}
viewport.setGlobalColourScheme(cs);
/** DOCUMENT ME!! */
- public Vector vconsensus;
+ public Hashtable [] hconsensus;
AlignmentAnnotation consensus;
AlignmentAnnotation conservation;
AlignmentAnnotation quality;
// We must set conservation and consensus before setting colour,
// as Blosum and Clustal require this to be done
- if(vconsensus==null && !isDataset)
+ if(hconsensus==null && !isDataset)
{
updateConservation();
updateConsensus();
if (globalColourScheme != null)
{
- globalColourScheme.setConsensus(vconsensus);
+ globalColourScheme.setConsensus(hconsensus);
}
}
}
if(alignment.isNucleotide())
return;
+ // System.out.println("UPDATING CONSERVATION");
+
try{
Conservation cons = new jalview.analysis.Conservation("All",
jalview.schemes.ResidueProperties.propHash, 3,
}
}
+
/**
* DOCUMENT ME!
*/
public void updateConsensus()
{
try{
- Annotation[] annotations = new Annotation[alignment.getWidth()];
-
- // this routine prevents vconsensus becoming a new object each time
- // consenus is calculated. Important for speed of Blosum62
- // and PID colouring of alignment
- if (vconsensus == null)
- {
- vconsensus = alignment.getAAFrequency();
- }
- else
- {
- Vector temp = alignment.getAAFrequency();
- vconsensus.clear();
-
- Enumeration e = temp.elements();
+ int aWidth = alignment.getWidth();
- while (e.hasMoreElements())
- {
- vconsensus.add(e.nextElement());
- }
- }
+ Annotation[] annotations = new Annotation[aWidth];
- Hashtable hash = null;
+ hconsensus = new Hashtable[aWidth];
+ AAFrequency.calculate(alignment.getSequencesArray(),
+ 0,
+ alignment.getWidth(),
+ hconsensus);
- for (int i = 0; i < alignment.getWidth(); i++)
+ for (int i = 0; i < aWidth; i++)
{
- hash = (Hashtable) vconsensus.elementAt(i);
-
float value = 0;
if (ignoreGapsInConsensusCalculation)
- value = ( (Float) hash.get("pid_nogaps")).floatValue();
+ value = ( (Float) hconsensus[i].get("pid_nogaps")).floatValue();
else
- value = ( (Float) hash.get("pid_gaps")).floatValue();
+ value = ( (Float) hconsensus[i].get("pid_gaps")).floatValue();
- String maxRes = hash.get("maxResidue").toString();
- String mouseOver = hash.get("maxResidue") + " ";
+ String maxRes = hconsensus[i].get("maxResidue").toString();
+ String mouseOver = hconsensus[i].get("maxResidue") + " ";
if (maxRes.length() > 1)
{
}
if (globalColourScheme != null)
- globalColourScheme.setConsensus(vconsensus);
+ globalColourScheme.setConsensus(hconsensus);
}catch(OutOfMemoryError error)
{
if(cs!=null)
{
cs.setThreshold(view.getPidThreshold(), true);
- cs.setConsensus(af.viewport.vconsensus);
+ cs.setConsensus(af.viewport.hconsensus);
}
}
if(cs!=null)\r
{\r
cs.setThreshold(view.getPidThreshold(), true);\r
- cs.setConsensus(af.viewport.vconsensus);\r
+ cs.setConsensus(af.viewport.hconsensus);\r
}\r
}\r
\r