X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fworkers%2FConsensusThread.java;h=335529c71f2395aac83628a51140601cb2d3c98e;hb=09d3b755d9b00f5c3acb44049aedd49361dc0690;hp=4bd8c4892e955df36aabdb226237484465bef095;hpb=0a5ce6145bb76fc7eb8a5cc2670e20453fbedd29;p=jalview.git diff --git a/src/jalview/workers/ConsensusThread.java b/src/jalview/workers/ConsensusThread.java index 4bd8c48..335529c 100644 --- a/src/jalview/workers/ConsensusThread.java +++ b/src/jalview/workers/ConsensusThread.java @@ -26,9 +26,9 @@ import jalview.api.AlignmentViewPanel; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.AlignmentI; import jalview.datamodel.Annotation; -import jalview.datamodel.Profile; +import jalview.datamodel.ProfilesI; import jalview.datamodel.SequenceI; -import jalview.schemes.ColourSchemeI; +import jalview.renderer.ResidueShaderI; public class ConsensusThread extends AlignCalcWorker { @@ -50,19 +50,21 @@ public class ConsensusThread extends AlignCalcWorker try { AlignmentAnnotation consensus = getConsensusAnnotation(); - if (consensus == null || calcMan.isPending(this)) + AlignmentAnnotation gap = getGapAnnotation(); + if ((consensus == null && gap == null) || calcMan.isPending(this)) { calcMan.workerComplete(this); return; } while (!calcMan.notifyWorking(this)) { - // System.err.println("Thread (Consensus"+Thread.currentThread().getName()+") Waiting around."); + // System.err.println("Thread + // (Consensus"+Thread.currentThread().getName()+") Waiting around."); try { if (ap != null) { - ap.paintAlignment(false); + ap.paintAlignment(false, false); } Thread.sleep(200); } catch (Exception ex) @@ -91,7 +93,7 @@ public class ConsensusThread extends AlignCalcWorker if (ap != null) { - ap.paintAlignment(true); + ap.paintAlignment(true, true); } } catch (OutOfMemoryError error) { @@ -117,6 +119,11 @@ public class ConsensusThread extends AlignCalcWorker { AlignmentAnnotation consensus = getConsensusAnnotation(); consensus.annotations = new Annotation[aWidth]; + AlignmentAnnotation gap = getGapAnnotation(); + if (gap != null) + { + gap.annotations = new Annotation[aWidth]; + } } /** @@ -124,10 +131,11 @@ public class ConsensusThread extends AlignCalcWorker */ protected void computeConsensus(AlignmentI alignment) { - Profile[] hconsensus = new Profile[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); @@ -144,13 +152,12 @@ public class ConsensusThread extends AlignCalcWorker /** * @param hconsensus */ - protected void setColourSchemeConsensus(Profile[] hconsensus) + protected void setColourSchemeConsensus(ProfilesI hconsensus) { - ColourSchemeI globalColourScheme = alignViewport - .getGlobalColourScheme(); - if (globalColourScheme != null) + ResidueShaderI cs = alignViewport.getResidueShading(); + if (cs != null) { - globalColourScheme.setConsensus(hconsensus); + cs.setConsensus(hconsensus); } } @@ -165,6 +172,16 @@ public class ConsensusThread extends AlignCalcWorker } /** + * Get the Gap annotation for the alignment + * + * @return + */ + protected AlignmentAnnotation getGapAnnotation() + { + return alignViewport.getAlignmentGapAnnotation(); + } + + /** * update the consensus annotation from the sequence profile data using * current visualization settings. */ @@ -177,11 +194,16 @@ public class ConsensusThread extends AlignCalcWorker public void updateResultAnnotation(boolean immediate) { AlignmentAnnotation consensus = getConsensusAnnotation(); - Profile[] hconsensus = (Profile[]) getViewportConsensus(); + ProfilesI hconsensus = (ProfilesI) getViewportConsensus(); if (immediate || !calcMan.isWorking(this) && consensus != null && hconsensus != null) { deriveConsensus(consensus, hconsensus); + AlignmentAnnotation gap = getGapAnnotation(); + if (gap != null) + { + deriveGap(gap, hconsensus); + } } } @@ -195,20 +217,39 @@ public class ConsensusThread extends AlignCalcWorker * the computed consensus data */ protected void deriveConsensus(AlignmentAnnotation consensusAnnotation, - Profile[] hconsensus) + ProfilesI hconsensus) { + long nseq = getSequences().length; - AAFrequency.completeConsensus(consensusAnnotation, hconsensus, 0, - hconsensus.length, alignViewport.isIgnoreGapsConsensus(), + AAFrequency.completeConsensus(consensusAnnotation, hconsensus, + hconsensus.getStartColumn(), hconsensus.getEndColumn() + 1, + alignViewport.isIgnoreGapsConsensus(), alignViewport.isShowSequenceLogo(), nseq); } /** + * Convert the computed consensus data into a gap annotation row for display. + * + * @param gapAnnotation + * the annotation to be populated + * @param hconsensus + * the computed consensus data + */ + protected void deriveGap(AlignmentAnnotation gapAnnotation, + ProfilesI hconsensus) + { + long nseq = getSequences().length; + AAFrequency.completeGapAnnot(gapAnnotation, hconsensus, + hconsensus.getStartColumn(), hconsensus.getEndColumn() + 1, + nseq); + } + + /** * Get the consensus data stored on the viewport. * * @return */ - protected Object[] getViewportConsensus() + protected Object getViewportConsensus() { // TODO convert ComplementConsensusThread to use Profile return alignViewport.getSequenceConsensusHash();