From: gmungoc Date: Wed, 2 Nov 2016 11:56:49 +0000 (+0000) Subject: JAL-98 ProfileI interface for Profile X-Git-Tag: Release_2_11_0~62^2~78 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=494a321d41897be1492b973fdb37fa4ccb0ec94e;p=jalview.git JAL-98 ProfileI interface for Profile --- diff --git a/src/jalview/analysis/AAFrequency.java b/src/jalview/analysis/AAFrequency.java index 30d5373..6bdffe1 100755 --- a/src/jalview/analysis/AAFrequency.java +++ b/src/jalview/analysis/AAFrequency.java @@ -25,6 +25,7 @@ import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.AlignmentI; import jalview.datamodel.Annotation; import jalview.datamodel.Profile; +import jalview.datamodel.ProfileI; import jalview.datamodel.ResidueCount; import jalview.datamodel.SequenceI; import jalview.datamodel.ResidueCount.SymbolCounts; @@ -64,13 +65,13 @@ public class AAFrequency } } - public static final Profile[] calculate(List list, + public static final ProfileI[] calculate(List list, int start, int end) { return calculate(list, start, end, false); } - public static final Profile[] calculate(List sequences, + public static final ProfileI[] calculate(List sequences, int start, int end, boolean profile) { SequenceI[] seqs = new SequenceI[sequences.size()]; @@ -86,7 +87,7 @@ public class AAFrequency } } - Profile[] reply = new Profile[width]; + ProfileI[] reply = new ProfileI[width]; if (end >= width) { @@ -112,7 +113,7 @@ public class AAFrequency * if true, store all symbol counts */ public static final void calculate(final SequenceI[] sequences, - int start, int end, Profile[] result, boolean saveFullProfile) + int start, int end, ProfileI[] result, boolean saveFullProfile) { // long now = System.currentTimeMillis(); int seqCount = sequences.length; @@ -172,7 +173,7 @@ public class AAFrequency int maxCount = residueCounts.getModalCount(); String maxResidue = residueCounts.getResiduesForCount(maxCount); int gapCount = residueCounts.getGapCount(); - Profile profile = new Profile(seqCount, gapCount, maxCount, + ProfileI profile = new Profile(seqCount, gapCount, maxCount, maxResidue); if (saveFullProfile) @@ -233,7 +234,7 @@ public class AAFrequency * number of sequences */ public static void completeConsensus(AlignmentAnnotation consensus, - Profile[] profiles, int iStart, int width, boolean ignoreGaps, + ProfileI[] profiles, int iStart, int width, boolean ignoreGaps, boolean showSequenceLogo, long nseq) { // long now = System.currentTimeMillis(); @@ -251,7 +252,7 @@ public class AAFrequency for (int i = iStart; i < width; i++) { - Profile profile; + ProfileI profile; if (i >= profiles.length || ((profile = profiles[i]) == null)) { /* @@ -301,7 +302,7 @@ public class AAFrequency * the number of decimal places to format percentages to * @return */ - static String getTooltip(Profile profile, float pid, + static String getTooltip(ProfileI profile, float pid, boolean showSequenceLogo, boolean ignoreGaps, int dp) { ResidueCount counts = profile.getCounts(); @@ -352,7 +353,7 @@ public class AAFrequency * calculations * @return */ - public static int[] extractProfile(Profile profile, + public static int[] extractProfile(ProfileI profile, boolean ignoreGaps) { int[] rtnval = new int[64]; diff --git a/src/jalview/api/AlignViewportI.java b/src/jalview/api/AlignViewportI.java index 32f9ecd..e30a052 100644 --- a/src/jalview/api/AlignViewportI.java +++ b/src/jalview/api/AlignViewportI.java @@ -26,7 +26,7 @@ import jalview.datamodel.AlignmentI; import jalview.datamodel.AlignmentView; import jalview.datamodel.CigarArray; import jalview.datamodel.ColumnSelection; -import jalview.datamodel.Profile; +import jalview.datamodel.ProfileI; import jalview.datamodel.SequenceCollectionI; import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; @@ -82,7 +82,7 @@ public interface AlignViewportI extends ViewStyleI ColumnSelection getColumnSelection(); - Profile[] getSequenceConsensusHash(); + ProfileI[] getSequenceConsensusHash(); /** * Get consensus data table for the cDNA complement of this alignment (if any) @@ -145,7 +145,7 @@ public interface AlignViewportI extends ViewStyleI * * @param hconsensus */ - void setSequenceConsensusHash(Profile[] hconsensus); + void setSequenceConsensusHash(ProfileI[] hconsensus); /** * Set the cDNA complement consensus for the viewport diff --git a/src/jalview/datamodel/Profile.java b/src/jalview/datamodel/Profile.java index 2951e9e..5464596 100644 --- a/src/jalview/datamodel/Profile.java +++ b/src/jalview/datamodel/Profile.java @@ -2,21 +2,20 @@ package jalview.datamodel; /** - * A data bean to hold the result of computing a profile for a column of an - * alignment + * A profile for one column of an alignment * * @author gmcarstairs * */ -public class Profile +public class Profile implements ProfileI { /* - * counts of keys (chars) + * an object holding counts of symbols in the profile */ private ResidueCount counts; /* - * the number of sequences in the profile + * the number of sequences (gapped or not) in the profile */ private int height; @@ -57,24 +56,19 @@ public class Profile this.modalResidue = modalRes; } - /** - * Set the full profile of counts - * - * @param residueCounts + /* (non-Javadoc) + * @see jalview.datamodel.ProfileI#setCounts(jalview.datamodel.ResidueCount) */ + @Override public void setCounts(ResidueCount residueCounts) { this.counts = residueCounts; } - /** - * Returns the percentage identity of the profile, i.e. the highest proportion - * of conserved (equal) symbols. The percentage is as a fraction of all - * sequences, or only ungapped sequences if flag ignoreGaps is set true. - * - * @param ignoreGaps - * @return + /* (non-Javadoc) + * @see jalview.datamodel.ProfileI#getPercentageIdentity(boolean) */ + @Override public float getPercentageIdentity(boolean ignoreGaps) { if (height == 0) @@ -93,63 +87,55 @@ public class Profile return pid; } - /** - * Returns the full symbol counts for this profile - * - * @return + /* (non-Javadoc) + * @see jalview.datamodel.ProfileI#getCounts() */ + @Override public ResidueCount getCounts() { return counts; } - /** - * Returns the number of sequences in the profile - * - * @return + /* (non-Javadoc) + * @see jalview.datamodel.ProfileI#getHeight() */ + @Override public int getHeight() { return height; } - /** - * Returns the number of sequences in the profile which had a gap character - * (or were too short to be included in this column's profile) - * - * @return + /* (non-Javadoc) + * @see jalview.datamodel.ProfileI#getGapped() */ + @Override public int getGapped() { return gapped; } - /** - * Returns the highest count for any symbol(s) in the profile - * - * @return + /* (non-Javadoc) + * @see jalview.datamodel.ProfileI#getMaxCount() */ + @Override public int getMaxCount() { return maxCount; } - /** - * Returns the symbol (or concatenated symbols) which have the highest count - * in the profile, or an empty string if there were no symbols counted - * - * @return + /* (non-Javadoc) + * @see jalview.datamodel.ProfileI#getModalResidue() */ + @Override public String getModalResidue() { return modalResidue; } - /** - * Answers the number of non-gapped sequences in the profile - * - * @return + /* (non-Javadoc) + * @see jalview.datamodel.ProfileI#getNonGapped() */ + @Override public int getNonGapped() { return height - gapped; diff --git a/src/jalview/datamodel/ProfileI.java b/src/jalview/datamodel/ProfileI.java new file mode 100644 index 0000000..cf2b394 --- /dev/null +++ b/src/jalview/datamodel/ProfileI.java @@ -0,0 +1,67 @@ +package jalview.datamodel; + +public interface ProfileI +{ + + /** + * Set the full profile of counts + * + * @param residueCounts + */ + public abstract void setCounts(ResidueCount residueCounts); + + /** + * Returns the percentage identity of the profile, i.e. the highest proportion + * of conserved (equal) symbols. The percentage is as a fraction of all + * sequences, or only ungapped sequences if flag ignoreGaps is set true. + * + * @param ignoreGaps + * @return + */ + public abstract float getPercentageIdentity(boolean ignoreGaps); + + /** + * Returns the full symbol counts for this profile + * + * @return + */ + public abstract ResidueCount getCounts(); + + /** + * Returns the number of sequences in the profile + * + * @return + */ + public abstract int getHeight(); + + /** + * Returns the number of sequences in the profile which had a gap character + * (or were too short to be included in this column's profile) + * + * @return + */ + public abstract int getGapped(); + + /** + * Returns the highest count for any symbol(s) in the profile + * + * @return + */ + public abstract int getMaxCount(); + + /** + * Returns the symbol (or concatenated symbols) which have the highest count + * in the profile, or an empty string if there were no symbols counted + * + * @return + */ + public abstract String getModalResidue(); + + /** + * Answers the number of non-gapped sequences in the profile + * + * @return + */ + public abstract int getNonGapped(); + +} \ No newline at end of file diff --git a/src/jalview/datamodel/SequenceGroup.java b/src/jalview/datamodel/SequenceGroup.java index a92eade..2870a2c 100755 --- a/src/jalview/datamodel/SequenceGroup.java +++ b/src/jalview/datamodel/SequenceGroup.java @@ -527,7 +527,7 @@ public class SequenceGroup implements AnnotatedCollectionI boolean upd = false; try { - Profile[] cnsns = AAFrequency.calculate(sequences, startRes, + ProfileI[] cnsns = AAFrequency.calculate(sequences, startRes, endRes + 1, showSequenceLogo); if (consensus != null) { @@ -599,9 +599,9 @@ public class SequenceGroup implements AnnotatedCollectionI c.completeAnnotations(conservation, null, startRes, endRes + 1); } - public Profile[] consensusData = null; + public ProfileI[] consensusData = null; - private void _updateConsensusRow(Profile[] cnsns, long nseq) + private void _updateConsensusRow(ProfileI[] cnsns, long nseq) { if (consensus == null) { diff --git a/src/jalview/renderer/AnnotationRenderer.java b/src/jalview/renderer/AnnotationRenderer.java index adcedcb..d7ae950 100644 --- a/src/jalview/renderer/AnnotationRenderer.java +++ b/src/jalview/renderer/AnnotationRenderer.java @@ -28,7 +28,7 @@ import jalview.api.AlignViewportI; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.Annotation; import jalview.datamodel.ColumnSelection; -import jalview.datamodel.Profile; +import jalview.datamodel.ProfileI; import jalview.schemes.ColourSchemeI; import jalview.schemes.ResidueProperties; import jalview.util.Platform; @@ -74,7 +74,7 @@ public class AnnotationRenderer private ColumnSelection columnSelection; - private Profile[] hconsensus; + private ProfileI[] hconsensus; private Hashtable[] complementConsensus; diff --git a/src/jalview/schemes/ColourSchemeI.java b/src/jalview/schemes/ColourSchemeI.java index 54c8c99..fb71686 100755 --- a/src/jalview/schemes/ColourSchemeI.java +++ b/src/jalview/schemes/ColourSchemeI.java @@ -21,7 +21,7 @@ package jalview.schemes; import jalview.datamodel.AnnotatedCollectionI; -import jalview.datamodel.Profile; +import jalview.datamodel.ProfileI; import jalview.datamodel.SequenceCollectionI; import jalview.datamodel.SequenceI; @@ -53,7 +53,7 @@ public interface ColourSchemeI /** * assign the given consensus profile for the colourscheme */ - public void setConsensus(Profile[] hconsensus); + public void setConsensus(ProfileI[] hconsensus); /** * assign the given conservation to the colourscheme diff --git a/src/jalview/schemes/FollowerColourScheme.java b/src/jalview/schemes/FollowerColourScheme.java index e1c343c..86fce4e 100644 --- a/src/jalview/schemes/FollowerColourScheme.java +++ b/src/jalview/schemes/FollowerColourScheme.java @@ -21,7 +21,7 @@ package jalview.schemes; import jalview.analysis.Conservation; -import jalview.datamodel.Profile; +import jalview.datamodel.ProfileI; /** * Colourscheme that takes its colours from some other colourscheme @@ -40,7 +40,7 @@ public class FollowerColourScheme extends ResidueColourScheme } @Override - public void setConsensus(Profile[] consensus) + public void setConsensus(ProfileI[] consensus) { if (colourScheme != null) { diff --git a/src/jalview/schemes/ResidueColourScheme.java b/src/jalview/schemes/ResidueColourScheme.java index c9abb0e..31b8320 100755 --- a/src/jalview/schemes/ResidueColourScheme.java +++ b/src/jalview/schemes/ResidueColourScheme.java @@ -22,7 +22,7 @@ package jalview.schemes; import jalview.analysis.Conservation; import jalview.datamodel.AnnotatedCollectionI; -import jalview.datamodel.Profile; +import jalview.datamodel.ProfileI; import jalview.datamodel.SequenceCollectionI; import jalview.datamodel.SequenceI; import jalview.util.ColorUtils; @@ -54,7 +54,7 @@ public class ResidueColourScheme implements ColourSchemeI /* * Consensus data indexed by column */ - Profile[] consensus; + ProfileI[] consensus; /* * Conservation string as a char array @@ -234,7 +234,7 @@ public class ResidueColourScheme implements ColourSchemeI * DOCUMENT ME! */ @Override - public void setConsensus(Profile[] consensus) + public void setConsensus(ProfileI[] consensus) { if (consensus == null) { diff --git a/src/jalview/viewmodel/AlignmentViewport.java b/src/jalview/viewmodel/AlignmentViewport.java index 54215e1..254a201 100644 --- a/src/jalview/viewmodel/AlignmentViewport.java +++ b/src/jalview/viewmodel/AlignmentViewport.java @@ -36,7 +36,7 @@ import jalview.datamodel.Annotation; import jalview.datamodel.CigarArray; import jalview.datamodel.ColumnSelection; import jalview.datamodel.HiddenSequences; -import jalview.datamodel.Profile; +import jalview.datamodel.ProfileI; import jalview.datamodel.SearchResults; import jalview.datamodel.Sequence; import jalview.datamodel.SequenceCollectionI; @@ -701,7 +701,7 @@ public abstract class AlignmentViewport implements AlignViewportI, /** * results of alignment consensus analysis for visible portion of view */ - protected Profile[] hconsensus = null; + protected ProfileI[] hconsensus = null; /** * results of cDNA complement consensus visible portion of view @@ -735,7 +735,7 @@ public abstract class AlignmentViewport implements AlignViewportI, } @Override - public void setSequenceConsensusHash(Profile[] hconsensus) + public void setSequenceConsensusHash(ProfileI[] hconsensus) { this.hconsensus = hconsensus; } @@ -747,7 +747,7 @@ public abstract class AlignmentViewport implements AlignViewportI, } @Override - public Profile[] getSequenceConsensusHash() + public ProfileI[] getSequenceConsensusHash() { return hconsensus; } diff --git a/src/jalview/workers/ConsensusThread.java b/src/jalview/workers/ConsensusThread.java index 4bd8c48..2b11477 100644 --- a/src/jalview/workers/ConsensusThread.java +++ b/src/jalview/workers/ConsensusThread.java @@ -26,7 +26,7 @@ import jalview.api.AlignmentViewPanel; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.AlignmentI; import jalview.datamodel.Annotation; -import jalview.datamodel.Profile; +import jalview.datamodel.ProfileI; import jalview.datamodel.SequenceI; import jalview.schemes.ColourSchemeI; @@ -124,7 +124,7 @@ public class ConsensusThread extends AlignCalcWorker */ protected void computeConsensus(AlignmentI alignment) { - Profile[] hconsensus = new Profile[alignment.getWidth()]; + ProfileI[] hconsensus = new ProfileI[alignment.getWidth()]; SequenceI[] aseqs = getSequences(); AAFrequency.calculate(aseqs, 0, alignment.getWidth(), hconsensus, true); @@ -144,7 +144,7 @@ public class ConsensusThread extends AlignCalcWorker /** * @param hconsensus */ - protected void setColourSchemeConsensus(Profile[] hconsensus) + protected void setColourSchemeConsensus(ProfileI[] hconsensus) { ColourSchemeI globalColourScheme = alignViewport .getGlobalColourScheme(); @@ -177,7 +177,7 @@ public class ConsensusThread extends AlignCalcWorker public void updateResultAnnotation(boolean immediate) { AlignmentAnnotation consensus = getConsensusAnnotation(); - Profile[] hconsensus = (Profile[]) getViewportConsensus(); + ProfileI[] hconsensus = (ProfileI[]) getViewportConsensus(); if (immediate || !calcMan.isWorking(this) && consensus != null && hconsensus != null) { @@ -195,7 +195,7 @@ public class ConsensusThread extends AlignCalcWorker * the computed consensus data */ protected void deriveConsensus(AlignmentAnnotation consensusAnnotation, - Profile[] hconsensus) + ProfileI[] hconsensus) { long nseq = getSequences().length; AAFrequency.completeConsensus(consensusAnnotation, hconsensus, 0, diff --git a/test/jalview/analysis/AAFrequencyTest.java b/test/jalview/analysis/AAFrequencyTest.java index bb3510a..1c04b8e 100644 --- a/test/jalview/analysis/AAFrequencyTest.java +++ b/test/jalview/analysis/AAFrequencyTest.java @@ -25,7 +25,7 @@ import static org.testng.AssertJUnit.assertNull; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.Annotation; -import jalview.datamodel.Profile; +import jalview.datamodel.ProfileI; import jalview.datamodel.Sequence; import jalview.datamodel.SequenceI; @@ -41,12 +41,12 @@ public class AAFrequencyTest SequenceI seq3 = new Sequence("Seq3", "C---G"); SequenceI seq4 = new Sequence("Seq4", "CA--t"); SequenceI[] seqs = new SequenceI[] { seq1, seq2, seq3, seq4 }; - Profile[] result = new Profile[seq1.getLength()]; + ProfileI[] result = new ProfileI[seq1.getLength()]; AAFrequency.calculate(seqs, 0, seq1.getLength(), result, false); // col 0 is 100% C - Profile col = result[0]; + ProfileI col = result[0]; assertEquals(100f, col.getPercentageIdentity(false)); assertEquals(100f, col.getPercentageIdentity(true)); assertEquals(4, col.getMaxCount()); @@ -90,10 +90,10 @@ public class AAFrequencyTest SequenceI seq3 = new Sequence("Seq3", "C--G"); SequenceI seq4 = new Sequence("Seq4", "CA-t"); SequenceI[] seqs = new SequenceI[] { seq1, seq2, seq3, seq4 }; - Profile[] result = new Profile[seq1.getLength()]; + ProfileI[] result = new ProfileI[seq1.getLength()]; AAFrequency.calculate(seqs, 0, seq1.getLength(), result, true); - Profile profile = result[0]; + ProfileI profile = result[0]; assertEquals(4, profile.getCounts().getCount('C')); assertEquals(4, profile.getHeight()); assertEquals(4, profile.getNonGapped()); @@ -124,7 +124,7 @@ public class AAFrequencyTest SequenceI seq3 = new Sequence("Seq3", "C--G"); SequenceI seq4 = new Sequence("Seq4", "CA-t"); SequenceI[] seqs = new SequenceI[] { seq1, seq2, seq3, seq4 }; - Profile[] result = new Profile[seq1.getLength()]; + ProfileI[] result = new ProfileI[seq1.getLength()]; // ensure class loaded and initialized AAFrequency.calculate(seqs, 0, seq1.getLength(), result, true); @@ -154,7 +154,7 @@ public class AAFrequencyTest SequenceI seq3 = new Sequence("Seq3", "C---G"); SequenceI seq4 = new Sequence("Seq4", "CA--t"); SequenceI[] seqs = new SequenceI[] { seq1, seq2, seq3, seq4 }; - Profile[] profiles = new Profile[seq1.getLength()]; + ProfileI[] profiles = new ProfileI[seq1.getLength()]; AAFrequency.calculate(seqs, 0, seq1.getLength(), profiles, true); AlignmentAnnotation consensus = new AlignmentAnnotation("Consensus", @@ -195,7 +195,7 @@ public class AAFrequencyTest SequenceI seq3 = new Sequence("Seq3", "C---G"); SequenceI seq4 = new Sequence("Seq4", "CA--t"); SequenceI[] seqs = new SequenceI[] { seq1, seq2, seq3, seq4 }; - Profile[] profiles = new Profile[seq1.getLength()]; + ProfileI[] profiles = new ProfileI[seq1.getLength()]; AAFrequency.calculate(seqs, 0, seq1.getLength(), profiles, true); AlignmentAnnotation consensus = new AlignmentAnnotation("Consensus", diff --git a/test/jalview/schemes/ResidueColourSchemeTest.java b/test/jalview/schemes/ResidueColourSchemeTest.java index dcd9f94..318ba3f 100644 --- a/test/jalview/schemes/ResidueColourSchemeTest.java +++ b/test/jalview/schemes/ResidueColourSchemeTest.java @@ -5,6 +5,7 @@ import static org.testng.AssertJUnit.assertFalse; import static org.testng.AssertJUnit.assertTrue; import jalview.datamodel.Profile; +import jalview.datamodel.ProfileI; import java.awt.Color; @@ -22,7 +23,7 @@ public class ResidueColourSchemeTest * SR-T * SR-T */ - Profile[] profiles = new Profile[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, "");