/*****************************************************************************
 * MEME > training_set > alphabet > letter
 * Read in a identifier and symbol pair for a letter.
 ****************************************************************************/
void mxml_alphabet_letter(void *ctx, char *id, char symbol, char* aliases, char complement, char *equals, char *name, int colour) {
  CTX_T *data;
  char sym[2];
  data = (CTX_T*)ctx;
  if (data->alph != NULL) {
    // check that the symbol exists in the alphabet
    if (!alph_is_concrete(data->alph, symbol)) {
      local_error(data, "The symbol %c does not exist in the built-in alphabet %s.\n",
          symbol, alph_name(data->alph));
      return;
    }
    // Note: don't bother checking complement value as it will not be set
  } else {
    if (equals == NULL) {
      alph_reader_core(data->alph_rdr, symbol, aliases, name, colour, complement);
    } else {
      alph_reader_ambig(data->alph_rdr, symbol, aliases, name, colour, equals);
    }
  }
  // create a mapping from the id to the symbol
  sym[0] = symbol;
  sym[1] = '\0';
  if (!rbtree_make(data->letter_lookup, id, sym)) {
    local_error(data, "The letter identifier %s has been used before.\n", id);
  }
}
示例#2
0
/****************************************************************************
 *  Does a column of an alignment contain any ambiguity codes?
 ****************************************************************************/
BOOLEAN_T alignment_site_ambiguous(ALPH_T alph, int index, ALIGNMENT_T* alignment) {

  int i;
  for (i = 0; i < alignment->num_sequences; i++) {
    char c = get_seq_char(index, alignment->sequences[i]);
    if (!alph_is_concrete(alph, c)) return(TRUE);
  }
  return(FALSE);
}
示例#3
0
/*
 *  plib_name       name of prior library file
 *  desired_beta    >  0, scale \beta_{i,j} so
 *                      \sum_{i=0}^L \lambda_i \sum_{j=1}^20 \beta_{i,j}
 *                      has this value
 *                  == 0, don't scale prior
 *                  <  0, just get alphabet
 */
PriorLib *read_PriorLib(char *plib_name, double desired_beta, ALPH_T *custom_alph)
{
  int i,j, line=0;
  int l;
  PriorLib *temp;
  char input[MAXS], foo[MAXS], alphabet[MAXALPH+1], checkstr[81], *token;
  double x;
  FILE *fp;
  ALPH_T *alph;

  // tlb 
  fp = fopen(plib_name, "r");
  if (!fp) {
    fprintf(stderr, "Can't find prior library %s\n", plib_name);
    exit(1);
  }

  token = "Alphabet="; line++;
  test_value(fscanf(fp,"%s %s\n", checkstr, alphabet) == 2);
  if (strcmp(checkstr, token)) {
    fprintf(stderr, "Line %d of prior library file \n %s \n"
        "should start with \"%s\" "
        "but it starts with \"%s\".\n", line, plib_name, token, checkstr);
    exit(1);
  }
  // determine alphabet
  if (custom_alph == NULL) {
    alph = alph_type(alphabet, 30);
    if (alph == NULL) {
      fprintf(stderr, "The partial alphabet specified in the prior library file"
          " does not match a built-in alphabet and no complete alphabet was specified.\n");
      exit(1);
    }
  } else {
    int alen_core;
    alen_core = strlen(alphabet);
    i = 0;
    if (alen_core == alph_size_core(custom_alph)) {
      for (i = 0; i < alen_core; i++) {
        if (!alph_is_concrete(custom_alph, alphabet[i])) break;
      }
    }
    if (i == 0 || i < alen_core) {
      fprintf(stderr, "The partial alphabet specified in the prior library file"
          " does not match the complete alphabet specified.\n");
      exit(1);
    }
    alph = alph_hold(custom_alph);
  }

  token = "NumDistr="; line++;
  test_value(fscanf(fp,"%s %d\n", checkstr, &l) == 2);
  if (strcmp(checkstr, token)) {
    fprintf(stderr, "Line %d of prior library file \n %s \n"
        "should start with \"%s\" "
        "but it starts with \"%s\"\n.", line, plib_name, token, checkstr);
    exit(1);
  }

  temp = alloc_PriorLib(l, alph);

  if (desired_beta < 0) {
    fclose(fp);
    return(temp);
  }

  for (i = 0; i < temp->L; i++) {
    // Get rid of number= 
    ignore_value(fscanf(fp,"%*s %*s\n"));
    // Mixture 
    ignore_value(fscanf(fp,"%*s"));
    test_value(fscanf(fp,"%lf\n", &x) == 1);
    temp->Mix[i] = x;
    // B (strength) 
    ignore_value(fscanf(fp,"%*s"));
    test_value(fscanf(fp,"%lf\n", &x) == 1);
    temp->B[i] = x;
    // Alpha 
    temp->Distr[i][0] = temp->B[i];
    ignore_value(fscanf(fp,"%*s"));
    for (j = 1; j < alph_size_wild(alph); j++) {
      test_value(fscanf(fp,"%lg", &x) == 1);
      temp->Distr[i][j] = x * temp->B[i];
    }
    // FullUpdate 
    ignore_value(fscanf(fp,"%*s"));
    test_value(fscanf(fp,"%d\n", &(temp->FullUpdate[i])) == 1);
    // QUpdate 
    ignore_value(fscanf(fp,"%*s"));
    test_value(fscanf(fp,"%d\n", &(temp->QUpdate[i])) == 1);
    // StructID 
    test_value(fgets(input, MAXS, fp) != NULL);
    test_value(sscanf(input,"%s",foo) == 1);
    input[strlen(input)-1] = '\0';
    strcpy( (temp->StructID[i]), (input + strlen(foo)) );
    // Comments 
    test_value(fgets(input, MAXS, fp) != NULL);
    test_value(sscanf(input,"%s",foo) == 1);
    strcpy( (temp->Comment[i]), (input + strlen(foo)) );
  }

  // tlb; scale beta to desired value 
  if (desired_beta > 0) {
    int i, j;
    double beta = 0;
    double scale;
    for (i=0; i<temp->L; i++) {
      beta += temp->Mix[i] * temp->B[i];
    }
    /*printf("beta = %10.6f\n", beta);*/
    scale = desired_beta/beta;
    for (i=0; i<temp->L; i++) {
      for (j=0; j < alph_size_wild(alph); j++) {
        temp->Distr[i][j] *= scale;
      }
    }
  }
  fclose(fp);

  alph_release(alph);
  return(temp);
}