+ // jalview.bin.Console.outPrintln(elapsed);
+ }
+
+
+ public static final ProfilesI calculateSS(List<SequenceI> list, int start,
+ int end)
+ {
+ return calculateSS(list, start, end, false);
+ }
+
+ public static final ProfilesI calculateSS(List<SequenceI> sequences,
+ int start, int end, boolean profile)
+ {
+ SequenceI[] seqs = new SequenceI[sequences.size()];
+ int width = 0;
+ synchronized (sequences)
+ {
+ for (int i = 0; i < sequences.size(); i++)
+ {
+ seqs[i] = sequences.get(i);
+ int length = seqs[i].getLength();
+ if (length > width)
+ {
+ width = length;
+ }
+ }
+
+ if (end >= width)
+ {
+ end = width;
+ }
+
+ ProfilesI reply = calculateSS(seqs, width, start, end, profile);
+ return reply;
+ }
+ }
+
+ public static final ProfilesI calculateSS(final SequenceI[] sequences,
+ int width, int start, int end, boolean saveFullProfile)
+ {
+ // long now = System.currentTimeMillis();
+ int seqCount = sequences.length;
+
+ ProfileI[] result = new ProfileI[width];
+
+ for (int column = start; column < end; column++)
+ {
+ /*
+ * Apply a heuristic to detect nucleotide data (which can
+ * be counted in more compact arrays); here we test for
+ * more than 90% nucleotide; recheck every 10 columns in case
+ * of misleading data e.g. highly conserved Alanine in peptide!
+ * Mistakenly guessing nucleotide has a small performance cost,
+ * as it will result in counting in sparse arrays.
+ * Mistakenly guessing peptide has a small space cost,
+ * as it will use a larger than necessary array to hold counts.
+ */
+
+ int ssCount = 0;
+
+ SecondaryStructureCount ssCounts = new SecondaryStructureCount();
+
+ for (int row = 0; row < seqCount; row++)
+ {
+ if (sequences[row] == null)
+ {
+ jalview.bin.Console.errPrintln(
+ "WARNING: Consensus skipping null sequence - possible race condition.");
+ continue;
+ }
+
+ char c = sequences[row].getCharAt(column);
+
+ if (sequences[row].getLength() > column && !Comparison.isGap(c))
+ {
+
+ AlignmentAnnotation[] aa = sequences[row].getAnnotation(SS_ANNOTATION_LABEL);
+ if(aa == null) {
+ continue;
+ }
+ int seqPosition = sequences[row].findPosition(column);
+ char ss;
+ if (aa[0].getAnnotationForPosition(seqPosition) != null) {
+ ss = aa[0].getAnnotationForPosition(seqPosition).secondaryStructure;
+
+ //There is no representation for coil and it can be either ' ' or null.
+ if (ss == ' ') {
+ ss = COIL;
+ }
+ }
+ else {
+ ss = COIL;
+ }
+
+ //secondaryStructures[row][column] = ss;
+
+ ssCounts.add(ss);
+ ssCount++;
+
+ }
+ else
+ {
+ /*
+ * count a gap if the sequence doesn't reach this column
+ */
+ ssCounts.addGap();
+ }
+ }
+
+ int maxSSCount = ssCounts.getModalCount();
+ String maxSS = ssCounts.getSSForCount(maxSSCount);
+ int gapCount = ssCounts.getGapCount();
+ ProfileI profile = new Profile(maxSS, ssCount, gapCount,
+ maxSSCount);
+
+ if (saveFullProfile)
+ {
+ profile.setSSCounts(ssCounts);
+ }
+
+ result[column] = profile;
+ }
+ return new Profiles(result);
+ // long elapsed = System.currentTimeMillis() - now;
+ // jalview.bin.Console.outPrintln(elapsed);