package jalview.analysis; import jalview.datamodel.*; import jalview.io.*; import java.util.*; public class CompareAlignments { Vector align; String refId; Vector ids; public CompareAlignments(Vector align) { this.align = align; ids = new Vector(); Alignment al0 = (Alignment)align.elementAt(0); for (int i = 0; i < al0.getHeight(); i++) { SequenceI seq = al0.getSequenceAt(i); ids.addElement(seq.getName()); if (i == 0) { setReferenceId(seq.getName()); } } } public void compare() { Hashtable positions = new Hashtable(); for (int k = 0; k < ids.size(); k++) { String id = (String)ids.elementAt(k); System.out.println("Ids " + id + " " + refId); if (!id.equals(refId)) { Hashtable fullhash = new Hashtable(); for (int i = 0; i < align.size(); i++) { System.out.println("Alignment " + i); Alignment al = (Alignment)align.elementAt(i); SequenceI refseq = null; for (int j = 0; j < al.getHeight(); j++) { if (((SequenceI)al.getSequenceAt(j)).getName().equals(refId)) { refseq = (SequenceI)al.getSequenceAt(j); } } if (refseq != null) { System.out.println("Refseq " + refseq.getName()); for (int jj = 0; jj < al.getHeight(); jj++) { SequenceI seq = (SequenceI)al.getSequenceAt(jj); if (seq.getName().equals(id)) { Hashtable hash = getAlignPositions(seq,refseq); Enumeration keys = hash.keys(); while (keys.hasMoreElements()) { Integer key = (Integer)keys.nextElement(); // System.out.println(key + " " + hash.get(key)); if (fullhash.get(key) == null) { fullhash.put(key,new Vector()); } Vector tmp = (Vector)fullhash.get(key); tmp.addElement(hash.get(key)); } } } } } System.out.println ("\nId " + id); Enumeration keys = fullhash.keys(); int totdiff = 0; while (keys.hasMoreElements()) { Integer key = (Integer)keys.nextElement(); Vector tmp = (Vector)fullhash.get(key); int diff0 = ((Integer)tmp.elementAt(0)).intValue();; int diff = 0; for (int l = 1; l < tmp.size(); l++) { diff += Math.abs(diff0 - ((Integer)tmp.elementAt(l)).intValue()); } if (diff > 0) { totdiff++; System.out.print(id + " Ref pos " + key + " : " + diff0 + " " + diff + " : "); for (int l = 1; l < tmp.size(); l++) { System.out.print(diff0 - ((Integer)tmp.elementAt(l)).intValue() + " "); } System.out.println(); } } System.out.println("Total " + id + " " + totdiff); } } } public void setReferenceId(String id) { this.refId = id; } public Hashtable getAlignPositions(SequenceI seq1, SequenceI seq2) { Hashtable hash = new Hashtable(); int i = 0; int pos1 = 0; int pos2 = 0; while (i < seq1.getLength()) { char c1 = seq1.getCharAt(i); char c2 = seq2.getCharAt(i); if (c1 != '-') { pos1++; } if (c2 != '-') { pos2++; } if (c1 != '-') { hash.put(new Integer(pos1),new Integer(pos2)); } i++; } return hash; } }