Ejemplo n.º 1
0
  /** gate score = smallest noise margin (distance in log(REU) of input REU to margin REU) */
  public static void evaluateGateNoiseMargin(Gate g, Args options) {

    if (options.is_noise_margin() == false) {
      g.get_scores().set_noise_margin_contract(true);
      return;
    }

    if (g.Type == GateType.INPUT || g.Type == GateType.OUTPUT || g.Type == GateType.OUTPUT_OR) {
      return;
    }

    // "x" to value
    HashMap<String, Double> lowest_on_reu = GateUtil.getIncomingONlow(g);
    HashMap<String, Double> highest_off_reu = GateUtil.getIncomingOFFhigh(g);

    ArrayList<Double> all_margins = new ArrayList<Double>();

    for (String var : highest_off_reu.keySet()) {

      if (g.get_variable_thresholds().get(var) != null) {

        // IL is the input-low threshold
        Double IL = g.get_variable_thresholds().get(var)[0];

        // actual REU
        Double log_input_reu = Math.log10(highest_off_reu.get(var));

        // NML is the margin/width between the actual REU and the threshold REU
        Double NML = Math.log10(IL) - log_input_reu;

        all_margins.add(NML);
      }
    }

    for (String var : lowest_on_reu.keySet()) {

      if (g.get_variable_thresholds().get(var) != null) {
        Double IH = g.get_variable_thresholds().get(var)[1];
        Double NMH = Math.log10(lowest_on_reu.get(var)) - Math.log10(IH);
        all_margins.add(NMH);
      }
    }

    if (all_margins.isEmpty()) {
      g.get_scores().set_noise_margin(0.0);
      g.get_scores().set_noise_margin_contract(true);
    } else {
      Collections.sort(all_margins);

      g.get_scores().set_noise_margin(all_margins.get(0));

      if (all_margins.get(0) < 0) {
        g.get_scores().set_noise_margin_contract(false);
      } else {
        g.get_scores().set_noise_margin_contract(true);
      }
    }
  }
Ejemplo n.º 2
0
  /**
   * A gate with two transcriptional units (e.g. AND) can have two different wirings. Doesn't matter
   * for a gate with one txn unit.
   *
   * @param g
   * @param gate_library
   * @param options
   */
  public static void setBestVariableMapping(Gate g, GateLibrary gate_library, Args options) {

    ArrayList<ArrayList<String>> variable_name_orders =
        Permute.getVariableNamePermutation(g.get_variable_names());
    Integer best_variable_name_order_index = 0;
    Double best_score = 0.0;

    int v = 0;
    for (ArrayList<String> variable_name_order : variable_name_orders) {

      g.get_outreus().clear();

      for (int i = 0; i < g.get_logics().size(); ++i) { // rows in truth table

        /*if (Args.dontcare_rows.contains(i)) {
            g.get_outreus().add(0.0);
            continue;
        }*/

        GateUtil.mapWiresToVariables(g, variable_name_order);

        double output_reu =
            ResponseFunction.computeOutput(
                GateUtil.getVariableValues(g, i, gate_library, options),
                g.get_params(),
                g.get_equation());

        g.get_outreus().add(output_reu);
      }

      evaluateGate(g, options);

      if (g.get_scores().get_score() > best_score) {
        best_score = g.get_scores().get_score();
        best_variable_name_order_index = v;
      }
      v++;
    }

    // this is the critical part, it's ordering the variable names in the list
    g.set_variable_names(variable_name_orders.get(best_variable_name_order_index));
  }
Ejemplo n.º 3
0
  /**
   * *********************************************************************
   *
   * <p>Synopsis [ ]
   *
   * <p>keep tracing back to child until find one with logics defined assume it has either 1 or 2
   * children this method is recursive Note: Recursion is not necessary and does not occur if we
   * sort the gates by distance to input, then simulate logic in that order.
   *
   * <p>logic is computed according to Gate type and input logics
   *
   * <p>*********************************************************************
   */
  public static void simulateLogic(Gate g) {

    if (g.is_unvisited()) {

      ArrayList<Gate> children = g.getChildren();

      for (Gate child : children) {
        if (child.is_unvisited()) {
          simulateLogic(child); // recursive
        }
      }

      // if all children have been visited, visit the current gate 'g'
      g.set_unvisited(false);
      g.set_logics(GateUtil.computeGateLogics(g));
    }
  }
Ejemplo n.º 4
0
  /**
   * *********************************************************************
   *
   * <p>Synopsis [ ]
   *
   * <p>*********************************************************************
   */
  public static void simulateHistogramREU(Gate g, GateLibrary gate_library, Args options) {

    if (g.is_unvisited()) {

      g.set_unvisited(false);

      ArrayList<Gate> children = g.getChildren();
      for (Gate child : children) {
        if (child.is_unvisited()) {
          simulateHistogramREU(child, gate_library, options);
        }
      }

      // initialize
      g.get_histogram_reus().clear();
      for (int i = 0; i < g.get_logics().size(); ++i) { // rows in truth table

        g.get_histogram_reus().add(new double[g.get_histogram_bins().get_NBINS()]);
        for (int j = 0; j < g.get_histogram_bins().get_NBINS(); ++j) {
          g.get_histogram_reus().get(i)[j] = 0.0;
        }
      }

      if (g.Type == GateType.OUTPUT_OR || g.Type == GateType.OUTPUT) {
        g.set_histogram_reus(GateUtil.getSumOfGateInputHistograms(g, gate_library, options));
      } else if (g.Type == GateType.AND) {
        g.set_histogram_reus(GateUtil.getANDOfGateInputHistograms(g));
      } else if (g.Type == GateType.NOT || g.Type == GateType.NOR) {
        // 2. For each row: for each bin: for each output bin: add normalizeToValue
        ArrayList<double[]> input_convreus =
            GateUtil.getSumOfGateInputHistograms(g, gate_library, options);
        g.set_in_histogram_reus(input_convreus);

        for (int i = 0; i < input_convreus.size(); ++i) {

          /*if(Args.dontcare_rows.contains(i)) {
              for(int bin=0; bin< g.get_histogram_reus().get(i).length; ++bin) {
                  g.get_histogram_reus().get(i)[bin] = 0.0;
              }
              continue;
          }*/

          double[] convhist = input_convreus.get(i);

          for (int bin = 0; bin < g.get_histogram_bins().get_NBINS(); ++bin) {
            double fractional_counts = convhist[bin];
            double[] xslice = g.get_xfer_hist().get_xfer_interp().get(bin);

            for (int xslice_bin = 0;
                xslice_bin < g.get_histogram_bins().get_NBINS();
                ++xslice_bin) {
              g.get_histogram_reus().get(i)[xslice_bin] += xslice[xslice_bin] * fractional_counts;
            }
          }
        }
      }

      // evaluateGateHistogramOverlap(g); //to compute gate scores

    }
  }
Ejemplo n.º 5
0
  /**
   * *********************************************************************
   *
   * <p>Synopsis [ ]
   *
   * <p>keep tracing back to child until find one with logics defined assume it has either 1 or 2
   * children this method is recursive Note: Recursion is not necessary and does not occur if we
   * sort the gates by distance to input, then simulate logic in that order.
   *
   * <p>For NOT gate, compute output REU based on child1 REU and xfer function For NOR gate, compute
   * output REU based on child1 REU + child2 REU and xfer function For OUTPUT gate, output REU =
   * child1 REU For OUTPUT_OR gate, output REU = child1 REU + child2 REU
   *
   * <p>*********************************************************************
   */
  public static void simulateREU(Gate g, GateLibrary gate_library, Args options) {

    if (g.is_unvisited()) {

      g.set_unvisited(false);

      ArrayList<Gate> children = g.getChildren();
      for (Gate child : children) {
        if (child.is_unvisited()) {
          simulateREU(child, gate_library, options);
        }
      }

      /**
       * Multidimensional response functions are not symmetric, so which wire maps to which variable
       * must be determined. Not relevant if there is only a single independent variable in the
       * response function (i.e. Hill equation).
       */
      if (g.get_variable_names().size() > 1) {
        setBestVariableMapping(g, gate_library, options);
      }

      ///////////////////////////////////////////////////////////////////
      // now that the best variable mapping was found, resimulate
      ///////////////////////////////////////////////////////////////////
      g.get_outreus().clear();

      g.get_inreus().clear();

      for (int i = 0; i < g.get_logics().size(); ++i) { // rows in truth table
        /*if (Args.dontcare_rows.contains(i)) {
            g.get_outreus().add(0.0);
            continue;
        }*/

        GateUtil.mapWiresToVariables(g, g.get_variable_names());

        /**
         * For example, String = "x". Double = summed REUs for tandem promoters i is the row in the
         * truth table.
         */
        HashMap<String, Double> variable_values =
            GateUtil.getVariableValues(g, i, gate_library, options);

        // v = "x"
        for (String v : variable_values.keySet()) {

          if (!g.get_inreus().containsKey(v)) {
            // initialize with empty arraylist
            g.get_inreus().put(v, new ArrayList<Double>());
          }
          g.get_inreus().get(v).add(variable_values.get(v));
        }

        double output_reu =
            ResponseFunction.computeOutput(
                // sum contributions of tandem promoters for this row in the truth table
                // ...unless there is tandem promoter data, then we look up the value instead of
                // adding
                variable_values, g.get_params(), g.get_equation());

        g.get_outreus().add(output_reu);
      }

      // evaluateGate(g);

      //////////////////////////////////////////////

    }
  }