X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=inline;f=src%2Fjalview%2Fanalysis%2FConservation.java;h=74381fd71505e34e646c84cff0f5aabe342a036a;hb=c3db82330376f20423dc617cfa92d131dc40e515;hp=520036edf8cbaf2566b2f500760a3012c23f3b29;hpb=ff75356cd448ad8bf24733c328054a53e87c242c;p=jalview.git diff --git a/src/jalview/analysis/Conservation.java b/src/jalview/analysis/Conservation.java index 520036e..74381fd 100755 --- a/src/jalview/analysis/Conservation.java +++ b/src/jalview/analysis/Conservation.java @@ -27,26 +27,64 @@ public class Conservation { Vector sequences; int start; int end; - - Vector total = new Vector(); - - String consString = ""; - - DrawableSequence consSequence; - Hashtable propHash; - int threshold; - Hashtable[] freqs; + Vector seqNums; // vector of int vectors where first is sequence checksum + int maxLength=0; // used by quality calcs + boolean seqNumsChanged = false; // updated after any change via calcSeqNum; + private void calcSeqNums() { + for (int i=0; i-1 && i ((Sequence)sequences.elementAt(i)).getSequence().length()) { count++; continue;} - String tmp = ((Sequence)sequences.elementAt(i)).getSequence().substring(j,j+1); - if (tmp.equals(" ") || tmp.equals(".") || tmp.equals("-")) { + char c = ((Sequence)sequences.elementAt(i)).getSequence().charAt(j); + if (jalview.util.Comparison.isGap((c))) count++; - } + } return count; } + /*** + * countConsNGaps + * returns gap count in int[0], and conserved residue count in int[1] + */ + public int[] countConsNGaps(int j) + { + int count = 0; + int cons=0; + int nres = 0; + int[] r = new int[2]; + char f='$'; + for (int i = 0; i < sequences.size();i++) + { + if( j >= ((Sequence)sequences.elementAt(i)).getSequence().length()) + { count++; + continue;} + + char c = ((Sequence)sequences.elementAt(i)).getSequence().charAt(j); + if (jalview.util.Comparison.isGap((c))) + count++; + else { + nres++; + if (nres==1) { + f = c; + cons++; + } else + if (f == c) { + cons++; + } + } + } + r[0] = (nres==cons) ? 1 : 0; + r[1] = count; + + + return r; + } public void verdict(boolean consflag, float percentageGaps) { String consString = ""; for (int i=start; i <= end; i++) { - int totGaps = countGaps(i); + int[] gapcons = countConsNGaps(i); + boolean cons = (gapcons[0]==1) ? true : false; + int totGaps = gapcons[1]; float pgaps = (float)totGaps*100/(float)sequences.size(); - + // System.out.println("percentage gaps = "+pgaps+"\n"); if (percentageGaps > pgaps) { Hashtable resultHash = (Hashtable)total.elementAt(i-start); @@ -171,9 +252,9 @@ public class Conservation { } if (count < 10) - consString = consString + String.valueOf(count); + consString = consString + String.valueOf(count);// Conserved props!=Identity else - consString = consString + "*"; + consString = consString + ((gapcons[0]==1) ? "*" : "+"); } else @@ -182,11 +263,149 @@ public class Conservation { } } - consSequence = new DrawableSequence(name,consString,start,end); + consSequence = new Sequence(name,consString,start,end); } - public jalview.gui.DrawableSequence getConsSequence() { + public Sequence getConsSequence() { return consSequence; } + // From Alignment.java in jalview118 + + public void findQuality() { + findQuality(0,maxLength-1); + } + + int[][] cons2; + + private void percentIdentity2() { + calcSeqNums(); // updates maxLength, too. + if (cons2==null || seqNumsChanged) { + cons2 = new int[maxLength][24]; + // Initialize the array + for (int j=0;j<24;j++) { + for (int i=0; i < maxLength;i++) { + cons2[i][j] = 0; + } + } + + int sqnum[]; + int j = 0; + while(j < sequences.size()) { + sqnum=(int[])seqNums.elementAt(j); + for (int i = 1; i < sqnum.length; i++) { + cons2[i-1][sqnum[i]]++; + } + for (int i=sqnum.length-1; i max) { + max = cons2[i][j]; + maxi = i; + maxj = j; + } + + } + } */ + } + +} + + +public void findQuality(int start, int end) { + quality = new Vector(); + double max = -10000; + String s = ""; + int[][] BLOSUM62 = jalview.schemes.ResidueProperties.getBLOSUM62(); + //Loop over columns // JBPNote Profiling info + // long ts = System.currentTimeMillis(); + //long te = System.currentTimeMillis(); + percentIdentity2(); + + int size = seqNums.size(); + int[] lengths = new int[size]; + + for (int l = 0; l < size; l++) + lengths[l] = ((int[]) seqNums.elementAt(l)).length-1; + + for (int j=start; j <= end; j++) { + double bigtot = 0; + + // First Xr = depends on column only + double x[] = new double[24]; + + for (int ii=0; ii < 24; ii++) { + x[ii] = 0; + try { + for (int i2=0; i2 < 24; i2++) { + x[ii] += (double)cons2[j][i2] * BLOSUM62[ii][i2]+4; + } + } catch (Exception e) { + System.out.println("Exception : " + e); + } + //System.out.println("X " + ii + " " + x[ii]); + x[ii] /= (size); + //System.out.println("X " + ii + " " + x[ii]); + } + // 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 = + (jnewmax) + newmax = tmp; + } + // System.out.println("Quality " + s); + qualityRange[0] = new Double(0); + qualityRange[1] = new Double(newmax); + } + + }