import java.util.Arrays;
import java.util.Hashtable;
import java.util.List;
-import java.util.Set;
/**
* Takes in a vector or array of sequences and column start and column end and
if (profile)
{
// TODO use a 1-dimensional array with jSize, nongap in [0] and [1]
- residueHash.put(PROFILE, new int[][]
- { values, new int[]
- { jSize, nongap } });
+ residueHash.put(PROFILE, new int[][] { values,
+ new int[] { jSize, nongap } });
}
residueHash.put(MAXCOUNT, new Integer(maxCount));
residueHash.put(MAXRESIDUE, maxResidue);
mouseOver.append(hci.get(AAFrequency.MAXRESIDUE) + " ");
}
int[][] profile = (int[][]) hci.get(AAFrequency.PROFILE);
- int sequenceCount = profile[1][0];
- int nonGappedCount = profile[1][1];
- int normalisedBy = ignoreGapsInConsensusCalculation ? nonGappedCount
- : sequenceCount;
if (profile != null && includeAllConsSymbols)
{
+ int sequenceCount = profile[1][0];
+ int nonGappedCount = profile[1][1];
+ int normalisedBy = ignoreGapsInConsensusCalculation ? nonGappedCount
+ : sequenceCount;
mouseOver.setLength(0);
if (alphabet != null)
{
.append("%");
}
consensus.annotations[i] = new Annotation(maxRes,
- mouseOver.toString(), ' ',
- value);
+ mouseOver.toString(), ' ', value);
}
}
* @param hashtable
* @return
*/
- public static int[] extractCdnaProfile(Hashtable hashtable, boolean ignoreGaps)
+ public static int[] extractCdnaProfile(Hashtable hashtable,
+ boolean ignoreGaps)
{
// this holds #seqs, #ungapped, and then codon count, indexed by encoded
// codon triplet
result[1] = distinctValuesCount;
return Arrays.copyOfRange(result, 0, j);
}
-
+
/**
* Compute a consensus for the cDNA coding for a protein alignment.
*
Hashtable[] hconsensus)
{
final char gapCharacter = alignment.getGapCharacter();
- Set<AlignedCodonFrame> mappings = alignment.getCodonFrames();
+ List<AlignedCodonFrame> mappings = alignment.getCodonFrames();
if (mappings == null || mappings.isEmpty())
{
return;
{
continue;
}
- char[] codon = MappingUtils.findCodonFor(seq, col, mappings);
- int codonEncoded = CodingUtils.encodeCodon(codon);
- if (codonEncoded >= 0)
+ List<char[]> codons = MappingUtils
+ .findCodonsFor(seq, col, mappings);
+ for (char[] codon : codons)
{
- codonCounts[codonEncoded + 2]++;
- ungappedCount++;
+ int codonEncoded = CodingUtils.encodeCodon(codon);
+ if (codonEncoded >= 0)
+ {
+ codonCounts[codonEncoded + 2]++;
+ ungappedCount++;
+ }
}
}
codonCounts[1] = ungappedCount;
// array holds #seqs, #ungapped, then codon counts indexed by codon
final int[] codonCounts = (int[]) hci.get(PROFILE);
int totalCount = 0;
- StringBuilder mouseOver = new StringBuilder(32);
/*
* First pass - get total count and find the highest
String modalCodon = String.valueOf(CodingUtils
.decodeCodon(modalCodonEncoded));
if (sortedCodonCounts.length > 1
- && sortedCodonCounts[codons.length - 2] == modalCodonEncoded)
+ && sortedCodonCounts[codons.length - 2] == sortedCodonCounts[codons.length - 1])
{
+ /*
+ * two or more codons share the modal count
+ */
modalCodon = "+";
}
float pid = sortedCodonCounts[sortedCodonCounts.length - 1] * 100
*/
/*
- * Scan sorted array backwards for most frequent values first.
+ * Scan sorted array backwards for most frequent values first. Show
+ * repeated values compactly.
*/
+ StringBuilder mouseOver = new StringBuilder(32);
+ StringBuilder samePercent = new StringBuilder();
+ String percent = null;
+ String lastPercent = null;
+ Format fmt = getPercentageFormat(nseqs);
+
for (int j = codons.length - 1; j >= 0; j--)
{
int codonCount = sortedCodonCounts[j];
if (codonCount == 0)
{
+ /*
+ * remaining codons are 0% - ignore, but finish off the last one if
+ * necessary
+ */
+ if (samePercent.length() > 0)
+ {
+ mouseOver.append(samePercent).append(": ").append(percent)
+ .append("% ");
+ }
break;
}
int codonEncoded = codons[j];
final int pct = codonCount * 100 / totalCount;
String codon = String
.valueOf(CodingUtils.decodeCodon(codonEncoded));
- Format fmt = getPercentageFormat(nseqs);
- String formatted = fmt == null ? Integer.toString(pct) : fmt
- .form(pct);
+ percent = fmt == null ? Integer.toString(pct) : fmt.form(pct);
if (showProfileLogo || codonCount == modalCodonCount)
{
- mouseOver.append(codon).append(": ").append(formatted)
- .append("% ");
+ if (percent.equals(lastPercent) && j > 0)
+ {
+ samePercent.append(samePercent.length() == 0 ? "" : ", ");
+ samePercent.append(codon);
+ }
+ else
+ {
+ if (samePercent.length() > 0)
+ {
+ mouseOver.append(samePercent).append(": ")
+ .append(lastPercent).append("% ");
+ }
+ samePercent.setLength(0);
+ samePercent.append(codon);
+ }
+ lastPercent = percent;
}
}