Exemplo n.º 1
0
  /** Same as above, but converts input distr to output distr using a matrix transfer function */
  public static void simulateHistogramREU(LogicCircuit lc, GateLibrary gate_library, Args options) {

    ArrayList<Gate> logic_and_output_gates = new ArrayList<Gate>();
    logic_and_output_gates.addAll(lc.get_logic_gates());
    logic_and_output_gates.addAll(lc.get_output_gates());

    // input gate REU already set
    for (Gate gate : logic_and_output_gates) {
      gate.set_unvisited(true);
    }
    for (Gate gate : logic_and_output_gates) {
      simulateHistogramREU(gate, gate_library, options);
    }
  }
Exemplo n.º 2
0
  /**
   * for all logic and output gates: set flag simulate_reu = true (indicates that REU needs to be
   * simulated) then call simulateREU() in Gate.java
   *
   * <p>Hill function evaluation
   */
  public static void simulateREU(LogicCircuit lc, GateLibrary gate_library, Args options) {
    ArrayList<Gate> logic_and_output_gates = new ArrayList<Gate>();
    logic_and_output_gates.addAll(lc.get_logic_gates());
    logic_and_output_gates.addAll(lc.get_output_gates());

    // input gate REU already set
    // make sure that all gates are re-simulated by setting simulate_reu to TRUE
    for (Gate gate : logic_and_output_gates) {
      gate.set_unvisited(true);
    }
    for (Gate gate : logic_and_output_gates) {
      simulateREU(gate, gate_library, options);
    }
  }
Exemplo 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));
    }
  }
Exemplo 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

    }
  }
Exemplo 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);

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

    }
  }