Esempio n. 1
0
entry_t copy_entry(entry_t other){

    entry_t r = NULL;
    if(other == NULL){
    
        return NULL;
    }
    switch(other->type_tag){
        case ENTRY_INT:
            r = new_entry_int(
                    other->e.scalar_int, 
                    other->name);
            break;
	    case ENTRY_STR:
	        r = new_entry_str(
                    other->e.scalar_str, 
                    other->name);
	        break;
	    case ENTRY_MAP:
	        r = new_entry_map(copy_config(other->e.conf), other->name);
	        
	        break;
	    case ENTRY_SEQ:
	        r = new_entry_seq(copy_sequence(other->e.seq), other->name);
	        break;
        default: //NULL
            r = new_entry_null();
    }
    return r;
}
Esempio n. 2
0
/* make a copy for editing sequence in sequences array */
int make_copy_for_editor (int seq_id) {

    int num_seq;
    num_seq = sequences->num_seq;
    
    sequences = realloc_sequences (sequences, num_seq);    
    sequences->sequence[num_seq] = copy_sequence (sequences->sequence[seq_id]);
    extend_unique_name (sequences->sequence[num_seq]);
    sequences->num_seq ++;
    return  num_seq;
}
Esempio n. 3
0
/****************************************************************************
 * Remove from an alignment any sequence whose ID is not in a given list.
 *
 * N.B. It is NOT an error for the given list to contain sequence IDs that 
 * are not in the alignment.
 ****************************************************************************/
ALIGNMENT_T* remove_alignment_seqs
  (STRING_LIST_T* seqs_to_keep,
   ALIGNMENT_T*   alignment)
{
  // Extract the names of the sequences in the alignment.
  STRING_LIST_T* alignment_species = get_species_names(alignment);
  int num_species = get_num_strings(alignment_species);

  // Count how many sequences will be in the new alignment.
  int i_species;
  int num_final = 0;
  for (i_species = 0; i_species < num_species; i_species++) {
    char* this_species = get_nth_string(i_species, alignment_species);

    if (have_string(this_species, seqs_to_keep)) {
      num_final++;
    } else {
      if (verbosity >= NORMAL_VERBOSE) {
        fprintf(stderr, "Removing %s from alignment.\n", this_species);
      }
    }
  }

  // Allocate space for the new sequences.
  SEQ_T** new_sequences = (SEQ_T**)mm_malloc(num_final * sizeof(SEQ_T*));

  // Copy the sequences.
  int final_index = 0;
  num_species = get_num_strings(seqs_to_keep);
  for (i_species = 0; i_species < num_species; i_species++) {
    char* this_species = get_nth_string(i_species, seqs_to_keep);

    // If the requested ID is in the alignment, then copy over the sequence.
    if (have_string(this_species, alignment_species)) {
      SEQ_T* this_seq 
	= get_alignment_sequence_by_name(this_species, alignment);
      new_sequences[final_index] = copy_sequence(this_seq);
      final_index++;
    }
  }

  // Allocate and return the new alignment.
  
  char *consensus = NULL;
  copy_string(&consensus, get_consensus_string(alignment));
  ALIGNMENT_T* new_alignment
    = allocate_alignment(get_alignment_name(alignment),
			 get_alignment_description(alignment),
			 num_final,
			 new_sequences,
			 consensus);

  return(new_alignment);
}
Esempio n. 4
0
int save_change_to_sequence (int seq_id, SEQUENCE *s) {

    int i, num_seq;
    num_seq = sequences->num_seq;

    for (i = 0; i < num_seq; i++) {
	if (seq_id == sequences->sequence[i]->id) {
	    free_sequence (sequences->sequence[i]);
	    sequences->sequence[i] = copy_sequence (s);
	    if (sequences->sequence[i] == NULL) return -1;
	}
    }
    return 0;
}