public void run(String arg) { ImageWindow iw = WindowManager.getCurrentWindow(); pw = jutils.getPW4SelCopy(iw); String title = pw.getTitle(); float[][] yvals = pw.getYValues(); float[][] xvals = pw.getXValues(); int length = yvals[0].length; if (pw.getShowErrors()) errs = pw.getErrors(0, false); int[] colors = pw.getColors(); colors[0] = 0; ScriptEngineManager manager = new ScriptEngineManager(); engine = manager.getEngineByName("js"); ce = (Compilable) engine; // hitcounter=0; c2 = 0.0f; iterations = 0; checkc2 = false; double[] stats = new double[3]; tempx = new float[length]; tempdata = new float[length]; System.arraycopy(xvals[0], 0, tempx, 0, length); System.arraycopy(yvals[0], 0, tempdata, 0, length); pw.addPoints(tempx, new float[tempx.length], false); series = pw.getNpts().length - 1; double[] params = new double[10]; int[] fixes = {0, 0, 0, 1, 1, 1, 1, 1, 1, 1}; init_options(params, fixes); if (!init_functions()) { return; } while (showoptions(params, fixes)) { NLLSfit_v2 fitclass; if (checkc2) { fitclass = new NLLSfit_v2(this, 0); } else { fitclass = new NLLSfit_v2(this, 0.0001, 50, 0.1); } float[] fit = fitclass.fitdata(params, fixes, constraints, yvals[0], weights, stats, true); pw.updateSeries(fit, series, false); c2 = (float) stats[1]; iterations = (int) stats[0]; } IJ.log("Chi Squared = " + (float) stats[1]); IJ.log("Iterations = " + (int) stats[0]); for (int i = 0; i < 10; i++) { IJ.log("P" + (i + 1) + " = " + (float) params[i] + " fixed = " + fixes[i]); } IJ.log("AIC = " + (float) stats[2]); // IJ.log("hits = "+hitcounter); set_options(params, fixes); }
public void run(String arg) { GenericDialog gd = new GenericDialog("Options"); gd.addCheckbox("Acceptor_First", true); gd.showDialog(); if (gd.wasCanceled()) return; boolean a1 = gd.getNextBoolean(); int asp = 0; int dsp = 1; int aop = 2; int dop = 3; int atp = 4; int dtp = 5; if (!a1) { asp = 1; dsp = 0; aop = 3; dop = 2; atp = 5; dtp = 4; } ImageWindow iw = WindowManager.getCurrentWindow(); float[][] xvals = (float[][]) jutils.runPW4VoidMethod(iw, "getXValues"); float[][] yvals = (float[][]) jutils.runPW4VoidMethod(iw, "getYValues"); int[] npts = (int[]) jutils.runPW4VoidMethod(iw, "getNpts"); int maxpts = (int) jstatistics.getstatistic("Max", npts, null); int nsets = npts.length / 6; float[][] rtxvals = new float[nsets][maxpts]; float[][] rtavals = new float[nsets][maxpts]; float[][] rtdvals = new float[nsets][maxpts]; int[] rtnpts = new int[nsets]; int fretlength = 10; float[][] stfretvals = new float[nsets][fretlength]; float[][] offfretvals = new float[nsets][fretlength]; TextWindow tw = jutils.selectTable("DNA Damage FRET"); if (tw == null) tw = new TextWindow( "DNA Damage FRET", "title\tacceptor\tdonor\testripe\teoff\tmaxart\tmaxdrt", "", 400, 200); // note that st stands for stripe and off is for areas off the damage stripe for (int i = 0; i < npts.length / 6; i++) { int len = npts[i * 6]; int damageindex = findbleach(yvals[i * 6 + dsp], len); int fretindex = findbleach(yvals[i * 6 + atp], len); IJ.log("set " + i + " damage pos = " + damageindex + " , fret pos = " + fretindex); int predamagestart = damageindex - 4; int prefretstart = fretindex - 5; float staccpredam = getavg(yvals[i * 6 + asp], len, predamagestart, damageindex - 1); float stdonpredam = getavg(yvals[i * 6 + dsp], len, predamagestart, damageindex - 1); float nucaccpredam = getavg(yvals[i * 6 + atp], len, predamagestart, damageindex - 1); float nucdonpredam = getavg(yvals[i * 6 + dtp], len, predamagestart, damageindex - 1); float stdonprefret = getavg(yvals[i * 6 + dsp], len, prefretstart, fretindex - 2); float stdonafret = getavg(yvals[i * 6 + dsp], len, fretindex, fretindex + 3); float offdonprefret = getavg(yvals[i * 6 + dop], len, prefretstart, fretindex - 2); float offdonafret = getavg(yvals[i * 6 + dop], len, fretindex, fretindex + 3); float estripe = 1.0f - stdonprefret / stdonafret; float eoff = 1.0f - offdonprefret / offdonafret; rtnpts[i] = len; for (int j = 0; j < len; j++) { rtxvals[i][j] = j - damageindex - 1; rtavals[i][j] = (yvals[i * 6 + asp][j] / staccpredam) / (yvals[i * 6 + atp][j] / nucaccpredam); rtdvals[i][j] = (yvals[i * 6 + dsp][j] / stdonpredam) / (yvals[i * 6 + dtp][j] / nucdonpredam); } float[] smart = (float[]) algutils.get_subarray(rtavals[i], 0, fretindex); float[] smdrt = (float[]) algutils.get_subarray(rtdvals[i], 0, fretindex); jsmooth.blur1D(smart, 2.0f); jsmooth.blur1D(smdrt, 2.0f); float maxart = 0.0f; float maxdrt = 0.0f; for (int j = 0; j < fretindex - 2; j++) { if (smart[j] > maxart) maxart = smart[j]; if (smdrt[j] > maxdrt) maxdrt = smdrt[j]; } stfretvals[i] = getregion(yvals[i * 6 + dsp], len, prefretstart, fretlength); offfretvals[i] = getregion(yvals[i * 6 + dop], len, prefretstart, fretlength); tw.append( iw.getTitle() + "-" + (i + 1) + "\t" + staccpredam + "\t" + stdonpredam + "\t" + estripe + "\t" + eoff + "\t" + maxart + "\t" + maxdrt); } new PlotWindow4("Stripe_FRET_profiles", "time", "intensity", stfretvals, null).draw(); new PlotWindow4("OffStripe_FRET_profiles", "time", "intensity", offfretvals, null).draw(); new PlotWindow4("Acc_Rt_profiles", "time", "intensity", rtxvals, rtavals, rtnpts).draw(); new PlotWindow4("Don_Rt_profiles", "time", "intensity", rtxvals, rtdvals, rtnpts).draw(); }