*/
package jalview.analysis;
-import java.util.Arrays;
-import java.util.Hashtable;
-import java.util.List;
-
import jalview.datamodel.AlignedCodonFrame;
import jalview.datamodel.AlignmentAnnotation;
import jalview.datamodel.AlignmentI;
import jalview.datamodel.Annotation;
+import jalview.datamodel.HiddenMarkovModel;
import jalview.datamodel.Profile;
import jalview.datamodel.ProfileI;
import jalview.datamodel.Profiles;
import jalview.datamodel.ResidueCount.SymbolCounts;
import jalview.datamodel.SequenceI;
import jalview.ext.android.SparseIntArray;
+import jalview.schemes.ResidueProperties;
import jalview.util.Comparison;
import jalview.util.Format;
import jalview.util.MappingUtils;
import jalview.util.QuickSort;
+import java.awt.Color;
+import java.util.Arrays;
+import java.util.Hashtable;
+import java.util.List;
+
/**
* Takes in a vector or array of sequences and column start and column end and
* returns a new Hashtable[] of size maxSeqLength, if Hashtable not supplied.
{
public static final String PROFILE = "P";
+ private static final String AMINO = "amino";
+
+ private static final String DNA = "DNA";
+
/*
* Quick look-up of String value of char 'A' to 'Z'
*/
}
}
+
/**
* Calculate the consensus symbol(s) for each column in the given range.
*
// always set ranges again
gaprow.graphMax = nseq;
gaprow.graphMin = 0;
+ double scale = 0.8/nseq;
for (int i = startCol; i < endCol; i++)
{
ProfileI profile = profiles.get(i);
final int gapped = profile.getNonGapped();
- String description = String.valueOf(gapped);
+ String description = "" + gapped;
- gaprow.annotations[i] = new Annotation(description, description,
- '\0',
- gapped);
+ gaprow.annotations[i] = new Annotation("", description,
+ '\0', gapped, jalview.util.ColorUtils.bleachColour(
+ Color.DARK_GRAY, (float) scale * gapped));
}
}
return result;
}
+
/**
* Extract a sorted extract of cDNA codon profile data. The returned array
* contains
for (int col = 0; col < cols; col++)
{
// todo would prefer a Java bean for consensus data
- Hashtable<String, int[]> columnHash = new Hashtable<String, int[]>();
+ Hashtable<String, int[]> columnHash = new Hashtable<>();
// #seqs, #ungapped seqs, counts indexed by (codon encoded + 1)
int[] codonCounts = new int[66];
codonCounts[0] = alignment.getSequences().size();
}
return scale;
}
+
+ /**
+ * produces a HMM profile for a column in an alignment
+ *
+ * @param aa
+ * Alignment annotation for which the profile is being calculated
+ * @param column
+ * column in the alignment the profile is being made for
+ * @param removeBelowBackground
+ * boolean, indicating whether to ignore residues with probabilities
+ * less than their background frequencies
+ * @return
+ */
+ public static int[] getHMMProfileFor(AlignmentAnnotation aa, int column,
+ boolean removeBelowBackground)
+ {
+
+ HiddenMarkovModel hmm;
+ hmm = aa.getHMM();
+ if (hmm != null)
+ {
+ String alph = hmm.getAlphabetType();
+ int size = hmm.getNumberOfSymbols();
+ char symbols[] = new char[size];
+ int values[] = new int[size];
+ List<Character> charList = hmm.getSymbols();
+ Integer totalCount = 0;
+
+ for (int i = 0; i < size; i++)
+ {
+ char symbol = charList.get(i);
+ symbols[i] = symbol;
+ Double value;
+
+ value = hmm.getMatchEmissionProbability(column, symbol);
+ double freq;
+
+ if (AMINO.equals(alph) && removeBelowBackground)
+ {
+ freq = ResidueProperties.aminoBackgroundFrequencies.get(symbol);
+ if (value < freq)
+ {
+ value = 0d;
+ }
+ }
+ else if (DNA.equals(alph) && removeBelowBackground)
+ {
+ freq = ResidueProperties.nucleotideBackgroundFrequencies
+ .get(symbol);
+ if (value < freq)
+ {
+ value = 0d;
+ }
+ }
+ value = value * 10000;
+ values[i] = value.intValue();
+ totalCount += value.intValue();
+ }
+
+ QuickSort.sort(values, symbols);
+
+ int[] profile = new int[3 + size * 2];
+
+ profile[0] = AlignmentAnnotation.SEQUENCE_PROFILE;
+ profile[1] = size;
+ profile[2] = totalCount / 100;
+
+ if (totalCount != 0)
+ {
+ int arrayPos = 3;
+ for (int k = size - 1; k >= 0; k--)
+ {
+ Double percentage;
+ Integer value = values[k];
+ percentage = (value.doubleValue() / totalCount.doubleValue())
+ * 100d;
+ profile[arrayPos] = symbols[k];
+ profile[arrayPos + 1] = percentage.intValue();
+ arrayPos += 2;
+ }
+ }
+ return profile;
+ }
+ return null;
+ }
}