+ result[column] = profile;
+ }
+ return new Profiles(result);
+ // long elapsed = System.currentTimeMillis() - now;
+ // System.out.println(elapsed);
+ }
+
+ /**
+ * Make an estimate of the profile size we are going to compute i.e. how many
+ * different characters may be present in it. Overestimating has a cost of
+ * using more memory than necessary. Underestimating has a cost of needing to
+ * extend the SparseIntArray holding the profile counts.
+ *
+ * @param profileSizes
+ * counts of sizes of profiles so far encountered
+ * @return
+ */
+ static int estimateProfileSize(SparseIntArray profileSizes)
+ {
+ if (profileSizes.size() == 0)
+ {
+ return 4;
+ }
+
+ /*
+ * could do a statistical heuristic here e.g. 75%ile
+ * for now just return the largest value
+ */
+ return profileSizes.keyAt(profileSizes.size() - 1);
+ }
+
+ /**
+ * Derive the consensus annotations to be added to the alignment for display.
+ * This does not recompute the raw data, but may be called on a change in
+ * display options, such as 'ignore gaps', which may in turn result in a
+ * change in the derived values.
+ *
+ * @param consensus
+ * the annotation row to add annotations to
+ * @param profiles
+ * the source consensus data
+ * @param startCol
+ * start column (inclusive)
+ * @param endCol
+ * end column (exclusive)
+ * @param ignoreGaps
+ * if true, normalise residue percentages ignoring gaps
+ * @param showSequenceLogo
+ * if true include all consensus symbols, else just show modal
+ * residue
+ * @param nseq
+ * number of sequences
+ */
+ public static void completeConsensus(AlignmentAnnotation consensus,
+ ProfilesI profiles, int startCol, int endCol, boolean ignoreGaps,
+ boolean showSequenceLogo, long nseq)
+ {
+ // long now = System.currentTimeMillis();
+ if (consensus == null || consensus.annotations == null
+ || consensus.annotations.length < endCol)
+ {
+ /*
+ * called with a bad alignment annotation row
+ * wait for it to be initialised properly
+ */
+ return;
+ }
+
+ for (int i = startCol; i < endCol; i++)
+ {
+ ProfileI profile = profiles.get(i);
+ if (profile == null)
+ {
+ /*
+ * happens if sequences calculated over were
+ * shorter than alignment width
+ */
+ consensus.annotations[i] = null;
+ return;