X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fworkers%2FConsensusThread.java;h=4242b2a47aa24cd2ed1211cbc75211a80b59184c;hb=3d0101179759ef157b088ea135423cd909512d9f;hp=4539ccebdb37370bda2340fd9a611a7596914475;hpb=c19d2a91ca05e052e3408bf5852d88eb5d0608f1;p=jalview.git diff --git a/src/jalview/workers/ConsensusThread.java b/src/jalview/workers/ConsensusThread.java index 4539cce..4242b2a 100644 --- a/src/jalview/workers/ConsensusThread.java +++ b/src/jalview/workers/ConsensusThread.java @@ -1,6 +1,6 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer (Version 2.9.0b2) - * Copyright (C) 2015 The Jalview Authors + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors * * This file is part of Jalview. * @@ -21,19 +21,16 @@ package jalview.workers; import jalview.analysis.AAFrequency; -import jalview.api.AlignCalcWorkerI; import jalview.api.AlignViewportI; import jalview.api.AlignmentViewPanel; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.AlignmentI; import jalview.datamodel.Annotation; +import jalview.datamodel.ProfilesI; import jalview.datamodel.SequenceI; -import jalview.schemes.ColourSchemeI; +import jalview.renderer.ResidueShaderI; -import java.util.Hashtable; - -public class ConsensusThread extends AlignCalcWorker implements - AlignCalcWorkerI +public class ConsensusThread extends AlignCalcWorker { public ConsensusThread(AlignViewportI alignViewport, AlignmentViewPanel alignPanel) @@ -53,14 +50,16 @@ public class ConsensusThread extends AlignCalcWorker implements 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) @@ -98,7 +97,7 @@ public class ConsensusThread extends AlignCalcWorker implements } } catch (OutOfMemoryError error) { - calcMan.workerCannotRun(this); + calcMan.disableWorker(this); ap.raiseOOMWarning("calculating consensus", error); } finally { @@ -120,6 +119,11 @@ public class ConsensusThread extends AlignCalcWorker implements { AlignmentAnnotation consensus = getConsensusAnnotation(); consensus.annotations = new Annotation[aWidth]; + AlignmentAnnotation gap = getGapAnnotation(); + if (gap != null) + { + gap.annotations = new Annotation[aWidth]; + } } /** @@ -127,10 +131,11 @@ public class ConsensusThread extends AlignCalcWorker implements */ protected void computeConsensus(AlignmentI alignment) { - Hashtable[] hconsensus = new Hashtable[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); @@ -147,13 +152,12 @@ public class ConsensusThread extends AlignCalcWorker implements /** * @param hconsensus */ - protected void setColourSchemeConsensus(Hashtable[] 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); } } @@ -168,6 +172,16 @@ public class ConsensusThread extends AlignCalcWorker implements } /** + * 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. */ @@ -180,11 +194,16 @@ public class ConsensusThread extends AlignCalcWorker implements public void updateResultAnnotation(boolean immediate) { AlignmentAnnotation consensus = getConsensusAnnotation(); - Hashtable[] hconsensus = 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); + } } } @@ -194,25 +213,45 @@ public class ConsensusThread extends AlignCalcWorker implements * * @param consensusAnnotation * the annotation to be populated - * @param consensusData + * @param hconsensus * the computed consensus data */ protected void deriveConsensus(AlignmentAnnotation consensusAnnotation, - Hashtable[] consensusData) + ProfilesI hconsensus) { + long nseq = getSequences().length; - AAFrequency.completeConsensus(consensusAnnotation, consensusData, 0, - consensusData.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 Hashtable[] getViewportConsensus() + protected Object getViewportConsensus() { + // TODO convert ComplementConsensusThread to use Profile return alignViewport.getSequenceConsensusHash(); } }