import jalview.datamodel.Annotation;
import jalview.datamodel.Profile;
import jalview.datamodel.ProfileI;
+import jalview.datamodel.Profiles;
+import jalview.datamodel.ProfilesI;
import jalview.datamodel.ResidueCount;
-import jalview.datamodel.SequenceI;
import jalview.datamodel.ResidueCount.SymbolCounts;
+import jalview.datamodel.SequenceI;
import jalview.ext.android.SparseIntArray;
import jalview.util.Comparison;
import jalview.util.Format;
}
}
- public static final ProfileI[] calculate(List<SequenceI> list,
+ public static final ProfilesI calculate(List<SequenceI> list,
int start, int end)
{
return calculate(list, start, end, false);
}
- public static final ProfileI[] calculate(List<SequenceI> sequences,
+ public static final ProfilesI calculate(List<SequenceI> sequences,
int start, int end, boolean profile)
{
SequenceI[] seqs = new SequenceI[sequences.size()];
for (int i = 0; i < sequences.size(); i++)
{
seqs[i] = sequences.get(i);
- if (seqs[i].getLength() > width)
+ int length = seqs[i].getLength();
+ if (length > width)
{
- width = seqs[i].getLength();
+ width = length;
}
}
- ProfileI[] reply = new ProfileI[width];
-
if (end >= width)
{
end = width;
}
- calculate(seqs, start, end, reply, profile);
+ ProfilesI reply = calculate(seqs, width, start, end, profile);
return reply;
}
}
* Calculate the consensus symbol(s) for each column in the given range.
*
* @param sequences
+ * @param width
+ * the full width of the alignment
* @param start
* start column (inclusive, base zero)
* @param end
* end column (exclusive)
- * @param result
- * array in which to store profile per column
* @param saveFullProfile
* if true, store all symbol counts
*/
- public static final void calculate(final SequenceI[] sequences,
- int start, int end, ProfileI[] result, boolean saveFullProfile)
+ public static final ProfilesI calculate(final SequenceI[] sequences,
+ int width, int start, int end, boolean saveFullProfile)
{
// long now = System.currentTimeMillis();
int seqCount = sequences.length;
int nucleotideCount = 0;
int peptideCount = 0;
+ ProfileI[] result = new ProfileI[width];
+
for (int column = start; column < end; column++)
{
/*
result[column] = profile;
}
+ return new Profiles(result);
// long elapsed = System.currentTimeMillis() - now;
// System.out.println(elapsed);
}
* the annotation row to add annotations to
* @param profiles
* the source consensus data
- * @param iStart
- * start column
- * @param width
- * end column
+ * @param startCol
+ * start column (inclusive)
+ * @param endCol
+ * end column (exclusive)
* @param ignoreGaps
* if true, normalise residue percentages ignoring gaps
* @param showSequenceLogo
* number of sequences
*/
public static void completeConsensus(AlignmentAnnotation consensus,
- ProfileI[] profiles, int iStart, int width, boolean ignoreGaps,
+ 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 < width)
+ || consensus.annotations.length < endCol)
{
/*
* called with a bad alignment annotation row
return;
}
- final int dp = getPercentageDp(nseq);
-
- for (int i = iStart; i < width; i++)
+ for (int i = startCol; i < endCol; i++)
{
- ProfileI profile;
- if (i >= profiles.length || ((profile = profiles[i]) == null))
+ ProfileI profile = profiles.get(i);
+ if (profile == null)
{
/*
* happens if sequences calculated over were
* shorter than alignment width
*/
consensus.annotations[i] = null;
- continue;
+ return;
}
+ final int dp = getPercentageDp(nseq);
+
float value = profile.getPercentageIdentity(ignoreGaps);
String description = getTooltip(profile, value, showSequenceLogo,
{
modalResidue = "+";
}
- consensus.annotations[i] = new Annotation(modalResidue,
- description, ' ', value);
+ consensus.annotations[i] = new Annotation(modalResidue, description,
+ ' ', value);
}
// long elapsed = System.currentTimeMillis() - now;
// System.out.println(-elapsed);
import jalview.datamodel.AlignmentView;
import jalview.datamodel.CigarArray;
import jalview.datamodel.ColumnSelection;
-import jalview.datamodel.ProfileI;
+import jalview.datamodel.ProfilesI;
import jalview.datamodel.SequenceCollectionI;
import jalview.datamodel.SequenceGroup;
import jalview.datamodel.SequenceI;
ColumnSelection getColumnSelection();
- ProfileI[] getSequenceConsensusHash();
+ ProfilesI getSequenceConsensusHash();
/**
* Get consensus data table for the cDNA complement of this alignment (if any)
*
* @param hconsensus
*/
- void setSequenceConsensusHash(ProfileI[] hconsensus);
+ void setSequenceConsensusHash(ProfilesI hconsensus);
/**
* Set the cDNA complement consensus for the viewport
boolean upd = false;
try
{
- ProfileI[] cnsns = AAFrequency.calculate(sequences, startRes,
+ ProfilesI cnsns = AAFrequency.calculate(sequences, startRes,
endRes + 1, showSequenceLogo);
if (consensus != null)
{
c.completeAnnotations(conservation, null, startRes, endRes + 1);
}
- public ProfileI[] consensusData = null;
+ public ProfilesI consensusData = null;
- private void _updateConsensusRow(ProfileI[] cnsns, long nseq)
+ private void _updateConsensusRow(ProfilesI cnsns, long nseq)
{
if (consensus == null)
{
import jalview.datamodel.AlignmentAnnotation;
import jalview.datamodel.Annotation;
import jalview.datamodel.ColumnSelection;
-import jalview.datamodel.ProfileI;
+import jalview.datamodel.ProfilesI;
import jalview.schemes.ColourSchemeI;
import jalview.schemes.ResidueProperties;
import jalview.util.Platform;
private ColumnSelection columnSelection;
- private ProfileI[] hconsensus;
+ private ProfilesI hconsensus;
private Hashtable[] complementConsensus;
{
// TODO? group consensus for cDNA complement
return AAFrequency.extractProfile(
- aa.groupRef.consensusData[column],
+ aa.groupRef.consensusData.get(column),
aa.groupRef.getIgnoreGapsConsensus());
}
// TODO extend annotation row to enable dynamic and static profile data to
}
else
{
- return AAFrequency.extractProfile(hconsensus[column],
+ return AAFrequency.extractProfile(
+hconsensus.get(column),
av_ignoreGapsConsensus);
}
}
res -= ('a' - 'A');
}
- if (consensus == null || j >= consensus.length || consensus[j] == null
+ if (consensus == null || consensus.get(j) == null
|| (threshold != 0 && !aboveThreshold(res, j)))
{
return Color.white;
/*
* test if this is the consensus (or joint consensus) residue
*/
- String max = consensus[j].getModalResidue();
+ String max = consensus.get(j).getModalResidue();
if (max.indexOf(res) > -1)
{
package jalview.schemes;
import jalview.datamodel.AnnotatedCollectionI;
-import jalview.datamodel.ProfileI;
+import jalview.datamodel.ProfilesI;
import jalview.datamodel.SequenceCollectionI;
import jalview.datamodel.SequenceI;
/**
* assign the given consensus profile for the colourscheme
*/
- public void setConsensus(ProfileI[] hconsensus);
+ public void setConsensus(ProfilesI hconsensus);
/**
* assign the given conservation to the colourscheme
package jalview.schemes;
import jalview.analysis.Conservation;
-import jalview.datamodel.ProfileI;
+import jalview.datamodel.ProfilesI;
/**
* Colourscheme that takes its colours from some other colourscheme
}
@Override
- public void setConsensus(ProfileI[] consensus)
+ public void setConsensus(ProfilesI consensus)
{
if (colourScheme != null)
{
*/
package jalview.schemes;
+import jalview.datamodel.ProfileI;
import jalview.datamodel.SequenceGroup;
import jalview.datamodel.SequenceI;
import jalview.util.Comparison;
c -= ('a' - 'A');
}
- if (consensus == null || j >= consensus.length || consensus[j] == null)
+ if (consensus == null || consensus.get(j) == null)
{
return Color.white;
}
double sc = 0;
- if (consensus.length <= j)
- {
- return Color.white;
- }
/*
* test whether this is the consensus (or joint consensus) residue
*/
- boolean matchesConsensus = consensus[j].getModalResidue().contains(
+ ProfileI profile = consensus.get(j);
+ boolean matchesConsensus = profile.getModalResidue().contains(
String.valueOf(c));
if (matchesConsensus)
{
- sc = consensus[j].getPercentageIdentity(ignoreGaps);
+ sc = profile.getPercentageIdentity(ignoreGaps);
if (!Comparison.isGap(c))
{
import jalview.analysis.Conservation;
import jalview.datamodel.AnnotatedCollectionI;
import jalview.datamodel.ProfileI;
+import jalview.datamodel.ProfilesI;
import jalview.datamodel.SequenceCollectionI;
import jalview.datamodel.SequenceI;
import jalview.util.ColorUtils;
/*
* Consensus data indexed by column
*/
- ProfileI[] consensus;
+ ProfilesI consensus;
/*
* Conservation string as a char array
residue -= ('a' - 'A');
}
- if (consensus == null || consensus.length < column
- || consensus[column] == null)
+ if (consensus == null)
{
return false;
}
+ ProfileI profile = consensus.get(column);
+
/*
* test whether this is the consensus (or joint consensus) residue
*/
- if (consensus[column].getModalResidue().contains(
- String.valueOf(residue)))
+ if (profile != null
+ && profile.getModalResidue().contains(String.valueOf(residue)))
{
- if (consensus[column].getPercentageIdentity(ignoreGaps) >= threshold)
+ if (profile.getPercentageIdentity(ignoreGaps) >= threshold)
{
return true;
}
* DOCUMENT ME!
*/
@Override
- public void setConsensus(ProfileI[] consensus)
+ public void setConsensus(ProfilesI consensus)
{
if (consensus == null)
{
import jalview.datamodel.CigarArray;
import jalview.datamodel.ColumnSelection;
import jalview.datamodel.HiddenSequences;
-import jalview.datamodel.ProfileI;
+import jalview.datamodel.ProfilesI;
import jalview.datamodel.SearchResults;
import jalview.datamodel.Sequence;
import jalview.datamodel.SequenceCollectionI;
/**
* results of alignment consensus analysis for visible portion of view
*/
- protected ProfileI[] hconsensus = null;
+ protected ProfilesI hconsensus = null;
/**
* results of cDNA complement consensus visible portion of view
}
@Override
- public void setSequenceConsensusHash(ProfileI[] hconsensus)
+ public void setSequenceConsensusHash(ProfilesI hconsensus)
{
this.hconsensus = hconsensus;
}
}
@Override
- public ProfileI[] getSequenceConsensusHash()
+ public ProfilesI getSequenceConsensusHash()
{
return hconsensus;
}
import jalview.datamodel.AlignmentAnnotation;
import jalview.datamodel.AlignmentI;
import jalview.datamodel.Annotation;
-import jalview.datamodel.ProfileI;
+import jalview.datamodel.ProfilesI;
import jalview.datamodel.SequenceI;
import jalview.schemes.ColourSchemeI;
*/
protected void computeConsensus(AlignmentI alignment)
{
- ProfileI[] hconsensus = new ProfileI[alignment.getWidth()];
SequenceI[] aseqs = getSequences();
- AAFrequency.calculate(aseqs, 0, alignment.getWidth(), hconsensus, true);
+ int width = alignment.getWidth();
+ ProfilesI hconsensus = AAFrequency.calculate(aseqs, width, 0,
+ width, true);
alignViewport.setSequenceConsensusHash(hconsensus);
setColourSchemeConsensus(hconsensus);
/**
* @param hconsensus
*/
- protected void setColourSchemeConsensus(ProfileI[] hconsensus)
+ protected void setColourSchemeConsensus(ProfilesI hconsensus)
{
ColourSchemeI globalColourScheme = alignViewport
.getGlobalColourScheme();
public void updateResultAnnotation(boolean immediate)
{
AlignmentAnnotation consensus = getConsensusAnnotation();
- ProfileI[] hconsensus = (ProfileI[]) getViewportConsensus();
+ ProfilesI hconsensus = (ProfilesI) getViewportConsensus();
if (immediate || !calcMan.isWorking(this) && consensus != null
&& hconsensus != null)
{
* the computed consensus data
*/
protected void deriveConsensus(AlignmentAnnotation consensusAnnotation,
- ProfileI[] hconsensus)
+ ProfilesI hconsensus)
{
+
long nseq = getSequences().length;
AAFrequency.completeConsensus(consensusAnnotation, hconsensus, 0,
- hconsensus.length, alignViewport.isIgnoreGapsConsensus(),
+ hconsensus.getEndColumn() + 1,
+ alignViewport.isIgnoreGapsConsensus(),
alignViewport.isShowSequenceLogo(), nseq);
}
*
* @return
*/
- protected Object[] getViewportConsensus()
+ protected Object getViewportConsensus()
{
// TODO convert ComplementConsensusThread to use Profile
return alignViewport.getSequenceConsensusHash();
import jalview.datamodel.AlignmentAnnotation;
import jalview.datamodel.Annotation;
import jalview.datamodel.ProfileI;
+import jalview.datamodel.ProfilesI;
import jalview.datamodel.Sequence;
import jalview.datamodel.SequenceI;
SequenceI seq3 = new Sequence("Seq3", "C---G");
SequenceI seq4 = new Sequence("Seq4", "CA--t");
SequenceI[] seqs = new SequenceI[] { seq1, seq2, seq3, seq4 };
- ProfileI[] result = new ProfileI[seq1.getLength()];
-
- AAFrequency.calculate(seqs, 0, seq1.getLength(), result, false);
+ int width = seq1.getLength();
+ ProfilesI result = AAFrequency.calculate(seqs, width, 0, width,
+ false);
// col 0 is 100% C
- ProfileI col = result[0];
+ ProfileI col = result.get(0);
assertEquals(100f, col.getPercentageIdentity(false));
assertEquals(100f, col.getPercentageIdentity(true));
assertEquals(4, col.getMaxCount());
assertNull(col.getCounts());
// col 1 is 75% A
- col = result[1];
+ col = result.get(1);
assertEquals(75f, col.getPercentageIdentity(false));
assertEquals(100f, col.getPercentageIdentity(true));
assertEquals(3, col.getMaxCount());
assertEquals("A", col.getModalResidue());
// col 2 is 50% G 50% C or 25/25 counting gaps
- col = result[2];
+ col = result.get(2);
assertEquals(25f, col.getPercentageIdentity(false));
assertEquals(50f, col.getPercentageIdentity(true));
assertEquals(1, col.getMaxCount());
assertEquals("CG", col.getModalResidue());
// col 3 is all gaps
- col = result[3];
+ col = result.get(3);
assertEquals(0f, col.getPercentageIdentity(false));
assertEquals(0f, col.getPercentageIdentity(true));
assertEquals(0, col.getMaxCount());
assertEquals("", col.getModalResidue());
// col 4 is 75% T 25% G
- col = result[4];
+ col = result.get(4);
assertEquals(75f, col.getPercentageIdentity(false));
assertEquals(75f, col.getPercentageIdentity(true));
assertEquals(3, col.getMaxCount());
SequenceI seq3 = new Sequence("Seq3", "C--G");
SequenceI seq4 = new Sequence("Seq4", "CA-t");
SequenceI[] seqs = new SequenceI[] { seq1, seq2, seq3, seq4 };
- ProfileI[] result = new ProfileI[seq1.getLength()];
+ int width = seq1.getLength();
+ ProfilesI result = AAFrequency.calculate(seqs, width, 0, width,
+ true);
- AAFrequency.calculate(seqs, 0, seq1.getLength(), result, true);
- ProfileI profile = result[0];
+ ProfileI profile = result.get(0);
assertEquals(4, profile.getCounts().getCount('C'));
assertEquals(4, profile.getHeight());
assertEquals(4, profile.getNonGapped());
- profile = result[1];
+ profile = result.get(1);
assertEquals(3, profile.getCounts().getCount('A'));
assertEquals(4, profile.getHeight());
assertEquals(3, profile.getNonGapped());
- profile = result[2];
+ profile = result.get(2);
assertEquals(1, profile.getCounts().getCount('C'));
assertEquals(1, profile.getCounts().getCount('G'));
assertEquals(4, profile.getHeight());
assertEquals(2, profile.getNonGapped());
- profile = result[3];
+ profile = result.get(3);
assertEquals(3, profile.getCounts().getCount('T'));
assertEquals(1, profile.getCounts().getCount('G'));
assertEquals(4, profile.getHeight());
SequenceI seq3 = new Sequence("Seq3", "C--G");
SequenceI seq4 = new Sequence("Seq4", "CA-t");
SequenceI[] seqs = new SequenceI[] { seq1, seq2, seq3, seq4 };
- ProfileI[] result = new ProfileI[seq1.getLength()];
- // ensure class loaded and initialized
- AAFrequency.calculate(seqs, 0, seq1.getLength(), result, true);
+ // ensure class loaded and initialised
+ int width = seq1.getLength();
+ AAFrequency.calculate(seqs, width, 0, width, true);
+
int reps = 100000;
long start = System.currentTimeMillis();
for (int i = 0; i < reps; i++)
{
- AAFrequency.calculate(seqs, 0, seq1.getLength(), result, true);
+ AAFrequency.calculate(seqs, width, 0, width, true);
}
System.out.println(System.currentTimeMillis() - start);
}
SequenceI seq3 = new Sequence("Seq3", "C---G");
SequenceI seq4 = new Sequence("Seq4", "CA--t");
SequenceI[] seqs = new SequenceI[] { seq1, seq2, seq3, seq4 };
- ProfileI[] profiles = new ProfileI[seq1.getLength()];
- AAFrequency.calculate(seqs, 0, seq1.getLength(), profiles, true);
+ int width = seq1.getLength();
+ ProfilesI profiles = AAFrequency.calculate(seqs, width, 0, width, true);
AlignmentAnnotation consensus = new AlignmentAnnotation("Consensus",
- "PID", new Annotation[seq1.getLength()]);
+ "PID", new Annotation[width]);
AAFrequency
.completeConsensus(consensus, profiles, 0, 5, false, true, 4);
SequenceI seq3 = new Sequence("Seq3", "C---G");
SequenceI seq4 = new Sequence("Seq4", "CA--t");
SequenceI[] seqs = new SequenceI[] { seq1, seq2, seq3, seq4 };
- ProfileI[] profiles = new ProfileI[seq1.getLength()];
- AAFrequency.calculate(seqs, 0, seq1.getLength(), profiles, true);
+ int width = seq1.getLength();
+ ProfilesI profiles = AAFrequency.calculate(seqs, width, 0, width, true);
AlignmentAnnotation consensus = new AlignmentAnnotation("Consensus",
- "PID", new Annotation[seq1.getLength()]);
+ "PID", new Annotation[width]);
AAFrequency
.completeConsensus(consensus, profiles, 0, 5, true, false, 4);
import jalview.datamodel.Profile;
import jalview.datamodel.ProfileI;
+import jalview.datamodel.Profiles;
import java.awt.Color;
* SR-T
* SR-T
*/
- ProfileI[] profiles = new ProfileI[4];
+ ProfileI[] profiles = new ProfileI[4];
profiles[0] = new Profile(4, 0, 2, "AS");
profiles[1] = new Profile(4, 0, 4, "R");
profiles[2] = new Profile(4, 4, 0, "");
profiles[3] = new Profile(4, 1, 2, "T");
ResidueColourScheme rcs = new ResidueColourScheme();
- rcs.setConsensus(profiles);
+ rcs.setConsensus(new Profiles(profiles));
/*
* no threshold