sam.c
/***************************************************************************
 *  Library:
 *      #include <biolibc/sam.h>
 *      -lbiolibc -lxtend
 *
 *  Description:
 *      Copy a SAM alignment as efficiently as possible, allocating memory
 *      as needed.
 *
 *  Arguments:
 *      dest    Pointer to bl_sam_t structure to receive copy
 *      src     Pointer to bl_sam_t structure to be copied
 *
 *  See also:
 *      bl_sam_read(3), bl_sam_init(3), bl_sam_free(3)
 *
 *  History: 
 *  Date        Name        Modification
 *  2020-05-27  Jason Bacon Begin
 ***************************************************************************/
#include 
-lbiolibc -lxtend

Copy a SAM alignment as efficiently as possible, allocating memory
as needed.

dest    Pointer to bl_sam_t structure to receive copy
src     Pointer to bl_sam_t structure to be copied



Date        Name        Modification
2020-05-27  Jason Bacon Begin
#include - lbiolibc - lxtend Copy a SAM alignment as efficiently as possible allocating memory as needed . dest Pointer to bl_sam_t structure to receive copy src Pointer to bl_sam_t structure to be copied Date Name Modification 2020 - 05 - 27 Jason Bacon Begin
void    bl_sam_copy(bl_sam_t *dest, bl_sam_t *src)
{
    strlcpy(dest->qname, src->qname, BL_SAM_QNAME_MAX_CHARS + 1);
    dest->flag = src->flag;
    strlcpy(dest->rname, src->rname, BL_SAM_RNAME_MAX_CHARS + 1);
    dest->pos = src->pos;
    dest->mapq = src->mapq;
    if ( src->cigar != NULL )
    {
	dest->cigar = strdup(src->cigar);
	if ( dest->cigar == NULL )
	{
	    fprintf(stderr, "bl_sam_copy(): Could not allocate cigar.\n");
	    exit(EX_UNAVAILABLE);
	}
	dest->cigar_array_size = src->cigar_len + 1;
	dest->cigar_len = src->cigar_len;
    }
    dest->cigar_array_size = src->cigar_array_size;
    dest->cigar_len = src->cigar_len;
    strlcpy(dest->rnext, src->rnext, BL_SAM_RNAME_MAX_CHARS + 1);
    dest->pnext = src->pnext;
    dest->tlen = src->tlen;
    if ( src->seq != NULL )
    {
	if ( (dest->seq = strdup(src->seq)) == NULL )
	{
	    fprintf(stderr, "bl_sam_copy(): Could not allocate seq.\n");
	    exit(EX_UNAVAILABLE);
	}
	dest->seq_array_size = src->seq_len + 1;
	dest->seq_len = src->seq_len;
    }
    dest->seq_array_size = src->seq_array_size;
    dest->seq_len = src->seq_len;
    if ( src->qual != NULL )
    {
	if ( (dest->qual = strdup(src->qual)) == NULL )
	{
	    fprintf(stderr, "bl_sam_copy(): Could not allocate qual.\n");
	    exit(EX_UNAVAILABLE);
	}
	dest->qual_array_size = src->qual_len + 1;
	dest->qual_len = src->qual_len;
    }
    dest->qual_array_size = src->qual_array_size;
    dest->qual_len = src->qual_len;
}
void bl_sam_copy ( bl_sam_t * dest , bl_sam_t * src ) { strlcpy ( dest -> qname , src -> qname , BL_SAM_QNAME_MAX_CHARS + 1 ) ; dest -> flag = src -> flag ; strlcpy ( dest -> rname , src -> rname , BL_SAM_RNAME_MAX_CHARS + 1 ) ; dest -> pos = src -> pos ; dest -> mapq = src -> mapq ; if ( src -> cigar != NULL ) { dest -> cigar = strdup ( src -> cigar ) ; if ( dest -> cigar == NULL ) { fprintf ( stderr , " \n " ) ; exit ( EX_UNAVAILABLE ) ; } dest -> cigar_array_size = src -> cigar_len + 1 ; dest -> cigar_len = src -> cigar_len ; } dest -> cigar_array_size = src -> cigar_array_size ; dest -> cigar_len = src -> cigar_len ; strlcpy ( dest -> rnext , src -> rnext , BL_SAM_RNAME_MAX_CHARS + 1 ) ; dest -> pnext = src -> pnext ; dest -> tlen = src -> tlen ; if ( src -> seq != NULL ) { if ( ( dest -> seq = strdup ( src -> seq ) ) == NULL ) { fprintf ( stderr , " \n " ) ; exit ( EX_UNAVAILABLE ) ; } dest -> seq_array_size = src -> seq_len + 1 ; dest -> seq_len = src -> seq_len ; } dest -> seq_array_size = src -> seq_array_size ; dest -> seq_len = src -> seq_len ; if ( src -> qual != NULL ) { if ( ( dest -> qual = strdup ( src -> qual ) ) == NULL ) { fprintf ( stderr , " \n " ) ; exit ( EX_UNAVAILABLE ) ; } dest -> qual_array_size = src -> qual_len + 1 ; dest -> qual_len = src -> qual_len ; } dest -> qual_array_size = src -> qual_array_size ; dest -> qual_len = src -> qual_len ; }
Library:
      #include <biolibc/sam.h>
      -lbiolibc -lxtend
Library : #include <biolibc / sam . h > - lbiolibc - lxtend
//fprintf(stderr, "src->seq = %s %zu\n", src->seq, src->seq_len); //fprintf(stderr, "src->qual = %s %zu\n", src->qual, src->qual_len); /*
     *  qual is an optional field.  If skipped using tsv_skip_field()
     *  qual_len will be non-zero, but qual will be NULL.
     */