- public static final Hashtable[] calculate(Vector sequences, int start,
- int end)
- {
- return calculate(sequences, start, end, false);
- }
-
- public static final Hashtable[] calculate(Vector sequences, int start,
- int end, boolean profile)
- {
- SequenceI[] seqs = new SequenceI[sequences.size()];
- int width = 0;
- for (int i = 0; i < sequences.size(); i++)
- {
- seqs[i] = (SequenceI) sequences.elementAt(i);
- if (seqs[i].getLength() > width)
- {
- width = seqs[i].getLength();
- }
- }
-
- Hashtable[] reply = new Hashtable[width];
-
- if (end >= width)
- {
- end = width;
- }
-
- calculate(seqs, start, end, reply, profile);
-
- return reply;
- }
-
- 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;
- String maxResidue;
- char c;
- float percentage;
-
- int[] values = new int[255];
-
- char[] seq;
-
- for (i = start; i < end; i++)
- {
- residueHash = new Hashtable();
- maxCount = 0;
- maxResidue = "";
- nongap = 0;
- values = new int[255];
-
- for (j = 0; j < jSize; j++)
- {
- if (sequences[j] == null)
- {
- System.err
- .println("WARNING: Consensus skipping null sequence - possible race condition.");
- continue;
- }
- seq = sequences[j].getSequence();
- if (seq.length > i)
- {
- c = seq[i];
-
- if (c == '.' || c == ' ')
- {
- c = '-';
- }
-
- if (c == '-')
- {
- values['-']++;
- continue;
- }
- else if ('a' <= c && c <= 'z')
- {
- c -= 32; // ('a' - 'A');
- }
-
- nongap++;
- values[c]++;
-
- }
- else
- {
- values['-']++;
- }
- }
-
- for (v = 'A'; v < 'Z'; v++)
- {
- if (values[v] < 2 || values[v] < maxCount)
- {
- continue;
- }
-
- if (values[v] > maxCount)
- {
- maxResidue = String.valueOf((char) v);
- }
- else if (values[v] == maxCount)
- {
- maxResidue += String.valueOf((char) v);
- }
- maxCount = values[v];
- }
-
- if (maxResidue.length() == 0)
- {
- maxResidue = "-";
- }
- if (profile)
- {
- residueHash.put(PROFILE, new int[][]
- { values, new int[]
- { jSize, nongap } });
- }
- residueHash.put(MAXCOUNT, new Integer(maxCount));
- residueHash.put(MAXRESIDUE, maxResidue);
-
- percentage = ((float) maxCount * 100) / (float) jSize;
- residueHash.put(PID_GAPS, new Float(percentage));
-
- percentage = ((float) maxCount * 100) / (float) nongap;
- residueHash.put(PID_NOGAPS, new Float(percentage));
- result[i] = residueHash;
- }
- }
-