use of cz1.hmm.model.HiddenMarkovModel in project polyGembler by c-zhou.
the class Haplotyper method run.
@Override
public void run() {
// TODO Auto-generated method stub
myLogger.info("Random seed - " + Constants.seed);
DataEntry[] de = start_pos == null ? DataCollection.readDataEntry(in_zip, scaff) : DataCollection.readDataEntry(in_zip, scaff, start_pos, end_pos);
// DataEntry[] de = DataCollection.readDataEntry(in_zip, Constants._ploidy_H);
final HiddenMarkovModel hmm = vbt ? new HiddenMarkovModelVBT(de, seperation, reverse, trainExp, field, founder_hap_coeff) : // new HiddenMarkovModelRST(de, seperation, reverse, trainExp, field, resampling):
(hmm_file == null ? new HiddenMarkovModelBWT(de, seperation, reverse, trainExp, field, founder_hap_coeff) : new HiddenMarkovModelBWT(de, seperation, reverse, trainExp, field, founder_hap_coeff, hmm_file));
if (Constants.plot()) {
Runnable run = new Runnable() {
public void run() {
try {
hmmf = new HMMFrame();
hmmf.clearTabs();
if (Constants.showHMM)
hmmp = hmmf.addHMMTab(hmm, hmm.de(), new File(out_prefix));
} catch (Exception e) {
Thread t = Thread.currentThread();
t.getUncaughtExceptionHandler().uncaughtException(t, e);
e.printStackTrace();
}
}
};
Thread th = new Thread(run);
th.run();
}
if (Constants.plot()) {
hmmf.pack();
hmmf.setVisible(true);
}
double ll, ll0 = hmm.loglik();
for (int i = 0; i < max_iter; i++) {
hmm.train();
if (Constants.plot())
hmmp.update();
ll = hmm.loglik();
myLogger.info("----------loglik " + ll);
if (ll < ll0) {
// throw new RuntimeException("Fatal error!!!");
myLogger.info("LOGLIK DECREASED!!!");
// break;
ll0 = ll;
continue;
}
if (ll0 != Double.NEGATIVE_INFINITY && Math.abs((ll - ll0) / ll0) < Constants.minImprov)
break;
ll0 = ll;
}
if (Constants.printPlots()) {
try {
float width = hmmf.jframe.getSize().width, height = hmmf.jframe.getSize().height;
Document document = new Document(new Rectangle(width, height));
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(plot_pdf));
document.open();
PdfContentByte canvas = writer.getDirectContent();
PdfTemplate template = canvas.createTemplate(width, height);
Graphics2D g2d = new PdfGraphics2D(template, width, height);
hmmf.jframe.paint(g2d);
g2d.dispose();
canvas.addTemplate(template, 0, 0);
document.close();
} catch (FileNotFoundException | DocumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
String scaff_str = scaff[0] + (start_pos == null || start_pos[0] == Integer.MIN_VALUE ? "" : "_" + start_pos[0]) + (end_pos == null || end_pos[0] == Integer.MAX_VALUE ? "" : "_" + end_pos[0]);
for (int i = 1; i < scaff.length; i++) {
if (scaff_str.length() + scaff[i].length() + 32 <= Constants.MAX_FILE_ID_LENGTH)
scaff_str += Constants.scaff_collapsed_str + scaff[i] + (start_pos == null || start_pos[i] == Integer.MIN_VALUE ? "" : "_" + start_pos[i]) + (end_pos == null || end_pos[i] == Integer.MAX_VALUE ? "" : "_" + end_pos[i]);
else {
scaff_str += Constants.scaff_collapsed_str + "etc" + scaff.length;
break;
}
}
hmm.write(out_prefix, expr_id, scaff_str, resampling);
}
use of cz1.hmm.model.HiddenMarkovModel in project polyGembler by c-zhou.
the class Resampler method run.
@Override
public void run() {
// TODO Auto-generated method stub
myLogger.info("Random seed - " + Constants.seed);
DataEntry[] de = start_pos == null ? DataCollection.readDataEntry(in_zip, scaff) : DataCollection.readDataEntry(in_zip, scaff, start_pos, end_pos);
// DataEntry[] de = DataCollection.readDataEntry(in_zip, Constants._ploidy_H);
final HiddenMarkovModel hmm = vbt ? new HiddenMarkovModelVBT(de, seperation, reverse, trainExp, field) : (hmm_file == null ? new HiddenMarkovModelBWT(de, seperation, reverse, trainExp, field) : new HiddenMarkovModelBWT(de, seperation, reverse, trainExp, field, hmm_file));
double ll, ll0 = hmm.loglik();
String scaff_str = scaff[0] + (start_pos == null || start_pos[0] == Integer.MIN_VALUE ? "" : "_" + start_pos[0]) + (end_pos == null || end_pos[0] == Integer.MAX_VALUE ? "" : "_" + end_pos[0]);
for (int i = 1; i < scaff.length; i++) {
if (scaff_str.length() + scaff[i].length() + 32 <= Constants.MAX_FILE_ID_LENGTH)
scaff_str += Constants.scaff_collapsed_str + scaff[i] + (start_pos == null || start_pos[i] == Integer.MIN_VALUE ? "" : "_" + start_pos[i]) + (end_pos == null || end_pos[i] == Integer.MAX_VALUE ? "" : "_" + end_pos[i]);
else {
scaff_str += Constants.scaff_collapsed_str + "etc" + scaff.length;
break;
}
}
hmm.write(out_prefix, expr_id, scaff_str, resampling);
}
Aggregations