1 package jalview.analysis;
\r
3 import jalview.datamodel.*;
\r
8 public class CompareAlignments {
\r
14 public CompareAlignments(Vector align) {
\r
20 Alignment al0 = (Alignment)align.elementAt(0);
\r
22 for (int i = 0; i < al0.getHeight(); i++) {
\r
23 SequenceI seq = al0.getSequenceAt(i);
\r
25 ids.addElement(seq.getName());
\r
28 setReferenceId(seq.getName());
\r
34 public void compare() {
\r
36 Hashtable positions = new Hashtable();
\r
38 for (int k = 0; k < ids.size(); k++) {
\r
40 String id = (String)ids.elementAt(k);
\r
42 System.out.println("Ids " + id + " " + refId);
\r
44 if (!id.equals(refId)) {
\r
46 Hashtable fullhash = new Hashtable();
\r
48 for (int i = 0; i < align.size(); i++) {
\r
49 System.out.println("Alignment " + i);
\r
51 Alignment al = (Alignment)align.elementAt(i);
\r
53 SequenceI refseq = null;
\r
55 for (int j = 0; j < al.getHeight(); j++) {
\r
56 if (((SequenceI)al.getSequenceAt(j)).getName().equals(refId)) {
\r
57 refseq = (SequenceI)al.getSequenceAt(j);
\r
61 if (refseq != null) {
\r
63 System.out.println("Refseq " + refseq.getName());
\r
65 for (int jj = 0; jj < al.getHeight(); jj++) {
\r
66 SequenceI seq = (SequenceI)al.getSequenceAt(jj);
\r
68 if (seq.getName().equals(id)) {
\r
69 Hashtable hash = getAlignPositions(seq,refseq);
\r
71 Enumeration keys = hash.keys();
\r
73 while (keys.hasMoreElements()) {
\r
74 Integer key = (Integer)keys.nextElement();
\r
75 // System.out.println(key + " " + hash.get(key));
\r
76 if (fullhash.get(key) == null) {
\r
77 fullhash.put(key,new Vector());
\r
80 Vector tmp = (Vector)fullhash.get(key);
\r
82 tmp.addElement(hash.get(key));
\r
90 System.out.println ("\nId " + id);
\r
92 Enumeration keys = fullhash.keys();
\r
96 while (keys.hasMoreElements()) {
\r
97 Integer key = (Integer)keys.nextElement();
\r
99 Vector tmp = (Vector)fullhash.get(key);
\r
103 int diff0 = ((Integer)tmp.elementAt(0)).intValue();;
\r
106 for (int l = 1; l < tmp.size(); l++) {
\r
107 diff += Math.abs(diff0 - ((Integer)tmp.elementAt(l)).intValue());
\r
113 System.out.print(id + " Ref pos " + key + " : " + diff0 + " " + diff + " : ");
\r
115 for (int l = 1; l < tmp.size(); l++) {
\r
116 System.out.print(diff0 - ((Integer)tmp.elementAt(l)).intValue() + " ");
\r
118 System.out.println();
\r
122 System.out.println("Total " + id + " " + totdiff);
\r
129 public void setReferenceId(String id) {
\r
133 public Hashtable getAlignPositions(SequenceI seq1, SequenceI seq2) {
\r
135 Hashtable hash = new Hashtable();
\r
142 while (i < seq1.getLength()) {
\r
144 char c1 = seq1.getCharAt(i);
\r
145 char c2 = seq2.getCharAt(i);
\r
156 hash.put(new Integer(pos1),new Integer(pos2));
\r