/**
   * Sets the partials from a sequence in an alignment.
   *
   * @param beagle beagle
   * @param patternList patternList
   * @param sequenceIndex sequenceIndex
   * @param nodeIndex nodeIndex
   */
  protected final void setPartials(
      Beagle beagle, PatternList patternList, int sequenceIndex, int nodeIndex) {
    double[] partials = new double[patternCount * stateCount * categoryCount];

    boolean[] stateSet;

    int v = 0;
    for (int i = 0; i < patternCount; i++) {

      int state = patternList.getPatternState(sequenceIndex, i);
      stateSet = dataType.getStateSet(state);

      for (int j = 0; j < stateCount; j++) {
        if (stateSet[j]) {
          partials[v] = 1.0;
        } else {
          partials[v] = 0.0;
        }
        v++;
      }
    }

    // if there is more than one category then replicate the partials for each
    int n = patternCount * stateCount;
    int k = n;
    for (int i = 1; i < categoryCount; i++) {
      System.arraycopy(partials, 0, partials, k, n);
      k += n;
    }

    beagle.setPartials(nodeIndex, partials);
  }
  /**
   * Sets the partials from a sequence in an alignment.
   *
   * @param beagle beagle
   * @param patternList patternList
   * @param sequenceIndex sequenceIndex
   * @param nodeIndex nodeIndex
   */
  protected final void setStates(
      Beagle beagle, PatternList patternList, int sequenceIndex, int nodeIndex) {
    int i;

    int[] states = new int[patternCount];

    for (i = 0; i < patternCount; i++) {

      states[i] = patternList.getPatternState(sequenceIndex, i);
    }

    beagle.setTipStates(nodeIndex, states);
  }
  /** Sets the partials from a sequence in an alignment. */
  protected final void setPartials(Beagle beagle, TipStatesModel tipStatesModel, int nodeIndex) {
    double[] partials = new double[patternCount * stateCount * categoryCount];

    tipStatesModel.getTipPartials(nodeIndex, partials);

    // if there is more than one category then replicate the partials for each
    int n = patternCount * stateCount;
    int k = n;
    for (int i = 1; i < categoryCount; i++) {
      System.arraycopy(partials, 0, partials, k, n);
      k += n;
    }

    beagle.setPartials(nodeIndex, partials);
  }