コード例 #1
0
 void updateSliceSummary() {
   int slices = imp.getStackSize();
   float[] areas = rt.getColumn(ResultsTable.AREA);
   if (areas == null) areas = new float[0];
   String label = imp.getTitle();
   if (slices > 1) {
     label = imp.getStack().getShortSliceLabel(slice);
     label = label != null && !label.equals("") ? label : "" + slice;
   }
   String aLine = null;
   double sum = 0.0;
   int start = areas.length - particleCount;
   if (start < 0) return;
   for (int i = start; i < areas.length; i++) sum += areas[i];
   int places = Analyzer.getPrecision();
   Calibration cal = imp.getCalibration();
   String total = "\t" + ResultsTable.d2s(sum, places);
   String average = "\t" + ResultsTable.d2s(sum / particleCount, places);
   String fraction = "\t" + ResultsTable.d2s(sum * 100.0 / totalArea, 1);
   aLine = label + "\t" + particleCount + total + average + fraction;
   aLine = addMeans(aLine, areas.length > 0 ? start : -1);
   if (slices == 1) {
     Frame frame = WindowManager.getFrame("Summary");
     if (frame != null && (frame instanceof TextWindow) && summaryHdr.equals(prevHdr))
       tw = (TextWindow) frame;
   }
   if (tw == null) {
     String title = slices == 1 ? "Summary" : "Summary of " + imp.getTitle();
     tw = new TextWindow(title, summaryHdr, aLine, 450, 300);
     prevHdr = summaryHdr;
   } else tw.append(aLine);
 }
コード例 #2
0
 public void run(String arg) {
   GenericDialog gd = new GenericDialog("Options");
   gd.addCheckbox("Add_Titles", true);
   gd.addCheckbox("Close Original", false);
   gd.showDialog();
   if (gd.wasCanceled()) {
     return;
   }
   boolean addtitles = gd.getNextBoolean();
   boolean closeorig = gd.getNextBoolean();
   // first get the table window
   Frame[] niframes = WindowManager.getNonImageWindows();
   boolean first = true;
   TextWindow tw2 = null;
   int ncols = 0;
   String[] col_labels = null;
   for (int i = 0; i < niframes.length; i++) {
     if (niframes[i] instanceof TextWindow && !niframes[i].getTitle().equals("Log")) {
       TextWindow tw = (TextWindow) niframes[i];
       TextPanel tp = tw.getTextPanel();
       List<List<String>> listtable = table_tools.table2listtable(tp);
       if (listtable.size() == 0) {
         col_labels = table_tools.getcollabels(tp);
         ncols = col_labels.length;
         ArrayList<String> temp = new ArrayList<String>();
         for (int j = 0; j < ncols; j++) temp.add("");
         listtable.add(temp);
       }
       if (first) {
         col_labels = table_tools.getcollabels(tp);
         ncols = col_labels.length;
         String headings = tp.getColumnHeadings();
         if (addtitles) {
           String[] titles = repeated(tw.getTitle(), listtable.size());
           table_tools.add_listtable_column(listtable, titles, 0);
           headings = "name\t" + headings;
         }
         tw2 =
             new TextWindow(
                 "Combined Table", headings, table_tools.print_listtable(listtable), 400, 200);
         first = false;
       } else {
         if (addtitles) {
           String[] titles = repeated(tw.getTitle(), listtable.size());
           table_tools.add_listtable_column(listtable, titles, 0);
         }
         tw2.append(table_tools.print_listtable(listtable));
       }
       if (closeorig) tw.close();
     }
   }
 }
コード例 #3
0
 public void showresults(String results) {
   if (redirect) tw.append(results);
   else IJ.log(results);
 }
コード例 #4
0
 public boolean get_errors(double[] params, int[] fixes) {
   GenericDialog gd = new GenericDialog("Error Options");
   String[] methods = {"Support Plane", "Monte Carlo"};
   gd.addChoice("Method", methods, methods[0]);
   float conf = 0.67f;
   gd.addNumericField("SP_Confidence Limit (%)", (int) (conf * 100.0f), 5, 10, null);
   String[] labels = {"P1", "P2", "P3", "P4", "P5", "P6", "P7", "P8", "P9", "P10"};
   gd.addChoice("SP_Parameter", labels, labels[0]);
   double spacing = 0.01;
   gd.addNumericField("SP_Chi^2_plot_spacing (% of value)?", spacing * 100.0, 2, 10, null);
   int ntrials = 100;
   gd.addNumericField("MC_#_Trials", ntrials, 0);
   gd.showDialog();
   if (gd.wasCanceled()) {
     return false;
   }
   int methodindex = gd.getNextChoiceIndex();
   conf = 0.01f * (float) gd.getNextNumber();
   int paramindex = gd.getNextChoiceIndex();
   spacing = 0.01 * gd.getNextNumber();
   ntrials = (int) gd.getNextNumber();
   if (methodindex == 0) {
     support_plane_errors_v2 erclass = new support_plane_errors_v2(this, 0.0001, 50, false, 0.1);
     int errindex = paramindex;
     int nfit = 0;
     for (int i = 0; i < labels.length; i++) {
       if (fixes[i] == 0) {
         nfit++;
       }
     }
     int npts = tempdata.length;
     int dofnum = npts - (nfit - 1) - 1;
     int dofden = npts - nfit - 1;
     double flim = (new jdist()).FLimit(dofnum, dofden, (double) conf);
     IJ.log("FLimit = " + (float) flim);
     if (flim == Double.NaN && flim < 1.0) {
       IJ.showMessage("Invalid Limiting F Value");
       return false;
     }
     double truespacing = Math.abs(params[errindex] * spacing);
     double[][] c2plot =
         erclass.geterrors(
             params, fixes, constraints, tempdata, weights, flim, truespacing, errindex);
     IJ.log("upper limit = " + c2plot[1][0] + " lower limit = " + c2plot[0][0]);
     IJ.log(
         "upper error = "
             + (c2plot[1][0] - params[errindex])
             + " lower error = "
             + (params[errindex] - c2plot[0][0]));
     int templength = c2plot[0].length;
     float[][] c2plotf = new float[2][templength - 1];
     for (int i = 0; i < (templength - 1); i++) {
       c2plotf[0][i] = (float) c2plot[0][i + 1];
       c2plotf[1][i] = (float) c2plot[1][i + 1];
     }
     new PlotWindow4("c2 plot", labels[errindex], "Chi^2", c2plotf[0], c2plotf[1]).draw();
   } else {
     StringBuffer sb = new StringBuffer();
     sb.append("Trial\t");
     for (int i = 0; i < labels.length; i++) {
       if (fixes[i] == 0) sb.append(labels[i] + "\t");
     }
     sb.append("chi^2");
     tw = new TextWindow("Monte Carlo Results", sb.toString(), "", 400, 400);
     redirect = true;
     monte_carlo_errors_v2 erclass = new monte_carlo_errors_v2(this, 0.0001, 50, false, 0.1);
     double[][] errors = erclass.geterrors(params, fixes, constraints, tempdata, weights, ntrials);
     sb = new StringBuffer();
     sb.append("StDev\t");
     for (int i = 0; i < errors.length; i++) {
       float[] ferr = new float[errors[0].length];
       for (int j = 0; j < ferr.length; j++) ferr[j] = (float) errors[i][j];
       float stdev = jstatistics.getstatistic("StDev", ferr, null);
       sb.append("" + stdev);
       if (i < (errors.length - 1)) sb.append("\t");
     }
     tw.append(sb.toString());
     redirect = false;
   }
   return true;
 }
コード例 #5
0
  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();
  }
コード例 #6
0
 public void run(String arg) {
   Frame[] niframes = WindowManager.getNonImageWindows();
   String[] titles = new String[niframes.length + 1];
   for (int i = 0; i < niframes.length; i++) {
     titles[i] = niframes[i].getTitle();
   }
   titles[niframes.length] = "Clipboard";
   GenericDialog gd = new GenericDialog("Windows");
   boolean importfile = false;
   gd.addCheckbox("Import from file?", importfile);
   gd.addChoice("Windows", titles, titles[0]);
   boolean hasxvals = false;
   gd.addCheckbox("X Vals Column?", hasxvals);
   boolean multix = false;
   gd.addCheckbox("Multi_X_Columns?", multix);
   boolean skipendzeros = false;
   gd.addCheckbox("Skip_end_zeros?", skipendzeros);
   String[] delimiters = {"Tab", "Comma", "Space"};
   gd.addChoice("Delimiter", delimiters, delimiters[0]);
   gd.showDialog();
   if (gd.wasCanceled()) {
     return;
   }
   importfile = gd.getNextBoolean();
   int index = gd.getNextChoiceIndex();
   hasxvals = gd.getNextBoolean();
   multix = gd.getNextBoolean();
   skipendzeros = gd.getNextBoolean();
   int delimindex = gd.getNextChoiceIndex();
   if (multix) hasxvals = true;
   String textdata = "";
   if (importfile) {
     OpenDialog od = new OpenDialog("Open File", "", ".txt");
     String directory = od.getDirectory();
     String name = od.getFileName();
     if (name == null) {
       return;
     }
     try {
       File infile = new File(directory + name);
       BufferedReader b = new BufferedReader(new FileReader(infile));
       textdata = (new jdataio()).readstringfile(b);
       b.close();
     } catch (IOException e) {
       return;
     }
   } else {
     if (index == niframes.length) {
       // here we get the data from the clipboard
       Transferable t = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null);
       try {
         if (t != null && t.isDataFlavorSupported(DataFlavor.stringFlavor)) {
           textdata = (String) t.getTransferData(DataFlavor.stringFlavor);
         }
       } catch (UnsupportedFlavorException e) {
       } catch (IOException e) {
       }
       if (textdata.equals("")) {
         IJ.error("Error copying from clipboard.");
         return;
       }
     } else {
       if (niframes[index] instanceof Editor) {
         Editor tw = (Editor) niframes[index];
         textdata = tw.getText();
       } else {
         if (niframes[index] instanceof TextWindow) {
           TextWindow tw = (TextWindow) niframes[index];
           textdata = tw.getTextPanel().getText();
         } else {
           IJ.showMessage("Not a valid text window");
           return;
         }
       }
     }
   }
   if (textdata == null) {
     IJ.showMessage("Error in Obtaining String");
     return;
   }
   if (textdata.indexOf("\r") >= 0) {
     textdata = textdata.replace('\r', '\n');
   }
   char[] delims = {'\t', ',', ' '};
   delimit_string ds = new delimit_string(delims[delimindex]);
   String[] rows = ds.getrows(textdata);
   int lines = rows.length;
   int columns = ds.getnumcolumns(rows[0]);
   int ycolumns = columns;
   if (hasxvals) {
     if (multix) {
       ycolumns /= 2;
     } else {
       ycolumns--;
     }
   }
   if (multix) {
     float[][] ydata = new float[ycolumns][lines];
     float[][] xdata = new float[ycolumns][lines];
     for (int i = 0; i < lines; i++) {
       float[] temp = ds.delim2float(rows[i], columns);
       for (int j = 0; j < ycolumns; j++) {
         ydata[j][i] = temp[2 * j + 1];
         xdata[j][i] = temp[2 * j];
       }
     }
     int[] npts = new int[ycolumns];
     for (int i = 0; i < ycolumns; i++) {
       npts[i] = lines;
     }
     if (skipendzeros) {
       for (int i = 0; i < ycolumns; i++) {
         int counter = lines - 1;
         while ((xdata[i][counter] == 0.0f || Float.isNaN(xdata[i][counter])) && counter > 0) {
           xdata[i][counter] = 0.0f;
           ydata[i][counter] = 0.0f;
           npts[i]--;
           counter--;
         }
       }
     }
     (new PlotWindow4("Text Plot", "x", "y", xdata, ydata, npts)).draw();
   } else {
     float[][] tempydata = new float[ycolumns][lines];
     float[] tempxdata = new float[lines];
     float[][] xdata = null;
     float[][] ydata = null;
     int startcolumn = 0;
     if (hasxvals) startcolumn = 1;
     for (int i = 0; i < lines; i++) {
       float[] temp = ds.delim2float(rows[i], columns);
       if (hasxvals) {
         tempxdata[i] = temp[0];
       } else {
         tempxdata[i] = (float) (i + 1);
       }
       for (int j = 0; j < ycolumns; j++) {
         tempydata[j][i] = temp[j + startcolumn];
       }
     }
     int[] npts = new int[ycolumns];
     npts[0] = lines;
     if (skipendzeros) {
       int maxpts = 0;
       for (int i = 0; i < ycolumns; i++) {
         int counter = lines - 1;
         npts[i] = lines;
         while ((tempydata[i][counter] == 0.0f || Float.isNaN(tempydata[i][counter]))
             && counter > 0) {
           npts[i]--;
           counter--;
         }
         if (npts[i] > maxpts) maxpts = npts[i];
         IJ.log("" + npts[i]);
       }
       ydata = new float[ycolumns][maxpts];
       xdata = new float[ycolumns][maxpts];
       for (int i = 0; i < ycolumns; i++) {
         // npts[i]=npts[0];
         System.arraycopy(tempxdata, 0, xdata[i], 0, npts[i]);
         System.arraycopy(tempydata[i], 0, ydata[i], 0, npts[i]);
       }
     } else {
       ydata = tempydata;
       xdata = new float[ycolumns][];
       for (int i = 0; i < ycolumns; i++) {
         npts[i] = npts[0];
         xdata[i] = tempxdata.clone();
       }
     }
     (new PlotWindow4("Text Plot", "x", "y", xdata, ydata, npts)).draw();
   }
 }