Ejemplo n.º 1
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.º 2
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);

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

    }
  }