From: amwaterhouse Date: Mon, 15 Aug 2005 12:04:32 +0000 (+0000) Subject: Declare variables outside loops X-Git-Tag: Release_2_03~51 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=3c3dff5249fee03952b293a4d79ea1c792aa0f60;p=jalview.git Declare variables outside loops --- diff --git a/src/jalview/analysis/Conservation.java b/src/jalview/analysis/Conservation.java index 0fe4f5e..d814abb 100755 --- a/src/jalview/analysis/Conservation.java +++ b/src/jalview/analysis/Conservation.java @@ -79,7 +79,8 @@ public class Conservation */ private void calcSeqNums() { - for (int i = 0; i < sequences.size(); i++) + int i=0, iSize=sequences.size(); + for (i=0; i < iSize; i++) { calcSeqNum(i); } @@ -142,29 +143,31 @@ public class Conservation */ public void calculate() { - for (int i = start; i <= end; i++) - { - Hashtable resultHash = null; - Hashtable residueHash = null; + Hashtable resultHash, residueHash, ht; + int count, thresh, j, jSize = sequences.size(); + String sequence, res, type; + Enumeration enumeration, enumeration2; + for (int i = start; i <= end; i++) + { resultHash = new Hashtable(); residueHash = new Hashtable(); - for (int j = 0; j < sequences.size(); j++) + for (j = 0; j < jSize; j++) { // JBPNote - have to make sure elements of the sequences vector // are tested like this everywhere... if (sequences.elementAt(j) instanceof Sequence) { - Sequence s = (Sequence) sequences.elementAt(j); + sequence = ((Sequence) sequences.elementAt(j)).getSequence(); - if (s.getLength() > i) + if (sequence.length() > i) { - String res = s.getSequence().substring(i, i + 1); + res = sequence.substring(i, i + 1); if (residueHash.containsKey(res)) { - int count = ((Integer) residueHash.get(res)).intValue(); + count = ((Integer) residueHash.get(res)).intValue(); count++; residueHash.put(res, new Integer(count)); } @@ -177,7 +180,7 @@ public class Conservation { if (residueHash.containsKey("-")) { - int count = ((Integer) residueHash.get("-")).intValue(); + count = ((Integer) residueHash.get("-")).intValue(); count++; residueHash.put("-", new Integer(count)); } @@ -190,24 +193,24 @@ public class Conservation } //What is the count threshold to count the residues in residueHash() - int thresh = (threshold * (sequences.size())) / 100; + thresh = (threshold * (sequences.size())) / 100; //loop over all the found residues - Enumeration e = residueHash.keys(); + enumeration = residueHash.keys(); - while (e.hasMoreElements()) + while (enumeration.hasMoreElements()) { - String res = (String) e.nextElement(); + res = (String) enumeration.nextElement(); if (((Integer) residueHash.get(res)).intValue() > thresh) { //Now loop over the properties - Enumeration e2 = propHash.keys(); + enumeration2 = propHash.keys(); - while (e2.hasMoreElements()) + while (enumeration2.hasMoreElements()) { - String type = (String) e2.nextElement(); - Hashtable ht = (Hashtable) propHash.get(type); + type = (String) enumeration2.nextElement(); + ht = (Hashtable) propHash.get(type); //Have we ticked this before? if (!resultHash.containsKey(type)) @@ -246,17 +249,18 @@ public class Conservation int nres = 0; int[] r = new int[2]; char f = '$'; + int i, iSize = sequences.size(); + char c; - for (int i = 0; i < sequences.size(); i++) + for (i = 0; i < iSize; i++) { - if (j >= ((Sequence) sequences.elementAt(i)).getSequence().length()) + if (j >= ((Sequence) sequences.elementAt(i)).getLength()) { count++; - continue; } - char c = ((Sequence) sequences.elementAt(i)).getSequence().charAt(j); + c = ((Sequence) sequences.elementAt(i)).getCharAt(j); if (jalview.util.Comparison.isGap((c))) { @@ -292,27 +296,34 @@ public class Conservation */ public void verdict(boolean consflag, float percentageGaps) { - String consString = ""; + StringBuffer consString = new StringBuffer(); + String type; + Integer result; + int[] gapcons; + int totGaps, count; + float pgaps; + Hashtable resultHash ; + Enumeration enumeration; + for (int i = start; i <= end; i++) { - int[] gapcons = countConsNGaps(i); - int totGaps = gapcons[1]; - float pgaps = ((float) totGaps * 100) / (float) sequences.size(); + gapcons = countConsNGaps(i); + totGaps = gapcons[1]; + pgaps = ((float) totGaps * 100) / (float) sequences.size(); - // System.out.println("percentage gaps = "+pgaps+"\n"); if (percentageGaps > pgaps) { - Hashtable resultHash = (Hashtable) total.elementAt(i - start); + resultHash = (Hashtable) total.elementAt(i - start); //Now find the verdict - int count = 0; - Enumeration e3 = resultHash.keys(); + count = 0; + enumeration = resultHash.keys(); - while (e3.hasMoreElements()) + while (enumeration.hasMoreElements()) { - String type = (String) e3.nextElement(); - Integer result = (Integer) resultHash.get(type); + type = (String) enumeration.nextElement(); + result = (Integer) resultHash.get(type); //Do we want to count +ve conservation or +ve and -ve cons.? if (consflag) @@ -333,20 +344,20 @@ public class Conservation if (count < 10) { - consString = consString + String.valueOf(count); // Conserved props!=Identity + consString.append(count); // Conserved props!=Identity } else { - consString = consString + ((gapcons[0] == 1) ? "*" : "+"); + consString.append((gapcons[0] == 1) ? "*" : "+"); } } else { - consString = consString + "-"; + consString.append("-"); } } - consSequence = new Sequence(name, consString, start, end); + consSequence = new Sequence(name, consString.toString(), start, end); } /** @@ -435,7 +446,6 @@ public class Conservation quality = new Vector(); double max = -10000; - String s = ""; int[][] BLOSUM62 = jalview.schemes.ResidueProperties.getBLOSUM62(); //Loop over columns // JBPNote Profiling info @@ -445,18 +455,22 @@ public class Conservation int size = seqNums.size(); int[] lengths = new int[size]; + double tot, bigtot, sr, tmp; + double [] x, xx; + int l, j, i, ii, seqNum; - for (int l = 0; l < size; l++) + for (l = 0; l < size; l++) lengths[l] = ((int[]) seqNums.elementAt(l)).length - 1; - for (int j = start; j <= end; j++) + + for (j = start; j <= end; j++) { - double bigtot = 0; + bigtot = 0; // First Xr = depends on column only - double[] x = new double[24]; + x = new double[24]; - for (int ii = 0; ii < 24; ii++) + for (ii = 0; ii < 24; ii++) { x[ii] = 0; @@ -483,15 +497,15 @@ public class Conservation // Now calculate D for each position and sum for (int k = 0; k < size; k++) { - double tot = 0; - double[] xx = new double[24]; - int seqNum = (j < lengths[k]) + tot = 0; + xx = new double[24]; + seqNum = (j < lengths[k]) ? ((int[]) seqNums.elementAt(k))[j + 1] : 23; // Sequence, or gap at the end // This is a loop over r - for (int i = 0; i < 23; i++) + for (i = 0; i < 23; i++) { - double sr = 0; + sr = 0; try { @@ -522,16 +536,15 @@ public class Conservation // bigtot = bigtot * (size-cons2[j][23])/size; quality.addElement(new Double(bigtot)); - s += "-"; // Need to normalize by gaps } double newmax = -10000; - for (int j = start; j <= end; j++) + for (j = start; j <= end; j++) { - double tmp = ((Double) quality.elementAt(j)).doubleValue(); + tmp = ((Double) quality.elementAt(j)).doubleValue(); tmp = ((max - tmp) * (size - cons2[j][23])) / size; // System.out.println(tmp+ " " + j);