Skip to content

Commit

Permalink
Expose a bit more of the CRAM API.
Browse files Browse the repository at this point in the history
This is to enable samtools cram2ref.
  • Loading branch information
jkbonfield committed May 27, 2022
1 parent 008eabd commit cc43900
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
13 changes: 13 additions & 0 deletions cram/cram_external.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,19 @@ int32_t cram_slice_hdr_get_num_blocks(cram_block_slice_hdr *hdr) {
return hdr->num_blocks;
}

int cram_slice_hdr_get_embed_ref_id(cram_block_slice_hdr *h) {
return h->ref_base_id;
}

void cram_slice_hdr_get_coords(cram_block_slice_hdr *h,
int *refid, int *start, int *span) {
if (refid)
*refid = h->ref_seq_id;
if (start)
*start = h->ref_seq_start;
if (span)
*span = h->ref_seq_span;
}

/*
*-----------------------------------------------------------------------------
Expand Down
40 changes: 40 additions & 0 deletions htslib/cram.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,46 @@ int cram_transcode_rg(cram_fd *in, cram_fd *out,
HTSLIB_EXPORT
int cram_copy_slice(cram_fd *in, cram_fd *out, int32_t num_slice);

/*
*-----------------------------------------------------------------------------
* cram slice interrogation
*/

/*
* Returns the number of cram blocks within this slice.
*/
HTSLIB_EXPORT
int32_t cram_slice_hdr_get_num_blocks(cram_block_slice_hdr *hdr);

/*
* Returns the block content_id for the block containing an embedded reference
* sequence. If none is present, -1 is returned.
*/
HTSLIB_EXPORT
int cram_slice_hdr_get_embed_ref_id(cram_block_slice_hdr *h);

/*
* Returns slice reference ID, start and span (length) coordinates.
* Return parameters may be NULL in which case they are ignored.
*/
HTSLIB_EXPORT
void cram_slice_hdr_get_coords(cram_block_slice_hdr *h,
int *refid, int *start, int *span);

/*
* Decodes a slice header from a cram block.
* Returns the opaque cram_block_slice_hdr pointer on success,
* NULL on failure.
*/
HTSLIB_EXPORT
cram_block_slice_hdr *cram_decode_slice_header(cram_fd *fd, cram_block *b);

/*
* Frees a cram_block_slice_hdr structure.
*/
HTSLIB_EXPORT
void cram_free_slice_header(cram_block_slice_hdr *hdr);

/*
*-----------------------------------------------------------------------------
* cram_io basics
Expand Down

0 comments on commit cc43900

Please sign in to comment.