deps/kb_meme/meme-5.0.1/src/seq.c
/**************************************************************************
 * Copy a sequence object.  Memory must be freed by caller.
 **************************************************************************/
Copy a sequence object.  Memory must be freed by caller.
Copy a sequence object . Memory must be freed by caller .
SEQ_T *copy_sequence
  (SEQ_T *source_sequence)
{
  SEQ_T* new_sequence;
  new_sequence = (SEQ_T*)mm_malloc(sizeof(SEQ_T));
  strncpy(new_sequence->name, source_sequence->name, MAX_SEQ_NAME);
  new_sequence->name[MAX_SEQ_NAME] = '\0';
  strncpy(new_sequence->desc, source_sequence->desc, MAX_SEQ_COMMENT);
  new_sequence->desc[MAX_SEQ_COMMENT] = '\0';
  new_sequence->starting_coord = source_sequence->starting_coord;
  new_sequence->length = source_sequence->length;
  new_sequence->offset = source_sequence->offset;
  new_sequence->weight = source_sequence->weight;
  new_sequence->is_complete = source_sequence->is_complete;
  new_sequence->num_priors = source_sequence->num_priors;
  if (source_sequence->sequence != NULL) {
    new_sequence->sequence = mm_malloc(sizeof(char) * (source_sequence->length + 1));
    memcpy(new_sequence->sequence, source_sequence->sequence, (sizeof(char) * source_sequence->length));
    new_sequence->sequence[source_sequence->length] = '\0';
  } else {
    new_sequence->sequence = NULL;
  }
  if (source_sequence->isequence != NULL) {
    new_sequence->isequence = mm_malloc(sizeof(int8_t) * source_sequence->length);
    memcpy(new_sequence->isequence, source_sequence->isequence, (sizeof(int8_t) * source_sequence->length));
  } else {
    new_sequence->isequence = NULL;
  }
  if (source_sequence->intseq != NULL) {
    new_sequence->intseq = (int*)mm_malloc(sizeof(int) * source_sequence->length);
    memcpy(new_sequence->intseq, source_sequence->intseq, (sizeof(int) * source_sequence->length));
  } else {
    new_sequence->intseq = NULL;
  }
  if (source_sequence->gc != NULL) {
    new_sequence->gc = (int*)mm_malloc(sizeof(int) * source_sequence->length);
    memcpy(new_sequence->gc, source_sequence->gc, (sizeof(int) * source_sequence->length));
  } else {
    source_sequence->gc = NULL;
  }
  if (source_sequence->priors && source_sequence->num_priors > 0) {
    new_sequence->priors = mm_malloc(sizeof(double) * source_sequence->num_priors);
    memcpy(new_sequence->priors, source_sequence->priors, (sizeof(double) * source_sequence->num_priors));
  } else {
    new_sequence->priors = NULL;
  }
  return(new_sequence);
}
SEQ_T * copy_sequence ( SEQ_T * source_sequence ) { SEQ_T * new_sequence ; new_sequence = ( SEQ_T * ) mm_malloc ( sizeof ( SEQ_T ) ) ; strncpy ( new_sequence -> name , source_sequence -> name , MAX_SEQ_NAME ) ; new_sequence -> name [ MAX_SEQ_NAME ] = ' \0 ' ; strncpy ( new_sequence -> desc , source_sequence -> desc , MAX_SEQ_COMMENT ) ; new_sequence -> desc [ MAX_SEQ_COMMENT ] = ' \0 ' ; new_sequence -> starting_coord = source_sequence -> starting_coord ; new_sequence -> length = source_sequence -> length ; new_sequence -> offset = source_sequence -> offset ; new_sequence -> weight = source_sequence -> weight ; new_sequence -> is_complete = source_sequence -> is_complete ; new_sequence -> num_priors = source_sequence -> num_priors ; if ( source_sequence -> sequence != NULL ) { new_sequence -> sequence = mm_malloc ( sizeof ( char ) * ( source_sequence -> length + 1 ) ) ; memcpy ( new_sequence -> sequence , source_sequence -> sequence , ( sizeof ( char ) * source_sequence -> length ) ) ; new_sequence -> sequence [ source_sequence -> length ] = ' \0 ' ; } else { new_sequence -> sequence = NULL ; } if ( source_sequence -> isequence != NULL ) { new_sequence -> isequence = mm_malloc ( sizeof ( int8_t ) * source_sequence -> length ) ; memcpy ( new_sequence -> isequence , source_sequence -> isequence , ( sizeof ( int8_t ) * source_sequence -> length ) ) ; } else { new_sequence -> isequence = NULL ; } if ( source_sequence -> intseq != NULL ) { new_sequence -> intseq = ( int * ) mm_malloc ( sizeof ( int ) * source_sequence -> length ) ; memcpy ( new_sequence -> intseq , source_sequence -> intseq , ( sizeof ( int ) * source_sequence -> length ) ) ; } else { new_sequence -> intseq = NULL ; } if ( source_sequence -> gc != NULL ) { new_sequence -> gc = ( int * ) mm_malloc ( sizeof ( int ) * source_sequence -> length ) ; memcpy ( new_sequence -> gc , source_sequence -> gc , ( sizeof ( int ) * source_sequence -> length ) ) ; } else { source_sequence -> gc = NULL ; } if ( source_sequence -> priors && source_sequence -> num_priors > 0 ) { new_sequence -> priors = mm_malloc ( sizeof ( double ) * source_sequence -> num_priors ) ; memcpy ( new_sequence -> priors , source_sequence -> priors , ( sizeof ( double ) * source_sequence -> num_priors ) ) ; } else { new_sequence -> priors = NULL ; } return ( new_sequence ) ; }
Copy a sequence object.
Copy a sequence object .
// Allocate the sequence object. // Store the name // moving from one buffer to another of identical size so no truncation // Store the description // moving from one buffer to another of identical size so no truncation // Fill in the always set fields // copy over the sequence (note that either this or the isequence will be present) // copy over the isequence (note that either this or the sequence will be present) // copy over the int sequence (this may be present, used by mhmm code,  // required to be int so that hashing of multiple characters can be done) // copy over the gc count (this may be present, used by mhmm code) // copy over the priors