Example #1
0
  /**
   * score = 1 - penalty of histogram overlap score all ON:OFF pairs and report the worst score
   *
   * <p>overlap penalty: for each bin, compute geometric mean of two ON:OFF histogram values, add
   * add bin penalty to total penalty alternative is to penalize the min of the two ON:OFF histogram
   * values
   */
  public static void evaluateGateHistogramOverlap(Gate g) {

    ArrayList<Double> scores_conv_overlap = new ArrayList<Double>();
    ArrayList<Integer> ons = new ArrayList<Integer>();
    ArrayList<Integer> offs = new ArrayList<Integer>();

    // get ons and offs
    for (int i = 0; i < g.get_logics().size(); ++i) {
      if (g.get_logics().get(i) == 1) {
        ons.add(i);
      } else if (g.get_logics().get(i) == 0) {
        offs.add(i);
      }
    }

    // compute scores of all on-off pairs
    for (int on = 0; on < ons.size(); ++on) {
      for (int off = 0; off < offs.size(); ++off) {

        // if(!Args.dontcare_rows.contains(on) && !Args.dontcare_rows.contains(off)) {

        double median_on =
            Math.pow(
                Math.E,
                HistogramUtil.median(
                    g.get_histogram_reus().get(ons.get(on)), g.get_histogram_bins()));
        double median_off =
            Math.pow(
                Math.E,
                HistogramUtil.median(
                    g.get_histogram_reus().get(offs.get(off)), g.get_histogram_bins()));
        double score = 1 - median_off / median_on;
        double overlap_penalty = 0.0;

        // if ON histogram is lower than OFF histogram, broken circuit
        if (score < 0) {
          scores_conv_overlap.add(0.0);
          continue;
        } else {
          double[] on_norm = HistogramUtil.normalize(g.get_histogram_reus().get(ons.get(on)));
          double[] off_norm = HistogramUtil.normalize(g.get_histogram_reus().get(offs.get(off)));

          // penalty is sum of geometric means for each bin
          // total counts have been normalized to 1
          for (int bin = 0; bin < g.get_histogram_bins().get_NBINS(); ++bin) {
            overlap_penalty += Math.sqrt(on_norm[bin] * off_norm[bin]); // geometric mean
            // overlap_penalty += Math.min( on_norm[bin] , off_norm[bin]); //min of the two bin
            // counts
          }
        }
        score = 1 - overlap_penalty;

        scores_conv_overlap.add(score);

        // }
      }
    }

    Collections.sort(scores_conv_overlap);

    g.get_scores().set_conv_overlap(scores_conv_overlap.get(0)); // worst
  }
  @Override
  public ArrayList<Map> getObjects() {

    ArrayList<Map> objects = new ArrayList<>();

    ArrayList<Double> REU_TITR = new ArrayList<Double>();
    REU_TITR.add(0.018806664);
    REU_TITR.add(0.028666538);
    REU_TITR.add(0.051722065);
    REU_TITR.add(0.14837545);
    REU_TITR.add(0.261559417);
    REU_TITR.add(0.447725869);
    REU_TITR.add(0.687508549);
    REU_TITR.add(1.131011516);
    REU_TITR.add(1.891798237);
    REU_TITR.add(3.27479675);
    REU_TITR.add(4.549973162);
    REU_TITR.add(8.687342616);

    HistogramBins hbins = new HistogramBins();
    hbins.init();
    GateLibrary gate_library = new GateLibrary(0, 0);

    ArrayList<String> gate_names = new ArrayList<String>();
    gate_names.add("an0_AmeR");
    gate_names.add("js2_AmtR");
    gate_names.add("js2_BM3R1");
    gate_names.add("js2_BetI");
    gate_names.add("js2_HlyIIR");
    gate_names.add("js2_IcaRA");
    gate_names.add("js2_LitR");
    gate_names.add("js2_PhlF");
    gate_names.add("js2_SrpR");
    gate_names.add("js_QacR");
    gate_names.add("js2_LitR");

    for (String gate_name : gate_names) {
      Gate g = new Gate();
      g.Name = gate_name;
      gate_library.get_GATES_BY_NAME().put(g.Name, g);
    }

    for (Gate g : gate_library.get_GATES_BY_NAME().values()) {
      String gate_name = g.Name;

      String rootpath = collection_writer.getRootPath();
      String filepath = rootpath + "/resources/data/nor_gates/cytometry_cb1/";
      HistogramUtil.getTransferFunctionHistogramTitrations(
          gate_name, gate_library, hbins, filepath);

      LinkedHashMap obj = new LinkedHashMap();
      obj.put("collection", "gate_cytometry"); // tag

      obj.put("gate_name", gate_name);

      ArrayList<LinkedHashMap> titrations = new ArrayList<LinkedHashMap>();

      for (int i = 0; i < REU_TITR.size(); ++i) {
        Double inREU = REU_TITR.get(i);

        ArrayList<Double> out_reu_bins = new ArrayList<Double>();
        ArrayList<Double> out_reu_counts = new ArrayList<Double>();

        for (int j = 0; j < hbins.get_NBINS(); ++j) {
          double[] normalized = HistogramUtil.normalize(g.get_xfer_hist().get_xfer_binned().get(i));
          out_reu_bins.add(Math.pow(10, hbins.get_LOG_BIN_CENTERS()[j]));
          out_reu_counts.add(normalized[j]);
        }

        LinkedHashMap titration = new LinkedHashMap();
        titration.put("maps_to_variable", "x");
        titration.put("input", inREU);
        titration.put("output_bins", out_reu_bins);
        titration.put("output_counts", out_reu_counts);
        titrations.add(titration);
      }

      obj.put("cytometry_data", titrations);

      objects.add(obj);
      // org.cellocad.ucf_writers_tetr.ConstraintFileWriter.JSONPrettyPrint(obj,
      // "resources/UCF/Eco1C1G1T1.gate_cytometry.json", true);

    }

    return objects;
  }