From b8b69cf39fa42b15ec245579d199af4aa589cbe1 Mon Sep 17 00:00:00 2001 From: janengelhardt Date: Thu, 11 Aug 2011 01:42:18 +0200 Subject: [PATCH] JAL-885; Structure conservation row is just added if alignment isNucleotide(); StructureFrequency.java cleaned; Change-Id: Ic86908cbea0791e7174b440cc4c7e7b12b978927 --- src/jalview/analysis/StructureFrequency.java | 155 ++------------------------ src/jalview/gui/AlignViewport.java | 19 ++-- 2 files changed, 20 insertions(+), 154 deletions(-) diff --git a/src/jalview/analysis/StructureFrequency.java b/src/jalview/analysis/StructureFrequency.java index 4d83019..9bdaa10 100644 --- a/src/jalview/analysis/StructureFrequency.java +++ b/src/jalview/analysis/StructureFrequency.java @@ -46,143 +46,12 @@ public class StructureFrequency public static final String PAIRPROFILE = "B"; - public static final Hashtable[] calculate(Vector sequences, int start, - int end) - { - return calculate(sequences, start, end, false); - } - - public static final Hashtable[] calculate(Vector sequences, int start, - int end, boolean profile) - { - SequenceI[] seqs = new SequenceI[sequences.size()]; - int width = 0; - for (int i = 0; i < sequences.size(); i++) - { - seqs[i] = (SequenceI) sequences.elementAt(i); - if (seqs[i].getLength() > width) - { - width = seqs[i].getLength(); - } - } - - Hashtable[] reply = new Hashtable[width]; - - if (end >= width) - { - end = width; - } - - calculate(seqs, start, end, reply, profile); - - return reply; - } - - public static final void calculate(SequenceI[] sequences, int start, - int end, Hashtable[] result) - { - calculate(sequences, start, end, result, false); - } - - public static final void calculate(SequenceI[] sequences, int start, - int end, Hashtable[] result, boolean profile) - { - Hashtable residueHash; - int maxCount, nongap, i, j, v, jSize = sequences.length; - String maxResidue; - char c; - float percentage; - - int[] values = new int[255]; - - char[] seq; - - for (i = start; i < end; i++) - { - residueHash = new Hashtable(); - maxCount = 0; - maxResidue = ""; - nongap = 0; - values = new int[255]; - - for (j = 0; j < jSize; j++) - { - if (sequences[j] == null) - { - System.err - .println("WARNING: Consensus skipping null sequence - possible race condition."); - continue; - } - seq = sequences[j].getSequence(); - if (seq.length > i) - { - c = seq[i]; - - if (c == '.' || c == ' ') - { - c = '-'; - } - - if (c == '-') - { - values['-']++; - continue; - } - else if ('a' <= c && c <= 'z') - { - c -= 32; // ('a' - 'A'); - } - - nongap++; - values[c]++; - - } - else - { - values['-']++; - } - } - - for (v = 'A'; v < 'Z'; v++) - { - if (values[v] < 2 || values[v] < maxCount) - { - continue; - } - - if (values[v] > maxCount) - { - maxResidue = String.valueOf((char) v); - } - else if (values[v] == maxCount) - { - maxResidue += String.valueOf((char) v); - } - maxCount = values[v]; - } - - if (maxResidue.length() == 0) - { - maxResidue = "-"; - } - if (profile) - { - residueHash.put(PROFILE, new int[][] - { values, new int[] - { jSize, nongap } }); - } - residueHash.put(MAXCOUNT, new Integer(maxCount)); - residueHash.put(MAXRESIDUE, maxResidue); - - percentage = ((float) maxCount * 100) / (float) jSize; - residueHash.put(PID_GAPS, new Float(percentage)); - - percentage = ((float) maxCount * 100) / (float) nongap; - residueHash.put(PID_NOGAPS, new Float(percentage)); - result[i] = residueHash; - } - } - +/** + * Returns the 3' position of a base pair + * @param pairs Secondary structure annotation + * @param indice 5' position of a base pair + * @return 3' position of a base pair + */ public static int findPair(SequenceFeature[] pairs, int indice) { for (int i = 0; i < pairs.length; i++) @@ -210,7 +79,6 @@ public class StructureFrequency int end, Hashtable[] result, boolean profile, AlignmentAnnotation rnaStruc) { - // System.out.println("StructureFrequency.calculateNEW4"); Hashtable residueHash; String maxResidue; char[] seq, struc = rnaStruc.getRNAStruc().toCharArray(); @@ -275,9 +143,7 @@ public class StructureFrequency { values['H']++; // H means it's a helix (structured) } - // System.out.println("pair: "+c+","+cEnd); pairs[c][cEnd]++; - // System.out.println("pairs: "+c+","+cEnd+" - "+pairs[c][cEnd]); maxResidue = "H"; } @@ -287,7 +153,6 @@ public class StructureFrequency // UPDATE this for new values if (profile) { - // System.out.println("profile"); residueHash.put(PROFILE, new int[][] { values, new int[] { jSize, (jSize - values['-']) } }); @@ -415,8 +280,6 @@ public class StructureFrequency boolean ignoreGapsInConsensusCalculation, boolean includeAllConsSymbols, char[] alphabet) { - System.out.println("StructureFrequency.completeConsensus " - + includeAllConsSymbols); float tval, value; if (consensus == null || consensus.annotations == null || consensus.annotations.length < width) @@ -460,7 +323,6 @@ public class StructureFrequency if (profile != null && includeAllConsSymbols) // Just responsible for the // tooltip { - // System.out.println("StructureFrequency.includeAllConsSymbols"); mouseOver = ""; if (alphabet != null) { @@ -476,7 +338,6 @@ public class StructureFrequency } else { - // System.out.println("StructureFrequency.NOTincludeAllConsSymbols"); Object[] ca = new Object[profile[0].length]; float[] vl = new float[profile[0].length]; for (int c = 0; c < ca.length; c++) @@ -514,10 +375,10 @@ public class StructureFrequency } /** - * get the sorted profile for the given position of the consensus + * get the sorted base-pair profile for the given position of the consensus * * @param hconsensus - * @return + * @return profile of the given column */ public static int[] extractProfile(Hashtable hconsensus, boolean ignoreGapsInConsensusCalculation, int column) diff --git a/src/jalview/gui/AlignViewport.java b/src/jalview/gui/AlignViewport.java index 1dbcf56..0a9cad4 100644 --- a/src/jalview/gui/AlignViewport.java +++ b/src/jalview/gui/AlignViewport.java @@ -413,17 +413,22 @@ public class AlignViewport implements SelectionSource, VamsasSource consensus.hasText = true; consensus.autoCalculated = true; - // TODO check if this can done accordingly - strucConsensus = new AlignmentAnnotation("StrucConsensus", "PID", - new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH); - strucConsensus.hasText = true; - strucConsensus.autoCalculated = true; - + if (alignment.isNucleotide()) + { + strucConsensus = new AlignmentAnnotation("StrucConsensus", "PID", + new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH); + strucConsensus.hasText = true; + strucConsensus.autoCalculated = true; + } + if (Cache.getDefault("SHOW_IDENTITY", true)) { alignment.addAnnotation(consensus); // TODO: Make own if for structure - alignment.addAnnotation(strucConsensus); + if (alignment.isNucleotide()) + { + alignment.addAnnotation(strucConsensus); + } } } -- 1.7.10.2