1 package jalview.analysis;
\r
3 import jalview.datamodel.*;
\r
4 import jalview.util.*;
\r
7 public class AlignmentUtil {
\r
9 private AlignmentUtil() {
\r
12 public static int[][] percentIdentity2(AlignmentI align) {
\r
13 return percentIdentity2(align,0,align.getWidth()-1);
\r
16 public static int[][] percentIdentity2(AlignmentI align, int start, int end) {
\r
17 int [][] cons2 = new int[align.getWidth()][24];
\r
18 // Initialize the array
\r
19 for (int j=0;j<24;j++) {
\r
20 for (int i=0; i < align.getWidth();i++) {
\r
27 public static int getPixelHeight(int i, int j,int charHeight) {
\r
37 public static Vector substitution_rates (AlignmentI align, int start, int end) {
\r
39 Vector rates = new Vector();
\r
41 int len = (end-start+1);
\r
43 // Turn seqs into char arrays
\r
45 int[][] seqint = new int[align.getHeight()][len];
\r
48 for (int j = 0; j < align.getHeight(); j++) {
\r
50 SequenceI seq = align.getSequenceAt(j);
\r
52 for (int i = 0 ; i < len; i++) {
\r
53 char c = seq.getCharAt(start + i - 1);
\r
57 } else if (c == 'C') {
\r
59 } else if (c == 'T') {
\r
61 } else if (c == 'G') {
\r
72 // print_matrix(seqint,2,len); for (int j = 0; j < align.getHeight(); j++) {
\r
74 for (int j = 0; j < align.getHeight(); j++) {
\r
76 for (int k = 0; k < align.getHeight(); k++) {
\r
78 int counts[][] = new int[4][4];
\r
80 int tots[] = new int[4];
\r
82 int fulltots[] = new int[4];
\r
84 for (int i = 0 ; i < len; i++) {
\r
88 // System.out.println("Seq " + j + " " + k + " " + i + " " + seqint[j][i] + " " + seqint[k][i]);
\r
89 if (seqint[j][i] >= 0 &&
\r
90 seqint[k][i] >= 0) {
\r
91 counts[seqint[k][i]][seqint[j][i]]++;
\r
93 // print_matrix(counts,4,4);
\r
94 tots[seqint[j][i]]++;
\r
97 if (seqint[j][i] != -1) {
\r
98 fulltots[seqint[j][i]]++;
\r
106 System.out.println();
\r
108 System.out.println("Sequence " + align.getSequenceAt(j).getName() + " " + align.getSequenceAt(k).getName());
\r
110 System.out.println();
\r
111 print_matrix(counts,4,4);
\r
112 System.out.println();
\r
116 double[][] out = new double[4][4];// = constant_multiply_matrix(counts,1.0/tot,4,4);
\r
118 for (int i = 0; i < 4; i++) {
\r
119 for (int jj = 0; jj < 4; jj++) {
\r
120 out[i][jj] = (double)counts[i][jj]/tots[jj];
\r
124 print_matrix(out,4,4);
\r
125 System.out.println();
\r
128 System.out.print("RATES\t");
\r
129 System.out.print(align.getSequenceAt(j).getName() + "\t" + align.getSequenceAt(k).getName() + "\t");
\r
131 for (int i = 0; i < 4; i++) {
\r
132 for (int jj = 0; jj < 4; jj++) {
\r
133 Format.print(System.out,"%4.3f\t",out[i][jj]);
\r
136 System.out.println();
\r
138 for (int i = 0; i < 4; i++) {
\r
139 Format.print(System.out,"%4.3f\t",(double)fulltots[i]*1.0/fulltot);
\r
142 System.out.println();
\r
143 System.out.print("\nGC ");
\r
145 Format.print(System.out,"%4.3f\t",(double)(100*fulltots[1]+fulltots[3])/fulltot);
\r
147 System.out.print((fulltots[1]+fulltots[3]) + "\t" + fulltot);
\r
150 System.out.println();
\r
152 rates.addElement(out);
\r
160 public static double[][] constant_multiply_matrix(int[][] matrix, double c,int n, int m) {
\r
161 double[][] out = new double[n][m];
\r
163 for (int i = 0; i < n; i++) {
\r
164 for (int j = 0; j < m; j++) {
\r
166 out[i][j] = matrix[i][j]*c;
\r
173 public static void print_matrix(int[][] matrix, int n, int m) {
\r
176 for (int i = 0; i < n; i++) {
\r
177 for (int j = 0; j < m; j++) {
\r
179 System.out.print(matrix[i][j] + "\t");
\r
181 System.out.println();
\r
184 public static void print_matrix(double[][] matrix, int n, int m) {
\r
187 for (int i = 0; i < n; i++) {
\r
188 for (int j = 0; j < m; j++) {
\r
190 Format.print(System.out,"%4.3f\t",matrix[i][j]);
\r
193 System.out.println();
\r
197 public static Hashtable findKmers(SequenceI seq, int start, int end, Vector kmers) {
\r
199 Hashtable pos = new Hashtable();
\r
201 for (int j = 0; j < kmers.size(); j++) {
\r
203 String kmer = ((Sequence)kmers.elementAt(j)).getSequence();
\r
204 Sequence kmerseq = (Sequence)kmers.elementAt(j);
\r
206 if (end < seq.getLength()) {
\r
208 String str = seq.getSequence(start,end);
\r
212 while (str.indexOf(kmer,i) != -1) {
\r
214 // System.out.println("STring " + str + " " + i);
\r
215 int coord = str.indexOf(kmer,i);
\r
217 pos.put(new Integer(coord),new Integer(kmerseq.getLength()));
\r
227 public static void fetchSequenceFeatures(AlignmentI al, jalview.gui.AlignmentPanel ap)
\r
229 SequenceFeatureFetcher sft = new SequenceFeatureFetcher(al, ap);
\r