boolean getCentreColumnLabels();
boolean isCalculationInProgress(AlignmentAnnotation alignmentAnnotation);
+
+ AlignmentAnnotation getAlignmentQualityAnnot();
+
+ AlignmentAnnotation getAlignmentConservationAnnotation();
+
+ /**
+ * Test to see if viewport is still open and active
+ * @return true indicates that all references to viewport should be dropped
+ */
+ boolean isClosed();
+ /**
+ * get the associated calculation thread manager for the view
+ * @return
+ */
+ AlignCalcManagerI getCalcManager();
+
+ /**
+ * get the percentage gaps allowed in a conservation calculation
+ *
+ */
+ public int getConsPercGaps();
}
if (conservationMenuItem.getState())
{
- Conservation c = new Conservation("Group",
+ sg.cs.setConservation(Conservation.calculateConservation("Group",
ResidueProperties.propHash, 3,
sg.getSequences(ap.av.hiddenRepSequences), 0,
- ap.av.alignment.getWidth());
-
- c.calculate();
- c.verdict(false, ap.av.ConsPercGaps);
-
- sg.cs.setConservation(c);
-
+ ap.av.alignment.getWidth(),
+ false, ap.av.getConsPercGaps(),false));
SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
SliderPanel.showConservationSlider();
}
al.getWidth() - 1);\r
\r
c.calculate();\r
- c.verdict(false, viewport.ConsPercGaps);\r
+ c.verdict(false, viewport.getConsPercGaps());\r
\r
cs.setConservation(c);\r
\r
sg.getSequences(viewport.hiddenRepSequences), 0,\r
viewport.alignment.getWidth() - 1);\r
c.calculate();\r
- c.verdict(false, viewport.ConsPercGaps);\r
+ c.verdict(false, viewport.getConsPercGaps());\r
sg.cs.setConservation(c);\r
}\r
else\r
import java.awt.*;
import jalview.analysis.*;
+import jalview.api.AlignCalcManagerI;
import jalview.api.AlignViewportI;
import jalview.bin.*;
import jalview.datamodel.*;
import jalview.schemes.*;
import jalview.structure.SelectionSource;
import jalview.structure.VamsasSource;
+import jalview.workers.ConservationThread;
-public class AlignViewport implements AlignViewportI, SelectionSource, VamsasSource
+public class AlignViewport extends AlignmentViewport implements AlignViewportI, SelectionSource, VamsasSource
{
int startRes;
boolean autocalculateConsensus = true;
- public int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
-
private java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(
this);
Hashtable hiddenRepSequences;
+ AlignCalcManagerI calculator=new jalview.workers.AlignCalcManager();
+
public void finalize() {
applet=null;
quality=null;
if (!alignment.isNucleotide())
{
conservation = new AlignmentAnnotation("Conservation",
- "Conservation of total alignment less than " + ConsPercGaps
+ "Conservation of total alignment less than " + getConsPercGaps()
+ "% gaps", new Annotation[1], 0f, 11f,
AlignmentAnnotation.BAR_GRAPH);
conservation.hasText = true;
return showSequenceFeatures;
}
- class ConservationThread extends Thread
- {
- AlignmentPanel ap;
-
- public ConservationThread(AlignmentPanel ap)
- {
- this.ap = ap;
- }
-
- public void run()
- {
- try
- {
- updatingConservation = true;
-
- while (UPDATING_CONSERVATION)
- {
- try
- {
- if (ap != null)
- {
- ap.paintAlignment(false);
- }
- Thread.sleep(200);
- } catch (Exception ex)
- {
- ex.printStackTrace();
- }
- }
-
- UPDATING_CONSERVATION = true;
-
- int alWidth = (alignment==null) ? -1 : alignment.getWidth();
- if (alWidth < 0)
- {
- updatingConservation = false;
- UPDATING_CONSERVATION = false;
- return;
- }
-
- Conservation cons = new jalview.analysis.Conservation("All",
- jalview.schemes.ResidueProperties.propHash, 3,
- alignment.getSequences(), 0, alWidth - 1);
-
- cons.calculate();
- cons.verdict(false, ConsPercGaps);
-
- if (quality != null)
- {
- cons.findQuality();
- }
-
- char[] sequence = cons.getConsSequence().getSequence();
- float minR;
- float minG;
- float minB;
- float maxR;
- float maxG;
- float maxB;
- minR = 0.3f;
- minG = 0.0f;
- minB = 0f;
- maxR = 1.0f - minR;
- maxG = 0.9f - minG;
- maxB = 0f - minB; // scalable range for colouring both Conservation and
- // Quality
-
- float min = 0f;
- float max = 11f;
- float qmin = 0f;
- float qmax = 0f;
-
- char c;
-
- conservation.annotations = new Annotation[alWidth];
-
- if (quality != null)
- {
- quality.graphMax = cons.qualityRange[1].floatValue();
- quality.annotations = new Annotation[alWidth];
- qmin = cons.qualityRange[0].floatValue();
- qmax = cons.qualityRange[1].floatValue();
- }
-
- for (int i = 0; i < alWidth; i++)
- {
- float value = 0;
-
- c = sequence[i];
-
- if (Character.isDigit(c))
- {
- value = (int) (c - '0');
- }
- else if (c == '*')
- {
- value = 11;
- }
- else if (c == '+')
- {
- value = 10;
- }
- // TODO - refactor to use a graduatedColorScheme to calculate the
- // histogram colors.
- float vprop = value - min;
- vprop /= max;
- conservation.annotations[i] = new Annotation(String.valueOf(c),
- String.valueOf(value), ' ', value, new Color(minR
- + (maxR * vprop), minG + (maxG * vprop), minB
- + (maxB * vprop)));
-
- // Quality calc
- if (quality != null)
- {
- value = ((Double) cons.quality.elementAt(i)).floatValue();
- vprop = value - qmin;
- vprop /= qmax;
- quality.annotations[i] = new Annotation(" ",
- String.valueOf(value), ' ', value, new Color(minR
- + (maxR * vprop), minG + (maxG * vprop), minB
- + (maxB * vprop)));
- }
- }
- } catch (OutOfMemoryError error)
- {
- System.out.println("Out of memory calculating conservation!!");
- conservation = null;
- quality = null;
- System.gc();
- }
-
- UPDATING_CONSERVATION = false;
- updatingConservation = false;
-
- if (ap != null)
- {
- ap.paintAlignment(true);
- }
-
- }
- }
-
- ConservationThread conservationThread;
ConsensusThread consensusThread;
return;
}
- conservationThread = new ConservationThread(ap);
- conservationThread.start();
+ calculator.startWorker(new ConservationThread(this, ap));
}
/**
cs.setConsensus(hconsensus);
if (cs.conservationApplied())
{
- Alignment al = (Alignment) alignment;
- Conservation c = new Conservation("All",
- ResidueProperties.propHash, 3, al.getSequences(), 0,
- al.getWidth() - 1);
- c.calculate();
- c.verdict(false, ConsPercGaps);
-
- cs.setConservation(c);
+ cs.setConservation(Conservation.calculateConservation("All",
+ ResidueProperties.propHash, 3, alignment.getSequences(), 0,
+ alignment.getWidth(), false, getConsPercGaps(), false));
}
}
{
return null; // TODO: JAL-891 port to jvlite : refactor and introduce hStrucConsensus;
}
+
+ @Override
+ public AlignmentAnnotation getAlignmentQualityAnnot()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public AlignmentAnnotation getAlignmentConservationAnnotation()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public boolean isClosed()
+ {
+ System.err.println("Alignment is "+alignment==null ? "closed" : "open");
+ return alignment==null;
+ }
+
+ @Override
+ public AlignCalcManagerI getCalcManager()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
}
sg.getStartRes(), sg.getEndRes());
c.calculate();
- c.verdict(false, av.ConsPercGaps);
+ c.verdict(false, av.getConsPercGaps());
cs.setConservation(c);
sg.cs = cs;
al.getWidth() - 1);
c.calculate();
- c.verdict(false, viewport.ConsPercGaps);
+ c.verdict(false, viewport.getConsPercGaps());
cs.setConservation(c);
sg.getSequences(viewport.hiddenRepSequences),
sg.getStartRes(), sg.getEndRes() + 1);
c.calculate();
- c.verdict(false, viewport.ConsPercGaps);
+ c.verdict(false, viewport.getConsPercGaps());
sg.cs.setConservation(c);
}
else
import java.awt.*;
import jalview.analysis.*;
+import jalview.api.AlignCalcManagerI;
import jalview.api.AlignViewportI;
+import jalview.api.AlignmentViewPanel;
+import jalview.api.OOMHandlerI;
import jalview.bin.*;
import jalview.structure.SelectionSource;
import jalview.structure.StructureSelectionManager;
import jalview.structure.VamsasSource;
+import jalview.workers.AlignCalcManager;
+import jalview.workers.ConservationThread;
/**
* DOCUMENT ME!
* @author $author$
* @version $Revision: 1.141 $
*/
-public class AlignViewport implements SelectionSource, VamsasSource, AlignViewportI
+public class AlignViewport extends AlignmentViewport implements SelectionSource, VamsasSource, AlignViewportI
{
private static final int RIGHT_JUSTIFY = 1;
boolean autoCalculateStrucConsensus = true;
- /** DOCUMENT ME!! */
- public int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
-
// JBPNote Prolly only need this in the applet version.
private java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(
this);
if (!alignment.isNucleotide())
{
conservation = new AlignmentAnnotation("Conservation",
- "Conservation of total alignment less than " + ConsPercGaps
+ "Conservation of total alignment less than " + getConsPercGaps()
+ "% gaps", new Annotation[1], 0f, 11f,
AlignmentAnnotation.BAR_GRAPH);
conservation.hasText = true;
{
return showSequenceFeatures;
}
-
- ConservationThread conservationThread;
+
+ AlignCalcManagerI calculator=new AlignCalcManager();
ConsensusThread consensusThread;
/**
* trigger update of conservation annotation
*/
- public void updateConservation(final AlignmentPanel ap)
+ public void updateConservation(final AlignmentViewPanel ap)
{
// see note in mantis : issue number 8585
if (alignment.isNucleotide() || conservation == null
{
return;
}
-
- conservationThread = new ConservationThread(this, ap);
- conservationThread.start();
+
+ calculator.startWorker(new jalview.workers.ConservationThread(this, ap));
}
/**
class ConsensusThread extends Thread
{
- AlignmentPanel ap;
-
+ AlignmentViewPanel ap;
public ConsensusThread(AlignmentPanel ap)
{
this.ap = ap;
alignment.deleteAnnotation(consensus);
consensus = null;
- hconsensus = null;
- new OOMWarning("calculating consensus", error);
+ hconsensus = null;
+ ap.raiseOOMWarning("calculating consensus", error);
}
UPDATING_CONSENSUS = false;
updatingConsensus = false;
cs.setConsensus(hconsensus);
if (cs.conservationApplied())
{
- Alignment al = (Alignment) alignment;
+ AlignmentI al = (Alignment) alignment;
Conservation c = new Conservation("All",
ResidueProperties.propHash, 3, al.getSequences(), 0, al
.getWidth() - 1);
c.calculate();
- c.verdict(false, ConsPercGaps);
+ c.verdict(false, getConsPercGaps());
cs.setConservation(c);
}
{
return hStrucConsensus;
}
+
+ @Override
+ public AlignmentAnnotation getAlignmentQualityAnnot()
+ {
+ return quality;
+ }
+
+ @Override
+ public AlignmentAnnotation getAlignmentConservationAnnotation()
+ {
+ return conservation;
+ }
+
+ @Override
+ public boolean isClosed()
+ {
+ // TODO: check that this isClosed is only true after panel is closed, not before it is fully constructed.
+ return alignment==null;
+ }
+
+ @Override
+ public AlignCalcManagerI getCalcManager()
+ {
+ return calculator;
+ }
}
+++ /dev/null
-/*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
- * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, G Barton, M Clamp, S Searle
- *
- * This file is part of Jalview.
- *
- * Jalview is free software: you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
- *
- * Jalview is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
- */
-package jalview.gui;
-
-import jalview.analysis.Conservation;
-import jalview.datamodel.Annotation;
-
-import java.awt.Color;
-
-class ConservationThread extends Thread
-{
- /**
- *
- */
- private AlignViewport alignViewport;
-
- AlignmentPanel ap;
-
- public ConservationThread(AlignViewport alignViewport, AlignmentPanel ap)
- {
- this.alignViewport = alignViewport;
- this.ap = ap;
- }
-
- public void run()
- {
- try
- {
- this.alignViewport.updatingConservation = true;
-
- while (AlignViewport.UPDATING_CONSERVATION)
- {
- try
- {
- if (ap != null)
- {
- ap.paintAlignment(false);
- }
- Thread.sleep(200);
- } catch (Exception ex)
- {
- ex.printStackTrace();
- }
- }
-
- AlignViewport.UPDATING_CONSERVATION = true;
-
- int alWidth;
-
- if (alignViewport==null || alignViewport.alignment==null || (alWidth=alignViewport.alignment.getWidth())< 0)
- {
- this.alignViewport.updatingConservation = false;
- AlignViewport.UPDATING_CONSERVATION = false;
- return;
- }
-
- Conservation cons = new jalview.analysis.Conservation("All",
- jalview.schemes.ResidueProperties.propHash, 3,
- this.alignViewport.alignment.getSequences(), 0, alWidth - 1);
-
- cons.calculate();
- cons.verdict(false, this.alignViewport.ConsPercGaps);
-
- if (this.alignViewport.quality != null)
- {
- cons.findQuality();
- }
- cons.completeAnnotations(alignViewport.conservation,
- alignViewport.quality, 0, alWidth);
- } catch (OutOfMemoryError error)
- {
- new OOMWarning("calculating conservation", error);
-
- this.alignViewport.conservation = null;
- this.alignViewport.quality = null;
-
- }
-
- AlignViewport.UPDATING_CONSERVATION = false;
- this.alignViewport.updatingConservation = false;
-
- if (ap != null)
- {
- ap.paintAlignment(true);
- }
-
- }
-}
sg.getEndRes() + 1);
c.calculate();
- c.verdict(false, ap.av.ConsPercGaps);
+ c.verdict(false, ap.av.getConsPercGaps());
sg.cs.setConservation(c);
sg.getStartRes(), sg.getEndRes());
c.calculate();
- c.verdict(false, aps[a].av.ConsPercGaps);
+ c.verdict(false, aps[a].av.getConsPercGaps());
sg.cs.setConservation(c);
}
--- /dev/null
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
+ * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, G Barton, M Clamp, S Searle
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
+ */
+package jalview.workers;
+
+import jalview.analysis.Conservation;
+import jalview.api.AlignCalcWorkerI;
+import jalview.api.AlignmentViewPanel;
+import jalview.api.AlignViewportI;
+import jalview.datamodel.AlignmentAnnotation;
+import jalview.datamodel.AlignmentI;
+
+public class ConservationThread extends AlignCalcWorker implements AlignCalcWorkerI
+{
+
+ private int ConsPercGaps = 25; // JBPNote : This should be a configurable property!
+
+ public ConservationThread(AlignViewportI alignViewport, AlignmentViewPanel alignPanel)
+ {
+ super(alignViewport, alignPanel);
+ ConsPercGaps = alignViewport.getConsPercGaps();
+ }
+
+ public void run()
+ {
+ try
+ {
+ calcMan.notifyStart(this); // updatingConservation = true;
+
+ while (calcMan.alreadyDoing(this)) //UPDATING_CONSERVATION)
+ {
+ try
+ {
+ if (ap != null)
+ {
+ ap.paintAlignment(false);
+ }
+ Thread.sleep(200);
+ } catch (Exception ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+ calcMan.notifyWorking(this);
+ if (alignViewport.isClosed()) {
+ abortAndDestroy();
+ }
+
+ AlignmentI alignment=alignViewport.getAlignment();
+ AlignmentAnnotation conservation=alignViewport.getAlignmentConservationAnnotation();
+ AlignmentAnnotation quality=alignViewport.getAlignmentQualityAnnot();
+ // AlignViewport.UPDATING_CONSERVATION = true;
+
+ int alWidth;
+
+ if (alignment==null || (alWidth=alignment.getWidth())< 0)
+ {
+ calcMan.workerComplete(this);
+ //.updatingConservation = false;
+ //AlignViewport.UPDATING_CONSERVATION = false;
+
+ return;
+ }
+
+ Conservation cons = Conservation.calculateConservation("All",
+ jalview.schemes.ResidueProperties.propHash, 3,
+ alignment.getSequences(), 0, alWidth - 1, false, ConsPercGaps, quality!=null);
+ cons.completeAnnotations(conservation,
+ quality, 0, alWidth);
+ } catch (OutOfMemoryError error)
+ {
+ ap.raiseOOMWarning("calculating conservation", error);
+ calcMan.workerCannotRun(this);
+ // alignViewport.conservation = null;
+ // this.alignViewport.quality = null;
+
+ }
+ calcMan.workerComplete(this);
+
+ if (ap != null)
+ {
+ ap.paintAlignment(true);
+ }
+
+ }
+}