File: ProAlign.java

package info (click to toggle)
proalign 0.603-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 492 kB
  • sloc: java: 8,673; sh: 27; makefile: 4
file content (231 lines) | stat: -rw-r--r-- 5,865 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
/**
 * Title:        ProAlign<p>
 * Description:  <p>
 * Copyright:    Copyright (c) Ari Loytynoja<p>
 * License:      GNU GENERAL PUBLIC LICENSE<p>
 * @see          http://www.gnu.org/copyleft/gpl.html
 * Company:      ULB<p>
 * @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);
    }
}