示例#1
0
/***********************************************************************
 * Discard motifs that are not connected.
 ***********************************************************************/
static void throw_out_unused_motifs
  (MATRIX_T* transp_freq,
   MATRIX_T* spacer_ave,
   int*      num_motifs,
   MOTIF_T*  motifs)
{
  int i_motif, j_motif;
  ARRAY_T* row_sums;
  ARRAY_T* col_sums;

  // Extract the margins of the transition matrix.
  row_sums = get_matrix_row_sums(transp_freq);
  col_sums = get_matrix_col_sums(transp_freq);

  for (i_motif = 0; i_motif < *num_motifs; i_motif++) {

    // Is this row or column empty?
    if ((get_array_item(i_motif + 1, row_sums) == 0.0) ||
      (get_array_item(i_motif + 1, col_sums) == 0.0)) {

      if (verbosity >= NORMAL_VERBOSE) {
        fprintf(stderr, "Removing unused motif %s. No occurrences of this motif were found.\n",
        get_motif_id(&(motifs[i_motif])));
      }

      // Remove the row and column from the transition matrix.
      remove_matrix_row(i_motif + 1, transp_freq);
      remove_matrix_col(i_motif + 1, transp_freq);
      assert(get_num_rows(transp_freq) == get_num_cols(transp_freq));

      remove_matrix_row(i_motif + 1, spacer_ave);
      remove_matrix_col(i_motif + 1, spacer_ave);
      assert(get_num_rows(spacer_ave) == get_num_cols(spacer_ave));

      // Remove the motif from the array.
      for (j_motif = i_motif + 1; j_motif < *num_motifs; j_motif++) {
        free_motif(&(motifs[j_motif - 1]));
        copy_motif(&(motifs[j_motif]), &(motifs[j_motif - 1]));
      }
      free_motif(&(motifs[j_motif - 1]));
      (*num_motifs)--;
      i_motif--;

      // Recalculate the row and column sums.
      free_array(row_sums);
      free_array(col_sums);
      row_sums = get_matrix_row_sums(transp_freq);
      col_sums = get_matrix_col_sums(transp_freq);

    }
  }

  free_array(row_sums);
  free_array(col_sums);
}
/******************************************************************************
  * This function returns a copy of the matrix for time t of a transition 
  * matrix array. Returns NUL is no matrix is found matching time t.
  * Caller is responsible for free the returned copy.
******************************************************************************/
MATRIX_T* get_substmatrix_for_time(
  SUBSTMATRIX_ARRAY_T *a, 
  double t
) {

  assert(a != NULL);
  // Create a copy of our matrix
  int i;
  MATRIX_T* src = NULL;
  for (i = 0; i < a->length; i++) {
    if (a->t[i] == t) {
      src = a->substmatrix[i];
      break;
    }
  }
  MATRIX_T* dst = NULL;
  if (src != NULL) {
    int num_rows = get_num_rows(src);
    int num_cols = get_num_cols(src);
    dst = allocate_matrix(num_rows, num_cols);
    copy_matrix(src, dst);
  }

  return dst;
}
/**
 * Given a matrix, find the row idx and column idx of the minimum value
 * that passes the score and count threshold. If none is found, then
 * row_idx, col_idx, and lowest will not be modified.
 */
void find_most_significant_within_matrix(MATRIX_T* binomial,
                                         MATRIX_T* phospho_count,
                                         int* row_idx,
                                         int* col_idx,
                                         double* lowest,
                                         MOMO_OPTIONS_T* options) {
  int i;
  int j;
  for (i = 0; i < get_num_rows(binomial); ++i) {
    for (j = 0; j < get_num_cols(binomial); ++j) {
      double binomial_value = get_matrix_cell_defcheck(i, j, binomial);
      double count_value = get_matrix_cell_defcheck(i, j, phospho_count);
      // 1. value cannot be nan/inf
      // 2. log(value) < log(options->score_threshold)
      // 3. value should not be the modified location
      if (i != options->width/2 && !isnan(binomial_value) && !isinf(binomial_value) && binomial_value < log(options->score_threshold) && count_value >= options->count_threshold) {
        if (binomial_value < *lowest || isnan(*lowest)) {
          *row_idx = i;
          *col_idx = j;
          *lowest = get_matrix_cell_defcheck(i, j, binomial);
        }
      }
      
    }
  }
}
示例#4
0
/***********************************************************************
 * Copy a motif from one place to another.
 ***********************************************************************/
void copy_motif
  (MOTIF_T* source,
   MOTIF_T* dest)
{
  strcpy(dest->id, source->id);
  strcpy(dest->id2, source->id2);
  dest->length = source->length;
  dest->alph_size = source->alph_size;
  dest->ambigs = source->ambigs;
  dest->evalue = source->evalue;
  dest->num_sites = source->num_sites;
  dest->complexity = source->complexity;
  dest->trim_left = source->trim_left;
  dest->trim_right = source->trim_right;
  if (source->freqs) {
    // Allocate memory for the matrix.
    dest->freqs = allocate_matrix(dest->length, dest->alph_size + dest->ambigs);
    // Copy the matrix.
    copy_matrix(source->freqs, dest->freqs);
  } else {
    dest->freqs = NULL;
  }
  if (source->scores) {
    // Allocate memory for the matrix. Note that scores don't contain ambigs.
    dest->scores = allocate_matrix(get_num_rows(source->scores), get_num_cols(source->scores));
    // Copy the matrix.
    copy_matrix(source->scores, dest->scores);
  } else {
    dest->scores = NULL;
  }
  copy_string(&(dest->url), source->url);
}
示例#5
0
文件: MtxLP.cpp 项目: kierzek/MUFINS
void MtxLP::getObjective(stomap* rv, bool withzeroes) const{
    for (int i = 1; i <= get_num_cols(); i++){
        double coef = get_obj_coef(i);
        if (withzeroes || coef != 0)
            (*rv)[get_col_name(i)] = coef;
    }
}
示例#6
0
/***********************************************************************
 * allocate memory for a motif
 ***********************************************************************/
MOTIF_T* allocate_motif(char *id, MATRIX_T* freqs){
	MOTIF_T* motif = mm_malloc(sizeof(MOTIF_T));

	assert(id != NULL);
	assert(freqs != NULL);

	motif->length = 0;
	motif->alph_size = 0;
	motif->ambigs = 0;
	motif->evalue = 0.0;
	motif->num_sites = 0.0;
	motif->complexity = 0.0;
	motif->freqs = duplicate_matrix(freqs);
  motif->scores = NULL;
	// Set required fields.
	int length = strlen(id) + 1;
	strncpy(motif->id, id, min(length,MAX_MOTIF_ID_LENGTH));

	motif->alph_size = get_num_cols(motif->freqs);
	motif->length = get_num_rows(motif->freqs);
  motif->url = NULL;
  motif->trim_left = 0;
  motif->trim_right = 0;
	return motif;
}
示例#7
0
文件: pssm.c 项目: a1aks/Haystack
/**************************************************************************
*
	hash_pssm_matrix_pos

	Recursively create a single position of a hashed PSSM.

*
**************************************************************************/
static void hash_pssm_matrix_pos(
  MATRIX_T *pssm, 		// pssm to hash
  MATRIX_T *hashed_pssm, 	// hashed pssm
  int  pos,			// position in pssm
  int  hashed_pos,		// position in hashed pssm
  int  n,			// number of columns to hash together
  double score,			// cumulative score; call with 0
  int index			// cumulative index; call with 0
)
{
  int i;
  int alen = get_num_cols(pssm);	// alphabet length
  int w = get_num_rows(pssm);		// pssm width

  if (n==0) {				// done, set hashed_pssm entry
    set_matrix_cell(hashed_pos, index, score, hashed_pssm);
  } else {				// combine next column of pssm
    for (i=0; i<=alen; i++) {		// letters + blank
      // not past right edge of motif and not blank?
      double s = (pos<w && i!=alen) ? get_matrix_cell(pos, i, pssm) : 0;
      hash_pssm_matrix_pos(pssm,
		    hashed_pssm,
		    pos+1, 		// position in old pssm
		    hashed_pos, 	// position working on
		    n-1, 		// positions remaining to hash
		    score+s, 		// score so far
		    index*(alen+1)+i);	// hashed alphabet index so far
    } // leter
  }
} // hash_pssm_matrix_pos
示例#8
0
void check_sq_matrix(MATRIX_T *sq, int expected_size) {
  int i;
  assert(get_num_rows(sq) == expected_size);
  assert(get_num_cols(sq) == expected_size);
  for (i = 0; i < expected_size; ++i) {
    assert(get_array_length(get_matrix_row(i, sq)) == expected_size);
  }
}
示例#9
0
 void udoc_relation::expand_column_vector(unsigned_vector& v, const udoc_relation* other) const {
     unsigned_vector orig;
     orig.swap(v);
     for (unsigned i = 0; i < orig.size(); ++i) {
         unsigned col, limit;
         if (orig[i] < get_num_cols()) {
             col = column_idx(orig[i]);
             limit = col + column_num_bits(orig[i]);
         } else {
             unsigned idx = orig[i] - get_num_cols();
             col = get_num_bits() + other->column_idx(idx);
             limit = col + other->column_num_bits(idx);
         }
         for (; col < limit; ++col) {
             v.push_back(col);
         }
     }
 }
示例#10
0
文件: MtxLP.cpp 项目: kierzek/MUFINS
strvec MtxLP::getColNames(int kind) const{
    strvec rv;
    int ncols = get_num_cols();
    for (int i = 1; i <= ncols; i++){
        if (kind == getColKind(i))
            rv.push_back(get_col_name(i));
    }
    return rv;
}
示例#11
0
void
MILPP::initialize(int nr_cols, int nr_rows)
{
  cons_matrix_.resize(nr_rows, nr_cols);

  col_to_row_mapping_.resize(nr_cols);
  for (int i = 0; i < get_num_cols(); i++)
    {
      col_to_row_mapping_[i] = new set<int>();
    }
  row_to_col_mapping_.resize(nr_rows);
  for (int i = 0; i < get_num_rows(); i++)
    {
      row_to_col_mapping_[i] = new set<int>();
    }

  /* Compute problem parameters and set default values if required */
  obj_coefs_.resize(nr_cols);
  cols_lower_bounds_.resize(nr_cols);
  cols_upper_bounds_.resize(nr_cols);

  /* Allocate rows related variables */
  rows_lower_bounds_.resize(nr_rows);
  rows_upper_bounds_.resize(nr_rows);
  rows_senses_.resize(nr_rows);

  /* Initialize cols related arrays */
  for (int i = 0; i < get_num_cols(); i++)
    {
      set_col_lower_bound(i, 0.);
      set_col_upper_bound(i, 1.);
      set_obj_coef(i, 0.);
    }

  /* Initialize rows related arrays */
  for (int i = 0; i < get_num_rows(); i++)
    {
      set_row_lower_bound(i, 0.);
      /* The actual upper bound values will be assigned later. */
      set_row_upper_bound(i, 0.);
      /* Set default row sense */
      set_row_sense(i, ROW_SENSE_LOWER);
    }
}
void Board::display() const {
	for (int r = get_num_rows() - 1; r >= 0; r--) {
		std::cout << r << ":| ";
		for (int c = 0; c < get_num_cols(); c++) {
			std::cout << get_cell(c, r) << " ";
		}
		std::cout << std::endl;
	}
	std::cout << "   -";
	for (int c = 0; c < get_num_cols(); c++) {
		std::cout << "--";
	}
	std::cout << "\n";
	std::cout << "    ";
	for (int c = 0; c < get_num_cols(); c++) {
		std::cout << c << " ";
	}
	std::cout << "\n\n";
}
示例#13
0
 /**
  * If autoresize is enabled and col or row doesn't exist, the matrix
  * will be resized.
  */
 inline void set_coefficient(int i, int j, double v,
                             bool autoresize=true)
 {
   if (autoresize)
     {
       int nr = ((i + 1) > get_num_rows()) ? (i + 1) : -1;
       int nc = ((j + 1) > get_num_cols()) ? (j + 1) : -1;
       if (nr || nc)
         resize(nr, nc);
     }
   slave_matrix_.modifyCoefficient(i, j, v);
 }
示例#14
0
/**
 * Given a bg frequency matrix and a phospho count matrix, we will convert the bg
 * freq matrix into a binomial matrix. No reason to keep a bg freq matrix, so we will recycle.
 */
void convert_bg_freqs_to_binomial(MATRIX_T* phospho_count, MATRIX_T* bg_freqs, int num_phospho_seqs) {
  int i;
  int j;
  for (i = 0; i < get_num_rows(bg_freqs); ++i) {
    for (j = 0; j < get_num_cols(bg_freqs); ++j) {
      double p = get_matrix_cell_defcheck(i, j, bg_freqs);
      double cxj = get_matrix_cell_defcheck(i, j, phospho_count);
      int n = num_phospho_seqs;
      double log_value = log_betai(cxj, n-cxj+1, p);
      set_matrix_cell_defcheck(i, j, log_value, bg_freqs);
    }
  }
}
// function that adds twos around the movement range where a player can attack
// THIS FUNCTION ONLY WORKS PROPERLY FOR ATTACK RANGES 1 AND 2.
void Valid_board::add_attack_spots(int range){

  for(int i = 0; i < valid_tiles.size(); i++){		// nested loops go through each element
    for(int j = 0; j < valid_tiles[0].size(); j++){
      if(valid_tiles[i][j]==1){				// if the tile is a 1,
        for( int k = range; k >= 1; k--){		// for each time in the range
	// Checks k tiles in each of the four directions, and if the tile is a 0, makes it a 2 to indicate that you can attack there
          if(i-k >= 0 && valid_tiles[i-k][j] == 0) valid_tiles[i-k][j] = 2;
          if(i+k < get_num_rows() && valid_tiles[i+k][j] == 0) valid_tiles[i+k][j] = 2;
          if(j-k >= 0 && valid_tiles[i][j-k] == 0) valid_tiles[i][j-k] = 2;
          if(j+k < get_num_cols() && valid_tiles[i][j+k] == 0) valid_tiles[i][j+k] = 2;
        }
	// if the range is 2, you need to add diagonal spots as well
        if(range > 1){	
          if(i-1 >= 0 && j-1 >= 0 && valid_tiles[i-1][j-1] == 0) valid_tiles[i-1][j-1] = 2; 
          if(i-1 >= 0 && j+1 < get_num_cols() && valid_tiles[i-1][j+1] == 0) valid_tiles[i-1][j+1] = 2; 
          if(i+1 < get_num_rows() && j-1 >= 0 && valid_tiles[i+1][j-1] == 0) valid_tiles[i+1][j-1] = 2; 
          if(i+1 < get_num_rows() && j+1 < get_num_cols() && valid_tiles[i+1][j+1] == 0) valid_tiles[i+1][j+1] = 2; 
        }
      }
    }
  }
}
示例#16
0
 expr_ref udoc_relation::to_formula(tbv const& t) const {
     udoc_plugin& p = get_plugin();
     ast_manager& m = p.get_ast_manager();
     expr_ref result(m);
     expr_ref_vector conjs(m);
     for (unsigned i = 0; i < get_num_cols(); ++i) {
         var_ref v(m);
         v = m.mk_var(i, get_signature()[i]);
         unsigned lo = column_idx(i);
         unsigned hi = column_idx(i+1);
         rational r(0);
         unsigned lo1 = lo;
         bool is_x = true;
         for (unsigned j = lo; j < hi; ++j) {
             switch(t[j]) {
             case BIT_0:
                 if (is_x) is_x = false, lo1 = j, r.reset();
                 break;
             case BIT_1:
                 if (is_x) is_x = false, lo1 = j, r.reset();
                 r += rational::power_of_two(j - lo1);
                 break;
             case BIT_x:
                 if (!is_x) {
                     SASSERT(p.bv.is_bv_sort(get_signature()[i]));
                     conjs.push_back(m.mk_eq(p.bv.mk_extract(j-1-lo,lo1-lo,v),
                                             p.bv.mk_numeral(r,j-lo1)));
                 }
                 is_x = true;
                 break;
             default:
                 UNREACHABLE();
             }
         }
         if (!is_x) {
             expr_ref num(m);
             if (lo1 == lo) {
                 num = p.mk_numeral(r, get_signature()[i]);
                 conjs.push_back(m.mk_eq(v, num));
             }
             else {
                 num = p.bv.mk_numeral(r, hi-lo1);
                 conjs.push_back(m.mk_eq(p.bv.mk_extract(hi-1-lo,lo1-lo,v), num));
             }
         }
     }
     result = mk_and(m, conjs.size(), conjs.c_ptr());
     return result;
 }
示例#17
0
MILPP::MILPP(double* c, int nr_cols, double* A, int nr_rows,
             char* s, double* b)
{
  set_initial_data();
  initialize(nr_cols, nr_rows);

  /* Assign vector of coefficients for objective function */
  assign_obj_coefs(c);
  assign_rows_lower_bounds((double*)calloc(get_num_cols(), sizeof(double)));
  assign_rows_upper_bounds(b);

  assign_rows_senses(s);

  /* Fill the constraint matrix */
  for (size_t i = 0; i < get_num_rows(); i++)
    for (size_t j = 0; j < get_num_cols(); j++)
      {
        double v = (A + i * get_num_cols())[j];
        if (!v) continue;
        cons_matrix_.set_coefficient(i, j, v);
        col_to_row_mapping_[j]->insert(i);
        row_to_col_mapping_[i]->insert(j);
      }
}
示例#18
0
文件: command2.c 项目: darkael88/42sh
void	empty_command_line(void)
{
	int		i;

	i = 0;
	while (i < get_num_cols())
	{
		tputs(tgetstr("le", NULL), 1, t_write);
		i++;
	}
	tputs(tgetstr("nd", NULL), 1, t_write);
	tputs(tgetstr("nd", NULL), 1, t_write);
	tputs(tgetstr("nd", NULL), 1, t_write);
	tputs(tgetstr("ce", NULL), 1, t_write);
}
示例#19
0
void
MILPP::print()
{
  int i;
  int j;
  int offset;

  /* Print objective function sense and its coefficients */
  for (int i = 0; i < get_num_cols(); ++i)
    {
      if (i) printf(" + ");
      printf("%.1fx%d", get_obj_coef(i), i);
    }
  printf(" -> %s\n", obj_sense_to_string());
  /* Print constraints represented by rows */
  printf("subject to\n");
  for (i = 0; i < cons_matrix_.get_num_rows(); i++)
    {
      int t = 0; /* start from col zero */
      PackedVector* row = cons_matrix_.get_vector(i);
      printf("(%d) ", i);
      for (j = 0; j < row->get_num_elements(); j++)
        {
          if (j > 0)
            printf(" + ");
          //printf("[%d|%d]", row->get_index_by_pos(j), t);
          if ((offset = row->get_index_by_pos(j) - t) >= 1)
            {
              if (j > 0)
                offset -= 1;
              //printf("(%d)", offset);
              offset *= 5 + 3;
              for (int s = 0; s < offset; s++)
                printf(" ");
            }
          t = row->get_index_by_pos(j);

          printf("%.1fx%d", row->get_element_by_pos(j),
                 row->get_index_by_pos(j));
        }
      /* Print row sense */
      printf(" <= ");
      /* Print row upper bound */
      printf("%.1f", get_row_upper_bound(i));
      printf("\n");
    }

}
示例#20
0
文件: MtxLP.cpp 项目: kierzek/MUFINS
stomap* MtxLP::getRowSto(string name) const{
    stomap* rv = new stomap;
    int n = nrow(name);
    if (n == 0) throw runtime_error(name + ": no such row!");
    int len = get_num_cols();
    int *ind = new int[len + 1];
    double *val = new double[len + 1];
    len = get_mat_row(n, ind, val);

    for (int i = 1; i <= len; i++)
        (*rv)[get_col_name(ind[i])] = val[i];

    delete ind;
    delete val;

    return rv;
}
/******************************************************************************
  * This function returns a copy of the ith matrix of a transition matrix array.
  * Caller is responsible for freeing the returned copy.
******************************************************************************/
static MATRIX_T* get_substmatrix_matrix(
  SUBSTMATRIX_ARRAY_T *a, 
  int i
) {
  assert(a != NULL);
  assert(i < a->length);
  // Create a copy of our matrix
  MATRIX_T* src = a->substmatrix[i];
  MATRIX_T* dst = NULL;
  if (src != NULL) {
    int num_rows = get_num_rows(src);
    int num_cols = get_num_cols(src);
    dst = allocate_matrix(num_rows, num_cols);
    copy_matrix(src, dst);
  }
  return dst;
}
示例#22
0
/***********************************************************************
 * Converts a TRANSFAC motif to a MEME motif.
 * Caller is responsible for freeing the returned MOTIF_T.
 ***********************************************************************/
MOTIF_T *convert_transfac_motif_to_meme_motif(
    char *id,
    int pseudocount,
    ARRAY_T *bg,
    TRANSFAC_MOTIF_T *motif
) {
    MATRIX_T *counts = get_transfac_counts(motif);
    if (counts == NULL) {
        die(
            "Unable to convert TRANSFAC motif %s to MEME motif: "
            "missing counts matrix.",
            id
        );
    };

    // Convert the motif counts to frequencies.
    int num_bases = get_num_cols(counts);
    int motif_width = get_num_rows(counts);
    int motif_position = 0;
    MATRIX_T *freqs = allocate_matrix(motif_width, num_bases);
    for (motif_position = 0; motif_position < motif_width; ++motif_position) {
        int i_base = 0;
        int num_seqs = 0; // motif columns may have different counts
        for (i_base = 0; i_base < num_bases; i_base++) {
            num_seqs += get_matrix_cell(motif_position, i_base, counts);
        }
        for (i_base = 0; i_base < num_bases; i_base++) {
            double freq =
                (get_matrix_cell(motif_position, i_base, counts)
                 + (pseudocount * get_array_item(i_base, bg))) / (num_seqs + pseudocount);
            set_matrix_cell(motif_position, i_base, freq, freqs);
        }
    }

    MOTIF_T *meme_motif = allocate_motif(id, DNA_ALPH, NULL, freqs);
    calc_motif_ambigs(meme_motif);
    return meme_motif;
}
示例#23
0
文件: command2.c 项目: darkael88/42sh
void	clear_command_line(t_char *list)
{
	int		i;
	int		j;
	int		numcols;

	numcols = get_num_cols();
	j = 0;
	i = 0;
	while (list)
	{
		i++;
		list = list->next;
	}
	tputs(tgetstr("rc", NULL), 1, t_write);
	while (j <= (i + 3) / numcols)
	{
		tputs(tgetstr("ce", NULL), 1, t_write);
		if ((i + 3) > ((j + 1) * numcols))
			tputs(tgetstr("do", NULL), 1, t_write);
		j++;
	}
	tputs(tgetstr("rc", NULL), 1, t_write);
}
示例#24
0
文件: pmp_bf.c 项目: brsaran/FuzzyApp
/*************************************************************************
 * Entry point for pmp_bf
 *************************************************************************/
int main(int argc, char *argv[]) {

  char* bg_filename = NULL;
  char* motif_name = "motif"; // Use this motif name in the output.
  STRING_LIST_T* selected_motifs = NULL;
  double fg_rate = 1.0;
  double bg_rate = 1.0;
  double purine_pyrimidine = 1.0; // r
  double transition_transversion = 0.5; // R
  double pseudocount = 0.1;
  GAP_SUPPORT_T gap_support = SKIP_GAPS;
  MODEL_TYPE_T model_type = F81_MODEL;
  BOOLEAN_T use_halpern_bruno = FALSE;
  char* ustar_label = NULL;	// TLB; create uniform star tree
  int i;

  program_name = "pmp_bf";

  /**********************************************
   * COMMAND LINE PROCESSING
   **********************************************/

  // Define command line options. (FIXME: Repeated code)
  // FIXME: Note that if you add or remove options you
  // must change n_options.
  int n_options = 12;
  cmdoption const pmp_options[] = {
    {"hb", NO_VALUE},
    {"ustar", REQUIRED_VALUE},
    {"model", REQUIRED_VALUE},
    {"pur-pyr", REQUIRED_VALUE},
    {"transition-transversion", REQUIRED_VALUE},
    {"bg", REQUIRED_VALUE},
    {"fg", REQUIRED_VALUE},
    {"motif", REQUIRED_VALUE},
    {"motif-name", REQUIRED_VALUE},
    {"bgfile", REQUIRED_VALUE},
    {"pseudocount", REQUIRED_VALUE},
    {"verbosity", REQUIRED_VALUE}
  };

  int option_index = 0;

  // Define the usage message.
  char      usage[1000] = "";
  strcat(usage, "USAGE: pmp [options] <tree file> <MEME file>\n");
  strcat(usage, "\n");
  strcat(usage, "   Options:\n");

  // Evolutionary model parameters.
  strcat(usage, "     --hb\n");
  strcat(usage, "     --model single|average|jc|k2|f81|f84|hky|tn");
  strcat(usage, " (default=f81)\n");
  strcat(usage, "     --pur-pyr <float> (default=1.0)\n");
  strcat(usage, "     --transition-transversion <float> (default=0.5)\n");
  strcat(usage, "     --bg <float> (default=1.0)\n");
  strcat(usage, "     --fg <float> (default=1.0)\n");

  // Motif parameters.
  strcat(usage, "     --motif <id> (default=all)\n");
  strcat(usage, "     --motif-name <string> (default from motif file)\n");

  // Miscellaneous parameters
  strcat(usage, "     --bgfile <background> (default from motif file)\n");
  strcat(usage, "     --pseudocount <float> (default=0.1)\n");
  strcat(usage, "     --ustar <label>\n");	// TLB; create uniform star tree
  strcat(usage, "     --verbosity [1|2|3|4] (default 2)\n");
  strcat(usage, "\n    Prints the FP and FN rate at each of 10000 score values.\n");
  strcat(usage, "\n    Output format: [<motif_id> score <score> FPR <fpr> TPR <tpr>]+\n");

  // Parse the command line.
  if (simple_setopt(argc, argv, n_options, pmp_options) != NO_ERROR) {
    die("Error processing command line options: option name too long.\n");
  }

  while (TRUE) { 
    int c = 0;
    char* option_name = NULL;
    char* option_value = NULL;
    const char * message = NULL;

    // Read the next option, and break if we're done.
    c = simple_getopt(&option_name, &option_value, &option_index);
    if (c == 0) {
      break;
    } else if (c < 0) {
      (void) simple_getopterror(&message);
      die("Error processing command line options (%s)\n", message);
    }
    
    if (strcmp(option_name, "model") == 0) {
      if (strcmp(option_value, "jc") == 0) {
        model_type = JC_MODEL;
      } else if (strcmp(option_value, "k2") == 0) {
        model_type = K2_MODEL;
      } else if (strcmp(option_value, "f81") == 0) {
        model_type = F81_MODEL;
      } else if (strcmp(option_value, "f84") == 0) {
        model_type = F84_MODEL;
      } else if (strcmp(option_value, "hky") == 0) {
        model_type = HKY_MODEL;
      } else if (strcmp(option_value, "tn") == 0) {
        model_type = TAMURA_NEI_MODEL;
      } else if (strcmp(option_value, "single") == 0) {
        model_type = SINGLE_MODEL;
      } else if (strcmp(option_value, "average") == 0) {
        model_type = AVERAGE_MODEL;
      } else {
        die("Unknown model: %s\n", option_value);
      }
    } else if (strcmp(option_name, "hb") == 0){
        use_halpern_bruno = TRUE;
    } else if (strcmp(option_name, "ustar") == 0){	// TLB; create uniform star tree
        ustar_label = option_value;
    } else if (strcmp(option_name, "pur-pyr") == 0){
        purine_pyrimidine = atof(option_value);
    } else if (strcmp(option_name, "transition-transversion") == 0){
        transition_transversion = atof(option_value);
    } else if (strcmp(option_name, "bg") == 0){
      bg_rate = atof(option_value);
    } else if (strcmp(option_name, "fg") == 0){
      fg_rate = atof(option_value);
    } else if (strcmp(option_name, "motif") == 0){
        if (selected_motifs == NULL) {
          selected_motifs = new_string_list();
        }
       add_string(option_value, selected_motifs);
    } else if (strcmp(option_name, "motif-name") == 0){
        motif_name = option_value;
    } else if (strcmp(option_name, "bgfile") == 0){
      bg_filename = option_value;
    } else if (strcmp(option_name, "pseudocount") == 0){
        pseudocount = atof(option_value);
    } else if (strcmp(option_name, "verbosity") == 0){
        verbosity = atoi(option_value);
    }
  }

  // Must have tree and motif file names
  if (argc != option_index + 2) {
    fprintf(stderr, "%s", usage);
    exit(EXIT_FAILURE);
  } 

  /**********************************************
   * Read the phylogenetic tree.
   **********************************************/
  char* tree_filename = NULL;
  TREE_T* tree = NULL;
  tree_filename = argv[option_index];
  option_index++;
  tree = read_tree_from_file(tree_filename);

  // get the species names
  STRING_LIST_T* alignment_species = make_leaf_list(tree);
  char *root_label = get_label(tree);	// in case target in center
  if (strlen(root_label)>0) add_string(root_label, alignment_species);
  //write_string_list(" ", alignment_species, stderr);

  // TLB; Convert the tree to a uniform star tree with
  // the target sequence at its center.
  if (ustar_label != NULL) {
    tree = convert_to_uniform_star_tree(tree, ustar_label);
    if (tree == NULL) 
      die("Tree or alignment missing target %s\n", ustar_label);
    if (verbosity >= NORMAL_VERBOSE) {
      fprintf(stderr, 
	"Target %s placed at center of uniform (d=%.3f) star tree:\n", 
          ustar_label, get_total_length(tree) / get_num_children(tree) 
      );
      write_tree(tree, stderr);
    }
  }

  /**********************************************
   * Read the motifs.
   **********************************************/
  char* meme_filename = argv[option_index];
  option_index++;
  int num_motifs = 0; 

  MREAD_T *mread;
  ALPH_T alph;
  ARRAYLST_T *motifs;
  ARRAY_T *bg_freqs;

  mread = mread_create(meme_filename, OPEN_MFILE);
  mread_set_bg_source(mread, bg_filename);
  mread_set_pseudocount(mread, pseudocount);
  // read motifs
  motifs = mread_load(mread, NULL);
  alph = mread_get_alphabet(mread);
  bg_freqs = mread_get_background(mread);
  // check
  if (arraylst_size(motifs) == 0) die("No motifs in %s.", meme_filename);

  

  // TLB; need to resize bg_freqs array to ALPH_SIZE items
  // or copy array breaks in HB mode.  This throws away
  // the freqs for the ambiguous characters;
  int asize = alph_size(alph, ALPH_SIZE);
  resize_array(bg_freqs, asize);

  /**************************************************************
  * Compute probability distributions for each of the selected motifs.
  **************************************************************/
  int motif_index;
  for (motif_index = 0; motif_index < arraylst_size(motifs); motif_index++) {

    MOTIF_T* motif = (MOTIF_T*)arraylst_get(motif_index, motifs);
    char* motif_id = get_motif_id(motif);
    char* bare_motif_id = motif_id;

    // We may have specified on the command line that
    // only certain motifs were to be used.
    if (selected_motifs != NULL) {
      if (*bare_motif_id == '+' || *bare_motif_id == '-') {
        // The selected  motif id won't included a strand indicator.
        bare_motif_id++;
      }
      if (have_string(bare_motif_id, selected_motifs) == FALSE) {
        continue;
      }
    }

    if (verbosity >= NORMAL_VERBOSE) {
      fprintf(
        stderr, 
        "Using motif %s of width %d.\n",
        motif_id, get_motif_length(motif)
      );
    }

    // Build an array of evolutionary models for each position in the motif.
    EVOMODEL_T** models = make_motif_models(
      motif, 
      bg_freqs,
      model_type,
      fg_rate, 
      bg_rate, 
      purine_pyrimidine, 
      transition_transversion, 
      use_halpern_bruno
    );

    // Get the frequencies under the background model (row 0) 
    // and position-dependent scores (rows 1..w)
    // for each possible alignment column.
    MATRIX_T* pssm_matrix = build_alignment_pssm_matrix(
      alph,
      alignment_species,
      get_motif_length(motif) + 1, 
      models, 
      tree, 
      gap_support
    );
    ARRAY_T* alignment_col_freqs = allocate_array(get_num_cols(pssm_matrix)); 
    copy_array(get_matrix_row(0, pssm_matrix), alignment_col_freqs);
    remove_matrix_row(0, pssm_matrix);		// throw away first row
    //print_col_frequencies(alph, alignment_col_freqs);

    //
    // Get the position-dependent null model alignment column frequencies
    //
    int w = get_motif_length(motif);
    int ncols = get_num_cols(pssm_matrix); 
    MATRIX_T* pos_dep_bkg = allocate_matrix(w, ncols);
    for (i=0; i<w; i++) {
      // get the evo model corresponding to this column of the motif
      // and store it as the first evolutionary model.
      myfree(models[0]);
      // Use motif PSFM for equilibrium freqs. for model.
      ARRAY_T* site_specific_freqs = allocate_array(asize);
      int j = 0;
      for(j = 0; j < asize; j++) {
	double value = get_matrix_cell(i, j, get_motif_freqs(motif));
	set_array_item(j, value, site_specific_freqs);
      }
      if (use_halpern_bruno == FALSE) {
	models[0] = make_model(
	  model_type,
	  fg_rate,
	  transition_transversion,
	  purine_pyrimidine,
	  site_specific_freqs,
          NULL
	);
      } else {
        models[0] = make_model(
	  model_type,
	  fg_rate,
	  transition_transversion,
	  purine_pyrimidine,
	  bg_freqs,
	  site_specific_freqs
	);
      }
      // get the alignment column frequencies using this model
      MATRIX_T* tmp_pssm_matrix = build_alignment_pssm_matrix(
        alph,
	alignment_species,
	2,				// only interested in freqs under bkg
	models, 
	tree, 
	gap_support
      );
      // assemble the position-dependent background alignment column freqs.
      set_matrix_row(i, get_matrix_row(0, tmp_pssm_matrix), pos_dep_bkg);
      // chuck the pssm (not his real name)
      free_matrix(tmp_pssm_matrix);
    }

    //
    // Compute and print the score distribution under the background model
    // and under the (position-dependent) motif model.
    //
    int range = 10000;	// 10^4 gives same result as 10^5, but 10^3 differs

    // under background model
    PSSM_T* pssm = build_matrix_pssm(alph, pssm_matrix, alignment_col_freqs, range);

    // under position-dependent background (motif) model
    PSSM_T* pssm_pos_dep = build_matrix_pssm(alph, pssm_matrix, alignment_col_freqs, range);
    get_pv_lookup_pos_dep(
      pssm_pos_dep, 
      pos_dep_bkg, 
      NULL // no priors used
    );

    // print FP and FN distributions
    int num_items = get_pssm_pv_length(pssm_pos_dep);
    for (i=0; i<num_items; i++) {
      double pvf = get_pssm_pv(i, pssm);
      double pvt = get_pssm_pv(i, pssm_pos_dep);
      double fpr = pvf;
      double fnr = 1 - pvt;
      if (fpr >= 0.99999 || fnr == 0) continue;
      printf("%s score %d FPR %.3g FNR %.3g\n", motif_id, i, fpr, fnr);
    }

    // free stuff
    free_pssm(pssm);
    free_pssm(pssm_pos_dep);
    if (models != NULL) {
      int model_index;
      int num_models = get_motif_length(motif) + 1;
      for (model_index = 0; model_index < num_models; model_index++) {
        free_model(models[model_index]);
      }
      myfree(models);
    }

  } // motif

  arraylst_destroy(destroy_motif, motifs);

  /**********************************************
   * Clean up.
   **********************************************/
  // TLB may have encountered a memory corruption bug here
  // CEG has not been able to reproduce it. valgrind says all is well.
  free_array(bg_freqs);
  free_tree(TRUE, tree);
  free_string_list(selected_motifs);

  return(0);
} // main
示例#25
0
void change_columns(int sig)
{
	columns = get_num_cols();
}
示例#26
0
int main(int argc, const char **argv)
{
	int resume = 0, recursive = 0;
	int c = 0;
	int debuglevel = 0;
	const char *file = NULL;
	char *rcfile = NULL;
	char *outputfile = NULL;
	struct poptOption long_options[] = {
		{"guest", 'a', POPT_ARG_NONE, NULL, 'a', "Work as user guest" },	
		{"resume", 'r', POPT_ARG_NONE, &resume, 0, "Automatically resume aborted files" },
		{"recursive", 'R',  POPT_ARG_NONE, &recursive, 0, "Recursively download files" },
		{"username", 'u', POPT_ARG_STRING, &username, 'u', "Username to use" },
		{"password", 'p', POPT_ARG_STRING, &password, 'p', "Password to use" },
		{"workgroup", 'w', POPT_ARG_STRING, &workgroup, 'w', "Workgroup to use (optional)" },
		{"nonprompt", 'n', POPT_ARG_NONE, &nonprompt, 'n', "Don't ask anything (non-interactive)" },
		{"debuglevel", 'd', POPT_ARG_INT, &debuglevel, 'd', "Debuglevel to use" },
		{"outputfile", 'o', POPT_ARG_STRING, &outputfile, 'o', "Write downloaded data to specified file" },
		{"dots", 'D', POPT_ARG_NONE, &dots, 'D', "Show dots as progress indication" },
		{"quiet", 'q', POPT_ARG_NONE, &quiet, 'q', "Be quiet" },
		{"verbose", 'v', POPT_ARG_NONE, &verbose, 'v', "Be verbose" },
		{"keep-permissions", 'P', POPT_ARG_NONE, &keep_permissions, 'P', "Keep permissions" },
		{"blocksize", 'b', POPT_ARG_INT, &blocksize, 'b', "Change number of bytes in a block"},
		{"rcfile", 'f', POPT_ARG_STRING, NULL, 0, "Use specified rc file"},
		POPT_AUTOHELP
		POPT_TABLEEND
	};
	poptContext pc;

	/* only read rcfile if it exists */
	asprintf(&rcfile, "%s/.smbgetrc", getenv("HOME"));
	if(access(rcfile, F_OK) == 0) readrcfile(rcfile, long_options);
	free(rcfile);

#ifdef SIGWINCH
	signal(SIGWINCH, change_columns);
#endif
	signal(SIGINT, signal_quit);
	signal(SIGTERM, signal_quit);

	pc = poptGetContext(argv[0], argc, argv, long_options, 0);

	while((c = poptGetNextOpt(pc)) >= 0) {
		switch(c) {
		case 'f':
			readrcfile(poptGetOptArg(pc), long_options);
			break;
		case 'a':
			username = ""; password = "";
			break;
		}
	}

	if(outputfile && recursive) {
		fprintf(stderr, "The -o and -R options can not be used together.\n");
		return 1;
	}

	if(smbc_init(get_auth_data, debuglevel) < 0) {
		fprintf(stderr, "Unable to initialize libsmbclient\n");
		return 1;
	}

	columns = get_num_cols();

	total_start_time = time(NULL);

	while((file = poptGetArg(pc))) {
		if(!recursive) return smb_download_file(file, "", recursive, resume, outputfile);
		else return smb_download_dir(file, "", resume);
	}

	clean_exit();

	return 0;
}
示例#27
0
文件: MtxLP.cpp 项目: kierzek/MUFINS
int MtxLP::getNumCols() const{
    return get_num_cols();
}
示例#28
0
文件: MtxLP.cpp 项目: kierzek/MUFINS
void MtxLP::setObjective(double coef){
    int ncols = get_num_cols();
    for (int i = 1; i <= ncols; i++)
        set_obj_coef(i, coef);
}
示例#29
0
文件: MtxLP.cpp 项目: kierzek/MUFINS
void MtxLP::emptyObjective(){
    int ncols = get_num_cols();
    for (int i = 1; i <= ncols; i++)
        set_obj_coef(i, 0.0);
}
示例#30
0
文件: smbget.c 项目: 0x24bin/winexe-1
int main(int argc, const char **argv)
{
	int c = 0;
	const char *file = NULL;
	char *rcfile = NULL;
	bool smb_encrypt = false;
	int resume = 0, recursive = 0;
	TALLOC_CTX *frame = talloc_stackframe();
	struct poptOption long_options[] = {
		{"guest", 'a', POPT_ARG_NONE, NULL, 'a', "Work as user guest" },	
		{"encrypt", 'e', POPT_ARG_NONE, NULL, 'e', "Encrypt SMB transport (UNIX extended servers only)" },	
		{"resume", 'r', POPT_ARG_NONE, &resume, 0, "Automatically resume aborted files" },
		{"update", 'U',  POPT_ARG_NONE, &update, 0, "Download only when remote file is newer than local file or local file is missing"},
		{"recursive", 'R',  POPT_ARG_NONE, &recursive, 0, "Recursively download files" },
		{"username", 'u', POPT_ARG_STRING, &username, 'u', "Username to use" },
		{"password", 'p', POPT_ARG_STRING, &password, 'p', "Password to use" },
		{"workgroup", 'w', POPT_ARG_STRING, &workgroup, 'w', "Workgroup to use (optional)" },
		{"nonprompt", 'n', POPT_ARG_NONE, &nonprompt, 'n', "Don't ask anything (non-interactive)" },
		{"debuglevel", 'd', POPT_ARG_INT, &debuglevel, 'd', "Debuglevel to use" },
		{"outputfile", 'o', POPT_ARG_STRING, &outputfile, 'o', "Write downloaded data to specified file" },
		{"stdout", 'O', POPT_ARG_NONE, &send_stdout, 'O', "Write data to stdout" },
		{"dots", 'D', POPT_ARG_NONE, &dots, 'D', "Show dots as progress indication" },
		{"quiet", 'q', POPT_ARG_NONE, &quiet, 'q', "Be quiet" },
		{"verbose", 'v', POPT_ARG_NONE, &verbose, 'v', "Be verbose" },
		{"keep-permissions", 'P', POPT_ARG_NONE, &keep_permissions, 'P', "Keep permissions" },
		{"blocksize", 'b', POPT_ARG_INT, &blocksize, 'b', "Change number of bytes in a block"},
		{"rcfile", 'f', POPT_ARG_STRING, NULL, 'f', "Use specified rc file"},
		POPT_AUTOHELP
		POPT_TABLEEND
	};
	poptContext pc;

	load_case_tables();

	/* only read rcfile if it exists */
	if (asprintf(&rcfile, "%s/.smbgetrc", getenv("HOME")) == -1) {
		return 1;
	}
	if(access(rcfile, F_OK) == 0) 
		readrcfile(rcfile, long_options);
	free(rcfile);

#ifdef SIGWINCH
	signal(SIGWINCH, change_columns);
#endif
	signal(SIGINT, signal_quit);
	signal(SIGTERM, signal_quit);

	pc = poptGetContext(argv[0], argc, argv, long_options, 0);

	while((c = poptGetNextOpt(pc)) >= 0) {
		switch(c) {
		case 'f':
			readrcfile(poptGetOptArg(pc), long_options);
			break;
		case 'a':
			username = ""; password = "";
			break;
		case 'e':
			smb_encrypt = true;
			break;
		}
	}

	if((send_stdout || resume || outputfile) && update) {
		fprintf(stderr, "The -o, -R or -O and -U options can not be used together.\n");
		return 1;
	}
	if((send_stdout || outputfile) && recursive) {
		fprintf(stderr, "The -o or -O and -R options can not be used together.\n");
		return 1;
	}

	if(outputfile && send_stdout) {
		fprintf(stderr, "The -o and -O options cannot be used together.\n");
		return 1;
	}

	if(smbc_init(get_auth_data, debuglevel) < 0) {
		fprintf(stderr, "Unable to initialize libsmbclient\n");
		return 1;
	}

	if (smb_encrypt) {
		SMBCCTX *smb_ctx = smbc_set_context(NULL);
		smbc_option_set(smb_ctx,
			CONST_DISCARD(char *, "smb_encrypt_level"),
			"require");
	}
	
	columns = get_num_cols();

	total_start_time = time(NULL);

	while ( (file = poptGetArg(pc)) ) {
		if (!recursive) 
			return smb_download_file(file, "", recursive, resume, outputfile);
		else 
			return smb_download_dir(file, "", resume);
	}

	clean_exit();
	TALLOC_FREE(frame);
	return 0;
}