<commit_before>#include <stdlib.h>
#include <stdbool.h>
#include <limits.h>

#include "pwlib.h"

bool _alnalt_B_allowed(dptable *T, int i, int j) {
  switch (T->mode) {
    case STD_MODE:
      if (i == 0 && j == 0) {
        return true;
      }
      if (T->std_prob->type == LOCAL || T->std_prob->type == END_ANCHORED) {
        return true;
      }
      if (T->std_prob->type == OVERLAP && (i == 0 || j == 0)) {
        return true;
      }
      if (T->std_prob->type == END_ANCHORED_OVERLAP && (i == 0 || j == 0)) {
        return true;
      }
      return false;
    case BANDED_MODE:
      //FIXME
      break;
  }
  return false;
}

int _alnalt_B(dptable *T, int i, int j, alnchoice* choice) {
  if (!_alnalt_B_allowed(T, i, j)) {
    return -1;
  }
  choice->op = 'B';
  choice->score = 0;
  choice->base = NULL;
  return 0;
}

int _alnalt_MS(dptable *T, int i, int j, alnchoice* choice) {
  int s,t, iprev, jprev;
  double score;
  switch (T->mode) {
    case STD_MODE:
      if (i <=0 || j <= 0) {
        return -1;
      }
      iprev = i - 1;
      jprev = j - 1;
      s = T->std_prob->frame->S[T->std_prob->frame->S_min_idx + i - 1];
      t = T->std_prob->frame->T[T->std_prob->frame->T_min_idx + j - 1];
      score = T->std_prob->scores->subst_scores[s][t];
      break;
    case BANDED_MODE:
      //FIXME
      break;
  }
  if (T->cells[iprev][jprev].num_choices <= 0) {
    return -1;
  }
  choice->op = (s==t ? 'M' : 'S');
  // All choices to (i-1,j-1) have the same score:
  choice->score = T->cells[iprev][jprev].choices[0].score + score;
  choice->base = &(T->cells[iprev][jprev].choices[0]);
  return 0;
}

int _alnalt_ID(dptable* T, int i, int j, alnchoice* choice, char op) {
  int iprev, jprev, base_idx, content;
  double score, max_score, gap_open_score, gap_extend_score;
  switch (T->mode) {
    case STD_MODE:
      if (op == 'D') {
        if (i <= 0) {
          return -1;
        }
        iprev = i-1;
        jprev = j;
        content = T->std_prob->frame->S[T->std_prob->frame->S_min_idx + i - 1];
      } else if (op == 'I') {
        if (j <= 0) {
          return -1;
        }
        iprev = i;
        jprev = j-1;
        content = T->std_prob->frame->T[T->std_prob->frame->T_min_idx + j - 1];
      } else {
        return -1;
      }
      gap_open_score = T->std_prob->scores->gap_open_score;<commit_msg>add docs to _pw_internals.c<commit_after>#include <stdlib.h>
#include <stdbool.h>
#include <limits.h>

#include "pwlib.h"

/**
 * Decides whether a B movement is allowed at a given position (position can be
 * in either coordinate system depending on alignment mode).
 *
 * @return 0 if choice successfully built, -1 if choice not possible.
 */
bool _alnalt_B_allowed(dptable *T, int i, int j) {
  switch (T->mode) {
    case STD_MODE:
      if (i == 0 && j == 0) {
        return true;
      }
      if (T->std_prob->type == LOCAL || T->std_prob->type == END_ANCHORED) {
        return true;
      }
      if (T->std_prob->type == OVERLAP && (i == 0 || j == 0)) {
        return true;
      }
      if (T->std_prob->type == END_ANCHORED_OVERLAP && (i == 0 || j == 0)) {
        return true;
      }
      return false;
    case BANDED_MODE:
      //FIXME
      break;
  }
  return false;
}

/**
 * If possible populates an alignment 'B' move for a given position of the table
 * (in either coordinate systems depending on alignment mode).
 *
 * @return 0 if choice successfully built, -1 if choice not possible.
 */
int _alnalt_B(dptable *T, int i, int j, alnchoice* choice) {
  if (!_alnalt_B_allowed(T, i, j)) {
    return -1;
  }
  choice->op = 'B';
  choice->score = 0;
  choice->base = NULL;
  return 0;
}

/**
 * If possible populates an alignment 'M' or 'S' move for a given position of
 * the table (in either coordinate systems depending on alignment mode).
 *
 * @return 0 if choice successfully built, -1 if choice not possible.
 */
int _alnalt_MS(dptable *T, int i, int j, alnchoice* choice) {
  int s,t, iprev, jprev;
  double score;
  switch (T->mode) {
    case STD_MODE:
      if (i <=0 || j <= 0) {
        return -1;
      }
      iprev = i - 1;
      jprev = j - 1;
      s = T->std_prob->frame->S[T->std_prob->frame->S_min_idx + i - 1];
      t = T->std_prob->frame->T[T->std_prob->frame->T_min_idx + j - 1];
      score = T->std_prob->scores->subst_scores[s][t];
      break;
    case BANDED_MODE:
      //FIXME
      break;
  }
  if (T->cells[iprev][jprev].num_choices <= 0) {
    return -1;
  }
  choice->op = (s==t ? 'M' : 'S');
  // All choices to (i-1,j-1) have the same score:
  choice->score = T->cells[iprev][jprev].choices[0].score + score;
  choice->base = &(T->cells[iprev][jprev].choices[0]);
  return 0;
}

/**
 * If possible populates an alignment 'M' or 'S' move for a given position of
 * the table (in either coordinate systems depending on alignment mode).
 *
 * @return 0 if choice successfully built, -1 if choice not possible.
 */
int _alnalt_ID(dptable* T, int i, int j, alnchoice* choice, char op) {
  int iprev, jprev, base_idx, content;
  double score, max_score, gap_open_score, gap_extend_score;
  switch (T->mode) {
    case STD_MODE:
      if (op == 'D') {
        if (i <= 0) {
          return -1;
        }
        iprev = i-1;
        jprev = j;
        content = T->std_prob->frame->S[T->std_prob->frame->S_min_idx + i - 1];
      } else if (op == 'I') {
        if (j <= 0) {
          return -1;
        }
        iprev = i;
        jprev = j-1;
        content = T->std_prob->frame->T[T->std_prob->frame->T_min_idx + j - 1];
      } else {
        return -1;
      }
      gap_open_score = T->std_prob->scores->gap_open_score;
{'fraction_non_alphanumeric': 0.16209034543844109, 'fraction_numerical': 0.012754650132860939, 'mean_word_length': 2.2392426850258174, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 109, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6859441', 'n_tokens_mistral': 2205, 'n_tokens_neox': 2142, 'n_words': 570}