Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose a bit more of the CRAM API. #1429

Merged
merged 1 commit into from
Jun 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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, hts_pos_t *start, hts_pos_t *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, hts_pos_t *start, hts_pos_t *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