AlignmentLoop.java0100644000077000001440000002220707613761743013362 0ustar arilusers/** * Title: ProAlign

* Description:

* Copyright: Copyright (c) Ari Loytynoja

* License: GNU GENERAL PUBLIC LICENSE

* @see http://www.gnu.org/copyleft/gpl.html * Company: ULB

* @author Ari Loytynoja * @version 1.0 */ package proalign; class AlignmentLoop { /* Do the viterbi path, and mark the track. Do forward & backward algorithm, calculate posterior probs */ ProAlign pa; AlignmentLoop al; AlignmentNode an; double[][][] price, priceX, priceY; double[][] vitM, vitX, vitY; double[][][] pathM; double[][] pathX, pathY; double[][] fwdM, fwdX, fwdY; double[][] bwdM, bwdX, bwdY; double vitEnd, fwdEnd; double[] pathEnd; double[][] seq1, seq2; float dist1, dist2; int aSize; int BWIDTH; int MIDDLE; int endPoint = 0; AlignmentLoop(ProAlign pa,AlignmentNode an) { this.pa = pa; this.an = an; al = this; BWIDTH = ProAlign.bandWidth; MIDDLE = BWIDTH/2+1; } void align(double[][] s1, double[][] s2, float d1, float d2) throws Exception { seq1 = s1; seq2 = s2; dist1 = d1; dist2 = d2; al.pa.sm.setBranchLength(dist1,dist2); aSize = seq1[0].length; // aSize = alphabet size; ProAlign.log("AlignmentLoop"); ProAlign.log(" seq1.length = "+seq1.length+", seq2.length = "+seq2.length); try { al.initialiseMatrices(); } catch(Error e) { if(ProAlign.isResultWindow) { String text = "\n Out Of Memory Error!\n Please, increase JVM memory.\n"; OpenDialog od = new OpenDialog(pa.rw); od.showDialog("Error!", text); System.exit(0); } else { ProAlign.log.println("AlignmentLoop: Out Of Memory Error. Increase JVM memory."); System.out.println("Out Of Memory Error.\nPlease, increase JVM memory."); if(ProAlign.exitInError) { System.exit(0); } else { // System.out.println("AlignmentLoop: throws an exception"); throw new OutOfMemoryException("Out Of Memory Error. Increase JVM memory"); } } } Viterbi v = new Viterbi(al); // do viterbi loop through the matrix; // at the same, do forward and mark the path // for the traceback for(int i=1; i seq2.length+1) { continue; } // lower border of real matrix if(i==1 && j==MIDDLE) { continue; } // starting point // exception if seq2 starts later; only X-gaps possible if(j-MIDDLE+i==1) { sumSubstPriceX(i,j); pathM[i][j][0] = -1d; pathM[i][j][1] = -1d; vitX[i][j] = v.getViterbiX(i,j); pathY[i][j] = -1d; fwdX[i][j] = v.getForwardX(i,j); endPoint = j; } // exception if seq1 starts later; only Y-gaps possible else if(i==1) { sumSubstPriceY(i,j); pathM[i][j][0] = -1d; pathM[i][j][1] = -1d; pathX[i][j] = -1d; vitY[i][j] = v.getViterbiY(i,j); fwdY[i][j] = v.getForwardY(i,j); endPoint = j; } else { // go through alphabet, get probability for each character sumSubstPrice(i,j); vitM[i][j] = v.getViterbiM(i,j); // for 'Match' vitX[i][j] = v.getViterbiX(i,j); // for 'X indel' vitY[i][j] = v.getViterbiY(i,j); // for 'Y indel' fwdM[i][j] = v.getForwardM(i,j); fwdX[i][j] = v.getForwardX(i,j); fwdY[i][j] = v.getForwardY(i,j); endPoint = j; } } } vitEnd = v.getViterbiEnd(endPoint); try { al.initialiseBwdMatrices(endPoint); } catch(Error e) { if(ProAlign.isResultWindow) { String text = "\n Out Of Memory Error!\n Please, increase JVM memory.\n"; OpenDialog od = new OpenDialog(pa.rw); od.showDialog("Error!", text); System.exit(0); } else { ProAlign.log.println("AlignmentLoop: Out Of Memory Error. Increase JVM memory."); System.out.println("Out Of Memory Error.\nPlease, increase JVM memory."); if(ProAlign.exitInError) { System.exit(0); } else { // System.out.println("AlignmentLoop: throws an exception"); throw new OutOfMemoryException("Out Of Memory Error. Increase JVM memory"); } } } // do backward loop through the matrix; for(int i=vitM.length-1; i>0; i--) { // go through seq1 for(int j=BWIDTH-1; j>=0; j--) { // go through seq2 if(j-MIDDLE+i < 1) { continue; } // upper border of real matrix else if(j-MIDDLE+i > seq2.length+1) { continue; } // lower border of real matrix else if(i==vitM.length-1 && j==endPoint) { continue; } // starting point else { bwdM[i][j] = v.getBackwardM(i,j); bwdX[i][j] = v.getBackwardX(i,j); bwdY[i][j] = v.getBackwardY(i,j); } } } if(ProAlign.DEBUG) { // ---DEBUG--- TransformLog tl = new TransformLog(); double bwdEnd = tl.sumLogs(bwdM[1][MIDDLE],tl.sumLogs(bwdX[1][MIDDLE], bwdY[1][MIDDLE])); double diff = (double) bwdEnd-fwdEnd; ProAlign.log.println("AlignmentLoop: vEnd: "+vitEnd+" fEnd: "+fwdEnd+ " bEnd: "+bwdEnd+" fwd-bwd: "+diff); } // ---DEBUG--- } // initialise all matrices before starting void initialiseMatrices() { // [seq1 length][band width][alphabet] price = new double[seq1.length+2][BWIDTH][aSize+1]; priceX = new double[seq1.length+2][BWIDTH][aSize+1]; priceY = new double[seq1.length+3][BWIDTH][aSize+1]; vitM = new double[seq1.length+2][BWIDTH]; vitX = new double[seq1.length+2][BWIDTH]; vitY = new double[seq1.length+2][BWIDTH]; pathM = new double[seq1.length+2][BWIDTH][2]; pathX = new double[seq1.length+2][BWIDTH]; pathY = new double[seq1.length+2][BWIDTH]; fwdM = new double[seq1.length+2][BWIDTH]; fwdX = new double[seq1.length+2][BWIDTH]; fwdY = new double[seq1.length+2][BWIDTH]; bwdM = new double[seq1.length+3][BWIDTH]; bwdX = new double[seq1.length+3][BWIDTH]; bwdY = new double[seq1.length+3][BWIDTH]; pathEnd = new double[2]; for(int j=0; jan.start1) { vitM[1][MIDDLE] = 0d; vitX[1][MIDDLE] = 0d; vitY[1][MIDDLE] = Double.NEGATIVE_INFINITY; fwdM[1][MIDDLE] = 0d; fwdX[1][MIDDLE] = 0d; fwdY[1][MIDDLE] = Double.NEGATIVE_INFINITY; } else { vitM[1][MIDDLE] = 0d; vitX[1][MIDDLE] = Double.NEGATIVE_INFINITY; vitY[1][MIDDLE] = 0d; fwdM[1][MIDDLE] = 0d; fwdX[1][MIDDLE] = Double.NEGATIVE_INFINITY; fwdY[1][MIDDLE] = 0d; } } else { // ([0] means actually [-1]) vitM[1][MIDDLE] = 0d; vitX[1][MIDDLE] = 0d; vitY[1][MIDDLE] = 0d; fwdM[1][MIDDLE] = 0d; fwdX[1][MIDDLE] = 0d; fwdY[1][MIDDLE] = 0d; } } void initialiseBwdMatrices(int endPoint) { bwdM[bwdM.length-2][endPoint] = 0d; bwdX[bwdX.length-2][endPoint] = 0d; bwdY[bwdY.length-2][endPoint] = 0d; } // calculate the sum of substitution prices for both branches separately; // iterate over all possible characters at the node, child 1 and child 2; // characters at [i] get values 'l'; at [j] values 'm'; node gets characters 'k' void sumSubstPrice(int i, int j){ // character at node int js = i+j-MIDDLE; // convert from "band" value to real value double[][] sum = new double[2][aSize]; for(int k=0; k * Description:

* Copyright: Copyright (c) Ari Loytynoja

* License: GNU GENERAL PUBLIC LICENSE

* @see http://www.gnu.org/copyleft/gpl.html * Company: ULB

* @author Ari Loytynoja * @version 1.0 */ package proalign; import java.io.IOException; import java.lang.ClassNotFoundException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; public class AlignmentNode implements Serializable { String sequence; String alphabet; String equateAlphabet; String name; String tree; float distance; int nodeNumber; String minimumProbNode = new String(); int minimumProbNumber; int treeX; int treeY; boolean isUnique = true; int sampleTimes = 0; boolean isBandWarning = false; boolean hasTrailers = false; int start0=0; int start1=0; int end0=0; int end1=0; double viterbiEnd; double forwardEnd; double[][] charProb; boolean isTerminal; int numChild; double[] postProb; int[][] cellPath; AlignmentNode[] child; AlignmentNode parent; ProAlign pa; AlignmentNode(ProAlign pa, String tree, float distance) { this.pa = pa; this.tree = tree; this.distance = Math.abs(distance); parent = this; sequence = new String(); // If this is internal node.. // if(tree.indexOf(",")>0) { nodeNumber = pa.getNodeNumber(); // set unique number child = new AlignmentNode[2]; String[] trees; float[] distances; TreeReader tr = new TreeReader(); if(nodeNumber==0) { // root is trifurcating: correction. ProAlign.log("AlignmentNode: "+tree); name = "root"; trees = tr.divideTree(tree); distances = tr.distance; } else { // other internal nodes bifurcating ProAlign.log("AlignmentNode: "+tree); name = "node"+nodeNumber; trees = tr.divideTree(tree); distances = tr.distance; } child[0] = new AlignmentNode(pa, trees[0], distances[0]); child[1] = new AlignmentNode(pa, trees[1], distances[1]); numChild = getNumChild(); } // ..else this is terminal node. // else { name = tree; alphabet = pa.sm.alphabet; equateAlphabet = pa.sm.equateAlphabet; sequence = (String) pa.seqs.get(name); isTerminal = true; numChild = 0; ProAlign.log("AlignmentNode: "+name+":"+distance+", "+sequence.length()); // Observed charcter has probability of 1, others 0. // charProb = new double[sequence.length()][alphabet.length()]; for(int i=0; i1) { child[0].align(); } if(child[1].getNumChild()>1) { child[1].align(); } } catch(TraceBackException tbe) { // throw exception if close to the edge throw tbe; } // NEW TRAILING >> int[] trail = new int[2]; double[][] midseq0 = new double[0][0]; double[][] midseq1 = new double[0][0]; if(ProAlign.removeTrailing) { CheckTrailing ct = new CheckTrailing(pa); trail = ct.trailing(child[0].sequence.trim(),child[1].sequence.trim()); if(Math.abs(trail[0])>ProAlign.offset || Math.abs(trail[1])>ProAlign.offset) { if(trail[0]>ProAlign.offset) { start0=trail[0]-ProAlign.offset; } if(trail[1]>ProAlign.offset) { end0 = trail[1]-ProAlign.offset; } midseq0 = new double[child[0].charProb.length-end0-start0][child[0].charProb[0].length]; int k=0; for(int i=start0; iProAlign.offset) { start1=Math.abs(trail[0])-ProAlign.offset; } if(-1*trail[1]>ProAlign.offset) { end1 = Math.abs(trail[1])-ProAlign.offset; } midseq1 = new double[child[1].charProb.length-end1-start1][child[1].charProb[0].length]; k=0; for(int i=start1; ibest) { best = charProb[i][j]; site = alphabet.charAt(j); } } sequence += site; } } // Get maximum depth (#internal nodes) of the tree. // int getTreeDepth() { if(isTerminal) { return 0; } if(child[0].getTreeDepth()>child[1].getTreeDepth()){ return child[0].getTreeDepth()+1; }else { return child[1].getTreeDepth()+1; } } // Get #terminal nodes below this node. // int getNumChild() { if(isTerminal) { return 1; } return (child[0].getNumChild() + child[1].getNumChild()); } // Get #times the path was sampled. // int getSampleTimes() { int times = parent.sampleTimes; if(!child[0].isTerminal) { times += child[0].getSampleTimes(); } if(!child[1].isTerminal) { times += child[1].getSampleTimes(); } return times; } // Was the path sampled. // boolean isUnique() { boolean unique0 = true; boolean unique1 = true; if(!child[0].isTerminal) { unique0 = child[0].isUnique(); } if(!child[1].isTerminal) { unique1 = child[1].isUnique(); } if(parent.isUnique && unique0 && unique1) { return true; } else { return false; } } // Was the path close to the edge. // boolean isBandWarning() { boolean warning0 = false; boolean warning1 = false; if(!child[0].isTerminal) { warning0 = child[0].isBandWarning(); } if(!child[1].isTerminal) { warning1 = child[1].isBandWarning(); } if(parent.isBandWarning || warning0 || warning1) { return true; } else { return false; } } // Get alphabet. // String getAlphabet() { if(isTerminal) { return alphabet; } return child[0].getAlphabet(); } // Get real site number at node 'str'. // int getSiteAt(int site, String str) { if(isTerminal) { if(site > sequence.length()-1){ // correct for values outside of range. return -1; } else if(site<0) { return -1; } else if(name.equals(str)) { // match - return! return site; } else { return -1; } } else { if(site > cellPath.length-1){ return -1; } else if(site<0) { return -1; } else if(name.equals(str)) { return site; } else if(child[0].getSiteAt(cellPath[site][0]-2, str)>=0) { // correct return child[0].getSiteAt(cellPath[site][0]-2, str); // for the } else if(child[1].getSiteAt(cellPath[site][1]-2, str)>=0) { // difference return child[1].getSiteAt(cellPath[site][1]-2, str); // on numbers. } else { return -1; } } } // Get characters at 'site'; returns an alignment column. // char[] getCharacterAt(int site) { char[] chars; // Terminal node returns a character or a gap // if(isTerminal) { chars = new char[1]; if(site<0) { chars[0] = '-'; } else { chars[0] = sequence.charAt(site); } return chars; } // Internal node returns a vector of.. // chars = new char[numChild]; if(site<0) { // ..gaps.. for(int i=0; i * Description:

* Copyright: Copyright (c) Ari Loytynoja

* License: GNU GENERAL PUBLIC LICENSE

* @see http://www.gnu.org/copyleft/gpl.html * Company: ULB

* @author Ari Loytynoja * @version 1.0 */ package proalign; import java.util.HashMap; import java.util.Iterator; public class CheckSequence { String error = new String(""); String alphabet; CheckSequence() { ProAlign.log("CheckSequence"); } boolean isDna(HashMap seqs) { Iterator seqKeys = seqs.keySet().iterator(); String name, seq; int acgt = 0, total = 0; while(seqKeys.hasNext()) { name = (String) seqKeys.next(); seq = (String) seqs.get(name); for(int i=0; i0.9d) { return true; } return false; } boolean isFromAlphabet(HashMap seqs,String alphabet) { boolean isFine = true; Iterator seqKeys = seqs.keySet().iterator(); String name, seq; while(seqKeys.hasNext()) { name = (String) seqKeys.next(); seq = (String) seqs.get(name); for(int i=0; i * Description:

* Copyright: Copyright (c) Ari Loytynoja

* License: GNU GENERAL PUBLIC LICENSE

* @see http://www.gnu.org/copyleft/gpl.html * Company: ULB

* @author Ari Loytynoja * @version 1.0 */ package proalign; class CheckTrailing { PwAlignment pwa; CheckTrailing(ProAlign pa) { ProAlign.log("CheckTrailing"); PwSubstitutionMatrix psm = new PwSubstitutionMatrix(); String pwAlphabet; int[][] pwSubst; int gOpen, gExt; if(ProAlign.isDna){ pwAlphabet = psm.dnaAlphabet; pwSubst = psm.swdna; gOpen = -1*pa.pwDnaOpen; gExt = -1*pa.pwDnaExt; } else { pwAlphabet = psm.protAlphabet; if(pa.pwProtMatrix.equals("pam60")) { pwSubst = psm.pam60; } else if(pa.pwProtMatrix.equals("pam160")) { pwSubst = psm.pam160; } else if(pa.pwProtMatrix.equals("pam250")) { pwSubst = psm.pam250; } else { pwSubst = psm.pam120; } gOpen = -1*pa.pwProtOpen; gExt = -1*pa.pwProtExt; } pwa = new PwAlignment(pwSubst,gOpen,gExt,pwAlphabet,ProAlign.isDna); } int[] trailing(String s1, String s2) { return pwa.trailing(s1,s2); } } CheckTreeAndData.java0100644000077000001440000000167707602640644013666 0ustar arilusers/** * Title: ProAlign

* Description:

* Copyright: Copyright (c) Ari Loytynoja

* License: GNU GENERAL PUBLIC LICENSE

* @see http://www.gnu.org/copyleft/gpl.html * Company: ULB

* @author Ari Loytynoja * @version 1.0 */ package proalign; import java.util.HashMap; class CheckTreeAndData { boolean isFine = true; boolean isDone = false; String error = new String(""); CheckTreeAndData(String[] treeNodes, HashMap seqs) { ProAlign.log("CheckTreeAndData"); for(int i=0; i * Description:

* Copyright: Copyright (c) Ari Loytynoja

* License: GNU GENERAL PUBLIC LICENSE

* @see http://www.gnu.org/copyleft/gpl.html * Company: ULB

* @author Ari Loytynoja * @version 1.0 */ package proalign; class EstimateFrequencies { double[] charFreqs; EstimateFrequencies(String[] dataArray, String alphabet, String equateAlphabet) { ProAlign.log("EstimateFrequencies"); equateAlphabet = equateAlphabet+"-"; int[] eqCounts = new int[equateAlphabet.length()]; int sum = 0; for(int i=0; i * Description: sequence alignment comparison program

* Copyright: Copyright (c) Ari Loytynoja

* License: GNU GENERAL PUBLIC LICENSE

* @see http://www.gnu.org/copyleft/gpl.html * Company: ULB

* @author Ari Loytynoja * @version 1.0 */ package proalign; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JViewport; import javax.swing.JScrollPane; import javax.swing.JScrollBar; import javax.swing.BorderFactory; import java.awt.Color; import java.awt.Dimension; import java.awt.Font; import java.awt.Container; import java.awt.Point; import java.awt.event.WindowEvent; import java.awt.event.WindowAdapter; public class MinimumProbWindow extends JFrame { JScrollPane sPane; int height; double[] minProb; PixelRule pixRule; PrintMinimumCurve curve; ResultWindow rw; String[] nodes; MinimumProbWindow(double[] minProb, String[] nodes, ResultWindow rw) { this.rw = rw; this.nodes = nodes; this.minProb = minProb; height = this.getHeight(); setTitle("Minimum posterior probability"); curve = new PrintMinimumCurve(MinimumProbWindow.this, minProb, nodes); // pixelruler. pixRule = new PixelRule(); pixRule.setPreferredWidth((int) curve.getPreferredSize().getWidth()); pixRule.setIncrement(curve.xScale); pixRule.setBackground(Color.white); sPane = new JScrollPane(curve, JScrollPane.VERTICAL_SCROLLBAR_NEVER, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); sPane.setViewportBorder(BorderFactory.createLineBorder(Color.black)); sPane.setColumnHeaderView(pixRule); sPane.setBackground(Color.white); Container cp = getContentPane(); cp.add(sPane); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e){ PrintTree.numOpenWindows--; dispose(); } }); } int getVisibleHeight() { return sPane.getViewport().getHeight(); } } NeighborJoining.java0100644000077000001440000000747007602641164013662 0ustar arilusers/** * Title: ProAlign

* Description:

* Copyright: Copyright (c) Ari Loytynoja

* License: GNU GENERAL PUBLIC LICENSE

* @see http://www.gnu.org/copyleft/gpl.html * Company: ULB

* @author Ari Loytynoja * @version 1.0 */ package proalign; // As Implemented by Studier and Keppler (1988) in Li (1997), p. 111. // class NeighborJoining { String[] newOtus; String tree = new String(); String tree3 = new String(); NeighborJoining(double[][] distance, String[] otus) { ProAlign.log("NeighborJoining"); while(distance.length>2) { distance = joinNeighbors(distance, otus); otus = newOtus; } double dist = Math.abs((distance[0][0]+distance[0][1])/2d); tree = "("+otus[0]+":"+dist+","+otus[1]+":"+dist+");"; if(otus[0].startsWith("(")&&otus[0].endsWith(")")) { tree3 = otus[0].substring(0,otus[0].length()-2)+","+ otus[1]+":"+dist*2d+");"; } else { tree3 = "("+otus[0]+":"+dist*2d+","+otus[1].substring(1)+";";; } } String getTree() { return tree; } String getTree3() { return tree3; } double[][] joinNeighbors(double[][] distance, String[] otus) { int no = distance.length; int otu1=0, otu2=0; double minM = Double.POSITIVE_INFINITY; double[] rDist = new double[no]; // sum of distances d_i,j for(int i=0; i * Description:

* Copyright: Copyright (c) Ari Loytynoja

* License: GNU GENERAL PUBLIC LICENSE

* @see http://www.gnu.org/copyleft/gpl.html * Company: ULB

* @author Ari Loytynoja * @version 1.0 */ package proalign; class NicePrint { NicePrint() { }; String dbl(double number, int length) { return ((""+number+" ").substring(0,length+1)); } String rdbl(double val, int prec) { String full = ""+val; if(full.indexOf('.')>-1) { String begin = full.substring(0,full.indexOf('.')); String end = full.substring(full.indexOf('.')+1); if(end.length()>prec) { String zeros = new String(); while(end.startsWith("0")) { end = end.substring(1); zeros += "0"; } char num = end.charAt(prec); if(num=='0'||num=='1'||num=='2'||num=='3'||num=='4') { full = begin+"."+zeros+end.substring(0,prec); } else { full = begin+"."+zeros+(new Integer(end.substring(0,prec)).intValue()+1); } } } return full; } void pdbl(double number, int length) { System.out.print((""+number+" ").substring(0,length+1)); } void str(String str) { System.out.print(str); } void strl(String str) { System.out.println(str); } } OpenDialog.java0100644000077000001440000000235407602640707012626 0ustar arilusers/** * Title: ProAlign

* Description:

* Copyright: Copyright (c) Ari Loytynoja

* License: GNU GENERAL PUBLIC LICENSE

* @see http://www.gnu.org/copyleft/gpl.html * Company: ULB

* @author Ari Loytynoja * @version 1.0 */ package proalign; import java.awt.Component; import java.awt.Font; import java.io.File; import java.io.IOException; import javax.swing.JTextArea; import javax.swing.BorderFactory; import javax.swing.border.Border; import javax.swing.JOptionPane; import javax.swing.JDialog; import java.awt.Color; public class OpenDialog extends JDialog { Font font = new Font(ProAlign.paFontName, Font.PLAIN, ProAlign.paFontSize); Component parent; OpenDialog(Component parent) { this.parent = parent; } void showDialog(String title, String text) { JTextArea ta = new JTextArea(text); ta.setFont(font); ta.setEditable(false); ta.setBackground(Color.white); Border loweredbevel = BorderFactory.createLoweredBevelBorder(); ta.setBorder(loweredbevel); JOptionPane op = new JOptionPane(); op.setMessage(ta); op.setMessageType(JOptionPane.PLAIN_MESSAGE); JDialog dialog = op.createDialog(parent,title); dialog.setLocation(150,150); dialog.show(); } } OpenFileChooser.java0100644000077000001440000000252107602640731013622 0ustar arilusers/** * Title: ProAlign

* Description:

* Copyright: Copyright (c) Ari Loytynoja

* License: GNU GENERAL PUBLIC LICENSE

* @see http://www.gnu.org/copyleft/gpl.html * Company: ULB

* @author Ari Loytynoja * @version 1.0 */ package proalign; import javax.swing.JFileChooser; import java.awt.Component; import java.awt.Font; import java.io.File; import java.io.IOException; public class OpenFileChooser extends JFileChooser { Component parent; String txt; boolean useFilter; OpenFileChooser(Component parent, String txt, boolean useFilter) { this.parent = parent; this.txt = txt; this.useFilter = useFilter; } String openFile() { String filepath = new String(""); JFileChooser jfc = new JFileChooser(ProAlign.folderPath); if(useFilter) { jfc.addChoosableFileFilter(new PAFileFilter()); } int returnValue = jfc.showDialog(parent, txt); if(returnValue == JFileChooser.APPROVE_OPTION) { File path; if (jfc.getCurrentDirectory().toString().endsWith(File.separator)) { path = new File(jfc.getCurrentDirectory().toString() + jfc.getSelectedFile().getName()); } else { path = new File(jfc.getCurrentDirectory().toString() + File.separator + jfc.getSelectedFile().getName()); } filepath = path.toString(); } return filepath; } } OpenFolderChooser.java0100644000077000001440000000234407602640735014165 0ustar arilusers/** * Title: ProAlign

* Description:

* Copyright: Copyright (c) Ari Loytynoja

* License: GNU GENERAL PUBLIC LICENSE

* @see http://www.gnu.org/copyleft/gpl.html * Company: ULB

* @author Ari Loytynoja * @version 1.0 */ package proalign; import javax.swing.JFileChooser; import java.awt.Component; import java.awt.Font; import java.io.File; import java.io.IOException; public class OpenFolderChooser extends JFileChooser { Component parent; String txt; OpenFolderChooser(Component parent, String txt) { this.parent = parent; this.txt = txt; } String openFile() { String filepath = new String(""); JFileChooser jfc = new JFileChooser(ProAlign.folderPath); jfc.setFileSelectionMode(1); int returnValue = jfc.showDialog(parent, txt); if(returnValue == JFileChooser.APPROVE_OPTION) { File path; if (jfc.getCurrentDirectory().toString().endsWith(File.separator)) { path = new File(jfc.getCurrentDirectory().toString() + jfc.getSelectedFile().getName()); } else { path = new File(jfc.getCurrentDirectory().toString() + File.separator + jfc.getSelectedFile().getName()); } filepath = path.toString(); } return filepath; } } OutFile.java0100644000077000001440000000067307602640743012156 0ustar ariluserspackage proalign; import java.io.File; import java.io.IOException; import java.io.PrintStream; import java.io.BufferedOutputStream; import java.io.FileOutputStream; public class OutFile extends PrintStream { public OutFile(String filename) throws IOException { super( new BufferedOutputStream( new FileOutputStream(filename))); } public OutFile(File file) throws IOException { this(file.getPath()); } } OutOfMemoryException.java0100644000077000001440000000070207613761753014713 0ustar arilusers/** * Title: ProAlign

* Description:

* Copyright: Copyright (c) Ari Loytynoja

* License: GNU GENERAL PUBLIC LICENSE

* @see http://www.gnu.org/copyleft/gpl.html * Company: ULB

* @author Ari Loytynoja * @version 1.0 */ package proalign; public class OutOfMemoryException extends Exception { public OutOfMemoryException() {} public OutOfMemoryException(String msg) { super(msg); } } PAFileFilter.java0100644000077000001440000000206407602640747013055 0ustar arilusers/** * Title: ProAlign

* Description:

* Copyright: Copyright (c) Ari Loytynoja

* License: GNU GENERAL PUBLIC LICENSE

* @see http://www.gnu.org/copyleft/gpl.html * Company: ULB

* @author Ari Loytynoja * @version 1.0 */ package proalign; import java.io.File; import javax.swing.filechooser.FileFilter; public class PAFileFilter extends FileFilter { // Accept all directories and files ending with ProAlign.fileExt . public boolean accept(File f) { if (f.isDirectory()) { return true; } String s = f.getName(); int i = s.lastIndexOf('.'); String ext = new String(); if (i > 0 && i < s.length() - 1) { ext = s.substring(i+1).toLowerCase(); } if (ext != null) { if (ext.equals(ProAlign.fileExt)) { return true; } else { return false; } } return false; } // The description of this filter public String getDescription() { return "ProAlign Object-file"; } } ParameterEstimates.java0100644000077000001440000001023307627642617014410 0ustar arilusers/** * Title: ProAlign

* Description:

* Copyright: Copyright (c) Ari Loytynoja

* License: GNU GENERAL PUBLIC LICENSE

* @see http://www.gnu.org/copyleft/gpl.html * Company: ULB

* @author Ari Loytynoja * @version 1.0 */ package proalign; import java.util.HashMap; public class ParameterEstimates { String[][] pairs; HashMap seqs; PwAlignment pwa; ParameterEstimates(ResultWindow rw,SetParameters sp) { this.seqs = rw.seqs; PwSubstitutionMatrix psm = new PwSubstitutionMatrix(); String pwAlphabet; int[][] pwSubst; int gOpen, gExt; if(ProAlign.isDna){ pwAlphabet = psm.dnaAlphabet; pwSubst = psm.swdna; gOpen = -1*rw.pa.pwDnaOpen; gExt = -1*rw.pa.pwDnaExt; } else { pwAlphabet = psm.protAlphabet; if(rw.pa.pwProtMatrix.equals("pam60")) { pwSubst = psm.pam60; } else if(rw.pa.pwProtMatrix.equals("pam160")) { pwSubst = psm.pam160; } else if(rw.pa.pwProtMatrix.equals("pam250")) { pwSubst = psm.pam250; } else { pwSubst = psm.pam120; } gOpen = -1*rw.pa.pwProtOpen; gExt = -1*rw.pa.pwProtExt; } pwa = new PwAlignment(pwSubst,gOpen,gExt,pwAlphabet,ProAlign.isDna); pairs = rw.root.getTerminalPairNames(); this.estimate(); sp.textDelta.setText((""+ProAlign.modelDelta+" ").substring(0,5)); sp.textEpsil.setText((""+ProAlign.modelEpsilon+" ").substring(0,5)); } ParameterEstimates(RunCommandLine rcl) { ProAlign.log("ParameterEstimates"); AlignmentNode root = rcl.root; seqs = rcl.pa.seqs; pwa = rcl.pwa; pairs = root.getTerminalPairNames(); this.estimate(); } void estimate() { double gapFreq = 0d; double sumDelta = 0d; double sumEpsilon = 0d; for(int i=0; i0) { if(mn>1) { mm = ((double)mm*(mn-1)+ml)/mn; } else { mm = (mm+ml)/2; } ml=0; gn++; } isM = false; } } else { ms++; ml++; if(!isM) { if(k>0) { if(gn>1) { mg = ((double)mg*(gn-1)+gl)/gn; } else { mg = (mg+gl)/2; } gl=0; mn++; } isM = true; } } if(k+1==revSeq[0].length()) { if(isM) { if(mn>1) { mm = ((double)mm*(mn-1)+ml)/mn; } else { mm = ml; } } else { if(gn>1) { mg = ((double)mg*(gn-1)+gl)/gn; } else { mg = gl; } } } all++; } gapFreq += (double)gs/(2*all); sumDelta += mm; sumEpsilon += mg; } gapFreq /= pairs.length; sumDelta /= pairs.length; sumEpsilon /= pairs.length; if(ProAlign.estimateDelta) { ProAlign.modelDelta = 0.5d/(sumDelta+1); ProAlign.log.println(" HMM delta estimate: "+ProAlign.modelDelta); // System.out.println("modelDelta: "+ProAlign.modelDelta); } if(ProAlign.estimateEpsilon) { ProAlign.modelEpsilon = (1d-1d/(sumEpsilon+1)); ProAlign.log.println(" HMM epsilon estimate: "+ProAlign.modelEpsilon); // System.out.println("modelEpsilon: "+ProAlign.modelEpsilon); } if(ProAlign.estimateGapFreq) { ProAlign.gapFreq = gapFreq; ProAlign.log.println(" gap frequency estimate: "+ProAlign.gapFreq); // System.out.println("gapFreq: "+ProAlign.gapFreq); } if(ProAlign.estimateGapProb) { if(ProAlign.isDna) { ProAlign.gapProb = gapFreq/4d; } else { ProAlign.gapProb = gapFreq/20d; } ProAlign.log.println(" gap probability estimate: "+ProAlign.gapProb); // System.out.println("gapProb: "+ProAlign.gapProb); } } } PixelRule.java0100644000077000001440000000446307602640753012522 0ustar arilusers/** * Title: ProAlign

* Description: sequence alignment comparison program

* Copyright: Copyright (c) Ari Loytynoja

* License: GNU GENERAL PUBLIC LICENSE

* @see http://www.gnu.org/copyleft/gpl.html * Company: ULB

* @author Ari Loytynoja * @version 1.0 */ package proalign; import java.awt.Toolkit; import java.awt.Graphics; import java.awt.Dimension; import java.awt.Color; import java.awt.Font; import java.awt.Rectangle; import javax.swing.JComponent; // A nice ruler for the quality window. // public class PixelRule extends JComponent { int rulerHeight = 15; private int increment; private int startPosition = 0; private int units; public PixelRule() { } public void setIncrement(int xScale) { increment = xScale; units = 25*xScale; } public void setPreferredWidth(int pw) { setPreferredSize(new Dimension(pw,rulerHeight)); } public void paintComponent(Graphics g) { Rectangle drawHere = g.getClipBounds(); // Fill clipping area g.setColor(Color.white); g.fillRect(drawHere.x, drawHere.y, drawHere.width, drawHere.height); // Do the ruler labels in a small font g.setFont(new Font(ProAlign.paFontName, Font.PLAIN, ProAlign.paFontSize-2)); g.setColor(Color.black); // Some vars we need. int tickLength = 0; String text = null; // Use clipping bounds to calculate first tick and last tick location. int start = (drawHere.x / increment) * increment; int end = (((drawHere.x + drawHere.width) / increment) + 1) * increment; // Make a special case of 0 to display the number // within the rule and draw a units label. if (start == 0) { text = Integer.toString(0); tickLength = 3; g.drawLine(0, rulerHeight-1, 0, rulerHeight-tickLength-1); g.drawString("0", 0, 10); start = increment; } // ticks and labels for (int i = start; i < end; i += increment) { if (i % units == 0) { tickLength = 3; text = Integer.toString(i/increment); } else if(i % 10 == 0) { tickLength = 1; text = null; } else { tickLength = 0; text = null; } if (tickLength != 0) { g.drawLine(i, rulerHeight-1, i, rulerHeight-tickLength-1); if (text != null) g.drawString(text, i-10, 10); } } } } PrintCurve.java0100644000077000001440000000370507602640757012714 0ustar arilusers/** * Title: ProAlign

* Description: sequence alignment comparison program

* Copyright: Copyright (c) Ari Loytynoja

* License: GNU GENERAL PUBLIC LICENSE

* @see http://www.gnu.org/copyleft/gpl.html * Company: ULB

* @author Ari Loytynoja * @version 1.0 */ package proalign; import javax.swing.JPanel; import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Dimension; import java.awt.event.MouseEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseListener; // Print a curve on a JPanel. // public class PrintCurve extends JPanel { double[] postProb; int height = 100; int xScale = 2; // scale: pixels per column. PrintCurve pc; QualityWindow qw; PrintCurve(QualityWindow qw, double[] postProb) { pc = this; this.qw = qw; this.postProb = postProb; setBackground(Color.white); setForeground(Color.black); setPreferredSize(new Dimension(xScale*postProb.length, height)); addMouseListener(new MiceListener()); } // Update data when changing node. // void upDateData(double[] postProb) { this.postProb = postProb; pc.updateUI(); } public void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g; super.paintComponent(g2); //clears the background height = pc.qw.getVisibleHeight(); pc.setPreferredSize(new Dimension(xScale*postProb.length, height)); for(int i=0; i0 && y2>0) { g2.drawLine(i*xScale,height-y1,(i+1)*xScale,height-y2); } } } // Listens mouse click: focus alignment, update messageText. // class MiceListener extends MouseAdapter { public void mouseClicked(MouseEvent e) { int x = e.getX(); int y = e.getY(); qw.rw.focusAlignment(x/xScale); qw.rw.convertNodeInfoX(x/xScale,qw.name); } } } PrintData.java0100644000077000001440000002317707602640763012503 0ustar arilusers/** * Title: ProAlign

* Description: sequence alignment comparison program

* Copyright: Copyright (c) Ari Loytynoja

* License: GNU GENERAL PUBLIC LICENSE

* @see http://www.gnu.org/copyleft/gpl.html * Company: ULB

* @author Ari Loytynoja * @version 1.0 */ package proalign; import javax.swing.JPanel; import javax.swing.JScrollPane; import java.awt.Color; import java.awt.Component; import java.awt.Dimension; import java.awt.RenderingHints; import java.awt.Font; import java.awt.FontMetrics; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.event.WindowEvent; import java.awt.event.WindowAdapter; import java.awt.event.MouseEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseListener; // Prints alignment characters with nice colors, shows quality as color. // public class PrintData extends JPanel { final Color bg = Color.white; final Color fg = Color.black; final Color purple = new Color(250,90,240); final Color lblue = new Color(90,210,250); final Color brown = new Color(200,160,30); final Color blue = new Color(205,205,255); int verticalCharSpace; int horizontalCharSpace; Font printFont; FontMetrics currentMetrics; int columnWidth, rowHeight; int totalWidth, totalHeight; int charWidth, charHeight; int maxLength; int startSite = -1; boolean isDataGiven = false; boolean isDataAligned = false; boolean hasMouseListener = false; boolean[] taxaRemoved = new boolean[0]; boolean[] sitesRemoved = new boolean[0]; String textArray[]; double[][] postProb; PrintData pd; ResultWindow parent; JScrollPane sPane = null; MiceListener mListener; public PrintData() { this.setParameters(); } public PrintData(String[] textArray, int maxLength, ResultWindow rw) { pd = this; parent = rw; this.maxLength = maxLength; this.textArray = textArray; verticalCharSpace = ResultWindow.verticalCharSpace; horizontalCharSpace = ResultWindow.horizontalCharSpace; this.setParameters(); isDataGiven = true; isDataAligned = false; totalWidth = maxLength*columnWidth+horizontalCharSpace; totalHeight = textArray.length*rowHeight+verticalCharSpace; setPreferredSize(new Dimension(totalWidth,totalHeight)); if(hasMouseListener) { removeMouseListener(mListener); hasMouseListener = false; } } public PrintData(String[] textArray, double[][] postProb, ResultWindow rw) { pd = this; parent = rw; this.textArray = textArray; this.postProb = postProb; verticalCharSpace = ResultWindow.verticalCharSpace; horizontalCharSpace = ResultWindow.horizontalCharSpace; this.setParameters(); isDataGiven = true; isDataAligned = true; sitesRemoved = new boolean[textArray[0].length()]; maxLength = textArray[0].length(); totalWidth = maxLength*columnWidth+horizontalCharSpace; totalHeight = textArray.length*rowHeight+verticalCharSpace; setPreferredSize(new Dimension(totalWidth,totalHeight)); mListener = new MiceListener(); addMouseListener(mListener); hasMouseListener = true; } // Some parameters need to be set even without data. // void setParameters() { printFont = new Font("monospaced", Font.BOLD, ResultWindow.rwFontSize); setBackground(bg); setForeground(fg); currentMetrics = this.getFontMetrics(printFont); charWidth = currentMetrics.charWidth(' '); charHeight = currentMetrics.getHeight(); columnWidth = charWidth + horizontalCharSpace; rowHeight = charHeight + verticalCharSpace; } public void paint(Graphics g) { if(printFont.getSize()!=ResultWindow.rwFontSize || horizontalCharSpace!=ResultWindow.horizontalCharSpace || verticalCharSpace!=ResultWindow.verticalCharSpace){ printFont = new Font("monospaced", Font.BOLD, ResultWindow.rwFontSize); horizontalCharSpace=ResultWindow.horizontalCharSpace; verticalCharSpace=ResultWindow.verticalCharSpace; this.setParameters(); } if(isDataGiven) { // if no data, no update. totalWidth = Math.max(maxLength*columnWidth+ horizontalCharSpace,sPane.getWidth()); totalHeight = Math.max(textArray.length*rowHeight+ verticalCharSpace,sPane.getHeight()); setPreferredSize(new Dimension(totalWidth,totalHeight)); int startX = sPane.getHorizontalScrollBar().getValue(); int endX = startX + sPane.getWidth(); int startY = sPane.getVerticalScrollBar().getValue(); int endY = startY + sPane.getHeight(); int startColumn = (int) (startX/columnWidth); int endColumn = Math.min((int)(endX/columnWidth)+1,maxLength); int startRow = (int) (startY/rowHeight); int endRow = Math.min((int)(endY/rowHeight)+1,textArray.length); int charX = startColumn * columnWidth; int charY = rowHeight + startRow * rowHeight; Graphics2D g2 = (Graphics2D) g; g2.setColor(bg); g2.setFont(printFont); g2.fillRect(Math.max(startX-10,0),Math.max(startY-10,0), Math.min(endX+10,totalWidth),Math.min(endY+10,totalHeight)); for (int i = startRow; i < endRow; i++) { String str = textArray[i]; for (int j = startColumn; j < endColumn; j++) { if(j>=str.length()) { break; } // unaligned seqs can be of different length. if(isDataAligned) { // if aligned, draw "selected/not-selected". // Do only once... if (i == startRow) { if (j < sitesRemoved.length) { if (sitesRemoved[j]) { g2.setColor(blue); g2.fillRect(charX,0,(charX+columnWidth),totalHeight); } else { g2.setColor(bg); g2.fillRect(charX,0,(charX+columnWidth),totalHeight); } } } // ..until here. } g2.setColor(getColor(str.charAt(j))); g2.drawString(""+str.charAt(j), charX, charY); charX += columnWidth; } if(isDataAligned) { // if aligned, draw color box. if(i= postProb.length) { col=postProb.length-1; } if(row >= postProb[0].length) { row = postProb[0].length-1; } parent.writeNodeInfo(col,row); } } // Called from Rule. // void updateStableSites(int x, int y, boolean shiftDown) { if(pd.isDataAligned) { if(shiftDown) { // shift down -> range selection if(startSite > 0) { int site = (int) x/columnWidth; int start, end; if(startSite>site) { start = site; end = startSite; } else { start = startSite+1; end = site+1; } for(int sx=start; sx single selection int site = (int) x/columnWidth; if (sitesRemoved[site]) sitesRemoved[site] = false; else sitesRemoved[site] = true; pd.repaint(); startSite = -1; } } } public boolean[] getRemovedSites() { return sitesRemoved; } Color getColor(char x) { if(ProAlign.isDna) { if (x == 'a' || x == 'A') return Color.red; if (x == 'c' || x == 'C') return Color.blue; if (x == 'g' || x == 'G') return Color.green; if (x == 't' || x == 'T' || x == 'u' || x == 'U') return brown; else return Color.gray; } else { if (x == 'g' || x == 'G' || x == 'a' || x == 'A' || x == 't' || x == 'T') return purple; if (x == 'p' || x == 'P' || x == 's' || x == 'S') return purple; if (x == 'l' || x == 'L' || x == 'i' || x == 'I') return Color.green; if (x == 'v' || x == 'V' || x == 'm' || x == 'M') return Color.green; if (x == 'k' || x == 'K' || x == 'r' || x == 'R' || x == 'h' || x == 'H') return lblue; if (x == 'f' || x == 'F' || x == 'w' || x == 'W' || x == 'y' || x == 'Y') return Color.blue; if (x == 'e' || x == 'E' || x == 'q' || x == 'Q') return Color.black; if (x == 'd' || x == 'D' || x == 'n' || x == 'N') return Color.black; if (x == 'c' || x == 'C') return Color.red; else return Color.gray; } } Color getProbColor(double x) { x = Math.exp(x); if(x<=0d) { return Color.white; } else if(x>0d && x<=0.1d) { return new Color(255,0,0); } else if(x>0.1d && x<=0.2d) { return new Color(255,26,0); } else if(x>0.2d && x<=0.3d) { return new Color(255,51,0); } else if(x>0.3d && x<=0.4d) { return new Color(255,78,0); } else if(x>0.4d && x<=0.5d) { return new Color(255,102,0); } else if(x>0.5d && x<=0.6d) { return new Color(255,128,0); } else if(x>0.6d && x<=0.7d) { return new Color(255,153,0); } else if(x>0.7d && x<=0.8d) { return new Color(255,179,0); } else if(x>0.8d && x<=0.9d) { return new Color(255,204,0); } else if(x>0.9d) { return new Color(255,230,0); } else { return Color.gray; } } } PrintMinimumCurve.java0100644000077000001440000000400507602640767014243 0ustar arilusers/** * Title: ProAlign

* Description: sequence alignment comparison program

* Copyright: Copyright (c) Ari Loytynoja

* License: GNU GENERAL PUBLIC LICENSE

* @see http://www.gnu.org/copyleft/gpl.html * Company: ULB

* @author Ari Loytynoja * @version 1.0 */ package proalign; import javax.swing.JPanel; import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Dimension; import java.awt.event.MouseEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseListener; // Print a curve on a JPanel. // public class PrintMinimumCurve extends JPanel { double[] minProb; String[] nodes; int height = 100; int xScale = 2; // scale: pixels per column. PrintMinimumCurve pc; MinimumProbWindow qw; PrintMinimumCurve(MinimumProbWindow qw, double[] minProb, String[] nodes) { pc = this; this.qw = qw; this.minProb = minProb; this.nodes = nodes; setBackground(Color.white); setForeground(Color.black); setPreferredSize(new Dimension(xScale*minProb.length, height)); addMouseListener(new MiceListener()); } public void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g; super.paintComponent(g2); //clears the background height = pc.qw.getVisibleHeight(); pc.setPreferredSize(new Dimension(xScale*minProb.length, height)); for(int i=0; i0 && y2>0) { g2.drawLine(i*xScale,height-y1,(i+1)*xScale,height-y2); } } } // Listens mouse click: focus alignment, update messageText. // class MiceListener extends MouseAdapter { public void mouseClicked(MouseEvent e) { int x = e.getX(); int y = e.getY(); qw.rw.focusAlignment(x/xScale); qw.rw.messageText.setText(" Minimum posterior probability "+ (""+Math.exp(minProb[x/xScale])+" ").substring(0,5)+ " at "+nodes[x/xScale]+"."); } } } PrintNames.java0100644000077000001440000001333207602641000012646 0ustar arilusers/** * Title: ProAlign

* Description: sequence alignment comparison program

* Copyright: Copyright (c) Ari Loytynoja

* License: GNU GENERAL PUBLIC LICENSE

* @see http://www.gnu.org/copyleft/gpl.html * Company: ULB

* @author Ari Loytynoja * @version 1.0 */ package proalign; import javax.swing.JPanel; import javax.swing.JScrollPane; import java.awt.Color; import java.awt.Component; import java.awt.Dimension; import java.awt.RenderingHints; import java.awt.Font; import java.awt.FontMetrics; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.event.WindowEvent; import java.awt.event.WindowAdapter; import java.awt.event.MouseEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseListener; // Prints taxa names, holds the info of sequences to remove. // public class PrintNames extends JPanel { final Color bg = Color.white; final Color fg = Color.black; final Color blue = new Color(205,205,255); int verticalCharSpace; int horizontalCharSpace = 1; Font printFont; FontMetrics currentMetrics; int columnWidth, rowHeight; int totalWidth, totalHeight; int charWidth, charHeight; int startSite = -1; boolean isNamesGiven = false; boolean[] taxaRemoved = new boolean[0]; String textArray[]; PrintNames pn; JScrollPane sPane = null; public PrintNames() { setBackground(bg); setForeground(fg); } public PrintNames(String[] textArray, boolean isAligned) { pn = this; this.textArray = textArray; verticalCharSpace = ResultWindow.verticalCharSpace; isNamesGiven = true; taxaRemoved = new boolean[textArray.length]; this.setParameters(); totalWidth = textArray[0].length()*columnWidth+horizontalCharSpace; totalHeight = textArray.length*rowHeight+verticalCharSpace; setPreferredSize(new Dimension(totalWidth,totalHeight)); if(isAligned) { addMouseListener(new MiceListener()); } } void setParameters() { printFont = new Font("monospaced", Font.PLAIN, ResultWindow.rwFontSize); setBackground(bg); setForeground(fg); currentMetrics = pn.getFontMetrics(printFont); charWidth = currentMetrics.charWidth(' '); charHeight = currentMetrics.getHeight(); columnWidth = charWidth + horizontalCharSpace; rowHeight = charHeight + verticalCharSpace; } public void paint(Graphics g) { if(isNamesGiven) { if(printFont.getSize()!=ResultWindow.rwFontSize || verticalCharSpace!=ResultWindow.verticalCharSpace){ printFont = new Font("monospaced", Font.BOLD, ResultWindow.rwFontSize); verticalCharSpace=ResultWindow.verticalCharSpace; this.setParameters(); } totalWidth = Math.max(textArray[0].length()*columnWidth+ horizontalCharSpace,sPane.getWidth()); totalHeight = Math.max(textArray.length*rowHeight+ verticalCharSpace,sPane.getHeight()); setPreferredSize(new Dimension(totalWidth,totalHeight)); int startX = sPane.getHorizontalScrollBar().getValue(); int endX = startX + sPane.getWidth(); int startY = sPane.getVerticalScrollBar().getValue(); int endY = startY + sPane.getHeight(); int startColumn = (int) (startX/columnWidth); int endColumn = Math.min((int)(endX/columnWidth)+1,textArray[0].length()); int startRow = (int) (startY/rowHeight); int endRow = Math.min((int)(endY/rowHeight)+1,textArray.length); int charX = startColumn*columnWidth; int charY = rowHeight+startRow*rowHeight; Graphics2D g2 = (Graphics2D) g; g2.setColor(bg); g2.setFont(printFont); g2.fillRect(Math.max(startX-10,0),Math.max(startY-10,0), Math.min(endX+10,totalWidth), Math.min(endY+10,totalHeight)); for (int i = startRow; i < endRow; i++) { String str = textArray[i]; for (int j = startColumn; j < endColumn; j++) { // Do only once... if (j == startColumn) { if (i < taxaRemoved.length) { if (taxaRemoved[i]) { g2.setColor(blue); g2.fillRect(0,(charY-rowHeight+3),totalWidth,charY+3); } else { g2.setColor(bg); g2.fillRect(0,(charY-rowHeight+3),totalWidth,charY+3); } g2.setColor(fg); } } // ..until here. g2.drawString(""+str.charAt(j), charX, charY); charX += columnWidth; } charX = startColumn * columnWidth ; charY += rowHeight; } } } // Click on a name excludes/includes the taxon. // class MiceListener extends MouseAdapter { public void mouseClicked(MouseEvent e) { int x = e.getX(); int y = e.getY(); if(e.isShiftDown()) { pn.updateTaxonList(x,y,true); } else { pn.updateTaxonList(x,y,false); } } } // Taxa list kept up-to-date. // void updateTaxonList(int x, int y, boolean shiftDown) { if(shiftDown) { if(startSite > 0) { int site = (int) y/rowHeight; int start, end; if(startSite>site) { start = site; end = startSite; } else { start = startSite+1; end = site+1; } end = Math.min(end,taxaRemoved.length); for(int sx=start; sx * Description: sequence alignment comparison program

* Copyright: Copyright (c) Ari Loytynoja

* License: GNU GENERAL PUBLIC LICENSE

* @see http://www.gnu.org/copyleft/gpl.html * Company: ULB

* @author Ari Loytynoja * @version 1.0 */ package proalign; import javax.swing.JPanel; import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Dimension; import java.awt.event.MouseEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseListener; // Print a tree on a JPanel. // public class PrintTree extends JPanel { int xBase, yBase, xMove, yMax, xMax, rowHeight; int cs = 3; // circleSize static int numOpenWindows = 0; boolean isTreeGiven = false; AlignmentNode root; ResultWindow rw; PrintTree pt; QualityWindow currentQw; PrintTree() { setBackground(Color.white); setForeground(Color.black); } PrintTree(AlignmentNode root, ResultWindow rw, boolean isAligned) { this.root = root; this.rw = rw; pt = this; isTreeGiven = true; this.setParameters(); setPreferredSize(new Dimension(rw.splitWidth, yMax)); if(isAligned) { addMouseListener(new MiceListener()); } } void setParameters() { setBackground(Color.white); setForeground(Color.black); rowHeight = rw.seqname.rowHeight; yMax = 4+root.getNumChild()*rowHeight; xMax = rw.splitWidth-10; yBase = 2+root.child[0].getNumChild()*rowHeight; xBase = 5; xMove = xMax/(root.getTreeDepth()); } public void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g; super.paintComponent(g2); //clears the background if(isTreeGiven) { if(rowHeight!=rw.seqname.rowHeight) { this.setParameters(); } setPreferredSize(new Dimension(rw.sPane1.getWidth(), yMax)); xMax = rw.sPane1.getWidth()-10; xMove = xMax/(root.getTreeDepth()); paintBranch(g2,root,yBase,xBase); g2.drawLine(xBase-2,yBase,xBase,yBase); } } // Called from 'paintComponent'. Calls recursively itself. // public void paintBranch(Graphics2D g2, AlignmentNode node, int y, int x) { int nc0 = 0; int nc1 = 0; // number of child nodes if(node.child[0].getNumChild() > 1) { nc0 = node.child[0].child[1].getNumChild(); } if(node.child[1].getNumChild()> 1) { nc1 = node.child[1].child[0].getNumChild(); } g2.fillOval(x-cs,y-cs,cs*2,cs*2); node.setTreeXY(x,y); g2.drawString(""+node.nodeNumber,x+cs*2,y+4); if(nc0>0) { g2.drawLine(x,y,x,y-nc0*rowHeight); g2.drawLine(x,y-nc0*rowHeight,x+xMove,y-nc0*rowHeight); paintBranch(g2,node.child[0],y-nc0*rowHeight,x+xMove); } else { g2.drawLine(x,y,x,y-rowHeight/2); g2.drawLine(x,y-rowHeight/2,xMax,y-rowHeight/2); } if(nc1>0) { g2.drawLine(x,y,x,y+nc1*rowHeight); g2.drawLine(x,y+nc1*rowHeight,x+xMove,y+nc1*rowHeight); paintBranch(g2,node.child[1],y+nc1*rowHeight,x+xMove); } else { g2.drawLine(x,y,x,y+rowHeight/2); g2.drawLine(x,y+rowHeight/2,xMax,y+rowHeight/2); } } // A click on a node opens an alignment quality window. // public void openQualityWindow(String name, boolean newWindow) { // ifShiftDown, open a new window. // if(!newWindow) { if(numOpenWindows==0) { QualityWindow qw = new QualityWindow(root, name,rw); qw.setSize(600,100); qw.setLocation(200,300); qw.setTitle("Posterior probability of "+name); qw.setVisible(true); currentQw = qw; numOpenWindows++; } else { currentQw.upDateData(root, name); currentQw.setTitle("Posterior probability of "+name); } } else { QualityWindow qw = new QualityWindow(root, name,rw); qw.setSize(600,100); qw.setLocation(220,320); qw.setTitle("Posterior probability of "+name); qw.setVisible(true); currentQw = qw; numOpenWindows++; } } class MiceListener extends MouseAdapter { public void mouseClicked(MouseEvent e) { int x = e.getX(); int y = e.getY(); String name = root.getNodeNameAtXY(x,y); if(!name.equals("")) { AlignmentNode node = root.getNodeNamed(name); if(node.name.equals(name)) { if(e.isShiftDown()) { pt.openQualityWindow(name,true); } else { pt.openQualityWindow(name,false); } } rw.messageText.setText(" viterbi:"+node.viterbiEnd+ "; forward: "+node.forwardEnd); } } } } ProAlign.java0100644000077000001440000001335107631104546012315 0ustar arilusers/** * Title: ProAlign

* Description:

* Copyright: Copyright (c) Ari Loytynoja

* License: GNU GENERAL PUBLIC LICENSE

* @see http://www.gnu.org/copyleft/gpl.html * Company: ULB

* @author Ari Loytynoja * @version 1.0 */ package proalign; import javax.swing.LookAndFeel; import javax.swing.UIManager; import java.util.HashMap; import java.util.Iterator; import java.io.File; import java.util.Calendar; import java.util.Date; /** * The main class of ProAlign, the probabilistic alignment program. */ public class ProAlign { public static double modelDelta = 0.1d; // HMM public static double modelEpsilon = 0.75d; // HMM public static double distScale = 1d; // distance scale factor public static double gapFreq = 0.05d; // prot model gap freq public static double gapProb = 0.001d; // prot model gap subst prob public int pwDnaOpen = 1500; // pw alignment public int pwDnaExt = 700; // pw alignment public int pwProtOpen = 1000; // pw alignment public int pwProtExt = 100; // pw alignment public String pwProtMatrix = "pam120"; // pw alignment public String treefile = new String(); public String seqfile; public String outfile = new String("proalign.out"); public boolean nogui = false; public boolean doTree = false; boolean isAligned = false; public int outformat = 2; int nodeNumber = -1; int defBandWidth; int defOffset; HashMap seqs; public static boolean isDna = true; static boolean isResultWindow = false; public static boolean trackBest = true; // traceback best static boolean DEBUG = true; // write log public static boolean removeTrailing = true; public static boolean penalizeTerminal = true; public static boolean correctMultiple = true; public static boolean writeMin = true; public static boolean writeMean = false; public static boolean writeAll = false; public static boolean writeRoot = false; public static boolean estimateGapFreq = false; public static boolean estimateGapProb = false; public static boolean estimateDelta = false; public static boolean estimateEpsilon = false; public static boolean exitInError = true; public static boolean estimateParameters = false; public static int bandWidth = 101; // diagonal alignment band width public static int offset = 15; static String fileExt = new String("paa"); // PA-file extension static String version = "0.5 alpha 0"; public static String protModel = "wag"; static int paFontSize = 11; static String paFontName = "sansserif"; static String clustalwPath; static String folderPath; static String tempFolder; static int wWidth = 800; // window size static int wHeight = 300; static OutFile log; public SubstitutionModel sm; AlignmentNode root; ResultWindow rw; public ProAlign() { // System.out.println("ProAlign"); } public ProAlign(String[] args){ defBandWidth = bandWidth; defOffset = offset; startNewLog("proalign.log"); setUserData(); if(args.length>0) { ReadArguments ra = new ReadArguments(ProAlign.this, args); } sm = new SubstitutionModel(ProAlign.this); if(ProAlign.isDna){ sm.jcDnaModel(); } else { if(ProAlign.protModel.equals("dayhoff")) { sm.dayhoffProteinModel(); } else if(ProAlign.protModel.equals("jtt")) { sm.jttProteinModel(); } else { sm.wagProteinModel(); } } if(nogui) { try { RunCommandLine rcl = new RunCommandLine(ProAlign.this); } catch(Exception e) { } } else { rw = new ResultWindow(ProAlign.this); rw.setSize(wWidth,wHeight); isResultWindow = true; rw.setVisible(true); } } /** * Keeps count on the new nodes that are created. Gives a unique number. */ int getNodeNumber() { nodeNumber++; return nodeNumber; } /** * Resets the counter. */ void setNodeNumber(int i) { nodeNumber = i; } /** * Keep log. */ public void startNewLog(String file) { try { log = new OutFile(file); } catch(Exception e) { } String date = Calendar.getInstance().getTime().toString(); log.println("\n------------------------------------"); log.println("ProAlign - starting a new event log."); log.println(" "+date); log.println("------------------------------------\n"); log.flush(); } /** * Get userdata from file */ void setUserData() { UserSettings user = new UserSettings(); String[] userdata = user.readSettings(); try { if(new File(userdata[0]).isDirectory()) folderPath = new File(userdata[0]).getAbsolutePath(); } catch (Exception e) { folderPath = new String("."); } try { if(new File(userdata[1]).isFile()) clustalwPath = new File(userdata[1]).getAbsolutePath(); } catch (Exception e) { clustalwPath = new String("clustalw"); } try { if(new File(userdata[2]).isDirectory()) folderPath = new File(userdata[0]).getAbsolutePath(); } catch (Exception e) { if(System.getProperty("os.name").startsWith("Windows")){ tempFolder = "C:\\TEMP"; } else { tempFolder = "/tmp"; } } } static void log(String txt) { if(DEBUG) { log.println(txt); log.flush(); } } /** * Main class. Takes command line arguments to run with scripts. */ public static void main(String[] args) { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception e) { } ProAlign pa = new ProAlign(args); } } PwAlignment.java0100644000077000001440000001470307616003112013017 0ustar arilusers/** * Title: ProAlign

* Description:

* Copyright: Copyright (c) Ari Loytynoja

* License: GNU GENERAL PUBLIC LICENSE

* @see http://www.gnu.org/copyleft/gpl.html * Company: ULB

* @author Ari Loytynoja * @version 1.0 */ package proalign; class PwAlignment { int len1,len2; int[][] matM,matX,matY,pointM,pointX,pointY; String[] rev = new String[2]; String seq1, seq2; int[][] subst; int gOpen; int gExt; String alphabet; boolean isDna; PwAlignment(int[][] substTable, int gapOpen, int gapExt, String alpha, boolean isD) { ProAlign.log("PwAlignment"); subst = substTable; gOpen = gapOpen; gExt = gapExt; alphabet = alpha; isDna = isD; } String[] revAligned(String s1, String s2) { ProAlign.log("PwAlignment"); len1 = s1.length(); len2 = s2.length(); seq1 = " "+s1; seq2 = " "+s2; initializeMatrices(); pwAlignment(); return rev; } double align(String s1, String s2) { len1 = s1.length(); len2 = s2.length(); seq1 = " "+s1; seq2 = " "+s2; initializeMatrices(); pwAlignment(); // Look for terminal gaps // int first = 0; int last = 0; for(int i=0; i=0; i--) { if(rev[0].charAt(i)=='-' || rev[1].charAt(i)=='-') { continue; } else { last = i; break; } } // Count identities // int all = 0; int same = 0; for(int i=first; i<=last; i++) { if(rev[0].charAt(i)==rev[1].charAt(i)) { same++; } all++; } // Print the alignment & path // boolean printAlignment = false; if(printAlignment) { for(int i=rev[0].length()-1; i>=0; i--) { System.out.print(rev[0].charAt(i)); } System.out.println(); for(int i=rev[1].length()-1; i>=0; i--) { System.out.print(rev[1].charAt(i)); } System.out.println(); System.out.println("same "+same+", all "+all); } // Return the distance // if(isDna) { double p = 1d-(double)same/(double)all; double jcK; if(p>0.75d) { jcK=5d; } else if(ProAlign.correctMultiple) { jcK = -0.75d*Math.log(1d-4d/3d*p); } else { jcK = p; } if(jcK>5d) { jcK=5d; } return jcK; } else { double p = 1d-(double)same/(double)all; double kD; if(p>0.85d) { kD=5d; } else if(ProAlign.correctMultiple) { kD = -1d*Math.log(1-p-0.2d*p*p); } else { kD = p; } if(kD>5d) { kD=5d; } return kD; } } int[] trailing(String s1, String s2) { len1 = s1.length(); len2 = s2.length(); seq1 = " "+s1; seq2 = " "+s2; initializeMatrices(); pwAlignment(); // Look for terminal gaps // int[] trail = new int[2]; int c1=0,c2=0; for(int i=0; i=0; i--) { if(rev[0].charAt(i)!='-') { c1++; } if(rev[1].charAt(i)!='-') { c2++; } if(rev[0].charAt(i)=='-' || rev[1].charAt(i)=='-') { continue; } else { trail[0] = c1-c2; break; } } return trail; } void pwAlignment() { // Fill the alignment tables // for(int i=0; i<=len1; i++) { for(int j=0; j<=len2; j++) { if(i==0 && j==0 ) { continue; } if(i>0 && j>0) { int match = subst[alphabet.indexOf(seq1.charAt(i))][alphabet.indexOf(seq2.charAt(j))]; if(matM[i-1][j-1] >= matX[i-1][j-1] && matM[i-1][j-1] >= matY[i-1][j-1]) { matM[i][j] = matM[i-1][j-1]+match; pointM[i][j] = 0; } else if(matX[i-1][j-1] >= matY[i-1][j-1]) { matM[i][j] = matX[i-1][j-1]+match; pointM[i][j] = 1; } else { matM[i][j] = matY[i-1][j-1]+match; pointM[i][j] = 2; } } if(j==0 && i>0 && !ProAlign.penalizeTerminal) { matX[i][j] = matX[i-1][j]; pointX[i][j] = 1; } else if(j==len2 && i>0 && !ProAlign.penalizeTerminal) { if(matM[i-1][j] >= matX[i-1][j]) { matX[i][j] = matM[i-1][j]; pointX[i][j] = 0; } else { matX[i][j] = matX[i-1][j]; pointX[i][j] = 1; } } else if(i>0) { if(matM[i-1][j]+gOpen >= matX[i-1][j]+gExt) { matX[i][j] = matM[i-1][j]+gOpen; pointX[i][j] = 0; } else { matX[i][j] = matX[i-1][j]+gExt; pointX[i][j] = 1; } } if(i==0 && j>0 && !ProAlign.penalizeTerminal) { matY[i][j] = matY[i][j-1]; pointY[i][j] = 2; } else if(i==len1 && j>0 && !ProAlign.penalizeTerminal) { if(matM[i][j-1] >= matY[i][j-1]) { matY[i][j] = matM[i][j-1]; pointY[i][j] = 0; } else { matY[i][j] = matY[i][j-1]; pointY[i][j] = 2; } } else if(j>0) { if(matM[i][j-1]+gOpen >= matY[i][j-1]+gExt) { matY[i][j] = matM[i][j-1]+gOpen; pointY[i][j] = 0; } else { matY[i][j] = matY[i][j-1]+gExt; pointY[i][j] = 2; } } } } // Look for best end path & score // int end = 0; int point = 0; if(matM[len1][len2] >= matX[len1][len2] && matM[len1][len2] >= matY[len1][len2]) { end = matM[len1][len2]; point = 0; } else if(matX[len1][len2] >= matY[len1][len2]) { end = matX[len1][len2]; point = 1; } else { end = matY[len1][len2]; point = 2; } // Trace back the path // rev[0] = ""; rev[1] = ""; int i=len1; int j=len2; while(i>0 || j>0) { if(point==0) { rev[0]+=seq1.charAt(i); rev[1]+=seq2.charAt(j); point = pointM[i][j]; i--;j--; continue; } else if(point==1) { rev[0]+=seq1.charAt(i); rev[1]+="-"; point = pointX[i][j]; i--; continue; } else if(point==2) { rev[0]+="-"; rev[1]+=seq2.charAt(j); point = pointY[i][j]; j--; continue; } else { System.out.println("wrong pointer!"); break; } } } // Initialize matrices for score and pointers // void initializeMatrices() { matM = new int[len1+1][len2+1]; matX = new int[len1+1][len2+1]; matY = new int[len1+1][len2+1]; pointM = new int[len1+1][len2+1]; pointX = new int[len1+1][len2+1]; pointY = new int[len1+1][len2+1]; int small = -100000; for(int j=1; j * Description:

* Copyright: Copyright (c) Ari Loytynoja

* License: GNU GENERAL PUBLIC LICENSE

* @see http://www.gnu.org/copyleft/gpl.html * Company: ULB

* @author Ari Loytynoja * @version 1.0 */ package proalign; import java.util.HashMap; import java.util.Iterator; class PwAlignmentLoop extends Thread { PwAlignment pa; ResultWindow rw; PwAlignmentLoop pal; double[][] distance; String[] names; String tree; PwAlignmentLoop(PwAlignment pa,HashMap seqs) { this.pa = pa; ProAlign.log("PwAlignmentLoop"); align(seqs); if(ProAlign.DEBUG) { for(int i=0; i=0; k--) { if(seqData[i].charAt(k)=='-' || seqData[j].charAt(k)=='-') { continue; } else { last = k; break; } } int all = 0; int same = 0; for(k=first; k<=last; k++) { if(seqData[i].charAt(k)==seqData[j].charAt(k)) { same++; } all++; } if(ProAlign.isDna) { double p = 1d-(double)same/(double)all; double jcK; if(ProAlign.correctMultiple) { jcK= -0.75d*Math.log(1d-4d/3d*p); } else { jcK = p; } if(jcK>5d) { jcK=5d; } distance[i][j] = distance[j][i] = jcK; } else { double p = 1d-(double)same/(double)all; double kD; if(ProAlign.correctMultiple) { kD = -1d*Math.log(1-p-0.2d*p*p); } else { kD = p; } if(kD>5d) { kD=5d; } distance[i][j] = distance[j][i] = kD; } } } } void align(HashMap seqs) { Iterator seqKeys = seqs.keySet().iterator(); int ns = seqs.size(); names = new String[ns]; int h=0; while(seqKeys.hasNext()) { names[h++] = (String)seqKeys.next(); } distance = new double[ns][ns]; for(int i=0; i * Description:

* Copyright: Copyright (c) Ari Loytynoja

* License: GNU GENERAL PUBLIC LICENSE

* @see http://www.gnu.org/copyleft/gpl.html * Company: ULB

* @author Ari Loytynoja * @version 1.0 */ package proalign; class PwSubstitutionMatrix { PwSubstitutionMatrix() { } String protAlphabet = "ABCDEFGHIKLMNPQRSTVWXYZ"; String dnaAlphabet = "ABCDGHKMNRSTUVWXY"; int[][] pam60 = { {500,-200,-500,-200,-100,-600,0,-500,-300,-500,-400,-300,-200,0,-300,-500,100,100,-100,-1000,-200,-600,-200}, {-200,500,-900,500,200,-800,-200,0,-400,-100,-700,-600,500,-400,-100,-500,0,-200,-500,-800,-300,-500,100}, {-500,-900,900,-1000,-1000,-900,-700,-600,-400,-1000,-1100,-1000,-700,-600,-1000,-600,-100,-500,-400,-1200,-600,-200,-1000}, {-200,500,-1000,700,300,-1100,-200,-200,-500,-200,-900,-700,200,-500,-100,-600,-200,-300,-600,-1100,-300,-800,200}, {-100,200,-1000,300,700,-1000,-200,-300,-400,-300,-700,-500,0,-300,200,-600,-200,-400,-400,-1200,-300,-700,500}, {-600,-800,-900,-1100,-1000,800,-700,-400,-100,-1000,-100,-200,-600,-700,-900,-700,-500,-600,-500,-300,-500,300,-1000}, {0,-200,-700,-200,-200,-700,600,-600,-700,-500,-800,-600,-100,-400,-500,-700,0,-300,-400,-1100,-300,-1000,-300}, {-500,0,-600,-200,-300,-400,-600,800,-600,-400,-400,-700,100,-200,200,0,-400,-500,-500,-500,-300,-200,0}, {-300,-400,-400,-500,-400,-100,-700,-600,700,-400,0,100,-400,-600,-500,-400,-400,-100,300,-1000,-300,-400,-400}, {-500,-100,-1000,-200,-300,-1000,-500,-400,-400,600,-600,0,0,-400,-100,200,-200,-200,-600,-800,-300,-700,-200}, {-400,-700,-1100,-900,-700,-100,-800,-400,0,-600,600,200,-500,-500,-300,-600,-600,-500,-100,-400,-400,-500,-500}, {-300,-600,-1000,-700,-500,-200,-600,-700,100,0,200,1000,-600,-600,-200,-200,-400,-200,0,-900,-300,-700,-400}, {-200,500,-700,200,0,-600,-100,100,-400,0,-500,-600,600,-400,-200,-300,100,-100,-500,-600,-200,-300,-100}, {0,-400,-600,-500,-300,-700,-400,-200,-600,-400,-500,-600,-400,700,-100,-200,0,-200,-400,-1000,-300,-1000,-200}, {-300,-100,-1000,-100,200,-900,-500,200,-500,-100,-300,-200,-200,-100,700,0,-300,-400,-500,-900,-300,-800,600}, {-500,-500,-600,-600,-600,-700,-700,0,-400,200,-600,-200,-300,-200,0,800,-200,-400,-500,0,-400,-800,-200}, {100,0,-100,-200,-200,-500,0,-400,-400,-200,-600,-400,100,0,-300,-200,500,100,-400,-400,-200,-500,-300}, {100,-200,-500,-300,-400,-600,-300,-500,-100,-200,-500,-200,-100,-200,-400,-400,100,600,-100,-900,-200,-500,-400}, {-100,-500,-400,-600,-400,-500,-400,-500,300,-600,-100,0,-500,-400,-500,-500,-400,-100,600,-1100,-300,-500,-500}, {-1000,-800,-1200,-1100,-1200,-300,-1100,-500,-1000,-800,-400,-900,-600,-1000,-900,0,-400,-900,-1100,1300,-800,-300,-1100}, {-200,-300,-600,-300,-300,-500,-300,-300,-300,-300,-400,-300,-200,-300,-300,-400,-200,-200,-300,-800,-300,-500,-300}, {-600,-500,-200,-800,-700,300,-1000,-200,-400,-700,-500,-700,-300,-1000,-800,-800,-500,-500,-500,-300,-500,900,-700}, {-200,100,-1000,200,500,-1000,-300,0,-400,-200,-500,-400,-100,-200,600,-200,-300,-400,-500,-1100,-300,-700,500} }; int[][] pam120 = { {300,0,-300,0,0,-400,100,-300,-100,-200,-300,-200,-100,100,-100,-300,100,100,0,-700,-100,-400,-100}, {0,400,-600,400,300,-500,0,100,-300,0,-400,-400,300,-200,0,-200,0,0,-300,-600,-100,-300,200}, {-300,-600,900,-700,-700,-600,-400,-400,-300,-700,-700,-600,-500,-400,-700,-400,0,-300,-300,-800,-400,-100,-700}, {0,400,-700,500,300,-700,0,0,-300,-100,-500,-400,200,-300,100,-300,0,-100,-300,-800,-200,-500,300}, {0,300,-700,300,500,-700,-100,-100,-300,-100,-400,-300,100,-200,200,-300,-100,-200,-300,-800,-100,-500,400}, {-400,-500,-600,-700,-700,800,-500,-300,0,-700,0,-100,-400,-500,-600,-500,-300,-400,-300,-100,-300,400,-600}, {100,0,-400,0,-100,-500,500,-400,-400,-300,-500,-400,0,-200,-300,-400,100,-100,-200,-800,-200,-600,-200}, {-300,100,-400,0,-100,-300,-400,700,-400,-200,-300,-400,200,-100,300,100,-200,-300,-300,-300,-200,-100,100}, {-100,-300,-300,-300,-300,0,-400,-400,600,-300,100,100,-200,-300,-300,-200,-200,0,300,-600,-100,-200,-300}, {-200,0,-700,-100,-100,-700,-300,-200,-300,500,-400,0,100,-200,0,200,-100,-100,-400,-500,-200,-500,-100}, {-300,-400,-700,-500,-400,0,-500,-300,100,-400,500,300,-400,-300,-200,-400,-400,-300,100,-300,-200,-200,-300}, {-200,-400,-600,-400,-300,-100,-400,-400,100,0,300,800,-300,-300,-100,-100,-200,-100,100,-600,-200,-400,-200}, {-100,300,-500,200,100,-400,0,200,-200,100,-400,-300,400,-200,0,-100,100,0,-300,-400,-100,-200,0}, {100,-200,-400,-300,-200,-500,-200,-100,-300,-200,-300,-300,-200,600,0,-100,100,-100,-200,-700,-200,-600,-100}, {-100,0,-700,100,200,-600,-300,300,-300,0,-200,-100,0,0,600,100,-200,-200,-300,-600,-100,-500,400}, {-300,-200,-400,-300,-300,-500,-400,100,-200,200,-400,-100,-100,-100,100,600,-100,-200,-300,100,-200,-500,-100}, {100,0,0,0,-100,-300,100,-200,-200,-100,-400,-200,100,100,-200,-100,300,200,-200,-200,-100,-300,-100}, {100,0,-300,-100,-200,-400,-100,-300,0,-100,-300,-100,0,-100,-200,-200,200,400,0,-600,-100,-300,-200}, {0,-300,-300,-300,-300,-300,-200,-300,300,-400,100,100,-300,-200,-300,-300,-200,0,500,-800,-100,-300,-300}, {-700,-600,-800,-800,-800,-100,-800,-300,-600,-500,-300,-600,-400,-700,-600,100,-200,-600,-800,1200,-500,-200,-700}, {-100,-100,-400,-200,-100,-300,-200,-200,-100,-200,-200,-200,-100,-200,-100,-200,-100,-100,-100,-500,-200,-300,-100}, {-400,-300,-100,-500,-500,400,-600,-100,-200,-500,-200,-400,-200,-600,-500,-500,-300,-300,-300,-200,-300,800,-500}, {-100,200,-700,300,400,-600,-200,100,-300,-100,-300,-200,0,-100,400,-100,-100,-200,-300,-700,-100,-500,400} }; int[][] pam160 = { {200,0,-200,0,0,-300,100,-200,-100,-200,-200,-100,0,100,-100,-200,100,100,0,-500,0,-300,0}, {0,300,-400,300,200,-400,0,100,-200,0,-400,-300,200,-100,100,-100,0,0,-200,-500,-100,-300,200}, {-200,-400,900,-500,-500,-500,-300,-300,-200,-500,-600,-500,-400,-300,-500,-300,0,-200,-200,-700,-300,0,-500}, {0,300,-500,400,300,-600,0,0,-300,0,-400,-300,200,-200,100,-200,0,-100,-300,-600,-100,-400,200}, {0,200,-500,300,400,-500,0,0,-200,-100,-300,-200,100,-100,200,-200,0,-100,-200,-700,-100,-400,300}, {-300,-400,-500,-600,-500,700,-400,-200,0,-500,100,0,-300,-400,-500,-400,-300,-300,-200,-100,-300,500,-500}, {100,0,-300,0,0,-400,400,-300,-300,-200,-400,-300,0,-100,-200,-300,100,-100,-200,-700,-100,-500,-100}, {-200,100,-300,0,0,-200,-300,600,-300,-100,-200,-300,200,-100,200,100,-100,-200,-200,-300,-100,0,100}, {-100,-200,-200,-300,-200,0,-300,-300,500,-200,200,200,-200,-200,-200,-200,-200,0,300,-500,-100,-200,-200}, {-200,0,-500,0,-100,-500,-200,-100,-200,400,-300,0,100,-200,0,300,-100,0,-300,-400,-100,-400,0}, {-200,-400,-600,-400,-300,100,-400,-200,200,-300,500,300,-300,-300,-200,-300,-300,-200,100,-200,-200,-200,-300}, {-100,-300,-500,-300,-200,0,-300,-300,200,0,300,700,-200,-200,-100,-100,-200,-100,100,-400,-100,-300,-200}, {0,200,-400,200,100,-300,0,200,-200,100,-300,-200,300,-100,0,-100,100,0,-200,-400,0,-200,100}, {100,-100,-300,-200,-100,-400,-100,-100,-200,-200,-300,-200,-100,500,0,-100,100,0,-200,-500,-100,-500,-100}, {-100,100,-500,100,200,-500,-200,200,-200,0,-200,-100,0,0,500,100,-100,-100,-200,-500,-100,-400,300}, {-200,-100,-300,-200,-200,-400,-300,100,-200,300,-300,-100,-100,-100,100,600,-100,-100,-300,100,-100,-400,0}, {100,0,0,0,0,-300,100,-100,-200,-100,-300,-200,100,100,-100,-100,200,100,-100,-200,0,-300,-100}, {100,0,-200,-100,-100,-300,-100,-200,0,0,-200,-100,0,0,-100,-100,100,300,0,-500,0,-300,-100}, {0,-200,-200,-300,-200,-200,-200,-200,300,-300,100,100,-200,-200,-200,-300,-100,0,400,-600,-100,-300,-200}, {-500,-500,-700,-600,-700,-100,-700,-300,-500,-400,-200,-400,-400,-500,-500,100,-200,-500,-600,1200,-400,-100,-600}, {0,-100,-300,-100,-100,-300,-100,-100,-100,-100,-200,-100,0,-100,-100,-100,0,0,-100,-400,-100,-300,-100}, {-300,-300,0,-400,-400,500,-500,0,-200,-400,-200,-300,-200,-500,-400,-400,-300,-300,-300,-100,-300,800,-400}, {0,200,-500,200,300,-500,-100,100,-200,0,-300,-200,100,-100,300,0,-100,-100,-200,-600,-100,-400,300} }; int[][] pam250 = { {200,0,-200,0,0,-300,100,-100,-100,-100,-200,-100,0,100,0,-200,100,100,0,-600,0,-300,0}, {0,300,-400,300,300,-400,0,100,-200,100,-300,-200,200,-100,100,-100,0,0,-200,-500,-100,-300,200}, {-200,-400,1200,-500,-500,-400,-300,-300,-200,-500,-600,-500,-400,-300,-500,-400,0,-200,-200,-800,-300,0,-500}, {0,300,-500,400,300,-600,100,100,-200,0,-400,-300,200,-100,200,-100,0,0,-200,-700,-100,-400,300}, {0,300,-500,300,400,-500,0,100,-200,0,-300,-200,100,-100,200,-100,0,0,-200,-700,-100,-400,300}, {-300,-400,-400,-600,-500,900,-500,-200,100,-500,200,0,-300,-500,-500,-400,-300,-300,-100,0,-200,700,-500}, {100,0,-300,100,0,-500,500,-200,-300,-200,-400,-300,0,0,-100,-300,100,0,-100,-700,-100,-500,0}, {-100,100,-300,100,100,-200,-200,600,-200,0,-200,-200,200,0,300,200,-100,-100,-200,-300,-100,0,200}, {-100,-200,-200,-200,-200,100,-300,-200,500,-200,200,200,-200,-200,-200,-200,-100,0,400,-500,-100,-100,-200}, {-100,100,-500,0,0,-500,-200,0,-200,500,-300,0,100,-100,100,300,0,0,-200,-300,-100,-400,0}, {-200,-300,-600,-400,-300,200,-400,-200,200,-300,600,400,-300,-300,-200,-300,-300,-200,200,-200,-100,-100,-300}, {-100,-200,-500,-300,-200,0,-300,-200,200,0,400,600,-200,-200,-100,0,-200,-100,200,-400,-100,-200,-200}, {0,200,-400,200,100,-300,0,200,-200,100,-300,-200,200,0,100,0,100,0,-200,-400,0,-200,100}, {100,-100,-300,-100,-100,-500,0,0,-200,-100,-300,-200,0,600,0,0,100,0,-100,-600,-100,-500,0}, {0,100,-500,200,200,-500,-100,300,-200,100,-200,-100,100,0,400,100,-100,-100,-200,-500,-100,-400,300}, {-200,-100,-400,-100,-100,-400,-300,200,-200,300,-300,0,0,0,100,600,0,-100,-200,200,-100,-400,0}, {100,0,0,0,0,-300,100,-100,-100,0,-300,-200,100,100,-100,0,200,100,-100,-200,0,-300,0}, {100,0,-200,0,0,-300,0,-100,0,0,-200,-100,0,0,-100,-100,100,300,0,-500,0,-300,-100}, {0,-200,-200,-200,-200,-100,-100,-200,400,-200,200,200,-200,-100,-200,-200,-100,0,400,-600,-100,-200,-200}, {-600,-500,-800,-700,-700,0,-700,-300,-500,-300,-200,-400,-400,-600,-500,200,-200,-500,-600,1700,-400,0,-600}, {0,-100,-300,-100,-100,-200,-100,-100,-100,-100,-100,-100,0,-100,-100,-100,0,0,-100,-400,-100,-200,-100}, {-300,-300,0,-400,-400,700,-500,0,-100,-400,-100,-200,-200,-500,-400,-400,-300,-300,-200,0,-200,1000,-400}, {0,200,-500,300,300,-500,0,200,-200,0,-300,-200,100,0,300,0,0,-100,-200,-600,-100,-400,300} }; int[][] swdna = { {1000,-900,-900,1000,-900,1000,-900,1000,1000,1000,-900,-900,-900,1000,1000,1000,-900}, {-900,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000}, {-900,1000,1000,-900,-900,1000,-900,1000,1000,-900,1000,-900,-900,1000,-900,1000,1000}, {1000,1000,-900,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000}, {-900,1000,-900,1000,1000,-900,1000,-900,1000,1000,1000,-900,-900,1000,-900,1000,-900}, {1000,1000,1000,1000,-900,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000}, {-900,1000,-900,1000,1000,1000,1000,-900,1000,1000,1000,1000,1000,1000,1000,1000,1000}, {1000,1000,1000,1000,-900,1000,-900,1000,1000,1000,1000,-900,-900,1000,1000,1000,1000}, {1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000}, {1000,1000,-900,1000,1000,1000,1000,1000,1000,1000,1000,-900,-900,1000,1000,1000,-900}, {-900,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,-900,-900,1000,-900,1000,1000}, {-900,1000,-900,1000,-900,1000,1000,-900,1000,-900,-900,1000,1000,-900,1000,1000,1000}, {-900,1000,-900,1000,-900,1000,1000,-900,1000,-900,-900,1000,1000,-900,1000,1000,1000}, {1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,-900,-900,1000,1000,1000,1000}, {1000,1000,-900,1000,-900,1000,1000,1000,1000,1000,-900,1000,1000,1000,1000,1000,1000}, {1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000}, {-900,1000,1000,1000,-900,1000,1000,1000,1000,-900,1000,1000,1000,1000,1000,1000,1000} }; } QualityWindow.java0100644000077000001440000000420507602641027013416 0ustar arilusers/** * Title: ProAlign

* Description:

* Copyright: Copyright (c) Ari Loytynoja

* License: GNU GENERAL PUBLIC LICENSE

* @see http://www.gnu.org/copyleft/gpl.html * Company: ULB

* @author Ari Loytynoja * @version 1.0 */ package proalign; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JViewport; import javax.swing.JScrollPane; import javax.swing.JScrollBar; import javax.swing.BorderFactory; import java.awt.Color; import java.awt.Dimension; import java.awt.Font; import java.awt.Container; import java.awt.Point; import java.awt.event.WindowEvent; import java.awt.event.WindowAdapter; public class QualityWindow extends JFrame { JScrollPane sPane; int height; double[] postProb; PixelRule pixRule; PrintCurve curve; ResultWindow rw; String name; QualityWindow(AlignmentNode root, String name, ResultWindow rw) { this.rw = rw; this.name = name; postProb = new double[root.cellPath.length]; for(int i=0; i * Description:

* Copyright: Copyright (c) Ari Loytynoja

* License: GNU GENERAL PUBLIC LICENSE

* @see http://www.gnu.org/copyleft/gpl.html * Company: ULB

* @author Ari Loytynoja * @version 1.0 */ package proalign; public class ReadArguments { ReadArguments(ProAlign pa, String[] args) { ProAlign.log("ReadArguments"); for(int i=0; i5) { pa.bandWidth = tmp; ProAlign.log.println(" band width: "+tmp); } else { ProAlign.log.println(" bad value: band width "+tmp); } // distance scale } else if(args[i].startsWith("-distscale=")) { double tmp = new Double( args[i].substring(args[i].indexOf("=")+1)).doubleValue(); if(tmp>0d && tmp<2.0d) { pa.distScale = tmp; ProAlign.log.println(" distance scale: "+tmp); } else { ProAlign.log.println(" bad value: distance scale "+tmp); } // multiple hits } else if(args[i].startsWith("-nocorrection")) { pa.correctMultiple = false ; ProAlign.log.println(" correctMultiple: "+pa.correctMultiple); // terminal gaps } else if(args[i].startsWith("-penalize")) { if(args[i].endsWith("=true")) { pa.penalizeTerminal = true ; } else if(args[i].endsWith("=false")) { pa.penalizeTerminal = false ; } ProAlign.log.println(" penalizeTerminal: "+pa.penalizeTerminal); // mean post prob. } else if(args[i].startsWith("-writemean")) { pa.writeMean = true ; ProAlign.log.println(" output mean: "+pa.writeMean); // all post prob. } else if(args[i].startsWith("-writeall")) { pa.writeAll = true ; ProAlign.log.println(" output all: "+pa.writeAll); // root characters } else if(args[i].startsWith("-writeroot")) { pa.writeRoot = true ; ProAlign.log.println(" output root: "+pa.writeRoot); // protein model } else if(args[i].startsWith("-wag")) { ProAlign.protModel = "wag"; ProAlign.isDna = false; ProAlign.log.println(" protein model: "+ProAlign.protModel); } else if(args[i].startsWith("-dayhoff")) { ProAlign.protModel = "dayhoff"; ProAlign.isDna = false; ProAlign.log.println(" protein model: "+ProAlign.protModel); } else if(args[i].startsWith("-jtt")) { ProAlign.protModel = "jtt"; ProAlign.isDna = false; ProAlign.log.println(" protein model: "+ProAlign.protModel); // trailing } else if(args[i].startsWith("-notrailing")) { pa.removeTrailing = false ; ProAlign.log.println(" removeTrailing: "+pa.removeTrailing); // allowed trailing } else if(args[i].startsWith("-trailing=")) { int tmp = new Integer( args[i].substring(args[i].indexOf("=")+1)).intValue(); if(tmp>5 && tmp < pa.bandWidth/2) { pa.offset = tmp; ProAlign.log.println(" trailing: "+tmp); } else { ProAlign.log.println(" bad value: trailing "+tmp); } // output file } else if(args[i].startsWith("-outfile=")) { pa.outfile = args[i].substring(args[i].indexOf("=")+1); ProAlign.log.println(" output file: "+pa.outfile); // output format } else if(args[i].startsWith("-outformat=")) { if(args[i].substring(args[i].indexOf("=")+1).equalsIgnoreCase("fasta")){ pa.outformat = 2; ProAlign.log.println(" outformat: PIR"); } else if(args[i].substring(args[i].indexOf("=")+1).equalsIgnoreCase("PIR")){ pa.outformat = 2; ProAlign.log.println(" outformat: PIR"); } else if(args[i].substring(args[i].indexOf("=")+1).equalsIgnoreCase("nexus")){ pa.outformat = 1; ProAlign.log.println(" outformat: nexus"); } else if(args[i].substring(args[i].indexOf("=")+1).equalsIgnoreCase("phylip")){ pa.outformat = 3; ProAlign.log.println(" outformat: phylip"); } else if(args[i].substring(args[i].indexOf("=")+1).equalsIgnoreCase("msf")){ pa.outformat = 4; ProAlign.log.println(" outformat: msf"); } // stay quiet, no log } else if(args[i].startsWith("-quiet")) { pa.DEBUG = false; ProAlign.log.println(" quiet..."); ProAlign.log.flush(); } else { ProAlign.log.println("Unrecognized paramter: "+args[i]); ProAlign.log.flush(); } } } } ResultWindow.java0100644000077000001440000011251007627641214013250 0ustar arilusers/** * Title: ProAlign

* Description:

* Copyright: Copyright (c) Ari Loytynoja

* License: GNU GENERAL PUBLIC LICENSE

* @see http://www.gnu.org/copyleft/gpl.html * Company: ULB

* @author Ari Loytynoja * @version 1.0 */ package proalign; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JSplitPane; import javax.swing.JTextField; import javax.swing.JScrollBar; import javax.swing.BorderFactory; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JMenu; import java.awt.Color; import java.awt.Component; import java.awt.Dimension; import java.awt.Font; import java.awt.FontMetrics; import java.awt.Container; import java.awt.Point; import java.awt.Graphics; import java.awt.event.AdjustmentEvent; import java.awt.event.AdjustmentListener; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.WindowEvent; import java.awt.event.WindowAdapter; import java.beans.PropertyChangeEvent ; import java.beans.PropertyChangeListener; import java.awt.event.MouseEvent; import java.awt.event.MouseMotionAdapter; import java.util.Iterator; import java.util.HashMap; import java.util.ArrayList; import java.io.File; import java.io.IOException; import java.io.InvalidClassException; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; public class ResultWindow extends JFrame { JMenuBar mb = new JMenuBar(); JMenu fm = new JMenu("File "), dm = new JMenu("Import"), em = new JMenu("Export"), am = new JMenu("Align "), tm = new JMenu("Font "), tm1 = new JMenu("Font size"), tm2 = new JMenu("Horizontal space"), tm3 = new JMenu("Vertical space"), pm = new JMenu("Result "), lm = new JMenu("Filter sites"); JMenuItem[] file = { new JMenuItem("About ProAlign"), new JMenuItem("Open alignment"), new JMenuItem("Save alignment"), new JMenuItem("Save guide tree"), new JMenuItem("Exit") }; JMenuItem[] data = { new JMenuItem("data"), new JMenuItem("guide tree") }; JMenuItem[] export = { new JMenuItem("PIR"), new JMenuItem("Phylip"), new JMenuItem("MSF"), new JMenuItem("Nexus") }; JMenuItem align[] = { new JMenuItem("Do ClustalW guide tree"), new JMenuItem("Do ProAlign guide tree"), new JMenuItem("Do multiple alignment"), new JMenuItem("Sample alignments"), new JMenuItem("Remove all gaps"), new JMenuItem("Set parameters"), }; JMenuItem proba[] = { new JMenuItem("Plot min. probability"), new JMenuItem("min 90%"), new JMenuItem("min 80%"), new JMenuItem("min 70%"), new JMenuItem("min 60%"), new JMenuItem("min 50%"), new JMenuItem("min 40%"), new JMenuItem("min 30%"), new JMenuItem("min 20%"), new JMenuItem("min 10%"), new JMenuItem("0% (reset)"), }; JMenuItem fom1[] = { new JMenuItem("8"), new JMenuItem("9"), new JMenuItem("10"), new JMenuItem("11"), new JMenuItem("12"), new JMenuItem("13"), new JMenuItem("14") }; JMenuItem fom2[] = { new JMenuItem("2"), new JMenuItem("3"), new JMenuItem("4"), new JMenuItem("5"), new JMenuItem("6"), new JMenuItem("7"), new JMenuItem("8"), new JMenuItem("9") }; JMenuItem fom3[] = { new JMenuItem("2"), new JMenuItem("3"), new JMenuItem("4"), new JMenuItem("5"), new JMenuItem("6"), new JMenuItem("7"), new JMenuItem("8"), new JMenuItem("9") }; JScrollPane sPane1; JScrollPane sPane2; JScrollPane sPane3; JScrollBar sButt1; JScrollBar sButt3; // ScrollListener scro; JSplitPane splitp1; JSplitPane splitp2; JTextField messageText; Container cp; Font font = new Font(ProAlign.paFontName,Font.PLAIN, ProAlign.paFontSize); Font font1 = new Font("monospaced", Font.PLAIN, ProAlign.paFontSize); PrintTree guidetree; PrintNames seqname; PrintData seqcont; Rule charRule; JPanel columnRule1; JPanel columnRule2; int splitWidth = 100; boolean isAligned = false; boolean hasData = false; boolean hasTree = false; String[] nodeNames; double[][] postProb; int wHeight; int wWidth; int maxLength; static int verticalCharSpace = 5; static int horizontalCharSpace = 5; static int rwFontSize = 11; HashMap seqs; static ResultWindow rw; AlignmentNode root; ProAlign pa; ResultWindow(ProAlign pa) { rw = this; this.pa = pa; setTitle("ProAlign "+ProAlign.version); // Create the JMenuBar - it's needed anyway. // FileMenuListener fle = new FileMenuListener(); AlignmentMenuListener alg = new AlignmentMenuListener(); ProbabilityMenuListener prb = new ProbabilityMenuListener(); FontMenuListener fon = new FontMenuListener(); file[0].setActionCommand("about"); file[0].addActionListener(fle); file[0].setFont(font); file[1].setActionCommand("open"); file[1].addActionListener(fle); file[1].setFont(font); file[2].setActionCommand("save"); file[2].addActionListener(fle); file[2].setFont(font); file[3].setActionCommand("savepag"); file[3].addActionListener(fle); file[3].setFont(font); file[4].setActionCommand("exit"); file[4].addActionListener(fle); file[4].setFont(font); data[0].setActionCommand("data"); data[0].addActionListener(fle); data[0].setFont(font); data[1].setActionCommand("tree"); data[1].addActionListener(fle); data[1].setEnabled(false); data[1].setFont(font); export[0].setActionCommand("fasta"); export[0].addActionListener(fle); export[0].setFont(font); export[1].setActionCommand("phylip"); export[1].addActionListener(fle); export[1].setFont(font); export[2].setActionCommand("msf"); export[2].addActionListener(fle); export[2].setFont(font); export[3].setActionCommand("nexus"); export[3].addActionListener(fle); export[3].setFont(font); align[0].setActionCommand("guide"); align[0].addActionListener(alg); align[0].setFont(font); align[0].setEnabled(false); align[1].setActionCommand("paguide"); align[1].addActionListener(alg); align[1].setFont(font); align[1].setEnabled(false); align[2].setActionCommand("multiple"); align[2].addActionListener(alg); align[2].setFont(font); align[2].setEnabled(false); align[3].setActionCommand("sample"); align[3].addActionListener(alg); align[3].setFont(font); align[3].setEnabled(false); align[4].setActionCommand("remove"); align[4].addActionListener(alg); align[4].setFont(font); align[4].setEnabled(false); align[5].setActionCommand("setting"); align[5].addActionListener(alg); align[5].setFont(font); align[5].setEnabled(true); for(int i=0; imaxLength) { maxLength = seqData[i].length(); } i++; } // Update info & create new JPanels. // rw.messageText.setText(" Data ready: "+seqData.length+" sequences. "); seqname = new PrintNames(seqNames, false); seqcont = new PrintData(seqData, maxLength, rw); guidetree = new PrintTree(); guidetree.setPreferredSize(new Dimension(50,seqname.getHeight())); rw.file[1].setEnabled(true); // open alignment rw.file[2].setEnabled(false); // save alignment rw.file[3].setEnabled(false); // save paguide rw.data[1].setEnabled(true); // import guide tree rw.align[0].setEnabled(true); // do clustalw guide tree rw.align[1].setEnabled(true); // do proalign guide tree rw.align[2].setEnabled(false); // do multiple rw.align[3].setEnabled(true); // sample rw.align[4].setEnabled(false); // remove gaps rw.dm.setEnabled(true); // import rw.em.setEnabled(false); // export rw.proba[0].setEnabled(false); // plot prob's rw.lm.setEnabled(false); // filter sites isAligned = false; hasData = true; hasTree = false; } void setRawDataAndTree(String tree) { rw.root = new AlignmentNode(pa,tree,0f); String[] seqNames = root.getTerminalNames(); String[] seqData = new String[seqNames.length]; for(int j=0; jmaxLength) { maxLength = seqData[i].length(); } } // Update info & create new JPanels. // rw.messageText.setText(" Data and tree ready: "+seqData.length+" sequences. "); seqname = new PrintNames(seqNames, false); seqcont = new PrintData(seqData, maxLength, rw); guidetree = new PrintTree(root, rw, false); rw.file[1].setEnabled(true); // open alignment rw.file[2].setEnabled(false); // save alignment rw.file[3].setEnabled(true); // save paguide rw.data[1].setEnabled(true); // import guide tree rw.align[0].setEnabled(true); // do guide tree rw.align[1].setEnabled(true); // do pa guide tree rw.align[2].setEnabled(true); // do multiple rw.align[3].setEnabled(true); // sample rw.align[4].setEnabled(false); // remove gaps rw.dm.setEnabled(true); // import rw.em.setEnabled(false); // export rw.proba[0].setEnabled(false); // plot prob's rw.lm.setEnabled(false); // filter sites isAligned = false; hasData = true; } // Update if the frame has been resized. // public void update(Graphics g) { wHeight = rw.getHeight(); wWidth = rw.getWidth(); if(System.getProperty("os.name").startsWith("Windows")){ splitp2.setBounds(0,0, wWidth-10,wHeight-76); messageText.setBounds(0,wHeight-75,wWidth-10,20); } else if(System.getProperty("os.name").startsWith("Mac")){ splitp2.setBounds(0,0, wWidth-10,wHeight-76); messageText.setBounds(0,wHeight-75,wWidth-20,25); } else { splitp2.setBounds(0,0, wWidth-10,wHeight-66); messageText.setBounds(0,wHeight-65,wWidth-10,25); } splitp2.updateUI(); messageText.updateUI(); } public void macUpdate() { // things don't work on OSX if(wHeight!=rw.getHeight() || wWidth!=rw.getWidth()){ wHeight = rw.getHeight(); wWidth = rw.getWidth(); splitp2.setBounds(0,0, wWidth-10,wHeight-76); messageText.setBounds(0,wHeight-75,wWidth-20,25); splitp2.updateUI(); messageText.updateUI(); } } void setScrollPanes() { sPane1 = new JScrollPane(guidetree, JScrollPane.VERTICAL_SCROLLBAR_NEVER, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); sPane2 = new JScrollPane(seqname, JScrollPane.VERTICAL_SCROLLBAR_NEVER, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); sPane3 = new JScrollPane(seqcont, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); sButt1 = new JScrollBar(); sButt3 = new JScrollBar(); rw.setRulers(); sPane1.setViewportBorder(BorderFactory.createLineBorder(Color.black)); sPane1.setColumnHeaderView(columnRule1); sPane1.setBackground(Color.white); sPane2.setViewportBorder(BorderFactory.createLineBorder(Color.black)); sPane2.setColumnHeaderView(columnRule2); sPane2.setBackground(Color.white); seqname.sPane = sPane2; sPane3.setViewportBorder(BorderFactory.createLineBorder(Color.black)); sPane3.setColumnHeaderView(charRule); sPane3.setBackground(Color.white); seqcont.sPane = sPane3; sButt3.setUnitIncrement(30); sButt3.setBlockIncrement(100); sButt3.addAdjustmentListener(new ScrollListener()); sPane3.setVerticalScrollBar(sButt3); sPane1.getHorizontalScrollBar().setBackground(Color.white); sPane2.getHorizontalScrollBar().setBackground(Color.white); sPane3.getHorizontalScrollBar().setBackground(Color.white); sPane1.getVerticalScrollBar().setBackground(Color.white); sPane3.getVerticalScrollBar().setBackground(Color.white); sPane3.getHorizontalScrollBar().setUnitIncrement(50); sPane3.getHorizontalScrollBar().setBlockIncrement(200); splitp1.setLeftComponent(sPane1); splitp1.setRightComponent(sPane2); splitp2.setLeftComponent(splitp1); splitp2.setRightComponent(sPane3); splitp1.setOneTouchExpandable(true); splitp1.setDividerLocation(splitWidth); splitp2.setOneTouchExpandable(true); splitp2.setDividerLocation(splitWidth*2); splitp1.updateUI(); splitp2.updateUI(); } void setRulers() { // Create a ruler for sequence data.. // charRule = new Rule(rw); charRule.setPreferredWidth(seqcont.totalWidth); charRule.setIncrement(seqcont.columnWidth, seqcont.horizontalCharSpace); charRule.setBackground(Color.white); // ..and two empty panels to fill the same space in other windows. // columnRule1 = new JPanel(); columnRule1.setPreferredSize(new Dimension(guidetree.getWidth(),charRule.rulerHeight)); columnRule1.setBackground(Color.white); // columnRule2 = new JPanel(); columnRule2.setPreferredSize(new Dimension(seqname.totalWidth,charRule.rulerHeight)); columnRule2.setBackground(Color.white); } // Focus the alignment view if clicked on the curve. // void focusAlignment(int x) { int y3 = (int) sPane3.getViewport().getViewPosition().getY(); int x3 = x*seqcont.columnWidth-sPane3.getWidth()/2; if(x3<0) { x3 = 0; } if(x3>(seqcont.totalWidth-sPane3.getWidth())) { x3 = seqcont.totalWidth-sPane3.getWidth(); } sPane3.getViewport().setViewPosition(new Point(x3,y3)); sPane3.getViewport().updateUI(); } // Write info at messageText field. // void writeNodeInfo(int col, int row) { String nn = nodeNames[row]; AlignmentNode an = root.getNodeNamed(nn); String alphabet = root.getAlphabet(); int site = root.getSiteAt(col,nn); String txt = ""; if(site>-1) { for(int i=0; i= postProb.length) { col=postProb.length-1; } int row = -1; for(int i=0; i -1) { rw.writeNodeInfo(col,row); } } void writeTempFasta() { try { OutFile out = new OutFile(ProAlign.tempFolder+File.separator+"proalign.seq"); Iterator seqKeys = seqs.keySet().iterator(); while(seqKeys.hasNext()) { String name = (String) seqKeys.next(); String data = (String) seqs.get(name); if(ProAlign.isDna) { out.println(">DL;" +name); } else { out.println(">P1;" +name); } out.println(); int count = 0; for(int j = 0; j= 0d) { boolean[] sitesRemoved = new boolean[root.cellPath.length]; int count = 0; for(int i=0; i * Description:

* Copyright: Copyright (c) Ari Loytynoja

* License: GNU GENERAL PUBLIC LICENSE

* @see http://www.gnu.org/copyleft/gpl.html * Company: ULB

* @author Ari Loytynoja * @version 1.0 */ package proalign; import java.awt.Toolkit; import java.awt.Graphics; import java.awt.Dimension; import java.awt.Color; import java.awt.Font; import java.awt.Rectangle; import javax.swing.JComponent; import java.awt.event.MouseEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseListener; public class Rule extends JComponent { int rulerHeight = 15; private int increment; private int startPosition; private int units; Rule rule; ResultWindow parent; public Rule(ResultWindow rw) { rule = this; parent = rw; addMouseListener(new MiceListener()); } public void setIncrement(int columnWidth, int startPosition) { increment = columnWidth; this.startPosition = startPosition; units = 10*columnWidth; } public void setPreferredWidth(int pw) { setPreferredSize(new Dimension(pw,rulerHeight)); } public void paintComponent(Graphics g) { Rectangle drawHere = g.getClipBounds(); // Fill clipping area g.setColor(Color.white); g.fillRect(drawHere.x, drawHere.y, drawHere.width, drawHere.height); // Do the ruler labels in a small font g.setFont(new Font(ProAlign.paFontName, Font.PLAIN, ProAlign.paFontSize-2)); g.setColor(Color.black); // Some vars we need. int tickLength = 0; String text = null; // Use clipping bounds to calculate first tick and last tick location. int start = (drawHere.x / increment) * increment; int end = (((drawHere.x + drawHere.width) / increment) + 1) * increment; // Make a special case of 0 to display the number // within the rule and draw a units label. if (start == 0) { text = Integer.toString(0); tickLength = 3; g.drawLine(0, rulerHeight-1, 0, rulerHeight-tickLength-1); start = increment; } // ticks and labels for (int i = start; i < end; i += increment) { if (i % units == 0) { tickLength = 3; text = Integer.toString(i/increment); } else { tickLength = 1; text = null; } if (tickLength != 0) { g.drawLine(i, rulerHeight-1, i, rulerHeight-tickLength-1); if (text != null) g.drawString(text, i-10, 10); } } } // A click on a site will include/exclude that character. // class MiceListener extends MouseAdapter { public void mouseClicked(MouseEvent e) { int x = e.getX(); int y = e.getY(); if(e.isShiftDown()) { parent.seqcont.updateStableSites(x,y,true); } else { parent.seqcont.updateStableSites(x,y,false); } } } } RunClustalw.java0100644000077000001440000000776707605112522013075 0ustar arilusers/** * Title: ProAlign

* Description:

* Copyright: Copyright (c) Ari Loytynoja

* License: GNU GENERAL PUBLIC LICENSE

* @see http://www.gnu.org/copyleft/gpl.html * Company: ULB

* @author Ari Loytynoja * @version 1.0 */ package proalign; import java.io.File; import java.io.IOException; import java.math.BigDecimal; import java.io.DataInputStream; import java.io.BufferedInputStream; /** * Running native ClustalW. */ public class RunClustalw extends Thread { String tempFolder; String clustalwPath; String cmdParameter; ResultWindow rw; Process process; DataInputStream clustalwOut; /** * Argument list describing the ClustalW loop. */ RunClustalw(ResultWindow rw) { this.rw = rw; ProAlign.log("RunClustalw"); clustalwPath = ProAlign.clustalwPath; tempFolder = ProAlign.tempFolder+File.separator; if(System.getProperty("os.name").startsWith("Windows")){ File oldFile = new File(tempFolder+"PROALIGN.TRE"); if(oldFile.exists()) { try { oldFile.delete(); } catch (Exception ie) { ProAlign.log.println(" can not delete old guide tree-file!"); } } } else { File oldFile = new File(tempFolder+"proalign.tre"); if(oldFile.exists()) { try { oldFile.delete(); } catch (Exception ie) { ProAlign.log.println(" can not delete old guide tree-file!"); } } } if(System.getProperty("os.name").startsWith("Windows")){ cmdParameter = "clustalw /tree /newtree="+tempFolder+"PROALIGN.TRE /infile="+ tempFolder+"proalign.seq"; } else { cmdParameter = " -tree -newtree="+tempFolder+"proalign.tre -infile="+ tempFolder+"proalign.seq"; } start(); } public void run(){ /** * Clustalw - make guide tree only! */ if(System.getProperty("os.name").startsWith("Windows")) { int narg = numArg(cmdParameter,"/"); try { WinClustalw wc = new WinClustalw(narg,cmdParameter); while(wc.running) { try{ Thread.currentThread().sleep(500); } catch(InterruptedException e) {} } } catch(Exception ex) { ProAlign.log("WinClustalw error"); } } else { try { process = Runtime.getRuntime().exec(clustalwPath+cmdParameter); clustalwOut = new DataInputStream(new BufferedInputStream(process.getInputStream())); String str; while((str = clustalwOut.readLine()) != null) { if (str.length() > 0) { ProAlign.log(str); } } } catch(IOException e) { } } if(ProAlign.DEBUG) { ProAlign.log.flush(); } String filepath; if(System.getProperty("os.name").startsWith("Windows")){ filepath = ProAlign.tempFolder+File.separator+"PROALIGN.TRE"; } else { filepath = ProAlign.tempFolder+File.separator+"proalign.tre"; } File newFile = new File(filepath); if(!newFile.exists()) { // for some reason ClustalW failed. String text = "\n ClustalW output not found!\n"; OpenDialog od = new OpenDialog(rw); od.showDialog("Error!", text); rw.setRawData(rw.seqs); rw.setScrollPanes(); } else { // guide tree is fine. TreeReader tr = new TreeReader(); String[] treeNodes = tr.getAllNodes(filepath); CheckTreeAndData chk = new CheckTreeAndData(treeNodes, rw.seqs); if(chk.nodesAreSame()) { String tree = tr.readFile(filepath); TreeNode tn = new TreeNode(tree); tree = tn.findMiddlePoint(); rw.setRawDataAndTree(tree); rw.setScrollPanes(); } else { String text = new String("\n Guide tree and sequence \n"+ " file do not match!\n"); OpenDialog od = new OpenDialog(rw); od.showDialog("Warning!", text); ProAlign.log.println("ClustalW: nodes and names do not match!"); } } } public int numArg(String cmnd,String csep) { int narg = 0; for(int i = 0, j = 0; i < cmnd.length();) { j = cmnd.indexOf(csep, i); if (j >= i){ narg++; i = j; } i++; } return narg; } } RunCommandLine.java0100644000077000001440000001213707616003026013450 0ustar arilusers/** * Title: ProAlign

* Description:

* Copyright: Copyright (c) Ari Loytynoja

* License: GNU GENERAL PUBLIC LICENSE

* @see http://www.gnu.org/copyleft/gpl.html * Company: ULB

* @author Ari Loytynoja * @version 1.0 */ package proalign; import java.io.File; import java.util.HashMap; public class RunCommandLine { ProAlign pa; PwAlignment pwa; PwAlignmentLoop pwal; AlignmentNode root; public RunCommandLine(ProAlign pa) throws Exception { ProAlign.log("RunCommandLine"); this.pa = pa; SequenceReader sr = new SequenceReader(); if(pa.seqfile != null && new File(pa.seqfile).exists()) { // ..and it's a valid file, if(sr.fromFile(pa.seqfile)) { pa.seqs = sr.getSequences(); CheckSequence cs = new CheckSequence(); if(cs.isDna(pa.seqs)){ pa.sm.jcDnaModel(); ProAlign.isDna = true; } else { if(ProAlign.protModel.equals("dayhoff")) { pa.sm.dayhoffProteinModel(); } else if(ProAlign.protModel.equals("jtt")) { pa.sm.jttProteinModel(); } else { pa.sm.wagProteinModel(); } ProAlign.isDna = false; } if(!cs.isFromAlphabet(pa.seqs,pa.sm.equateAlphabet)) { ProAlign.log.println("Sequence reading error: Illegal characters!"); System.out.println("Sequence reading error: Illegal characters!"); if(ProAlign.exitInError) { System.exit(0); } else { throw new Exception("Sequence reading error: Illegal characters"); } } } else { String msg = sr.getErrors(); ProAlign.log.println(msg); System.out.println(msg); if(ProAlign.exitInError) { System.exit(0); } else { throw new Exception("Sequence reading error"); } } } else { ProAlign.log.println("Sequence file doesn't exist!"); System.out.println("Sequence file doesn't exist!"); if(ProAlign.exitInError) { System.exit(0); } else { throw new Exception("Sequence file doesn't exist"); } } String tree = new String(); TreeReader tr = new TreeReader(); // do a new tree PwSubstitutionMatrix psm = new PwSubstitutionMatrix(); String pwAlphabet; int[][] pwSubst; int gOpen, gExt; if(ProAlign.isDna){ pwAlphabet = psm.dnaAlphabet; pwSubst = psm.swdna; gOpen = -1*pa.pwDnaOpen; gExt = -1*pa.pwDnaExt; } else { pwAlphabet = psm.protAlphabet; if(pa.pwProtMatrix.equals("pam60")) { pwSubst = psm.pam60; } else if(pa.pwProtMatrix.equals("pam160")) { pwSubst = psm.pam160; } else if(pa.pwProtMatrix.equals("pam250")) { pwSubst = psm.pam250; } else { pwSubst = psm.pam120; } gOpen = -1*pa.pwProtOpen; gExt = -1*pa.pwProtExt; } pwa = new PwAlignment(pwSubst,gOpen,gExt,pwAlphabet,ProAlign.isDna); if(pa.doTree) { pwal = new PwAlignmentLoop(pwa,pa.seqs); tree = pwal.getTree(); if(pa.treefile!=null) { try { OutFile newtree = new OutFile(pa.treefile); newtree.println(tree); newtree.close(); } catch(Exception e) { } } // open an existing tree file } else if(pa.treefile != null && new File(pa.treefile).exists()) { String[] treeNodes = tr.getAllNodes(pa.treefile); CheckTreeAndData chk = new CheckTreeAndData(treeNodes,pa.seqs); // ..and it's a valid file, set the tree. if(chk.nodesAreSame()) { tree = tr.readFile(pa.treefile); if(tr.isUnRooted) { TreeNode tn = new TreeNode(tree); tree = tn.findMiddlePoint(); } } else { ProAlign.log.println("Sequence and tree files don't match!"); System.out.println("Sequence and tree files don't match!"); if(ProAlign.exitInError) { System.exit(0); } else { throw new Exception("Sequence and tree files don't match"); } } } else { ProAlign.log.println("Tree file doesn't exist!"); System.out.println("Tree file doesn't exist!"); if(ProAlign.exitInError) { System.exit(0); }else { throw new Exception("Tree file doesn't exist"); } } if(tree != null) { root = new AlignmentNode(pa,tree,0f); // if(ProAlign.estimateParameters) { ParameterEstimates pe = new ParameterEstimates(RunCommandLine.this); } // try { root.align(); } catch(TraceBackException tbe) { String msg = tbe.getMessage(); ProAlign.log.println(msg); System.out.println(msg); if(ProAlign.exitInError) { System.exit(0); }else { throw new Exception(msg); } } catch(Exception e) { // System.out.println("RunCommandLine: throws an exception"); throw e; } // seems to be fine - save results. if(pa.outformat==1) { SaveData sd = new SaveData(pa.outfile,1,root); } else if(pa.outformat==2){ SaveData sd = new SaveData(pa.outfile,2,root); } else if(pa.outformat==3){ SaveData sd = new SaveData(pa.outfile,3,root); } else if(pa.outformat==4){ SaveData sd = new SaveData(pa.outfile,4,root); } } else { ProAlign.log.println("Problems with tree!"); System.out.println("Problems with tree!"); if(ProAlign.exitInError) { System.exit(0); } else { throw new Exception("Problems with tree"); } } } } RunMultiple.java0100644000077000001440000000441107613755461013067 0ustar arilusers/** * Title: ProAlign

* Description:

* Copyright: Copyright (c) Ari Loytynoja

* License: GNU GENERAL PUBLIC LICENSE

* @see http://www.gnu.org/copyleft/gpl.html * Company: ULB

* @author Ari Loytynoja * @version 1.0 */ package proalign; import java.io.File; import java.io.IOException; import java.math.BigDecimal; import java.io.DataInputStream; import java.io.BufferedInputStream; /** * Running alignment in a separate thread */ public class RunMultiple extends Thread { ResultWindow rw; RunMultiple(ResultWindow rw) { this.rw = rw; ProAlign.log("RunMultiple"); start(); } public void run() { boolean isError = false; String errorMsg = new String(); try { rw.root.align(); } catch(TraceBackException tbe) { isError = true; errorMsg = tbe.getMessage(); } catch(Exception e) { } if(isError) { OpenDialog od = new OpenDialog(rw); od.showDialog("Error!", "\n "+errorMsg+"\n Try to increase the band width.\n"); rw.file[1].setEnabled(true); // open alignment rw.file[2].setEnabled(false); // save alignment rw.data[0].setEnabled(true); // import data rw.data[1].setEnabled(true); // import guide tree rw.align[0].setEnabled(true); // do guide tree NOT YET rw.align[1].setEnabled(true); // do multiple rw.align[2].setEnabled(true); // do complete NOT YET rw.align[3].setEnabled(true); // sample rw.align[4].setEnabled(false); // remove gaps rw.dm.setEnabled(true); // import rw.em.setEnabled(false); // export } else { rw.setAlignedData(rw.root); rw.setScrollPanes(); if(rw.root.isBandWarning()) { String text = new String( "\n Traceback path came very close\n to the band edge."+ " Alignment may\n not be the correct one!"); OpenDialog od = new OpenDialog(rw); od.showDialog("Warning!",text); } if(!rw.root.isUnique()) { String text = new String( "\n There exist more than one possible\n alignment. The backtrace "+ "path was\n chosen "+rw.root.getSampleTimes()+" times randomly between\n"+ " two equally good alternatives.\n"); OpenDialog od = new OpenDialog(rw); od.showDialog("Notice!",text); } } } } SampleAlignments.java0100644000077000001440000003031407602641056014043 0ustar arilusers/** * Title: ProAlign

* Description:

* Copyright: Copyright (c) Ari Loytynoja

* License: GNU GENERAL PUBLIC LICENSE

* @see http://www.gnu.org/copyleft/gpl.html * Company: ULB

* @author Ari Loytynoja * @version 1.0 */ package proalign; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JLabel; import javax.swing.JButton; import javax.swing.JRadioButton; import javax.swing.ButtonGroup; import javax.swing.JCheckBox; import javax.swing.JTextField; import javax.swing.JTextArea; import javax.swing.JScrollPane; import javax.swing.JScrollBar; import java.awt.GridLayout; import java.awt.BorderLayout; import java.awt.Font; import java.awt.Container; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.WindowEvent; import java.awt.event.WindowAdapter; import java.awt.event.ItemListener; import java.awt.event.ItemEvent; import java.io.File; import java.io.IOException; public class SampleAlignments extends JFrame { JTextArea textOutput; JTextField textNumber; JCheckBox boxResult; JCheckBox boxFolder; JCheckBox boxNexus; JCheckBox boxFasta; JScrollPane sp; JScrollBar sb; String resultPath = new String("sample_result.csv"); String folderPath = new String(""); String nexusPath = new String(""); String fastaPath = new String(""); int numRun; boolean writeResults = true; boolean writeAlignments = false; boolean writeNexus = false; boolean writeFasta = false; boolean isRunning = true; OutFile resultOut; int height = 300; int width = 600; ProAlign pa; ResultWindow rw; SampleAlignments sa; SampleAlignments(ResultWindow rw) { setTitle("Sample alignments"); this.rw = rw; this.pa = rw.pa; sa = this; Font font = new Font(ProAlign.paFontName, Font.PLAIN, ProAlign.paFontSize); try { resultOut = new OutFile(resultPath); } catch(IOException ioe) { } JButton buttonResult = new JButton("Select"); buttonResult.setFont(font); buttonResult.setActionCommand("result"); buttonResult.addActionListener(new ButtonL()); JButton buttonFolder = new JButton("Select"); buttonFolder.setFont(font); buttonFolder.setActionCommand("folder"); buttonFolder.addActionListener(new ButtonL()); JButton buttonNexus = new JButton("Select"); buttonNexus.setFont(font); buttonNexus.setActionCommand("nexus"); buttonNexus.addActionListener(new ButtonL()); JButton buttonFasta = new JButton("Select"); buttonFasta.setFont(font); buttonFasta.setActionCommand("fasta"); buttonFasta.addActionListener(new ButtonL()); JButton buttonStart = new JButton("Start"); buttonStart.setFont(font); buttonStart.setActionCommand("start"); buttonStart.addActionListener(new ButtonL()); JButton buttonStop = new JButton("Stop"); buttonStop.setFont(font); buttonStop.setActionCommand("stop"); buttonStop.addActionListener(new ButtonL()); JButton buttonClose = new JButton("Close"); buttonClose.setFont(font); buttonClose.setActionCommand("close"); buttonClose.addActionListener(new ButtonL()); JLabel labelHeader = new JLabel(" Sampling parameters"); labelHeader.setFont(font); JLabel labelResult = new JLabel("Change file"); labelResult.setFont(font); JLabel labelFolder = new JLabel("Change folder"); labelFolder.setFont(font); JLabel labelNexus = new JLabel("Change folder"); labelNexus.setFont(font); JLabel labelFasta = new JLabel("Change folder"); labelFasta.setFont(font); JLabel labelNumber = new JLabel("Permutations"); labelNumber.setFont(font); JLabel labelSample = new JLabel("Traceback route"); labelSample.setFont(font); textNumber = new JTextField("100"); textNumber.setFont(font); boxResult = new JCheckBox("Write results"); boxResult.setActionCommand("result"); boxResult.setFont(font); if(writeResults) { boxResult.setSelected(true); } else { boxResult.setSelected(false); } boxFolder = new JCheckBox("Save ."+ProAlign.fileExt); boxFolder.setActionCommand("folder"); boxFolder.setFont(font); boxFolder.setSelected(false); boxNexus = new JCheckBox("Save .nex"); boxNexus.setActionCommand("nexus"); boxNexus.setFont(font); boxNexus.setSelected(false); boxFasta = new JCheckBox("Save .pir"); boxFasta.setActionCommand("fasta"); boxFasta.setFont(font); boxFasta.setSelected(false); JRadioButton traceBest = new JRadioButton("select best"); traceBest.setFont(font); traceBest.setActionCommand("best"); JRadioButton traceSample = new JRadioButton("sample"); traceSample.setFont(font); traceSample.setActionCommand("sample"); if(ProAlign.trackBest) { traceBest.setSelected(true); } else { traceSample.setSelected(true); } CheckBoxListener chboxL = new CheckBoxListener(); boxResult.addItemListener(chboxL); boxFolder.addItemListener(chboxL); boxNexus.addItemListener(chboxL); boxFasta.addItemListener(chboxL); JPanel fullPanel = new JPanel(); fullPanel.setLayout(new GridLayout(1,2,15,15)); JPanel halfPanel = new JPanel(); halfPanel.setLayout(new GridLayout(10,1,5,5)); halfPanel.add(labelHeader); JPanel pnl = new JPanel(); pnl.setLayout(new GridLayout(1,3,5,5)); pnl.add(new JLabel()); pnl.add(labelNumber); pnl.add(textNumber); halfPanel.add(pnl); pnl = new JPanel(); pnl.setLayout(new GridLayout(1,3,5,5)); pnl.add(boxResult); pnl.add(labelResult); pnl.add(buttonResult); halfPanel.add(pnl); pnl = new JPanel(); pnl.setLayout(new GridLayout(1,3,5,5)); pnl.add(boxFolder); pnl.add(labelFolder); pnl.add(buttonFolder); halfPanel.add(pnl); pnl = new JPanel(); pnl.setLayout(new GridLayout(1,3,5,5)); pnl.add(boxNexus); pnl.add(labelNexus); pnl.add(buttonNexus); halfPanel.add(pnl); pnl = new JPanel(); pnl.setLayout(new GridLayout(1,3,5,5)); pnl.add(boxFasta); pnl.add(labelFasta); pnl.add(buttonFasta); halfPanel.add(pnl); ButtonGroup traceBack = new ButtonGroup(); traceBack.add(traceBest); traceBack.add(traceSample); RadioListener radioL = new RadioListener(); traceBest.addActionListener(radioL); traceSample.addActionListener(radioL); pnl = new JPanel(); pnl.setLayout(new GridLayout(1,2,5,5)); pnl.add(labelSample); pnl.add(traceBest); halfPanel.add(pnl); pnl = new JPanel(); pnl.setLayout(new GridLayout(1,2,5,5)); pnl.add(new JPanel()); pnl.add(traceSample); halfPanel.add(pnl); halfPanel.add(new JPanel()); pnl = new JPanel(); pnl.setLayout(new GridLayout(1,3,5,5)); pnl.add(buttonStart); pnl.add(buttonStop); pnl.add(buttonClose); halfPanel.add(pnl); fullPanel.add(halfPanel); textOutput = new JTextArea(); textOutput.setFont(font); sp = new JScrollPane(textOutput,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); sb = sp.getVerticalScrollBar(); fullPanel.add(sp); Container cp = getContentPane(); cp.add(fullPanel); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { dispose(); } }); } public void write(String str) { if (str != "") { textOutput.append(" " + str + " \n"); sb.setValue(sb.getMaximum()); } } class ButtonL implements ActionListener { public void actionPerformed(ActionEvent e) { JButton target = (JButton)e.getSource(); String actionCommand = target.getActionCommand(); if(actionCommand.equals("result")) { OpenFileChooser opf = new OpenFileChooser(SampleAlignments.this,"Save",false); String filepath = opf.openFile(); if(!filepath.equals("")) { resultOut.close(); try { resultOut = new OutFile(filepath); } catch(IOException ioe) { } sa.write("result file is: "+filepath); resultPath = filepath; UserSettings user = new UserSettings(); String[] userdata = user.readSettings(); userdata[0] = new File(filepath).getParent(); user.writeSettings(userdata); } } else if(actionCommand.equals("folder")) { OpenFolderChooser opf = new OpenFolderChooser(SampleAlignments.this,"Select"); String filepath = opf.openFile(); if(!filepath.equals("")) { folderPath = filepath; sa.write("alignment folder is: "+new File(folderPath).getAbsolutePath()); UserSettings user = new UserSettings(); String[] userdata = user.readSettings(); userdata[0] = new File(filepath).getParent(); user.writeSettings(userdata); } } else if(actionCommand.equals("nexus")) { OpenFolderChooser opf = new OpenFolderChooser(SampleAlignments.this,"Select"); String filepath = opf.openFile(); if(!filepath.equals("")) { nexusPath = filepath; sa.write("nexus folder is: "+new File(nexusPath).getAbsolutePath()); UserSettings user = new UserSettings(); String[] userdata = user.readSettings(); userdata[0] = new File(filepath).getParent(); user.writeSettings(userdata); } } else if(actionCommand.equals("fasta")) { OpenFolderChooser opf = new OpenFolderChooser(SampleAlignments.this,"Select"); String filepath = opf.openFile(); if(!filepath.equals("")) { fastaPath = filepath; sa.write("fasta folder is: "+new File(fastaPath).getAbsolutePath()); UserSettings user = new UserSettings(); String[] userdata = user.readSettings(); userdata[0] = new File(filepath).getParent(); user.writeSettings(userdata); } } else if(actionCommand.equals("start")) { while(true) { try{ int maxRun = new Integer(textNumber.getText()).intValue(); if(maxRun>0) { numRun = maxRun; } else { String text = new String("\n Illegal value! \n"); OpenDialog od = new OpenDialog(SampleAlignments.this); od.showDialog("Error!", text); break; } if(ProAlign.DEBUG) { ProAlign.log("SampleAlignments"); ProAlign.log("resultPath="+resultPath+","+writeResults); ProAlign.log("folderPath="+folderPath+","+writeAlignments); ProAlign.log("nexusPath="+nexusPath+","+writeNexus); ProAlign.log("fastaPath="+fastaPath+","+writeFasta); ProAlign.log("numRun="+numRun); ProAlign.log("trackBest="+ProAlign.trackBest); ProAlign.log.flush(); } } catch(NumberFormatException nfe) { String text = new String("\n Illegal value! \n"); OpenDialog od = new OpenDialog(SampleAlignments.this); od.showDialog("Error!", text); break; } SampleLoop sl = new SampleLoop(SampleAlignments.this); break; } } else if(actionCommand.equals("stop")) { isRunning = false; } else if(actionCommand.equals("close")) { dispatchEvent(new WindowEvent(SampleAlignments.this, WindowEvent.WINDOW_CLOSING)); } } } class CheckBoxListener implements ItemListener { public void itemStateChanged(ItemEvent e) { JCheckBox target = (JCheckBox)e.getItem(); String actionCommand = target.getActionCommand(); if(actionCommand.equals("result")) { if (e.getStateChange() == ItemEvent.DESELECTED) { writeResults = false; sa.write("writing results stopped!"); } else { writeResults = true; sa.write("writing results started."); } } else if(actionCommand.equals("folder")) { if (e.getStateChange() == ItemEvent.DESELECTED) { writeAlignments = false; sa.write("sampled alignments are not saved!"); } else { writeAlignments = true; sa.write("all sampled alignments are saved."); } } else if(actionCommand.equals("nexus")) { if (e.getStateChange() == ItemEvent.DESELECTED) { writeNexus = false; sa.write("nexus files are not saved!"); } else { writeNexus = true; sa.write("alignments are saved as nexus files."); } } else if(actionCommand.equals("fasta")) { if (e.getStateChange() == ItemEvent.DESELECTED) { writeFasta = false; sa.write("fasta files are not saved!"); } else { writeFasta = true; sa.write("alignments are saved as fasta files."); } } } } class RadioListener implements ActionListener { public void actionPerformed(ActionEvent e) { String actionCommand = e.getActionCommand(); if(actionCommand.equals("sample")) { ProAlign.trackBest = false; } else if(actionCommand.equals("best")) { ProAlign.trackBest = true; } } } } SampleLoop.java0100644000077000001440000000721707613755543012672 0ustar arilusers/** * Title: ProAlign

* Description:

* Copyright: Copyright (c) Ari Loytynoja

* License: GNU GENERAL PUBLIC LICENSE

* @see http://www.gnu.org/copyleft/gpl.html * Company: ULB

* @author Ari Loytynoja * @version 1.0 */ package proalign; import java.io.File; import java.io.IOException; import java.io.InvalidClassException; import java.io.FileOutputStream; import java.io.ObjectOutputStream; class SampleLoop extends Thread { SampleAlignments sl; AlignmentNode best; AlignmentNode current; double bestEnd = 0d; int currentRun = 0; int maxRun; SampleLoop(SampleAlignments sl) { this.sl = sl; current = sl.rw.root; maxRun = sl.numRun; ProAlign.log("SampleLoop"); sl.write("\n Sampling "+maxRun+" alignments: "); if(sl.writeResults) { String[] names = current.getInternalNames(); String str = "number,length,total"; for(int i=0; i bestEnd) { bestEnd = current.sumViterbiEnd(); sl.rw.root = current; sl.rw.setAlignedData(sl.rw.root); sl.rw.setScrollPanes(); sl.rw.messageText.setText(" Sample "+(currentRun+1)+"/"+maxRun+": "+current.sumViterbiEnd()); } if(sl.writeAlignments) { String path = sl.folderPath+File.separator+(currentRun+1)+"."+ProAlign.fileExt; try { ObjectOutputStream os = new ObjectOutputStream(new FileOutputStream(path)); os.writeObject((AlignmentNode) current); os.flush(); os.close(); } catch(IOException ioe) { ProAlign.log.println("Sample exception1: "+path+"\n"+ioe.toString()); ProAlign.log.flush(); //ioe.printStackTrace(); } catch(Exception oe) { ProAlign.log.println("Sample exception2: "+path+"\n"+oe.toString()); ProAlign.log.flush(); //oe.printStackTrace(); } } if(sl.writeNexus) { String path = sl.nexusPath+File.separator+(currentRun+1)+".nex"; SaveData sd = new SaveData(path,1,current); } if(sl.writeFasta) { String path = sl.fastaPath+File.separator+(currentRun+1)+".pir"; SaveData sd = new SaveData(path,2,current); } sl.write("Sample "+(currentRun+1)+"/"+maxRun+": "+current.sumViterbiEnd()+"; best: "+bestEnd); if(sl.writeResults) { double[] vit = current.getInternalViterbiEnd(); String str = (currentRun+1)+","+current.cellPath.length+","+current.sumViterbiEnd(); for(int i=0; i * Description:

* Copyright: Copyright (c) Ari Loytynoja

* License: GNU GENERAL PUBLIC LICENSE

* @see http://www.gnu.org/copyleft/gpl.html * Company: ULB

* @author Ari Loytynoja * @version 1.0 */ package proalign; import javax.swing.JOptionPane; import java.io.File; import java.io.IOException; import java.util.Calendar; import java.util.Date; public class SaveData { boolean[] sitesRemoved; boolean[] taxaRemoved; String filename; String resultString; String[] sequenceNames; String[] sequenceData; String spaceStr = " "; int taxaNum; int seqLength; int numTaxa; int numSite; AlignmentNode root; double[] minProb; // public SaveData(String file, int type, AlignmentNode root) { ProAlign.log("SaveData"); this.root = root; resultString = "vitEnd: "+root.sumViterbiEnd()+", fwdEnd: "+root.sumForwardEnd(); sequenceNames = root.getTerminalNames(); for(int i=0; i= (seqLength)) { break; } str += (""+sequenceData[i].charAt(j++)); if(m > 0) if((m+1) % 20 == 0) { str += (" "); } } out.println(str); } out.println(""); if(j >= (seqLength)) { break; } k += 100; } } else { // nexus sequential for(int i = 0; i < taxaNum; ++i) { out.print((sequenceNames[i]+spaceStr).substring(0,21) + " "); out.println(sequenceData[i]); } } out.println(" ;\nEnd;\n"); // Write the paup block. out.println("Begin paup;"); // Delete sequnces String str = " Delete"; for (int i = 0; i < taxaNum; i++) { if(taxaRemoved[i]) { str += (" "+(sequenceNames[i]+spaceStr).substring(0,21).trim()); } } str += ";"; out.println(str); // Exclude sites boolean exc = false; int prev = 0; int start = 0; str = " Exclude"; for (int n = 0; n < sitesRemoved.length; n++) { if(sitesRemoved[n]) { prev = n; if(!exc) { // array starts form 0, Nexus matrix from 1! str += (" " + (n+1)); start = n; exc = true; } } else { if(exc) { if (start != prev) str += ("-" + (prev+1)); exc = false; } } } if(exc) if (start != prev) str += ("-" + (prev+1)); str += ";"; out.println(str); out.println("End;\n"); // Write the assumptions block. out.println("Begin assumptions;"); str = " wtset ProAlignWeights (VECTOR) = \n "; for (int i = 0; i < minProb.length; i++) { str += (roundDoubleToString((double)minProb[i],3)+" ").substring(0,5)+" "; if(type==1 && i>0 && (i+1)%15==0) str += "\n "; } str += ";"; out.println(str); out.println("End;\n"); out.close(); } catch (IOException e) { } } // Write data in fasta format. // public void outputFasta(String file) { try { OutFile out = new OutFile(file); for(int i = 0; i < taxaNum; i++) { if(!taxaRemoved[i]) { if(ProAlign.isDna) { out.println(">DL;" + sequenceNames[i].trim()+"\n"); } else { out.println(">P1;" + sequenceNames[i].trim()+"\n"); } int count = 0; for(int j = 0; j < seqLength; j++) { if(!sitesRemoved[j]) { count++; out.print(sequenceData[i].charAt(j)); if(count == 50) { out.println(""); count = 0; } } } out.println("*"); } } out.close(); } catch (IOException e) { } if(ProAlign.writeMin) { outputWeights(file+".min", false); } if(ProAlign.writeMean) { outputMean(file+".mean", false); } if(ProAlign.writeAll) { outputAll(file+".all", false); } } // // Write data table in given file in phylip int. format. // public void outputPhylip(String file) { numTaxa=0; for(int i = 0; i < taxaNum; i++) { if(!taxaRemoved[i]) { numTaxa++; } } numSite=0; for(int j = 0; j < seqLength; j++) { if(!sitesRemoved[j]) { numSite++; } } try { OutFile out = new OutFile(file); int k = 0; int j = 0; int max = 0; boolean newline = true; out.println(" "+numTaxa+" "+numSite); while(true) { for(int i = 0; i < taxaNum; i++) { newline = true; j = k; if(!taxaRemoved[i]) { if(k == 0) out.print((sequenceNames[i].trim()+ spaceStr).substring(0,10) + " "); else out.print(" "); int count = 0; while(count < 50) { if (j >= seqLength) { max = j; break; } else if(!sitesRemoved[j]) { out.print(sequenceData[i].charAt(j)); count++; if(count % 50 == 0) { out.print(""); } else if(count % 10 == 0) out.print(" "); } j++; } max = j; out.println(""); } else { newline = false; } } if (newline) //out.println(""); if(max >= seqLength) { break; } k = max; out.println(""); } out.close(); } catch (IOException e) { } if(ProAlign.writeMin) { outputWeights(file+".min", false); } if(ProAlign.writeMean) { outputMean(file+".mean", false); } if(ProAlign.writeAll) { outputAll(file+".all", false); } } // // // Write data table in given file in phylip int. format. // public void outputMsf(String file) { numSite=0; for(int j = 0; j < seqLength; j++) { if(!sitesRemoved[j]) { numSite++; } } try { OutFile out = new OutFile(file); int k = 0; int j = 0; int max = 0; boolean newline = true; out.println("PileUp\n"); out.print(" MSF: "+numSite); if(ProAlign.isDna) { out.println(" Type: N\n"); } else { out.println(" Type: P\n"); } for(int i = 0; i < taxaNum; i++) { if(!taxaRemoved[i]) { out.println(" Name: "+(sequenceNames[i].trim() +spaceStr).substring(0,21) + " "); } } out.println("\n//\n"); while(true) { for(int i = 0; i < taxaNum; i++) { newline = true; j = k; if(!taxaRemoved[i]) { out.print((sequenceNames[i].trim() +spaceStr).substring(0,21) + " "); int count = 0; while(count < 50) { if (j >= seqLength) { max = j; break; } else if(!sitesRemoved[j]) { out.print(sequenceData[i].charAt(j)); count++; if(count % 50 == 0) { out.print(""); } else if(count % 10 == 0) out.print(" "); } j++; } max = j; out.println(""); } else { newline = false; } } if (newline) //out.println(""); if(max >= seqLength) { break; } k = max; out.println(""); } out.close(); } catch (IOException e) { } if(ProAlign.writeMin) { outputWeights(file+".min", false); } if(ProAlign.writeMean) { outputMean(file+".mean", false); } if(ProAlign.writeAll) { outputAll(file+".all", false); } } // // Write probabilities in plain text format. // public void outputWeights(String file, boolean all) { if (all) { double min=0d; int nc=0; for (int i = 0; i < minProb.length; i++) { min+=minProb[i]; nc++; } min=min/nc; double mean=0d; nc=0; for (int i=0; i0 && (i+1)%20==0) out.print("\n"); } out.print("\n"); out.close(); } catch (IOException e) { } }else { double min=0d; int nc=0; for (int i = 0; i < minProb.length; i++) { if(!sitesRemoved[i]) { min+=minProb[i]; nc++; } } min=min/nc; double mean=0d; nc=0; for (int i=0; i0 && (i+1)%20==0) out.print("\n"); } out.print("\n"); out.close(); } catch (IOException e) { } }else { double min=0d; int nc=0; for (int i = 0; i < minProb.length; i++) { if(!sitesRemoved[i]) { min+=minProb[i]; nc++; } } min=min/nc; double mean=0d; nc=0; for (int i=0; i0 && (i+1)%20==0) out.print("\n"); } out.print("\n"); } out.print("\n"); out.close(); } catch (IOException e) { } }else { try { OutFile out = new OutFile(file); out.print("# ProAlign: mean posterior probability.\n"); out.print("# "+resultString+".\n"); String[] nodeNames = root.getInternalNames(); for (int j=0; j-1) { String begin = full.substring(0,full.indexOf('.')); String end = full.substring(full.indexOf('.')+1); if(end.length()>prec) { char num = end.charAt(prec); if(num=='0'||num=='1'||num=='2'||num=='3'||num=='4') { full = begin+"."+end.substring(0,prec); // last one is greater than 4 -> rounded up } else { char[] digit = new char[prec]; for(int i=0; i=0; i--) { if(digit[i]=='9') { add = 1; digit[i]='0'; } else { digit[i]= (char)((int)digit[i]+add); add = 0; break; } } begin = ""+(new Integer(begin).intValue()+add); end = new String(); for(int i=0; i * Description:

* Copyright: Copyright (c) Ari Loytynoja

* License: GNU GENERAL PUBLIC LICENSE

* @see http://www.gnu.org/copyleft/gpl.html * Company: ULB

* @author Ari Loytynoja * @version 1.0 */ package proalign; import java.io.File; import java.util.Iterator; import java.util.ArrayList; import java.util.HashMap; import java.io.IOException; import java.io.FileNotFoundException; /** * Reads FASTA/PIR format alignment files. * Data read into a hashtable: String 'name', String 'data' */ public class SequenceReader { String row, str1, str2 = new String(); HashMap seqmap; boolean allFine; String alphabet; String errors; SequenceReader() { } /** * Tries to read from a file. Returns TRUE if fine, FALSE if errors. */ boolean fromFile(String infile) { allFine = true; seqmap = new HashMap(); errors = new String("\n"); ProAlign.log("SequenceReader: "+infile); String firstRow = new String(); try { InFile in = new InFile(infile); while(true) { firstRow = in.readLine().trim(); if(firstRow.equals("")) { continue; } break; } } catch(FileNotFoundException e) { warnError("File not found:" + infile); } catch(IOException e) { } if(firstRow.startsWith(">")) { readFasta(infile); } else if(Character.isDigit(firstRow.charAt(0))) { readPhylip(infile); } else if(firstRow.equalsIgnoreCase("#nexus")) { readNexus(infile); } else if(firstRow.equalsIgnoreCase("PileUp")|| firstRow.equalsIgnoreCase("!!AA_MULTIPLE_ALIGNMENT")|| firstRow.equalsIgnoreCase("!!NA_MULTIPLE_ALIGNMENT")) { readMsf(infile); } else { warnError(" The file does not look like Fasta-,\n"+ " PIR-, Phylip-, MSF-, or Nexus-format!"); } if(seqmap.size()>0 && allFine) { return true; } else { return false; } } void readFasta(String infile) { try { // Calls ready-made filereader InFile in = new InFile(infile); int formatType = 0; while(true) { // Read first non-empty line row = in.readLine().trim(); if(row.equals("")) { continue; } break; } while(row != null) { // Takes sequence name and checks // that same name doesn't exist if(row.startsWith(">")) { row = row.substring(1); row = row.trim(); // Sequence is PIR if(row.startsWith("DL;")) { formatType = 1; row = row.substring(3); row = row.trim(); in.readLine(); // skip one row! } else if(row.startsWith("P1;")) { formatType = 2; row = row.substring(3); row = row.trim(); in.readLine(); // skip one row! //Sequence must be FASTA } else { formatType = 0; } // Same sequence name given twice!! if(seqmap.containsKey(row)) { warnError(" Sequence " + row + "\n is double defined!"); } if(formatType > 0) { // If PIR -> has to end with '*' str2 = ""; while((str1 = in.readLine())!= null) { // remove "gap" signs if(str1.indexOf("-")>-1) { str1 = removeChar(str1,'-'); } if(str1.indexOf(" ")>-1) { str1 = removeSpace(str1); } if(str1.length() == 0) { // Skips empty lines. continue; } str2 += str1; if(str1.endsWith("*")){ // Reads until the asterisk (needed!) str1 = str2.substring(0,str2.indexOf("*")); // but removed. str1 = str1.toUpperCase(); seqmap.put(row, str1); ProAlign.log(">"+row+"\n"+str1); row = in.readLine(); // New one in! break; } } } // Append FASTA sequence and save it. else { // If FASTA -> no '*' in the end str2 = ""; while((str1 = in.readLine())!= null) { // remove "gap" signs if(str1.indexOf("-")>-1) { str1 = removeChar(str1,'-'); } if(str1.indexOf(" ")>-1) { str1 = removeSpace(str1); } if(str1.length() == 0) { // Skips empty lines. continue; } if(str1.startsWith(">")){ // Loop works until a new seqname str2 = str2.toUpperCase(); seqmap.put(row, str2); ProAlign.log(">"+row+"\n"+str2); row = str1; // Copy new one row = row.trim(); break; } str2 += str1; } if(str1 == null) { // Take the last seq. End of the file. str2 = str2.toUpperCase(); seqmap.put(row, str2); ProAlign.log(">"+row+"\n"+str2); row = str1; // Copy null so first loop stops } } } else if(row.trim().equals("")){ row = in.readLine(); continue; } else { warnError(" File '" + infile + "'\n"+ " is supposed to start with '>'!"); break; //row = in.readLine(); } } in.close(); // Something wrong. Give warnings and return. } catch(FileNotFoundException e) { warnError("File not found:" + infile); } catch(IOException e) { } } void readPhylip(String infile) { String[] seqNames = new String[0]; String[] seqData = new String[0]; String row = new String(); try { InFile in = new InFile(infile); while(true) { row = in.readLine().trim(); if(row.equals("")) { continue; } break; } int numTaxa = new Integer(row.substring(0,row.indexOf(" ")).trim()).intValue(); int seqLength = new Integer(row.substring(row.indexOf(" ")+1).trim()).intValue(); seqNames = new String[numTaxa]; seqData = new String[numTaxa]; int sn = 0; int rn = 0; while((row = in.readLine())!= null) { if(row.trim().equals("")) { continue; } if(rn"+seqNames[i]+"\n"+seq); } } void readMsf(String infile) { String[] seqNames = new String[0]; String[] seqData = new String[0]; HashMap names = new HashMap(); String row = new String(); try { InFile in = new InFile(infile); int s=0; while(true) { row = in.readLine().trim(); if(row.startsWith("//")) { break; } else if(row.indexOf("Name:")>-1) { row = row.substring(row.indexOf("Name:")+5).trim(); if(row.indexOf(" ")>-1) { row = row.substring(0,row.indexOf(" ")).trim(); } names.put(row,new Integer(s)); s++; } else { continue; } } seqNames = new String[names.size()]; seqData = new String[names.size()]; Iterator nameKeys = names.keySet().iterator(); while(nameKeys.hasNext()) { String n = (String) nameKeys.next(); s = ((Integer)names.get(n)).intValue(); seqNames[s] = n; seqData[s] = ""; } while((row = in.readLine())!= null) { if(row.trim().equals("")) { continue; } String begin = row.substring(0,row.indexOf(" ")).trim(); if(names.containsKey(begin)) { String end = row.substring(row.indexOf(" ")+1).trim(); s = ((Integer)names.get(begin)).intValue(); seqData[s] += end; } } in.close(); // Something wrong. Give warnings and return. } catch(FileNotFoundException e) { warnError("File not found:" + infile); } catch(IOException e) { } for(int i=0; i"+seqNames[i]+"\n"+seq); } // ProAlign.log.print("CORE "); for(int m=0; m-1) { String ntax = row.substring(row.indexOf("NTAX")); ntax = ntax.substring(ntax.indexOf("=")+1); if(ntax.indexOf(" ")>0) { ntax = ntax.substring(0,ntax.indexOf(" ")); } else { ntax = ntax.substring(0,ntax.indexOf(";")); } numTaxa = Integer.valueOf(ntax).intValue(); } if(row.indexOf("NCHAR")>-1) { String nchar = row.substring(row.indexOf("NCHAR")); nchar = nchar.substring(nchar.indexOf("=")+1); if(nchar.indexOf(" ")>0) { nchar = nchar.substring(0,nchar.indexOf(" ")); } else { nchar = nchar.substring(0,nchar.indexOf(";")); } numChar = Integer.valueOf(nchar).intValue(); } } if(row.indexOf("MISSING")>-1) { missing = row.substring(row.indexOf("MISSING")); missing = missing.substring(missing.indexOf("=")+1); if(missing.indexOf(" ")>0) { missing = missing.substring(0,missing.indexOf(" ")); } else { missing = missing.substring(0,missing.indexOf(";")); } } else if(row.indexOf("GAP")>-1) { missing = row.substring(row.indexOf("GAP")); missing = missing.substring(missing.indexOf("=")+1); if(missing.indexOf(" ")>0) { missing = missing.substring(0,missing.indexOf(" ")); } else if(missing.indexOf(";")>0) { missing = missing.substring(0,missing.indexOf(";")); } else { missing = missing.trim(); } } if(row.indexOf("INTERLEAVE")>0) { interleave = true; } if(row.startsWith("MATRIX")) { // sequence data starts. seqNames = new String[numTaxa]; seqData = new String[numTaxa]; row = in.readLine(); while((row != null)) { row = row.trim(); if(!interleave) { for(int i=0; i-1) { row = removeComment(row); } //System.out.println(i+": "+row); if(row.indexOf(" ")>-1) { seqNames[i] = row.substring(0,row.indexOf(" ")); row = row.substring(row.indexOf(" ")+1).toUpperCase(); seqData[i] = removeSpace(row); row = in.readLine(); while(seqData[i].length() < numChar) { if(row.length() == 0 ) { row = in.readLine().trim(); continue; } row = row.toUpperCase(); seqData[i] += removeSpace(row); row = in.readLine(); } } else { seqNames[i] = row.trim(); row = in.readLine().trim(); //System.out.println(i+": "+row); seqData[i] = removeSpace(row); row = in.readLine(); while(seqData[i].length() < numChar) { if(row.length() == 0 ) { row = in.readLine().trim(); continue; } row = row.toUpperCase(); seqData[i] += removeSpace(row); row = in.readLine(); } } } break; } else { for(int i=0; i"+seqNames[i]+"\n"+seq); } } String removeSpace(String row) { if(row.indexOf(" ")>-1) { String str = new String(""); for(int j=0; j-1) { String str = new String(""); for(int j=0; j * Description:

* Copyright: Copyright (c) Ari Loytynoja

* License: GNU GENERAL PUBLIC LICENSE

* @see http://www.gnu.org/copyleft/gpl.html * Company: ULB

* @author Ari Loytynoja * @version 1.0 */ package proalign; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JLabel; import javax.swing.JMenuItem; import javax.swing.JComboBox; import javax.swing.JButton; import javax.swing.JRadioButton; import javax.swing.ButtonGroup; import javax.swing.JCheckBox; import javax.swing.JTextField; import java.awt.GridLayout; import java.awt.BorderLayout; import java.awt.Font; import java.awt.Container; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.WindowEvent; import java.awt.event.WindowAdapter; import java.awt.event.ItemListener; import java.awt.event.ItemEvent; import java.io.File; public class SetParameters extends JFrame { JTextField textDelta; JTextField textEpsil; JTextField textGapF; JTextField textGapP; JTextField[] textFreq; JTextField textPwOpen; JTextField textPwExt; JTextField textPwMat; JTextField textWidth; JTextField textClustalw; JTextField textTemp; JTextField textOffset; JTextField textScale; JCheckBox boxLog; JCheckBox boxTrail; JCheckBox boxMultiple; JCheckBox boxPenalize; JComboBox pwSubst; String[] pwMatrix = {"pam60","pam120","pam160","pam250"}; int height = 300; int width = 600; ProAlign pa; ResultWindow rw; SetParameters(ResultWindow rw) { setTitle("Set parameters"); this.rw = rw; this.pa = rw.pa; Font font = new Font(ProAlign.paFontName, Font.PLAIN, ProAlign.paFontSize); ButtonListener but = new ButtonListener(); JButton buttonEstFreq = new JButton("Estimate"); buttonEstFreq.setFont(font); buttonEstFreq.setActionCommand("estimatefreq"); buttonEstFreq.addActionListener(but); JButton buttonDefFreq = new JButton("Default"); buttonDefFreq.setFont(font); buttonDefFreq.setActionCommand("defaultfreq"); buttonDefFreq.addActionListener(but); JButton buttonSetFreq = new JButton("Set"); buttonSetFreq.setFont(font); buttonSetFreq.setActionCommand("setfreq"); buttonSetFreq.addActionListener(but); JButton buttonLock = new JButton(); buttonLock.setFont(font); buttonLock.setActionCommand("lock"); buttonLock.addActionListener(but); JButton buttonHmmE = new JButton("Default"); buttonHmmE.setFont(font); buttonHmmE.setActionCommand("hmmE"); buttonHmmE.addActionListener(but); JButton buttonHmmD = new JButton("Default"); buttonHmmD.setFont(font); buttonHmmD.setActionCommand("hmmD"); buttonHmmD.addActionListener(but); JButton buttonHmmEst = new JButton("Estimate"); buttonHmmEst.setFont(font); buttonHmmEst.setActionCommand("hmmEst"); buttonHmmEst.addActionListener(but); if(rw.hasTree) { buttonHmmEst.setEnabled(true); } else { buttonHmmEst.setEnabled(false); } JButton buttonGapF = new JButton("Default"); buttonGapF.setFont(font); buttonGapF.setActionCommand("gapF"); buttonGapF.addActionListener(but); JButton buttonGapP = new JButton("Default"); buttonGapP.setFont(font); buttonGapP.setActionCommand("gapP"); buttonGapP.addActionListener(but); JButton buttonOffset = new JButton("Default"); buttonOffset.setFont(font); buttonOffset.setActionCommand("offset"); buttonOffset.addActionListener(but); JButton buttonLog = new JButton("Select"); buttonLog.setFont(font); buttonLog.setActionCommand("log"); buttonLog.addActionListener(but); JButton buttonWidth = new JButton("Default"); buttonWidth.setFont(font); buttonWidth.setActionCommand("defwidth"); buttonWidth.addActionListener(but); JButton buttonClustalw = new JButton("Change"); buttonClustalw.setFont(font); buttonClustalw.setActionCommand("clustalw"); buttonClustalw.addActionListener(but); JButton buttonTemp = new JButton("Change"); buttonTemp.setFont(font); buttonTemp.setActionCommand("temp"); buttonTemp.addActionListener(but); JButton buttonOK = new JButton("OK"); buttonOK.setFont(font); buttonOK.setActionCommand("ok"); buttonOK.addActionListener(but); JButton buttonCancel = new JButton("Cancel"); buttonCancel.setFont(font); buttonCancel.setActionCommand("cancel"); buttonCancel.addActionListener(but); JLabel labelHMM = new JLabel(" HMM model"); labelHMM.setFont(font); JLabel labelVit = new JLabel(" Viterbi parameters"); labelVit.setFont(font); JLabel labelSet = new JLabel(" Other parameters"); labelSet.setFont(font); JLabel labelChar = new JLabel(" Character frequencies"); labelChar.setFont(font); JLabel labelTrail = new JLabel(" Trailing sequences"); labelTrail.setFont(font); JLabel labelPenalize = new JLabel(" Terminal gaps"); labelPenalize.setFont(font); JLabel labelOffset = new JLabel(" Max allow"); labelOffset.setFont(font); JLabel labelMultiple = new JLabel(" Distances"); labelMultiple.setFont(font); JLabel labelScale = new JLabel(" scale"); labelScale.setFont(font); JLabel labelSample = new JLabel(" Viterbi traceback"); labelSample.setFont(font); JLabel labelClustalw = new JLabel(" ClustalW"); labelClustalw.setFont(font); JLabel labelTemp = new JLabel(" Temp folder"); labelTemp.setFont(font); JLabel labelLog = new JLabel(" Change file"); labelLog.setFont(font); JLabel labelDelta = new JLabel(" Delta"); labelDelta.setFont(font); JLabel labelEpsil = new JLabel(" Epsilon"); labelEpsil.setFont(font); JLabel labelGapF = new JLabel(" Gap frequency"); labelGapF.setFont(font); JLabel labelGapP = new JLabel(" Gap probability"); labelGapP.setFont(font); JLabel labelPwPar = new JLabel(" Pairwise alignment"); labelPwPar.setFont(font); JLabel labelPwOpen = new JLabel(" Gap opening"); labelPwOpen.setFont(font); JLabel labelPwExt = new JLabel(" Gap extension"); labelPwExt.setFont(font); JLabel labelWidth = new JLabel(" Band width"); labelWidth.setFont(font); JLabel[] labelFreq = new JLabel[pa.sm.alphabet.length()]; textDelta = new JTextField(" "); textDelta.setText(""+pa.sm.delta); textDelta.setFont(font); textEpsil = new JTextField(" "); textEpsil.setText(""+pa.sm.epsilon); textEpsil.setFont(font); textGapF = new JTextField(" "); textGapF.setText(""+pa.gapFreq); textGapF.setFont(font); textGapP = new JTextField(" "); textGapP.setText(""+pa.gapProb); textGapP.setFont(font); textPwOpen = new JTextField(" "); textPwExt = new JTextField(" "); textPwMat = new JTextField(" "); textPwOpen.setFont(font); textPwExt.setFont(font); if(ProAlign.isDna) { textPwOpen.setText(""+(float)pa.pwDnaOpen/100f); textPwExt.setText(""+(float)pa.pwDnaExt/100f); textPwMat.setText(" DNA"); textPwMat.setEditable(false); } else { textPwOpen.setText(""+(float)pa.pwProtOpen/100f); textPwExt.setText(""+(float)pa.pwProtExt/100f); textPwMat.setText(" "+pa.pwProtMatrix); textPwMat.setEditable(false); } // Pairwise protein score matrix pwSubst = new JComboBox(); pwSubst.setFont(font); pwSubst.addItemListener(new ComboBoxListener()); for(int i=0; i0d && gapF<0.5d && gapP>0d && gapP<0.5d) { pa.sm.gapFreq = gapF; pa.sm.gapProb = gapP; } else { String text = new String("\n Illegal value for gap frequency/"+ "probability!\n Value not changed.\n"); OpenDialog od = new OpenDialog(SetParameters.this); od.showDialog("Warning!", text); } } double delta = new Double(textDelta.getText()).doubleValue(); if(delta>0d && delta<0.5d) { pa.sm.delta = delta; } else { String text = new String("\n Illegal value for delta!\n"+ " Value not changed.\n"); OpenDialog od = new OpenDialog(SetParameters.this); od.showDialog("Warning!", text); } double epsilon = new Double(textEpsil.getText()).doubleValue(); if(epsilon>0d && epsilon<1.0d) { pa.sm.epsilon = epsilon; } else { String text = new String("\n Illegal value for epsilon!\n"+ " Value not changed.\n"); OpenDialog od = new OpenDialog(SetParameters.this); od.showDialog("Warning!", text); } int bandWidth = new Integer(textWidth.getText()).intValue(); if(bandWidth>10) { pa.bandWidth = bandWidth; } else { String text = new String("\n Band width too low!\n"+ " Value not changed.\n"); OpenDialog od = new OpenDialog(SetParameters.this); od.showDialog("Warning!", text); } if(bandWidth>200) { String text = new String("\n Too great band width may run\n"+ " your system out of memory!\n"); OpenDialog od = new OpenDialog(SetParameters.this); od.showDialog("Warning!", text); } int gapOpen = (int)(new Float(textPwOpen.getText()).floatValue()*100f); if(gapOpen>=0 && gapOpen<5100) { if(ProAlign.isDna) { pa.pwDnaOpen = gapOpen; } else { pa.pwProtOpen = gapOpen; } } else { String text = new String("\n Illegal value for gap opening!\n"+ " Value not changed.\n"); OpenDialog od = new OpenDialog(SetParameters.this); od.showDialog("Warning!", text); } int gapExt = (int)(new Float(textPwExt.getText()).floatValue()*100f); if(gapExt>=0 && gapExt<2100) { if(ProAlign.isDna) { pa.pwDnaExt = gapExt; } else { pa.pwProtExt = gapExt; } } else { String text = new String("\n Illegal value for gap extension!\n"+ " Value not changed.\n"); OpenDialog od = new OpenDialog(SetParameters.this); od.showDialog("Warning!", text); } int offset = new Integer(textOffset.getText()).intValue(); if(offset>0 && offset0d && scale<2.0d) { pa.distScale = scale; } else { String text = new String("\n Distance scale should be \n"+ " between 0.0 and 2.0!\n"+ " Value not changed.\n"); OpenDialog od = new OpenDialog(SetParameters.this); od.showDialog("Warning!", text); } if(!ProAlign.isDna) { pa.pwProtMatrix = textPwMat.getText().trim(); } if(ProAlign.DEBUG) { ProAlign.log("SetParameters"); ProAlign.log(" trackBest="+ProAlign.trackBest); ProAlign.log(" bandWidth="+ProAlign.bandWidth); ProAlign.log(" clustalwPath="+ProAlign.clustalwPath); ProAlign.log(" tempFolder="+ProAlign.tempFolder); ProAlign.log(" offset="+ProAlign.offset); ProAlign.log(" distScale="+ProAlign.distScale); ProAlign.log(" removeTrailing="+ProAlign.removeTrailing); ProAlign.log(" penalizeTerminal="+ProAlign.penalizeTerminal); if(ProAlign.isDna) { ProAlign.log(" pwGapOpen="+pa.pwDnaOpen); ProAlign.log(" pwGapExt="+pa.pwDnaExt); } else { ProAlign.log(" pwGapOpen="+pa.pwProtOpen); ProAlign.log(" pwGapExt="+pa.pwProtExt); ProAlign.log(" pwGapMatrix="+pa.pwProtMatrix); } ProAlign.log.flush(); } } catch(NumberFormatException nfe) { String text = new String("\n Illegal value!\n"); OpenDialog od = new OpenDialog(SetParameters.this); od.showDialog("Error!", text); break; } dispatchEvent(new WindowEvent(SetParameters.this, WindowEvent.WINDOW_CLOSING)); break; } } } } class RadioListener implements ActionListener { public void actionPerformed(ActionEvent e) { String actionCommand = e.getActionCommand(); if(actionCommand.equals("sample")) { ProAlign.trackBest = false; } else if(actionCommand.equals("best")) { ProAlign.trackBest = true; } } } class ComboBoxListener implements ItemListener { public void itemStateChanged(ItemEvent e) { if(!ProAlign.isDna) { String item = (String) e.getItem(); textPwMat.setText(" "+item); } } } class CheckBoxListener implements ActionListener { public void actionPerformed(ActionEvent e) { String actionCommand = e.getActionCommand(); if(actionCommand.equals("log")) { if(boxLog.isSelected()) { ProAlign.DEBUG = true; } else { ProAlign.DEBUG = false; } } else if(actionCommand.equals("trailing")) { if(boxTrail.isSelected()) { ProAlign.removeTrailing = true; textOffset.setEditable(true); } else { ProAlign.removeTrailing = false; textOffset.setEditable(false); } } else if(actionCommand.equals("multiple")) { if(boxMultiple.isSelected()) { ProAlign.correctMultiple = true; } else { ProAlign.correctMultiple = false; } } else if(actionCommand.equals("terminal")) { if(boxPenalize.isSelected()) { ProAlign.penalizeTerminal = true; } else { ProAlign.penalizeTerminal = false; } } } } } SubstitutionModel.java0100644000077000001440000004322007613752477014311 0ustar arilusers /** * Title: ProAlign

* Description:

* Copyright: Copyright (c) Ari Loytynoja

* License: GNU GENERAL PUBLIC LICENSE

* @see http://www.gnu.org/copyleft/gpl.html * Company: ULB

* @author Ari Loytynoja * @version 1.0 */ package proalign; public class SubstitutionModel { double delta, epsilon; double deltaDefault, epsilonDefault; double[] charFreqs; double[] charFreqsDefault; double[][] substProb1, substProb2; String alphabet; String equateAlphabet; double[] aaFreqs; double[][] aaPam; double[][] gapPam; double gapFreq; double gapProb; double gapFreqDefault, gapProbDefault; String modelName; /** * Holds a handle to ProAlign-class. */ public SubstitutionModel(ProAlign pa) { delta = pa.modelDelta; // prob to move to INSERT(X/Y) epsilon = pa.modelEpsilon; // prob to stay in INSERT(X/Y) gapFreq = pa.gapFreq; gapProb = pa.gapProb; // save defaults deltaDefault = delta; epsilonDefault = epsilon; gapFreqDefault = gapFreq; gapProbDefault = gapProb; ProAlign.log("SubstitutionModel"); } /** * Simple DNA model. Currently the alphabet is "ACGT-", all the background * frequencies are 0.2, and substitution probabilities are equal. */ void jcDnaModel() { modelName = "jcDnaModel"; alphabet = "ACGT-"; equateAlphabet = "ACGTRYMKSWHBVDNU"; charFreqs = new double[5]; charFreqs[0] = 0.2d; charFreqs[1] = 0.2d; charFreqs[2] = 0.2d; charFreqs[3] = 0.2d; charFreqs[4] = 0.2d; printDebug(); // save defaults charFreqsDefault = charFreqs; } /** * Simple protein model based on WAG. */ void wagProteinModel() { modelName = "wagProteinModel"; alphabet = "ARNDCQEGHILKMFPSTWYV-"; equateAlphabet = "ARNDCQEGHILKMFPSTWYVX"; double[] tmp = {0.086628,0.043972,0.039089,0.057045,0.019308, 0.036728,0.058059,0.083252,0.024431,0.048466, 0.086209,0.062029,0.019503,0.038432,0.045763, 0.069518,0.061013,0.014386,0.035274,0.070896}; aaFreqs = tmp; double[][] tmp2 = {{0.989896,0.000294,0.000272,0.000394,0.000548, 0.000485,0.000844,0.000756,0.000169,0.000103, 0.000212,0.000483,0.000477,0.000112,0.000767, 0.001798,0.001131,6.03e-05,0.000128,0.00107}, {0.000294,0.989794,0.000339,7.86e-05,0.000282, 0.001619,0.000234,0.000312,0.00114,9.97e-05, 0.000265,0.002854,0.000364,5.48e-05,0.000362, 0.000653,0.000296,0.000621,0.000203,0.000134}, {0.000272,0.000339,0.986156,0.002896,0.000141, 0.000823,0.000505,0.0006,0.00211,0.000296, 7.01e-05,0.001606,0.000106,5.13e-05,0.000104, 0.00212,0.001083,3.84e-05,0.000579,0.000105}, {0.000394,7.86e-05,0.002896,0.990311,1.62e-05, 0.000329,0.003293,0.000462,0.000496,2.1e-05, 4.52e-05,0.000256,5.53e-05,2.49e-05,0.000226, 0.000572,0.0002,6.92e-05,0.000174,8.12e-05}, {0.000548,0.000282,0.000141,1.62e-05,0.995607, 5.27e-05,1.14e-05,0.000164,0.000133,9.07e-05, 0.000205,3.95e-05,0.000208,0.000212,5.83e-05, 0.000751,0.000274,0.000382,0.00029,0.000534}, {0.000485,0.001619,0.000823,0.000329,5.27e-05, 0.985928,0.002917,0.000176,0.00229,6.08e-05, 0.000464,0.002077,0.000824,5.33e-05,0.000498, 0.000549,0.000458,0.000115,0.000121,0.000161}, {0.000844,0.000234,0.000505,0.003293,1.14e-05, 0.002917,0.988168,0.000303,0.000304,6.79e-05, 8.23e-05,0.001378,0.000168,4.33e-05,0.000364, 0.000376,0.000439,8.35e-05,0.000105,0.000314}, {0.000756,0.000312,0.0006,0.000462,0.000164, 0.000176,0.000303,0.995427,0.000133,1.62e-05, 3.27e-05,0.000199,9.29e-05,2.66e-05,0.00013, 0.000716,0.00012,0.00018,5.53e-05,9.99e-05}, {0.000169,0.00114,0.00211,0.000496,0.000133, 0.00229,0.000304,0.000133,0.988544,7.37e-05, 0.000266,0.000475,0.000216,0.000362,0.000371, 0.000395,0.000252,0.00014,0.002066,6.31e-05}, {0.000103,9.97e-05,0.000296,2.1e-05,9.07e-05, 6.08e-05,6.79e-05,1.62e-05,7.37e-05,0.988961, 0.001691,0.000173,0.002271,0.000565,5.33e-05, 0.00017,0.000778,0.000113,0.000224,0.004171}, {0.000212,0.000265,7.01e-05,4.52e-05,0.000205, 0.000464,8.23e-05,3.27e-05,0.000266,0.001691, 0.990704,0.000137,0.002589,0.001128,0.000222, 0.000184,0.000174,0.000355,0.000213,0.00096}, {0.000483,0.002854,0.001606,0.000256,3.95e-05, 0.002077,0.001378,0.000199,0.000475,0.000173, 0.000137,0.987915,0.000498,4.74e-05,0.000297, 0.000516,0.00074,7.33e-05,7.11e-05,0.000163}, {0.000477,0.000364,0.000106,5.53e-05,0.000208, 0.000824,0.000168,9.29e-05,0.000216,0.002271, 0.002589,0.000498,0.988732,0.000635,9.14e-05, 0.000263,0.000809,0.000275,0.000228,0.001098}, {0.000112,5.48e-05,5.13e-05,2.49e-05,0.000212, 5.33e-05,4.33e-05,2.66e-05,0.000362,0.000565, 0.001128,4.74e-05,0.000635,0.99161,8.61e-05, 0.000291,9.17e-05,0.000816,0.003442,0.000347}, {0.000767,0.000362,0.000104,0.000226,5.83e-05, 0.000498,0.000364,0.00013,0.000371,5.33e-05, 0.000222,0.000297,9.14e-05,8.61e-05,0.994727, 0.00086,0.000424,7.43e-05,0.000115,0.000168}, {0.001798,0.000653,0.00212,0.000572,0.000751, 0.000549,0.000376,0.000716,0.000395,0.00017, 0.000184,0.000516,0.000263,0.000291,0.00086, 0.986629,0.002335,0.000279,0.00042,0.000124}, {0.001131,0.000296,0.001083,0.0002,0.000274, 0.000458,0.000439,0.00012,0.000252,0.000778, 0.000174,0.00074,0.000809,9.17e-05,0.000424, 0.002335,0.989442,5.91e-05,0.000155,0.00074}, {6.03e-05,0.000621,3.84e-05,6.92e-05,0.000382, 0.000115,8.35e-05,0.00018,0.00014,0.000113, 0.000355,7.33e-05,0.000275,0.000816,7.43e-05, 0.000279,5.91e-05,0.994745,0.001326,0.000195}, {0.000128,0.000203,0.000579,0.000174,0.00029, 0.000121,0.000105,5.53e-05,0.002066,0.000224, 0.000213,7.11e-05,0.000228,0.003442,0.000115, 0.00042,0.000155,0.001326,0.989916,0.000168}, {0.00107,0.000134,0.000105,8.12e-05,0.000534, 0.000161,0.000314,9.99e-05,6.31e-05,0.004171, 0.00096,0.000163,0.001098,0.000347,0.000168, 0.000124,0.00074,0.000195,0.000168,0.989304}}; aaPam = tmp2; setGapPam(); printDebug(); } void dayhoffProteinModel() { modelName = "dayhoffProteinModel"; alphabet = "ARNDCQEGHILKMFPSTWYV-"; equateAlphabet = "ARNDCQEGHILKMFPSTWYVX"; double[] tmp = {0.087,0.041,0.04,0.047,0.033, 0.038,0.05,0.089,0.034,0.037, 0.085,0.08,0.015,0.04,0.051, 0.07,0.058,0.01,0.03,0.065}; aaFreqs = tmp; double[][] tmp2 = {{0.988234,0.000137,0.000509,0.000612,0.000187, 0.000457,0.000994,0.001216,0.000115,0.000333, 0.000209,0.000133,0.000361,9.35e-05,0.001264, 0.002061,0.001901,5.46e-06,0.000125,0.00105}, {0.000137,0.991108,0.000169,8.44e-06,0.00012, 0.001252,7.93e-06,4.46e-05,0.001202,0.000322, 7.93e-05,0.002365,0.000449,6.94e-05,0.000521, 0.000776,0.000137,0.001071,3.97e-05,0.000122}, {0.000509,0.000169,0.983089,0.004602,1.05e-05, 0.000535,0.000764,0.000713,0.002702,0.000396, 0.000177,0.001636,2.71e-05,7.11e-05,0.000215, 0.002509,0.001185,0.000122,0.000488,8.13e-05}, {0.000612,8.44e-06,0.004602,0.985754,3.62e-06, 0.000692,0.00575,0.00063,0.000438,0.000122, 3.68e-06,0.000368,1.65e-05,1.84e-06,6.78e-05, 0.000484,0.00034,4.59e-06,1.15e-05,9.05e-05}, {0.000187,0.00012,1.05e-05,3.62e-06,0.99741, 3.1e-06,2.09e-06,5.54e-05,0.000145,0.000226, 5.54e-06,1.15e-06,2.01e-05,1.23e-05,9.66e-05, 0.000824,8.5e-05,4.93e-05,0.000493,0.00025}, {0.000457,0.001252,0.000535,0.000692,3.1e-06, 0.98687,0.003612,0.000144,0.003058,9.25e-05, 0.000378,0.000786,0.000571,2.56e-06,0.00078, 0.000287,0.000273,1.36e-05,1.43e-05,0.000178}, {0.000994,7.93e-06,0.000764,0.00575,2.09e-06, 0.003612,0.986165,0.000409,0.00022,0.000308, 5.74e-05,0.000423,0.000152,2.81e-06,0.000255, 0.0004,0.000174,1.04e-05,0.000108,0.000185}, {0.001216,4.46e-05,0.000713,0.00063,5.54e-05, 0.000144,0.000409,0.994594,5.37e-05,3.28e-06, 3.65e-05,0.000137,8.53e-05,7.77e-05,0.000176, 0.001175,0.000158,1.83e-05,2.43e-06,0.000273}, {0.000115,0.001202,0.002702,0.000438,0.000145, 0.003058,0.00022,5.37e-05,0.989644,3.88e-05, 0.000225,0.000138,1.78e-05,0.000239,0.000469, 0.000178,0.000115,0.000143,0.000638,0.000221}, {0.000333,0.000322,0.000396,0.000122,0.000226, 9.25e-05,0.000308,3.28e-06,3.88e-05,0.988119, 0.001308,0.000236,0.00167,0.000989,6.03e-05, 0.000126,0.000977,1.4e-05,0.00019,0.004469}, {0.000209,7.93e-05,0.000177,3.68e-06,5.54e-06, 0.000378,5.74e-05,3.65e-05,0.000225,0.001308, 0.992281,9.33e-05,0.00264,0.000799,0.000161, 8.75e-05,0.000172,0.000249,0.000147,0.000892}, {0.000133,0.002365,0.001636,0.000368,1.15e-06, 0.000786,0.000423,0.000137,0.000138,0.000236, 9.33e-05,0.990977,0.00122,9.45e-07,0.000171, 0.000488,0.000701,4.86e-06,6.78e-05,5.32e-05}, {0.000361,0.000449,2.71e-05,1.65e-05,2.01e-05, 0.000571,0.000152,8.53e-05,1.78e-05,0.00167, 0.00264,0.00122,0.990068,0.000461,8.5e-05, 0.00031,0.000523,2.3e-05,1.63e-05,0.001284}, {9.35e-05,6.94e-05,7.11e-05,1.84e-06,1.23e-05, 2.56e-06,2.81e-06,7.77e-05,0.000239,0.000989, 0.000799,9.45e-07,0.000461,0.99283,5.58e-05, 0.000232,7.01e-05,0.000407,0.003523,6.25e-05}, {0.001264,0.000521,0.000215,6.78e-05,9.66e-05, 0.00078,0.000255,0.000176,0.000469,6.03e-05, 0.000161,0.000171,8.5e-05,5.58e-05,0.993738, 0.001225,0.000401,5.08e-06,6.21e-06,0.000245}, {0.002061,0.000776,0.002509,0.000484,0.000824, 0.000287,0.0004,0.001175,0.000178,0.000126, 8.75e-05,0.000488,0.00031,0.000232,0.001225, 0.985332,0.002788,0.000395,0.00017,0.000154}, {0.001901,0.000137,0.001185,0.00034,8.5e-05, 0.000273,0.000174,0.000158,0.000115,0.000977, 0.000172,0.000701,0.000523,7.01e-05,0.000401, 0.002788,0.988977,5.96e-06,0.000215,0.000802}, {5.46e-06,0.001071,0.000122,4.59e-06,4.93e-05, 1.36e-05,1.04e-05,1.83e-05,0.000143,1.4e-05, 0.000249,4.86e-06,2.3e-05,0.000407,5.08e-06, 0.000395,5.96e-06,0.997116,0.000325,1.79e-05}, {0.000125,3.97e-05,0.000488,1.15e-05,0.000493, 1.43e-05,0.000108,2.43e-06,0.000638,0.00019, 0.000147,6.78e-05,1.63e-05,0.003523,6.21e-06, 0.00017,0.000215,0.000325,0.993278,0.000142}, {0.00105,0.000122,8.13e-05,9.05e-05,0.00025, 0.000178,0.000185,0.000273,0.000221,0.004469, 0.000892,5.32e-05,0.001284,6.25e-05,0.000245, 0.000154,0.000802,1.79e-05,0.000142,0.989428}}; aaPam = tmp2; setGapPam(); printDebug(); } void jttProteinModel() { modelName = "jttProteinModel"; alphabet = "ARNDCQEGHILKMFPSTWYV-"; equateAlphabet = "ARNDCQEGHILKMFPSTWYVX"; double[] tmp = {0.077,0.051,0.043,0.052,0.02, 0.041,0.062,0.074,0.023,0.052, 0.091,0.059,0.024,0.04,0.051, 0.069,0.059,0.014,0.032,0.066}; aaFreqs = tmp; double[][] tmp2 = {{0.986454,0.000128,0.000552,0.000645,0.00036, 0.000494,0.000935,0.001705,0.000199,0.000277, 0.000228,0.000211,0.000263,0.000109,0.001474, 0.002439,0.00218,4.55e-06,0.000136,0.001205}, {0.000128,0.991919,0.00013,6.33e-06,0.000165, 0.000963,5.31e-06,4.45e-05,0.001474,0.00019, 6.15e-05,0.00266,0.000233,5.76e-05,0.000432, 0.000653,0.000112,0.000635,3.09e-05,9.97e-05}, {0.000552,0.00013,0.982571,0.003993,1.66e-05, 0.000476,0.000592,0.000823,0.003835,0.00027, 0.000159,0.00213,1.63e-05,6.83e-05,0.000207, 0.002444,0.001118,8.36e-05,0.000439,7.69e-05}, {0.000645,6.33e-06,0.003993,0.987626,5.57e-06, 0.000598,0.004326,0.000707,0.000603,8.07e-05, 3.2e-06,0.000465,9.64e-06,1.71e-06,6.33e-05, 0.000458,0.000312,3.06e-06,1.01e-05,8.31e-05}, {0.00036,0.000165,1.66e-05,5.57e-06,0.995644, 4.89e-06,2.88e-06,0.000113,0.000365,0.000274, 8.82e-06,2.64e-06,2.14e-05,2.1e-05,0.000165, 0.001423,0.000142,5.99e-05,0.000787,0.00042}, {0.000494,0.000963,0.000476,0.000598,4.89e-06, 0.986951,0.002786,0.000166,0.004325,6.3e-05, 0.000337,0.00102,0.000341,2.45e-06,0.000746, 0.000279,0.000257,9.32e-06,1.28e-05,0.000167}, {0.000935,5.31e-06,0.000592,0.004326,2.88e-06, 0.002786,0.988953,0.00041,0.000271,0.000182, 4.46e-05,0.000477,7.9e-05,2.34e-06,0.000212, 0.000337,0.000142,6.16e-06,8.46e-05,0.000152}, {0.001705,4.45e-05,0.000823,0.000707,0.000113, 0.000166,0.00041,0.993253,9.86e-05,2.9e-06, 4.24e-05,0.000231,6.61e-05,9.64e-05,0.000218, 0.001479,0.000192,1.62e-05,2.82e-06,0.000333}, {0.000199,0.001474,0.003835,0.000603,0.000365, 0.004325,0.000271,9.86e-05,0.985237,4.21e-05, 0.000321,0.000284,1.7e-05,0.000365,0.000715, 0.000275,0.000173,0.000156,0.000912,0.000332}, {0.000277,0.00019,0.00027,8.07e-05,0.000274, 6.3e-05,0.000182,2.9e-06,4.21e-05,0.991779, 0.000897,0.000235,0.000767,0.000726,4.43e-05, 9.35e-05,0.000706,7.35e-06,0.000131,0.003232}, {0.000228,6.15e-05,0.000159,3.2e-06,8.82e-06, 0.000337,4.46e-05,4.24e-05,0.000321,0.000897, 0.993861,0.000122,0.001591,0.00077,0.000155, 8.55e-05,0.000163,0.000171,0.000133,0.000847}, {0.000211,0.00266,0.00213,0.000465,2.64e-06, 0.00102,0.000477,0.000231,0.000284,0.000235, 0.000122,0.98903,0.001067,1.32e-06,0.00024, 0.000693,0.000964,4.86e-06,8.89e-05,7.33e-05}, {0.000263,0.000233,1.63e-05,9.64e-06,2.14e-05, 0.000341,7.9e-05,6.61e-05,1.7e-05,0.000767, 0.001591,0.001067,0.993806,0.000297,5.48e-05, 0.000203,0.000332,1.06e-05,9.87e-06,0.000816}, {0.000109,5.76e-05,6.83e-05,1.71e-06,2.1e-05, 2.45e-06,2.34e-06,9.64e-05,0.000365,0.000726, 0.00077,1.32e-06,0.000297,0.993338,5.76e-05, 0.000243,7.11e-05,0.0003,0.003409,6.36e-05}, {0.001474,0.000432,0.000207,6.33e-05,0.000165, 0.000746,0.000212,0.000218,0.000715,4.43e-05, 0.000155,0.00024,5.48e-05,5.76e-05,0.993266, 0.001283,0.000407,3.75e-06,6.01e-06,0.000249}, {0.002439,0.000653,0.002444,0.000458,0.001423, 0.000279,0.000337,0.001479,0.000275,9.35e-05, 8.55e-05,0.000693,0.000203,0.000243,0.001283, 0.984122,0.002869,0.000295,0.000167,0.000158}, {0.00218,0.000112,0.001118,0.000312,0.000142, 0.000257,0.000142,0.000192,0.000173,0.000706, 0.000163,0.000964,0.000332,7.11e-05,0.000407, 0.002869,0.98885,4.32e-06,0.000204,0.000802}, {4.55e-06,0.000635,8.36e-05,3.06e-06,5.99e-05, 9.32e-06,6.16e-06,1.62e-05,0.000156,7.35e-06, 0.000171,4.86e-06,1.06e-05,0.0003,3.75e-06, 0.000295,4.32e-06,0.997991,0.000225,1.3e-05}, {0.000136,3.09e-05,0.000439,1.01e-05,0.000787, 1.28e-05,8.46e-05,2.82e-06,0.000912,0.000131, 0.000133,8.89e-05,9.87e-06,0.003409,6.01e-06, 0.000167,0.000204,0.000225,0.993076,0.000135}, {0.001205,9.97e-05,7.69e-05,8.31e-05,0.00042, 0.000167,0.000152,0.000333,0.000332,0.003232, 0.000847,7.33e-05,0.000816,6.36e-05,0.000249, 0.000158,0.000802,1.3e-05,0.000135,0.990742}}; aaPam = tmp2; setGapPam(); printDebug(); } void setBranchLength(double dist1, double dist2) { dist1 = ProAlign.distScale*dist1; dist2 = ProAlign.distScale*dist2; if(ProAlign.isDna) { setDnaSubstTable(dist1,1); setDnaSubstTable(dist2,2); } else { setProtSubstTable(dist1*100,1); setProtSubstTable(dist2*100,2); } } void setDnaSubstTable(double dist, int table) { // probablility matrix to observe character pairs double[][] sProb = new double[5][5]; for(int i=0; i * Description:

* Copyright: Copyright (c) Ari Loytynoja

* License: GNU GENERAL PUBLIC LICENSE

* @see http://www.gnu.org/copyleft/gpl.html * Company: ULB

* @author Ari Loytynoja * @version 1.0 */ package proalign; import java.util.Random; class TraceBackPath { AlignmentLoop al; AlignmentNode an; Random r; int warnLimit = 10; int stopLimit = 3; boolean isBandWarning = false; int state = 0; int aSize; int[][] cellPath; double[] postProb; double siteSum; double trailProb; double logDelta; double logEpsilon; double logMinusEpsilon; int sampleTimes = 0; boolean isUnique = true; boolean BEST; TraceBackPath(AlignmentNode an, AlignmentLoop al) { this.an = an; this.al = al; r = new Random(); logDelta = Math.log(al.pa.sm.delta); logEpsilon = Math.log(al.pa.sm.epsilon); logMinusEpsilon = Math.log(1-al.pa.sm.epsilon); ProAlign.log("TraceBackPath"); } double[][] getNode(boolean best) throws TraceBackException { this.BEST = best; this.aSize = al.aSize; char path = getEndPath(); int i=al.pathM.length-1; // back trace strting point (i,j) int j=al.endPoint; double[][] cProb = new double[i+j][aSize]; // char. probs. on the path double[] pProb = new double[i+j]; // post. probs. on the path int[][] cell = new int[i+j][2]; int ppc = 0; // go through the matrix; // start from end, stop when at (1,1) while(true) { if(jProAlign.bandWidth-stopLimit) { throw new TraceBackException("traceback path comes too close to the band edge."); } else if(jProAlign.bandWidth-warnLimit) { isBandWarning = true; } if(i==1 && j==al.MIDDLE) { // currently(?) stops at middle break; } if(state==0) { // -> match path = getPathM(i,j); for(int l=0; l gap X path = getPathX(i,j); for(int l=0; l gap Y path = getPathY(i,j); for(int l=0; l0) { if(an.start0>an.start1) { for(int k=0; k0) { cellPath[k+start][0] = cell[ppc-k-1][0]+start; } else { cellPath[k+start][0] = cell[ppc-k-1][0]; } cellPath[k+start][1] = cell[ppc-k-1][1]; postProb[k+start] = pProb[ppc-k-1]; } } else { for(int k=0; k0) { cellPath[k+start][1] = cell[ppc-k-1][1]+start; } else { cellPath[k+start][1] = cell[ppc-k-1][1]; } postProb[k+start] = pProb[ppc-k-1]; } } } else { for(int k=0; k0) { if(an.end0>an.end1) { for(int k=0; k px && pm > py) { path = 'M'; } else if(pm > py && pm == px) { if(r.nextBoolean()) { path = 'M'; } else { path = 'x'; state = 1; } isUnique = false; sampleTimes++; } else if(pm > px && pm == py) { if(r.nextBoolean()) { path = 'M'; } else { path = 'y'; state = 2; } isUnique = false; sampleTimes++; } else if(px > py) { path = 'x'; state = 1; } else if(px == py) { if(r.nextBoolean()) { path = 'x'; state = 1; } else { path = 'y'; state = 2; } isUnique = false; sampleTimes++; } else { path = 'y'; state = 2; } // sample from paths according to their probabilities } else { double rdn = r.nextDouble(); if(rdn < pm) { path = 'M'; } else if(rdn < (pm+px)) { path = 'X'; state = 1; } else { path = 'Y'; state = 2; } } return path; } char getPathM(int i, int j) { char path = ' '; double pm = al.pathM[i][j][0]; double px = al.pathM[i][j][1]; double py = (double) 1d - pm - px; // select viterbi path; if equally good, take one randomly if(BEST) { if(pm > px && pm > py) { path = 'M'; } else if(pm > py && pm == px) { if(r.nextBoolean()) { path = 'M'; } else { path = 'X'; } isUnique = false; sampleTimes++; } else if(pm > px && pm == py) { if(r.nextBoolean()) { path = 'M'; } else { path = 'Y'; } isUnique = false; sampleTimes++; } else if(px > py) { path = 'X'; } else if(px == py) { if(r.nextBoolean()) { path = 'X'; } else { path = 'Y'; } isUnique = false; sampleTimes++; } else { path = 'Y'; } // sample from paths according to their probabilities } else { double rdn = r.nextDouble(); if(rdn < pm) { path = 'M'; } else if(rdn < (pm+px)) { path = 'X'; } else { path = 'Y'; } } return path; } char getPathX(int i, int j) { char path = ' '; double pm = al.pathX[i][j]; double px = (double) 1d - pm; if(BEST) { if(pm > px) { path = 'm'; } else if( pm == px) { if(r.nextBoolean()) { path = 'm'; } else { path = 'x'; } isUnique = false; sampleTimes++; } else { path = 'x'; } } else { double rdn = r.nextDouble(); if(rdn < pm) { path = 'm'; } else { path = 'x'; } } return path; } char getPathY(int i, int j) { char path = ' '; double pm = al.pathY[i][j]; double py = (double) 1d - pm; if(BEST) { if(pm > py) { path = 'm'; } else if( pm == py) { if(r.nextBoolean()) { path = 'm'; } else { path = 'y'; } isUnique = false; sampleTimes++; } else { path = 'y'; } } else { double rdn = r.nextDouble(); if(rdn < pm) { path = 'm'; } else { path = 'y'; } } return path; } double[] trailerCharProb1(int i) { double[] cProb = new double[aSize]; siteSum = 0d; for(int k=0; k * Description:

* Copyright: Copyright (c) Ari Loytynoja

* License: GNU GENERAL PUBLIC LICENSE

* @see http://www.gnu.org/copyleft/gpl.html * Company: ULB

* @author Ari Loytynoja * @version 1.0 */ package proalign; class TransformLog { TransformLog() { } double sumLogs(double a, double b) { if(Double.isNaN(a) && Double.isNaN(b)) { return Double.NEGATIVE_INFINITY; } else if(Double.isNaN(a)){ return b; } else if(Double.isNaN(b)){ return a; } if(b>a){ double c = a; a = b; b = c; } return (a+Math.log(1+Math.exp(b-a))); } } TreeNode.java0100644000077000001440000002140207631101264012275 0ustar arilusers/** * Title: ProAlign

* Description:

* Copyright: Copyright (c) Ari Loytynoja

* License: GNU GENERAL PUBLIC LICENSE

* @see http://www.gnu.org/copyleft/gpl.html * Company: ULB

* @author Ari Loytynoja * @version 1.0 */ package proalign; class TreeNode { String tree; String[] subTrees; String[] revTrees; static String mpTree; TreeNode parent; TreeNode child0; TreeNode child1; static float halfLength; static float maxSpan; static float minDiff; float[] subDistances; float maxLength = 0f; float totalDist = 0f; // weight boolean isLast = true; TreeNode(String t) { mpTree = new String(); minDiff = 100f; ProAlign.log("TreeNode"); tree = t; TreeReader tr = new TreeReader(); subTrees = tr.divideTree(tree); subDistances = tr.distance; subDistances[0] = Math.abs(subDistances[0]); subDistances[1] = Math.abs(subDistances[1]); // System.out.println(subTrees[0]+" "+subTrees[1]); float tot = subDistances[0]+subDistances[1]; revTrees = new String[2]; revTrees[0] = subTrees[1]+":"+tot; revTrees[1] = subTrees[0]+":"+tot; child0 = new TreeNode(tr,subTrees[0],TreeNode.this,0); child1 = new TreeNode(tr,subTrees[1],TreeNode.this,1); totalDist = subDistances[0]+subDistances[1]+ child0.totalDist+child1.totalDist; float currPair = subDistances[0]+child0.maxLength+ subDistances[1]+child1.maxLength; if(currPair > TreeNode.maxSpan) { TreeNode.maxSpan = currPair; // System.out.println("ms0 "+child0.tree+":"+subDistances[0]+" | "+ // child1.tree+":"+subDistances[1]+" "+currPair); } } TreeNode(TreeReader tr,String t,TreeNode p,int branch) { tree = t; parent = p; if(tree.indexOf(",")>0) { isLast = false; subTrees = tr.divideTree(tree); subDistances = tr.distance; subDistances[0] = Math.abs(subDistances[0]); subDistances[1] = Math.abs(subDistances[1]); revTrees = new String[2]; revTrees[0] = "("+parent.revTrees[branch]+","+ subTrees[1]+":"+subDistances[1]+"):"+subDistances[0]; revTrees[1] = "("+parent.revTrees[branch]+","+ subTrees[0]+":"+subDistances[0]+"):"+subDistances[1]; child0 = new TreeNode(tr,subTrees[0],TreeNode.this,0); child1 = new TreeNode(tr,subTrees[1],TreeNode.this,1); totalDist = subDistances[0]+subDistances[1]+ child0.totalDist+child1.totalDist; float currPair = subDistances[0]+child0.maxLength+ subDistances[1]+child1.maxLength; if(currPair > TreeNode.maxSpan) { TreeNode.maxSpan = currPair; // System.out.println("ms1 "+child0.tree+":"+subDistances[0]+" | "+ // child1.tree+":"+subDistances[1]+" "+currPair); } if(subDistances[0]+child0.maxLength > subDistances[1]+child1.maxLength) { maxLength = subDistances[0]+child0.maxLength; } else { maxLength = subDistances[1]+child1.maxLength; } // System.out.println("ml "+maxLength); } } String findMiddlePoint() { TreeNode.halfLength = TreeNode.maxSpan/2f; if(TreeNode.halfLength > child0.maxLength && TreeNode.halfLength < child0.maxLength+subDistances[0]+subDistances[1]) { float b0 = TreeNode.halfLength-child0.maxLength; float b1 = subDistances[0]+subDistances[1]-b0; TreeNode.mpTree = "("+child0.tree+": "+b0+","+child1.tree+":"+b1+");"; } child0.findMiddle(1); child1.findMiddle(0); ProAlign.log("mprooted: "+TreeNode.mpTree); return TreeNode.mpTree; } void findMiddle(int branch) { if(!isLast) { if(branch==0) { if(TreeNode.halfLength > child0.maxLength && TreeNode.halfLength < child0.maxLength+subDistances[0]) { float b0 = TreeNode.halfLength-child0.maxLength; float b1 = subDistances[0]-b0; TreeNode.mpTree = "("+child0.tree+": "+b0+",("+parent.revTrees[1]+","+ subTrees[1]+":"+subDistances[1]+"):"+b1+");"; // System.out.println("nt "+branch+": "+child0.tree+" "+child0.maxLength+" "+ // child1.tree+" "+child1.maxLength+" "+TreeNode.halfLength+" "+TreeNode.minDiff); } if(TreeNode.halfLength > child1.maxLength && TreeNode.halfLength < child1.maxLength+subDistances[1]) { float b0 = TreeNode.halfLength-child1.maxLength; float b1 = subDistances[1]-b0; TreeNode.mpTree = "("+child1.tree+": "+b0+",("+parent.revTrees[1]+","+ subTrees[0]+":"+subDistances[0]+"):"+b1+");"; // System.out.println("nt "+branch+": "+child0.tree+" "+child0.maxLength+" "+ // child1.tree+" "+child1.maxLength+" "+TreeNode.halfLength+" "+TreeNode.minDiff); } child0.findMiddle(1); child1.findMiddle(0); } else { if(TreeNode.halfLength > child0.maxLength && TreeNode.halfLength < child0.maxLength+subDistances[0]) { float b0 = TreeNode.halfLength-child0.maxLength; float b1 = subDistances[0]-b0; TreeNode.mpTree = "("+child0.tree+": "+b0+",("+parent.revTrees[0]+ ","+subTrees[1]+":"+subDistances[1]+"):"+b1+");"; // System.out.println("nt "+branch+": "+child0.tree+" "+child0.maxLength+" "+ // child1.tree+" "+child1.maxLength+" "+TreeNode.halfLength+" "+TreeNode.minDiff); } if(TreeNode.halfLength > child1.maxLength && TreeNode.halfLength < child1.maxLength+subDistances[1]) { float b0 = TreeNode.halfLength-child1.maxLength; float b1 = subDistances[1]-b0; TreeNode.mpTree = "("+child1.tree+": "+b0+",("+parent.revTrees[0]+ ","+subTrees[0]+":"+subDistances[0]+"):"+b1+");"; // System.out.println("nt "+branch+": "+child0.tree+" "+child0.maxLength+" "+ // child1.tree+" "+child1.maxLength+" "+TreeNode.halfLength+" "+TreeNode.minDiff); } child0.findMiddle(1); child1.findMiddle(0); } } } /* This was the first attempt for the tree rooting. Not used anymore. */ String findMiddleWeightPoint() { TreeNode.halfLength = totalDist/2f; child0.findMiddle(1); child1.findMiddle(0); ProAlign.log("mprooted: "+TreeNode.mpTree); return TreeNode.mpTree; } void findMiddleWeight(int branch) { if(!isLast) { if(branch==0) { if(Math.abs(TreeNode.halfLength-child0.totalDist)child0.totalDist) { b0 = TreeNode.halfLength-child0.totalDist; b1 = subDistances[0]-b0; } else if(subDistances[0]>0.001f) { b0 = 0.001f; b1 = subDistances[0]-b0; } else { b0 = 0f; b1 = subDistances[0]; } TreeNode.mpTree = "("+child0.tree+": "+b0+",("+parent.revTrees[1]+","+ subTrees[1]+":"+subDistances[1]+"):"+b1+");"; } if(Math.abs(TreeNode.halfLength-child1.totalDist)child1.totalDist) { b0 = TreeNode.halfLength-child1.totalDist; b1 = subDistances[1]-b0; } else if(subDistances[1]>0.001f) { b0 = 0.001f; b1 = subDistances[1]-b0; } else { b0 = 0f; b1 = subDistances[1]; } TreeNode.mpTree = "("+child1.tree+": "+b0+",("+parent.revTrees[1]+","+ subTrees[0]+":"+subDistances[0]+"):"+b1+");"; } child0.findMiddle(1); child1.findMiddle(0); } else { if(Math.abs(TreeNode.halfLength-child0.totalDist)child0.totalDist) { b0 = TreeNode.halfLength-child0.totalDist; b1 = subDistances[0]-b0; } else if(subDistances[0]>0.001f) { b0 = 0.001f; b1 = subDistances[0]-b0; } else { b0 = 0f; b1 = subDistances[0]; } TreeNode.mpTree = "("+child0.tree+": "+b0+",("+parent.revTrees[0]+ ","+subTrees[1]+":"+subDistances[1]+"):"+b1+");"; } if(Math.abs(TreeNode.halfLength-child1.totalDist)child1.totalDist) { b0 = TreeNode.halfLength-child1.totalDist; b1 = subDistances[1]-b0; } else if(subDistances[1]>0.001f) { b0 = 0.001f; b1 = subDistances[1]-b0; } else { b0 = 0f; b1 = subDistances[1]; } TreeNode.mpTree = "("+child1.tree+": "+b0+",("+parent.revTrees[0]+ ","+subTrees[0]+":"+subDistances[0]+"):"+b1+")"; } child0.findMiddle(1); child1.findMiddle(0); } } } void printNames() { if(isLast) { System.out.println(tree); } else { child0.printNames(); child1.printNames(); System.out.println("node: "+totalDist); } } /* public static void main(String[] args) { TreeReader2 tr = new TreeReader2(); String tree = tr.readFile(args[0]); TreeNode root = new TreeNode(tree); TreeNode.halfLength = root.totalDist/2f; System.out.println(root.findMiddlePoint()); } //*/ } TreeReader.java0100644000077000001440000001244407602641122012620 0ustar arilusers/** * Title: ProAlign

* Description:

* Copyright: Copyright (c) Ari Loytynoja

* License: GNU GENERAL PUBLIC LICENSE

* @see http://www.gnu.org/copyleft/gpl.html * Company: ULB

* @author Ari Loytynoja * @version 1.0 */ package proalign; import java.io.File; import java.io.IOException; import java.io.FileNotFoundException; import java.util.ArrayList; class TreeReader { float[] distance; boolean isUnRooted = false; TreeReader(){ } // Read a tree from a file and remove branch lengths // String readFile(String filename) { String tree = new String(); ProAlign.log("TreeReader: "+filename); try { InFile in = new InFile(filename); String row = new String(); while((row = in.readLine()) != null) { tree += row; } } catch (Exception e) {} return tree; } // Take a tree and divide it into two subtrees. // Notice that clustalw root is trifurcating // String[] divideTree(String tree) { // System.out.println("tree "+tree+"\n"); String[] trees = new String[2]; distance = new float[2]; trees[0] = ""; if(tree.endsWith(";")) { tree = tree.substring(0,tree.length()-1); // remove last ';' } tree = tree.substring(1,tree.length()-1); // remove first & last '(' if(tree.charAt(0)!='(') { // only one taxon String tmp = tree.substring(0,tree.indexOf(",")); trees[0] = tmp.substring(0,tmp.indexOf(":")); distance[0] = new Float(tmp.substring(tmp.indexOf(":")+1)).floatValue(); boolean trifurc = false; int open = 0; for(int j = tree.indexOf(",")+1; j0) { trifurc = true; } } // correction for trifurcating root if(trifurc) { isUnRooted = true; trees[1] = "("+tree.substring(tree.indexOf(",")+1)+")"; distance[0] = distance[0]/2f; distance[1] = distance[0]; } else { trees[1] = tree.substring(tree.indexOf(",")+1,tree.lastIndexOf(":")); tmp = tree.substring(tree.lastIndexOf(":")+1); distance[1] = new Float(tmp).floatValue(); } // System.out.println("1o: "+trees[0]+" "+distance[0]+"\n"); // System.out.println("2o: "+trees[1]+" "+distance[1]+"\n"); } else { int open = 0; for(int i=0; i0) { trifurc = true; } } // correction for trifurcating root if(trifurc) { isUnRooted = true; trees[1] = "("+tree.substring(tree.indexOf(",",i+2)+1)+")"; distance[0] = distance[0]/2f; distance[1] = distance[0]; // System.out.println("1: "+trees[0]+" "+distance[0]+"\n"); // System.out.println("2a: "+trees[1]+" "+distance[1]+"\n"); } else { tmp = tree.substring(tree.indexOf(",",i+2)+1); trees[1] = tmp.substring(0,tmp.lastIndexOf(":")); tmp = tmp.substring(tmp.lastIndexOf(":")+1); distance[1] = new Float(tmp).floatValue(); // System.out.println("1: "+trees[0]+" "+distance[0]+"\n"); // System.out.println("2b: "+trees[1]+" "+distance[1]+"\n"); } break; } } } //System.out.println("0: "+trees[0]+" ["+distance[0]+"]"); //System.out.println("1: "+trees[1]+" ["+distance[1]+"]"); return trees; } String[] getAllNodes(String filepath) { ArrayList nl = new ArrayList(); TreeReader tr = this; String tree = this.readFile(filepath); // if(ProAlign.DEBUG) { // ProAlign.log.println(" reading a list of all the nodes."); // } //System.out.println(clustalw); String[] trees = tr.divideTree(tree); tr.loopThroughNodes(trees[0],tr,nl); tr.loopThroughNodes(trees[1],tr,nl); String[] nodes = new String[nl.size()]; for(int i=0; i0) { String[] trees = tr.divideTree(tree); tr.loopThroughNodes(trees[0],tr,nl); tr.loopThroughNodes(trees[1],tr,nl); } else { nl.add(tree); //System.out.println(nl.size()+" "+tree); } } // ---DEBUGGING ONLY --> void loopTreeTest(String tree, TreeReader tr) { if(tree.indexOf(",")>0) { String[] trees = tr.divideTree(tree); tr.loopTreeTest(trees[0],tr); tr.loopTreeTest(trees[1],tr); } else { //System.out.println("l "+tree); } } public static void main(String[] args) { TreeReader tr = new TreeReader(); String tree = tr.readFile(args[0]); String[] trees = tr.divideTree(tree); tr.loopTreeTest(trees[0],tr); tr.loopTreeTest(trees[1],tr); System.out.println("OK"); String[] nodes = tr.getAllNodes(args[0]); for(int i=0; i * Description:

* Copyright: Copyright (c) Ari Loytynoja

* License: GNU GENERAL PUBLIC LICENSE

* @see http://www.gnu.org/copyleft/gpl.html * Company: ULB

* @author Ari Loytynoja * @version 1.0 */ package proalign; import java.io.File; import java.io.IOException; /** * Reads and writes a file for user settings */ public class UserSettings { String filepath; File file; UserSettings() { ProAlign.log("UserSettings"); if(System.getProperty("os.name").startsWith("Windows")){ filepath = "proalign.ini"; } else { filepath = ".proalignrc"; } file = new File(filepath); } // Read existing settings String[] readSettings() { String[] userdata = new String[3]; String str = new String(); if(file.exists()) { try { InFile dataIn = new InFile(filepath); if((str = dataIn.readLine())!=null) { if(new File(str).isDirectory()){ userdata[0] = str; } } if((str = dataIn.readLine())!=null) { if(new File(str).isFile()){ userdata[1] = str; } } if((str = dataIn.readLine())!=null) { if(new File(str).isDirectory()){ userdata[2] = str; } } dataIn.close(); } catch (IOException ie) { } } return userdata; } // Write current settings void writeSettings(String[] userdata) { if(file.exists()) { try { file.delete(); } catch (Exception ie) { } } try { OutFile dataOut = new OutFile(filepath); dataOut.println(userdata[0]); // ProAlign data dataOut.println(userdata[1]); // ProAlign ClustalW dataOut.println(userdata[2]); // temp dataOut.close(); } catch (IOException ie) { } } } Viterbi.java0100644000077000001440000002100507602641131012173 0ustar arilusers/** * Title: ProAlign

* Description:

* Copyright: Copyright (c) Ari Loytynoja

* License: GNU GENERAL PUBLIC LICENSE

* @see http://www.gnu.org/copyleft/gpl.html * Company: ULB

* @author Ari Loytynoja * @version 1.0 */ package proalign; class Viterbi { AlignmentLoop al; double[] charFreqs; String alphabet; double delta; double epsilon; double logDelta; double logEpsilon; double logMinus2Delta; double logMinusEpsilon; double constantM; double constantX; double constantY; TransformLog tl; int aSize; Viterbi(AlignmentLoop al) { this.al = al; this.charFreqs = al.pa.sm.charFreqs; this.alphabet = al.pa.sm.alphabet; delta = al.pa.sm.delta; epsilon = al.pa.sm.epsilon; logDelta = Math.log(al.pa.sm.delta); logEpsilon = Math.log(al.pa.sm.epsilon); logMinus2Delta = Math.log(1-2*al.pa.sm.delta); logMinusEpsilon = Math.log(1-al.pa.sm.epsilon); aSize = al.seq1[0].length; // aSize = alphabet size; tl = new TransformLog(); } // get viterbi value for M-state; set probability of each path to this cell; // pathM[i][j][0] = P(match to M) // pathM[i][j][1] = P(match to X) // 1 - pathM[i][j][0] - pathM[i][j][1] = P(match to Y) double getViterbiM(int i, int j) { constantM = Math.log(sumOverChars(i,j)); double max = maxOfThree(logMinus2Delta+al.vitM[i-1][j], logMinusEpsilon+al.vitX[i-1][j], logMinusEpsilon+al.vitY[i-1][j]); double pm = logMinus2Delta+al.vitM[i-1][j]; double px = logMinusEpsilon+al.vitX[i-1][j]; double py = logMinusEpsilon+al.vitY[i-1][j]; double sum = tl.sumLogs(pm,tl.sumLogs(px,py)); al.pathM[i][j][0] = (double) Math.exp(pm-sum); al.pathM[i][j][1] = (double) Math.exp(px-sum); return (constantM+max); } // get viterbi value for X-state; set probability of each path to this cell; // pathX[i][j] = P(match to M) // 1 - pathX[i][j] = P(match to X) double getViterbiX(int i, int j) { if(j==al.BWIDTH-1) { // lower border of band, an X-gap impossible return Double.NEGATIVE_INFINITY; } constantX = Math.log(sumOverCharsX(i,j)); double max = maxOfTwoX(logDelta+al.vitM[i-1][j+1], logEpsilon+al.vitX[i-1][j+1]); double pm = logDelta+al.vitM[i-1][j+1]; double px = logEpsilon+al.vitX[i-1][j+1]; double sum = tl.sumLogs(px,pm); al.pathX[i][j] = (double) Math.exp(pm-sum); return constantX+max; } // get viterbi value for X-state; set probability of each path to this cell; // pathY[i][j] = P(match to M) // 1 - pathY[i][j] = P(match to Y) double getViterbiY(int i, int j) { if(j==0) { // upper border of band, a Y-gap impossible return Double.NEGATIVE_INFINITY; } constantY = Math.log(sumOverCharsY(i,j)); double max = maxOfTwoY(logDelta+al.vitM[i][j-1], logEpsilon+al.vitY[i][j-1]); double pm = logDelta+al.vitM[i][j-1]; double py = logEpsilon+al.vitY[i][j-1]; double sum = tl.sumLogs(py,pm); al.pathY[i][j] = (double) Math.exp(pm-sum); return constantY+max; } // set vierbi end, set forward end, // set probability of each path ending. // pathEnd[0] = P(match to M), pathEnd[1] = P(gap to x) // 1 - pathEnd[0] - pathEnd[1] = P(gap to y) // endPoint is not necessarily MIDDLE! double getViterbiEnd(int endPoint) { if(al.an.hasTrailers) { double pm = al.vitM[al.vitM.length-1][endPoint]; double px = al.vitX[al.vitX.length-1][endPoint]; double py = al.vitY[al.vitY.length-1][endPoint]; double sum; if(al.an.end0>al.an.end1) { sum = tl.sumLogs(pm,px); al.pathEnd[0] = (double) Math.exp(pm-sum); al.pathEnd[1] = (double) Math.exp(px-sum); al.fwdEnd = (double) tl.sumLogs(al.fwdM[al.fwdM.length-1][endPoint], al.fwdX[al.fwdX.length-1][endPoint]); } else { sum = tl.sumLogs(pm,py); al.pathEnd[0] = (double) Math.exp(pm-sum); al.pathEnd[1] = Double.NEGATIVE_INFINITY; al.fwdEnd = (double) tl.sumLogs(al.fwdM[al.fwdM.length-1][endPoint], al.fwdY[al.fwdY.length-1][endPoint]); } } else { double pm = al.vitM[al.vitM.length-1][endPoint]; double px = al.vitX[al.vitX.length-1][endPoint]; double py = al.vitY[al.vitY.length-1][endPoint]; double sum = tl.sumLogs(pm,tl.sumLogs(px,py)); al.pathEnd[0] = (double) Math.exp(pm-sum); al.pathEnd[1] = (double) Math.exp(px-sum); al.fwdEnd = (double) tl.sumLogs(al.fwdM[al.fwdM.length-1][endPoint], tl.sumLogs(al.fwdX[al.fwdX.length-1][endPoint], al.fwdY[al.fwdY.length-1][endPoint])); } return (double) maxOfThree(al.vitM[al.vitM.length-1][endPoint], al.vitX[al.vitX.length-1][endPoint], al.vitY[al.vitY.length-1][endPoint]); } double getForwardM(int i, int j) { return constantM+tl.sumLogs(logMinus2Delta+al.fwdM[i-1][j], logMinusEpsilon+tl.sumLogs(al.fwdX[i-1][j],al.fwdY[i-1][j])); } double getForwardX(int i, int j) { if(j==al.BWIDTH-1) { // lower border of band, an X-gap impossible return Double.NEGATIVE_INFINITY; } if(j-al.MIDDLE+i==1) { // only X-gaps possible, constant's not set constantX = Math.log(sumOverCharsX(i,j)); } return constantX+tl.sumLogs(logDelta+al.fwdM[i-1][j+1],logEpsilon+al.fwdX[i-1][j+1]); } double getForwardY(int i, int j) { if(j==0) { // upper border of band, a Y-gap impossible return Double.NEGATIVE_INFINITY; } if(i==1) { // only Y-gaps possible, constant's not set constantY = Math.log(sumOverCharsY(i,j)); } return constantY+tl.sumLogs(logDelta+al.fwdM[i][j-1],logEpsilon+al.fwdY[i][j-1]); } double getBackwardM(int i, int j) { if(i==al.vitM.length-1) { // left border of matrix constantM = Double.NEGATIVE_INFINITY; constantX = Double.NEGATIVE_INFINITY; constantY = Math.log(sumOverCharsY(i,j+1)); }else if(j-al.MIDDLE+i==al.seq2.length+1) { // lower border of real matrix constantM = Double.NEGATIVE_INFINITY; constantX = Math.log(sumOverCharsX(i+1,j-1)); constantY = Double.NEGATIVE_INFINITY; }else if(j==0) { constantM = Math.log(sumOverChars(i+1,j)); constantX = Double.NEGATIVE_INFINITY; constantY = Math.log(sumOverCharsY(i,j+1)); }else if(j==al.BWIDTH-1) { constantM = Math.log(sumOverChars(i+1,j)); constantX = Math.log(sumOverCharsX(i+1,j-1)); constantY = Double.NEGATIVE_INFINITY; } else { constantM = Math.log(sumOverChars(i+1,j)); constantX = Math.log(sumOverCharsX(i+1,j-1)); constantY = Math.log(sumOverCharsY(i,j+1)); } if(j==0) { // upper border of the band; an X-gap impossible return tl.sumLogs(logMinus2Delta+constantM+al.bwdM[i+1][j], logDelta+constantY+al.bwdY[i][j+1]); } if(j==al.BWIDTH-1) { // lower border of the band; a Y-gap impossible return tl.sumLogs(logMinus2Delta+constantM+al.bwdM[i+1][j], logDelta+constantX+al.bwdX[i+1][j-1]); } return tl.sumLogs(logMinus2Delta+constantM+al.bwdM[i+1][j], logDelta+tl.sumLogs(constantX+al.bwdX[i+1][j-1], constantY+al.bwdY[i][j+1])); } double getBackwardX(int i, int j) { if(j==0) { // upper border of the band; an X-gap impossible return logMinusEpsilon+constantM+al.bwdM[i+1][j]; } return tl.sumLogs(logMinusEpsilon+constantM+al.bwdM[i+1][j], logEpsilon+constantX+al.bwdX[i+1][j-1]); } double getBackwardY(int i, int j) { if(j==al.BWIDTH-1) { // lower border of the band; a Y-gap impossible return logMinusEpsilon+constantM+al.bwdM[i+1][j]; } return tl.sumLogs(logMinusEpsilon+constantM+al.bwdM[i+1][j], logEpsilon+constantY+al.bwdY[i][j+1]); } // sum over all possible characters [k] at the node [i][j] double sumOverChars(int i, int j){ double sum = 0d; for(int k = 0; k x) { max = m; } else { max = x; } return max; } double maxOfTwoY(double m, double y) { double max = 0d; if(m > y) { max = m; } else { max = y; } return max; } double maxOfThree(double m, double x, double y) { double max = 0d; if(m > x && m > y) { max = m; } else if(x > y){ max = x; } else { max = y; } return max; } } WinClustalw.java0100644000077000001440000000171707605112201013045 0ustar arilusers/** * Title: ProAlign

* Description:

* Copyright: Copyright (c) Ari Loytynoja

* License: GNU GENERAL PUBLIC LICENSE

* @see http://www.gnu.org/copyleft/gpl.html * Company: ULB

* @author Ari Loytynoja * @version 1.0 */ package proalign; public class WinClustalw extends Thread { String command; int num; boolean running = true; WinClustalw(int num, String command) { this.num = num; this.command = command; start(); } public void run(){ runClustalw(num,command); running = false; } /** * Run native ClustalW */ public native void runClustalw(int num, String cmnd); static { Runtime.getRuntime().load(ProAlign.clustalwPath); } /** * Get output and write it in the log. */ private void writeout(String txt) { //System.out.println(txt); ProAlign.log(txt); try { sleep(20); } catch(InterruptedException e) {} } }