From 42959f09b255337ab66e0abebb02896745400a29 Mon Sep 17 00:00:00 2001 From: amwaterhouse Date: Thu, 8 Sep 2005 15:50:11 +0000 Subject: [PATCH] update consensus and conservation are in try catch for out of memory error --- src/jalview/gui/AlignViewport.java | 191 ++++++++++++++++++++---------------- 1 file changed, 104 insertions(+), 87 deletions(-) diff --git a/src/jalview/gui/AlignViewport.java b/src/jalview/gui/AlignViewport.java index ea974d5..1efb272 100755 --- a/src/jalview/gui/AlignViewport.java +++ b/src/jalview/gui/AlignViewport.java @@ -1,4 +1,4 @@ -/* + /* * Jalview - A Sequence Alignment Editor and Viewer * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle * @@ -176,9 +176,10 @@ public class AlignViewport */ public void updateConservation() { + try{ Conservation cons = new jalview.analysis.Conservation("All", - jalview.schemes.ResidueProperties.propHash, 3, - alignment.getSequences(), 0, alignment.getWidth() - 1); + jalview.schemes.ResidueProperties.propHash, 3, + alignment.getSequences(), 0, alignment.getWidth() - 1); cons.calculate(); cons.verdict(false, ConsPercGaps); cons.findQuality(); @@ -207,71 +208,80 @@ public class AlignViewport for (int i = 0; i < alWidth; i++) { - float value = 0; - - try + float value = 0; + + try + { + value = Integer.parseInt(sequence.charAt(i) + ""); + } + catch (Exception ex) + { + if (sequence.charAt(i) == '*') { - value = Integer.parseInt(sequence.charAt(i) + ""); + value = 11; } - catch (Exception ex) - { - if (sequence.charAt(i) == '*') - { - value = 11; - } - if (sequence.charAt(i) == '+') - { - value = 10; - } + if (sequence.charAt(i) == '+') + { + value = 10; } - - float vprop = value - min; - vprop /= max; - annotations[i] = new Annotation(sequence.charAt(i) + "", - String.valueOf(value), ' ', value, - new Color(minR + (maxR * vprop), minG + (maxG * vprop), - minB + (maxB * vprop))); - - // Quality calc - value = ((Double) cons.quality.get(i)).floatValue(); - vprop = value - qmin; - vprop /= qmax; - qannotations[i] = new Annotation(" ", String.valueOf(value), ' ', - value, - new Color(minR + (maxR * vprop), minG + (maxG * vprop), - minB + (maxB * vprop))); + } + + float vprop = value - min; + vprop /= max; + annotations[i] = new Annotation(sequence.charAt(i) + "", + String.valueOf(value), ' ', value, + new Color(minR + (maxR * vprop), + minG + (maxG * vprop), + minB + (maxB * vprop))); + + // Quality calc + value = ( (Double) cons.quality.get(i)).floatValue(); + vprop = value - qmin; + vprop /= qmax; + qannotations[i] = new Annotation(" ", String.valueOf(value), ' ', + value, + new Color(minR + (maxR * vprop), + minG + (maxG * vprop), + minB + (maxB * vprop))); } if (conservation == null) { - conservation = new AlignmentAnnotation("Conservation", - "Conservation of total alignment less than " + - ConsPercGaps + "% gaps", annotations, 0f, // cons.qualityRange[0].floatValue(), - 11f, // cons.qualityRange[1].floatValue() - 1); - - if (showConservation) - { - alignment.addAnnotation(conservation); - } - - quality = new AlignmentAnnotation("Quality", - "Alignment Quality based on Blosum62 scores", qannotations, - cons.qualityRange[0].floatValue(), - cons.qualityRange[1].floatValue(), 1); - - if (showQuality) - { - alignment.addAnnotation(quality); - } + conservation = new AlignmentAnnotation("Conservation", + "Conservation of total alignment less than " + + ConsPercGaps + "% gaps", + annotations, 0f, // cons.qualityRange[0].floatValue(), + 11f, // cons.qualityRange[1].floatValue() + 1); + + if (showConservation) + { + alignment.addAnnotation(conservation); + } + + quality = new AlignmentAnnotation("Quality", + "Alignment Quality based on Blosum62 scores", + qannotations, + cons.qualityRange[0].floatValue(), + cons.qualityRange[1].floatValue(), + 1); + + if (showQuality) + { + alignment.addAnnotation(quality); + } } else { - conservation.annotations = annotations; - quality.annotations = qannotations; - quality.graphMax = cons.qualityRange[1].floatValue(); + conservation.annotations = annotations; + quality.annotations = qannotations; + quality.graphMax = cons.qualityRange[1].floatValue(); } + }catch(OutOfMemoryError error) + { + System.out.println("Out of memory calculating conservation."); + } } /** @@ -279,6 +289,7 @@ public class AlignViewport */ public void updateConsensus() { + try{ Annotation[] annotations = new Annotation[alignment.getWidth()]; // this routine prevents vconsensus becoming a new object each time @@ -286,63 +297,69 @@ public class AlignViewport // and PID colouring of alignment if (vconsensus == null) { - vconsensus = alignment.getAAFrequency(); + vconsensus = alignment.getAAFrequency(); } else { - Vector temp = alignment.getAAFrequency(); - vconsensus.clear(); + Vector temp = alignment.getAAFrequency(); + vconsensus.clear(); - Enumeration e = temp.elements(); + Enumeration e = temp.elements(); - while (e.hasMoreElements()) - { - vconsensus.add(e.nextElement()); - } + while (e.hasMoreElements()) + { + vconsensus.add(e.nextElement()); + } } Hashtable hash = null; for (int i = 0; i < alignment.getWidth(); i++) { - hash = (Hashtable) vconsensus.elementAt(i); + hash = (Hashtable) vconsensus.elementAt(i); - float value = 0; - if(ignoreGapsInConsensusCalculation) - value = ((Float)hash.get("pid_nogaps")).floatValue(); - else - value = ((Float)hash.get("pid_gaps")).floatValue(); + float value = 0; + if (ignoreGapsInConsensusCalculation) + value = ( (Float) hash.get("pid_nogaps")).floatValue(); + else + value = ( (Float) hash.get("pid_gaps")).floatValue(); - String maxRes = hash.get("maxResidue").toString(); - String mouseOver = hash.get("maxResidue")+" "; + String maxRes = hash.get("maxResidue").toString(); + String mouseOver = hash.get("maxResidue") + " "; - if (maxRes.length() > 1) - { - mouseOver = "[" + maxRes + "] "; - maxRes = "+"; - } + if (maxRes.length() > 1) + { + mouseOver = "[" + maxRes + "] "; + maxRes = "+"; + } - mouseOver += ((int) value + "%"); - annotations[i] = new Annotation(maxRes, mouseOver, ' ', value); + mouseOver += ( (int) value + "%"); + annotations[i] = new Annotation(maxRes, mouseOver, ' ', value); } if (consensus == null) { - consensus = new AlignmentAnnotation("Consensus", "PID", - annotations, 0f, 100f, 1); + consensus = new AlignmentAnnotation("Consensus", "PID", + annotations, 0f, 100f, 1); - if (showIdentity) - { - alignment.addAnnotation(consensus); - } + if (showIdentity) + { + alignment.addAnnotation(consensus); + } } else { - consensus.annotations = annotations; + consensus.annotations = annotations; } - if(globalColourScheme!=null) + if (globalColourScheme != null) globalColourScheme.setConsensus(vconsensus); + + }catch(OutOfMemoryError error) + { + System.out.println("Out of memory calculating consensus."); + } + } /** -- 1.7.10.2