*/
package jalview.analysis;
-import java.util.*;
-
+import jalview.datamodel.AlignmentAnnotation;
+import jalview.datamodel.Annotation;
+import jalview.datamodel.SequenceI;
import jalview.util.Format;
-import jalview.datamodel.*;
+
+import java.util.Hashtable;
+import java.util.List;
/**
* Takes in a vector or array of sequences and column start and column end and
*/
public class AAFrequency
{
- // No need to store 1000s of strings which are not
- // visible to the user.
+ private static final int TO_UPPER_CASE = 'A' - 'a'; // -32
+
public static final String MAXCOUNT = "C";
public static final String MAXRESIDUE = "R";
public static final String PROFILE = "P";
+ /*
+ * Quick look-up of String value of char 'A' to 'Z'
+ */
+ private static final String[] CHARS = new String['Z' - 'A' + 1];
+
+ static
+ {
+ for (char c = 'A'; c <= 'Z'; c++)
+ {
+ CHARS[c - 'A'] = String.valueOf(c);
+ }
+ }
+
public static final Hashtable[] calculate(List<SequenceI> list,
int start, int end)
{
}
public static final void calculate(SequenceI[] sequences, int start,
- int end, Hashtable[] result)
- {
- calculate(sequences, start, end, result, false);
- }
-
- public static final void calculate(SequenceI[] sequences, int start,
int end, Hashtable[] result, boolean profile)
{
Hashtable residueHash;
- int maxCount, nongap, i, j, v, jSize = sequences.length;
+ int maxCount, nongap, i, j, v;
+ int jSize = sequences.length;
String maxResidue;
char c = '-';
float percentage;
}
else if ('a' <= c && c <= 'z')
{
- c -= 32; // ('a' - 'A');
+ c += TO_UPPER_CASE;
}
nongap++;
}
else
{
- for (v = 'A'; v < 'Z'; v++)
+ for (v = 'A'; v <= 'Z'; v++)
{
if (values[v] < 2 || values[v] < maxCount)
{
if (values[v] > maxCount)
{
- maxResidue = String.valueOf((char) v);
+ maxResidue = CHARS[v - 'A'];
}
else if (values[v] == maxCount)
{
- maxResidue += String.valueOf((char) v);
+ maxResidue += CHARS[v - 'A'];
}
maxCount = values[v];
}
{
completeConsensus(consensus, hconsensus, iStart, width,
ignoreGapsInConsensusCalculation, includeAllConsSymbols, null,
- nseq); // new
- // char[]
- // { 'A', 'C', 'G', 'T', 'U' });
+ nseq);
}
public static void completeConsensus(AlignmentAnnotation consensus,
int[] rtnval = new int[64];
int[][] profile = (int[][]) hconsensus.get(AAFrequency.PROFILE);
if (profile == null)
+ {
return null;
- Object[] ca = new Object[profile[0].length];
+ }
+ char[][] ca = new char[profile[0].length][];
float[] vl = new float[profile[0].length];
for (int c = 0; c < ca.length; c++)
{
{ (char) c };
vl[c] = profile[0][c];
}
- ;
jalview.util.QuickSort.sort(vl, ca);
rtnval[0] = 2;
rtnval[1] = 0;
- for (int c = ca.length - 1; profile[0][((char[]) ca[c])[0]] > 0; c--)
+ for (int c = ca.length - 1; profile[0][ca[c][0]] > 0; c--)
{
- if (((char[]) ca[c])[0] != '-')
+ if (ca[c][0] != '-')
{
- rtnval[rtnval[0]++] = ((char[]) ca[c])[0];
- rtnval[rtnval[0]] = (int) (profile[0][((char[]) ca[c])[0]] * 100f / profile[1][ignoreGapsInConsensusCalculation ? 1
+ rtnval[rtnval[0]++] = ca[c][0];
+ rtnval[rtnval[0]] = (int) (profile[0][ca[c][0]] * 100f / profile[1][ignoreGapsInConsensusCalculation ? 1
: 0]);
rtnval[1] += rtnval[rtnval[0]++];
}
seqs[i] = align.getSequenceAt(i);
}
- QuickSort.sort(scores, 0, scores.length - 1, seqs);
+ QuickSort.sort(scores, seqs);
setReverseOrder(align, seqs);
}
// TODO there may be one AlignedCodonFrame per dataset sequence, or one with
// all mappings. Would it help to constrain this?
List<AlignedCodonFrame> mappings = al.getCodonFrame(seq);
- if (mappings == null)
+ if (mappings == null || mappings.isEmpty())
{
return false;
}
*/
package jalview.io;
-import java.io.*;
-import java.util.*;
+import jalview.datamodel.Sequence;
+import jalview.datamodel.SequenceI;
+import jalview.util.Format;
-import jalview.datamodel.*;
-import jalview.util.*;
+import java.io.IOException;
+import java.util.Hashtable;
+import java.util.StringTokenizer;
+import java.util.Vector;
/**
* DOCUMENT ME!
super(source);
}
- {
- // TODO Auto-generated constructor stub
- }
-
/**
* DOCUMENT ME!
*/
import jalview.datamodel.SequenceI;
import java.awt.Color;
-import java.util.Hashtable;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.Vector;
-public class ClustalxColourScheme extends ResidueColourScheme // implements
-// IParameterizable
+public class ClustalxColourScheme extends ResidueColourScheme
{
- public static Hashtable colhash = new Hashtable();
+ private static final int EIGHTY_FIVE = 85;
- Hashtable[] cons;
+ private static final int FIFTY = 50;
- int[][] cons2;
+ private static final int EIGHTY = 80;
- ConsensusColour[] colours;
+ private static final int SIXTY = 60;
- ConsensusColour[] ResidueColour;
+ /*
+ * Map from conventional colour names to Clustal version of the same
+ */
+ private static Map<Color, Color> colhash = new HashMap<Color, Color>();
+
+ private int[][] cons2;
+
+ private ConsensusColour[] colours;
- int size;
+ private ConsensusColour[] residueColour;
- Consensus[] conses = new Consensus[32];
+ private int size;
- Vector colourTable = new Vector();
+ private Consensus[] conses = new Consensus[32];
private boolean includeGaps = true;
+ static
{
- colhash.put("RED", new Color((float) 0.9, (float) 0.2, (float) 0.1));
- colhash.put("BLUE", new Color((float) 0.5, (float) 0.7, (float) 0.9));
- colhash.put("GREEN", new Color((float) 0.1, (float) 0.8, (float) 0.1));
- colhash.put("ORANGE", new Color((float) 0.9, (float) 0.6, (float) 0.3));
- colhash.put("CYAN", new Color((float) 0.1, (float) 0.7, (float) 0.7));
- colhash.put("PINK", new Color((float) 0.9, (float) 0.5, (float) 0.5));
- colhash.put("MAGENTA", new Color((float) 0.8, (float) 0.3, (float) 0.8));
- colhash.put("YELLOW", new Color((float) 0.8, (float) 0.8, (float) 0.0));
+ colhash.put(Color.RED, new Color(0.9f, 0.2f, 0.1f));
+ colhash.put(Color.BLUE, new Color(0.5f, 0.7f, 0.9f));
+ colhash.put(Color.GREEN, new Color(0.1f, 0.8f, 0.1f));
+ colhash.put(Color.ORANGE, new Color(0.9f, 0.6f, 0.3f));
+ colhash.put(Color.CYAN, new Color(0.1f, 0.7f, 0.7f));
+ colhash.put(Color.PINK, new Color(0.9f, 0.5f, 0.5f));
+ colhash.put(Color.MAGENTA, new Color(0.8f, 0.3f, 0.8f));
+ colhash.put(Color.YELLOW, new Color(0.8f, 0.8f, 0.0f));
}
public ClustalxColourScheme(AnnotatedCollectionI alignment,
public void makeColours()
{
- conses[0] = new Consensus("WLVIMAFCYHP", 60);
- conses[1] = new Consensus("WLVIMAFCYHP", 80);
- conses[2] = new Consensus("ED", 50);
- conses[3] = new Consensus("KR", 60);
- conses[4] = new Consensus("G", 50);
- conses[5] = new Consensus("N", 50);
- conses[6] = new Consensus("QE", 50);
- conses[7] = new Consensus("P", 50);
- conses[8] = new Consensus("TS", 50);
-
- conses[26] = new Consensus("A", 85);
- conses[27] = new Consensus("C", 85);
- conses[10] = new Consensus("E", 85);
- conses[11] = new Consensus("F", 85);
- conses[12] = new Consensus("G", 85);
- conses[13] = new Consensus("H", 85);
- conses[14] = new Consensus("I", 85);
- conses[15] = new Consensus("L", 85);
- conses[16] = new Consensus("M", 85);
- conses[17] = new Consensus("N", 85);
- conses[18] = new Consensus("P", 85);
- conses[19] = new Consensus("Q", 85);
- conses[20] = new Consensus("R", 85);
- conses[21] = new Consensus("S", 85);
- conses[22] = new Consensus("T", 85);
- conses[23] = new Consensus("V", 85);
- conses[24] = new Consensus("W", 85);
- conses[25] = new Consensus("Y", 85);
- conses[28] = new Consensus("K", 85);
- conses[29] = new Consensus("D", 85);
+ conses[0] = new Consensus("WLVIMAFCYHP", SIXTY);
+ conses[1] = new Consensus("WLVIMAFCYHP", EIGHTY);
+ conses[2] = new Consensus("ED", FIFTY);
+ conses[3] = new Consensus("KR", SIXTY);
+ conses[4] = new Consensus("G", FIFTY);
+ conses[5] = new Consensus("N", FIFTY);
+ conses[6] = new Consensus("QE", FIFTY);
+ conses[7] = new Consensus("P", FIFTY);
+ conses[8] = new Consensus("TS", FIFTY);
+
+ conses[26] = new Consensus("A", EIGHTY_FIVE);
+ conses[27] = new Consensus("C", EIGHTY_FIVE);
+ conses[10] = new Consensus("E", EIGHTY_FIVE);
+ conses[11] = new Consensus("F", EIGHTY_FIVE);
+ conses[12] = new Consensus("G", EIGHTY_FIVE);
+ conses[13] = new Consensus("H", EIGHTY_FIVE);
+ conses[14] = new Consensus("I", EIGHTY_FIVE);
+ conses[15] = new Consensus("L", EIGHTY_FIVE);
+ conses[16] = new Consensus("M", EIGHTY_FIVE);
+ conses[17] = new Consensus("N", EIGHTY_FIVE);
+ conses[18] = new Consensus("P", EIGHTY_FIVE);
+ conses[19] = new Consensus("Q", EIGHTY_FIVE);
+ conses[20] = new Consensus("R", EIGHTY_FIVE);
+ conses[21] = new Consensus("S", EIGHTY_FIVE);
+ conses[22] = new Consensus("T", EIGHTY_FIVE);
+ conses[23] = new Consensus("V", EIGHTY_FIVE);
+ conses[24] = new Consensus("W", EIGHTY_FIVE);
+ conses[25] = new Consensus("Y", EIGHTY_FIVE);
+ conses[28] = new Consensus("K", EIGHTY_FIVE);
+ conses[29] = new Consensus("D", EIGHTY_FIVE);
conses[30] = new Consensus("G", 0);
conses[31] = new Consensus("P", 0);
Consensus[] tmp8 = new Consensus[1];
tmp8[0] = conses[30]; // G
- colours[7] = new ConsensusColour((Color) colhash.get("ORANGE"), tmp8);
+ colours[7] = new ConsensusColour(colhash.get(Color.ORANGE), tmp8);
Consensus[] tmp9 = new Consensus[1];
tmp9[0] = conses[31]; // P
- colours[8] = new ConsensusColour((Color) colhash.get("YELLOW"), tmp9);
+ colours[8] = new ConsensusColour(colhash.get(Color.YELLOW), tmp9);
Consensus[] tmp10 = new Consensus[1];
tmp10[0] = conses[27]; // C
- colours[9] = new ConsensusColour((Color) colhash.get("PINK"), tmp8);
+ colours[9] = new ConsensusColour(colhash.get(Color.PINK), tmp8);
Consensus[] tmp1 = new Consensus[14];
tmp1[0] = conses[0]; // %
tmp1[11] = conses[25]; // Y
tmp1[12] = conses[18]; // P
tmp1[13] = conses[19]; // p
- colours[0] = new ConsensusColour((Color) colhash.get("BLUE"), tmp1);
+ colours[0] = new ConsensusColour(colhash.get(Color.BLUE), tmp1);
- colours[10] = new ConsensusColour((Color) colhash.get("CYAN"), tmp1);
+ colours[10] = new ConsensusColour(colhash.get(Color.CYAN), tmp1);
Consensus[] tmp2 = new Consensus[5];
tmp2[0] = conses[8]; // t
tmp2[2] = conses[22]; // T
tmp2[3] = conses[0]; // %
tmp2[4] = conses[1]; // #
- colours[1] = new ConsensusColour((Color) colhash.get("GREEN"), tmp2);
+ colours[1] = new ConsensusColour(colhash.get(Color.GREEN), tmp2);
Consensus[] tmp3 = new Consensus[3];
tmp3[0] = conses[17]; // N
tmp3[1] = conses[29]; // D
tmp3[2] = conses[5]; // n
- colours[2] = new ConsensusColour((Color) colhash.get("GREEN"), tmp3);
+ colours[2] = new ConsensusColour(colhash.get(Color.GREEN), tmp3);
Consensus[] tmp4 = new Consensus[6];
tmp4[0] = conses[6]; // q = QE
tmp4[3] = conses[3]; // +
tmp4[4] = conses[28]; // K
tmp4[5] = conses[20]; // R
- colours[3] = new ConsensusColour((Color) colhash.get("GREEN"), tmp4);
+ colours[3] = new ConsensusColour(colhash.get(Color.GREEN), tmp4);
Consensus[] tmp5 = new Consensus[4];
tmp5[0] = conses[3]; // +
tmp5[1] = conses[28]; // K
tmp5[2] = conses[20]; // R
tmp5[3] = conses[19]; // Q
- colours[4] = new ConsensusColour((Color) colhash.get("RED"), tmp5);
+ colours[4] = new ConsensusColour(colhash.get(Color.RED), tmp5);
Consensus[] tmp6 = new Consensus[6];
tmp6[0] = conses[3]; // -
tmp6[3] = conses[6]; // QE
tmp6[4] = conses[19]; // Q
tmp6[5] = conses[2]; // DE
- colours[5] = new ConsensusColour((Color) colhash.get("MAGENTA"), tmp6);
+ colours[5] = new ConsensusColour(colhash.get(Color.MAGENTA), tmp6);
Consensus[] tmp7 = new Consensus[5];
tmp7[0] = conses[3]; // -
tmp7[2] = conses[10]; // E
tmp7[3] = conses[17]; // N
tmp7[4] = conses[2]; // DE
- colours[6] = new ConsensusColour((Color) colhash.get("MAGENTA"), tmp7);
+ colours[6] = new ConsensusColour(colhash.get(Color.MAGENTA), tmp7);
// Now attach the ConsensusColours to the residue letters
- ResidueColour = new ConsensusColour[20];
- ResidueColour[0] = colours[0]; // A
- ResidueColour[1] = colours[4]; // R
- ResidueColour[2] = colours[2]; // N
- ResidueColour[3] = colours[6]; // D
- ResidueColour[4] = colours[0]; // C
- ResidueColour[5] = colours[3]; // Q
- ResidueColour[6] = colours[5]; // E
- ResidueColour[7] = colours[7]; // G
- ResidueColour[8] = colours[10]; // H
- ResidueColour[9] = colours[0]; // I
- ResidueColour[10] = colours[0]; // L
- ResidueColour[11] = colours[4]; // K
- ResidueColour[12] = colours[0]; // M
- ResidueColour[13] = colours[0]; // F
- ResidueColour[14] = colours[8]; // P
- ResidueColour[15] = colours[1]; // S
- ResidueColour[16] = colours[1]; // T
- ResidueColour[17] = colours[0]; // W
- ResidueColour[18] = colours[10]; // Y
- ResidueColour[19] = colours[0]; // V
+ residueColour = new ConsensusColour[20];
+ residueColour[0] = colours[0]; // A
+ residueColour[1] = colours[4]; // R
+ residueColour[2] = colours[2]; // N
+ residueColour[3] = colours[6]; // D
+ residueColour[4] = colours[0]; // C
+ residueColour[5] = colours[3]; // Q
+ residueColour[6] = colours[5]; // E
+ residueColour[7] = colours[7]; // G
+ residueColour[8] = colours[10]; // H
+ residueColour[9] = colours[0]; // I
+ residueColour[10] = colours[0]; // L
+ residueColour[11] = colours[4]; // K
+ residueColour[12] = colours[0]; // M
+ residueColour[13] = colours[0]; // F
+ residueColour[14] = colours[8]; // P
+ residueColour[15] = colours[1]; // S
+ residueColour[16] = colours[1]; // T
+ residueColour[17] = colours[0]; // W
+ residueColour[18] = colours[10]; // Y
+ residueColour[19] = colours[0]; // V
}
@Override
return currentColour;
}
- for (int k = 0; k < ResidueColour[i].conses.length; k++)
+ for (int k = 0; k < residueColour[i].conses.length; k++)
{
- if (ResidueColour[i].conses[k].isConserved(cons2, j, size,
+ if (residueColour[i].conses[k].isConserved(cons2, j, size,
includeGaps))
{
- currentColour = ResidueColour[i].c;
+ currentColour = residueColour[i].c;
}
}
{
if (conses[27].isConserved(cons2, j, size, includeGaps))
{
- currentColour = (Color) colhash.get("PINK");
+ currentColour = colhash.get(Color.PINK);
}
}
*/
package jalview.util;
+/**
+ * A class to perform efficient sorting of arrays of objects based on arrays of
+ * scores or other attributes. For example, residues by frequency.
+ *
+ * @author gmcarstairs
+ *
+ */
public class QuickSort
{
+ /**
+ * Sorts both arrays with respect to ascending order of the items in the first
+ * array.
+ *
+ * @param arr
+ * @param s
+ */
public static void sort(int[] arr, Object[] s)
{
sort(arr, 0, arr.length - 1, s);
}
+ /**
+ * Sorts both arrays with respect to ascending order of the items in the first
+ * array.
+ *
+ * @param arr
+ * @param s
+ */
public static void sort(float[] arr, Object[] s)
{
sort(arr, 0, arr.length - 1, s);
}
+ /**
+ * Sorts both arrays with respect to ascending order of the items in the first
+ * array.
+ *
+ * @param arr
+ * @param s
+ */
public static void sort(double[] arr, Object[] s)
{
sort(arr, 0, arr.length - 1, s);
}
+ /**
+ * Sorts both arrays with respect to descending order of the items in the
+ * first array.
+ *
+ * @param arr
+ * @param s
+ */
public static void sort(String[] arr, Object[] s)
{
stringSort(arr, 0, arr.length - 1, s);
}
- public static void stringSort(String[] arr, int p, int r, Object[] s)
+ static void stringSort(String[] arr, int p, int r, Object[] s)
{
int q;
}
}
- public static void sort(float[] arr, int p, int r, Object[] s)
+ static void sort(float[] arr, int p, int r, Object[] s)
{
int q;
}
}
- public static void sort(double[] arr, int p, int r, Object[] s)
+ static void sort(double[] arr, int p, int r, Object[] s)
{
int q;
}
}
- public static void sort(int[] arr, int p, int r, Object[] s)
+ static void sort(int[] arr, int p, int r, Object[] s)
{
int q;
}
}
- private static int partition(float[] arr, int p, int r, Object[] s)
+ static int partition(float[] arr, int p, int r, Object[] s)
{
float x = arr[p];
int i = p - 1;
}
}
- private static int partition(int[] arr, int p, int r, Object[] s)
+ static int partition(int[] arr, int p, int r, Object[] s)
{
int x = arr[p];
int i = p - 1;
}
}
- private static int partition(double[] arr, int p, int r, Object[] s)
+ static int partition(double[] arr, int p, int r, Object[] s)
{
double x = arr[p];
int i = p - 1;
}
}
- private static int stringPartition(String[] arr, int p, int r, Object[] s)
+ static int stringPartition(String[] arr, int p, int r, Object[] s)
{
String x = arr[p];
int i = p - 1;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
+import java.util.Map;
+import java.util.Set;
import compbio.data.sequence.FastaSequence;
import compbio.data.sequence.JpredAlignment;
return "calculating consensus secondary structure prediction using JPred service";
}
- private static HashMap<String, String[]> jpredRowLabels = new HashMap<String, String[]>();
+ private static Map<String, String[]> jpredRowLabels = new HashMap<String, String[]>();
- private static HashSet<String> jpredRes_graph, jpredRes_ssonly;
+ private static final Set<String> jpredRes_graph;
+
+ private static final Set<String> jpredRes_ssonly;
+ static
{
- jpredRes_ssonly = new HashSet();
+ jpredRes_ssonly = new HashSet<String>();
jpredRes_ssonly.add("jnetpred".toLowerCase());
jpredRes_ssonly.add("jnetpssm".toLowerCase());
jpredRes_ssonly.add("jnethmm".toLowerCase());
- jpredRes_graph = new HashSet();
+ jpredRes_graph = new HashSet<String>();
jpredRes_graph.add("jnetconf".toLowerCase());
jpredRes_graph.add("jnet burial".toLowerCase());
}
--- /dev/null
+package jalview.analysis;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import jalview.datamodel.Sequence;
+import jalview.datamodel.SequenceI;
+
+import java.util.Hashtable;
+
+import org.junit.Test;
+
+public class AAFrequencyTest
+{
+ private static final String C = AAFrequency.MAXCOUNT;
+
+ private static final String R = AAFrequency.MAXRESIDUE;
+
+ private static final String G = AAFrequency.PID_GAPS;
+
+ private static final String N = AAFrequency.PID_NOGAPS;
+
+ private static final String P = AAFrequency.PROFILE;
+
+ @Test
+ public void testCalculate_noProfile()
+ {
+ SequenceI seq1 = new Sequence("Seq1", "CAGT");
+ SequenceI seq2 = new Sequence("Seq2", "CACT");
+ SequenceI seq3 = new Sequence("Seq3", "C--G");
+ SequenceI seq4 = new Sequence("Seq4", "CA-t");
+ SequenceI[] seqs = new SequenceI[]
+ { seq1, seq2, seq3, seq4 };
+ Hashtable[] result = new Hashtable[seq1.getLength()];
+
+ AAFrequency.calculate(seqs, 0, seq1.getLength(), result, false);
+ Hashtable col = result[0];
+ assertEquals(100f, (Float) col.get(G), 0.0001f);
+ assertEquals(100f, (Float) col.get(N), 0.0001f);
+ assertEquals(4, col.get(C));
+ assertEquals("C", col.get(R));
+ assertNull(col.get(P));
+ col = result[1];
+ assertEquals(75f, (Float) col.get(G), 0.0001f);
+ assertEquals(100f, (Float) col.get(N), 0.0001f);
+ assertEquals(3, col.get(C));
+ assertEquals("A", col.get(R));
+ col = result[2];
+ assertEquals(0f, (Float) col.get(G), 0.0001f);
+ assertEquals(0f, (Float) col.get(N), 0.0001f);
+ assertEquals(0, col.get(C));
+ assertEquals("-", col.get(R));
+ col = result[3];
+ assertEquals(75f, (Float) col.get(G), 0.0001f);
+ assertEquals(75f, (Float) col.get(N), 0.0001f);
+ assertEquals(3, col.get(C));
+ assertEquals("T", col.get(R));
+ }
+
+ @Test
+ public void testCalculate_withProfile()
+ {
+ SequenceI seq1 = new Sequence("Seq1", "CAGT");
+ SequenceI seq2 = new Sequence("Seq2", "CACT");
+ SequenceI seq3 = new Sequence("Seq3", "C--G");
+ SequenceI seq4 = new Sequence("Seq4", "CA-t");
+ SequenceI[] seqs = new SequenceI[]
+ { seq1, seq2, seq3, seq4 };
+ Hashtable[] result = new Hashtable[seq1.getLength()];
+
+ AAFrequency.calculate(seqs, 0, seq1.getLength(), result, true);
+ int[][] profile = (int[][]) result[0].get(P);
+ assertEquals(4, profile[0]['C']);
+ assertEquals(4, profile[1][0]); // no of seqs
+ assertEquals(4, profile[1][1]); // nongapped in column
+
+ profile = (int[][]) result[1].get(P);
+ assertEquals(3, profile[0]['A']);
+ assertEquals(4, profile[1][0]);
+ assertEquals(3, profile[1][1]);
+
+ profile = (int[][]) result[2].get(P);
+ assertEquals(1, profile[0]['G']);
+ assertEquals(1, profile[0]['C']);
+ assertEquals(4, profile[1][0]);
+ assertEquals(2, profile[1][1]);
+
+ profile = (int[][]) result[3].get(P);
+ assertEquals(3, profile[0]['T']);
+ assertEquals(1, profile[0]['G']);
+ assertEquals(4, profile[1][0]);
+ assertEquals(4, profile[1][1]);
+ }
+
+ @Test
+ public void testCalculate_withProfileTiming()
+ {
+ SequenceI seq1 = new Sequence("Seq1", "CAGT");
+ SequenceI seq2 = new Sequence("Seq2", "CACT");
+ SequenceI seq3 = new Sequence("Seq3", "C--G");
+ SequenceI seq4 = new Sequence("Seq4", "CA-t");
+ SequenceI[] seqs = new SequenceI[]
+ { seq1, seq2, seq3, seq4 };
+ Hashtable[] result = new Hashtable[seq1.getLength()];
+
+ // ensure class loaded and initialized
+ AAFrequency.calculate(seqs, 0, seq1.getLength(), result, true);
+ int reps = 100000;
+ long start = System.currentTimeMillis();
+ for (int i = 0; i < reps; i++)
+ {
+ AAFrequency.calculate(seqs, 0, seq1.getLength(), result, true);
+ }
+ System.out.println(System.currentTimeMillis() - start);
+ }
+}
import java.util.Arrays;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
public class QuickSortTest
assertTrue(Arrays.equals(new Object[]
{ c3, c2, c1, c4 }, things));
}
+
+ /**
+ * Test whether sort is stable i.e. equal values retain their mutual ordering.
+ */
+ @Test
+ @Ignore
+ public void testSort_withDuplicates()
+ {
+ int[] values = new int[]
+ { 3, 4, 2, 4, 1 };
+ Object [] things = new Object [] {"A", "X", "Y", "B", "Z"};
+ QuickSort.sort(values, things);
+ assertTrue(Arrays.equals(new int[]
+ { 1, 2, 3, 4, 4 }, values));
+ // this fails - do we care?
+ assertTrue(Arrays.equals(new Object[]
+ { "Z", "Y", "A", "X", "B" }, things));
+ }
}