-
Notifications
You must be signed in to change notification settings - Fork 442
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
Add method sam_open_write #1055
Open
valeriuo
wants to merge
2
commits into
samtools:develop
Choose a base branch
from
valeriuo:split-tag_2
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -894,7 +894,9 @@ int bam_index_build(const char *fn, int min_shift) | |
// Initialise fp->idx for the current format type. | ||
// This must be called after the header has been written but no other data. | ||
int sam_idx_init(htsFile *fp, sam_hdr_t *h, int min_shift, const char *fnidx) { | ||
fp->fnidx = fnidx; | ||
fp->fnidx = strdup(fnidx); | ||
if (!fp->fnidx) return -1; | ||
|
||
if (fp->format.format == bam || fp->format.format == bcf || | ||
(fp->format.format == sam && fp->format.compression == bgzf)) { | ||
int n_lvls, fmt = HTS_FMT_CSI; | ||
|
@@ -1671,6 +1673,30 @@ int sam_hdr_write(htsFile *fp, const sam_hdr_t *h) | |
return 0; | ||
} | ||
|
||
htsFile *sam_open_write(const char *fn, sam_hdr_t *hdr, const char *mode, const htsFormat *fmt) { | ||
htsFile *sf = NULL; | ||
if (fn && mode) { | ||
if (strchr(mode, 'w')) { | ||
sf = hts_open_format(fn, mode, fmt); | ||
if (sf) { | ||
if (sam_hdr_write(sf, hdr) < 0) { | ||
hts_log_error("Writing header to file \"%s\" failed", fn); | ||
sam_close(sf); | ||
sf = NULL; | ||
} else { | ||
if (sf->bam_header) | ||
sam_hdr_destroy(sf->bam_header); | ||
sf->bam_header = hdr; | ||
} | ||
} | ||
} else { | ||
hts_log_error("Only write mode allowed"); | ||
} | ||
} | ||
|
||
return sf; | ||
} | ||
|
||
static int old_sam_hdr_change_HD(sam_hdr_t *h, const char *key, const char *val) | ||
{ | ||
char *p, *q, *beg = NULL, *end = NULL, *newtext; | ||
|
@@ -3192,8 +3218,12 @@ int sam_format1(const bam_hdr_t *h, const bam1_t *b, kstring_t *str) | |
|
||
// Sadly we need to be able to modify the bam_hdr here so we can | ||
// reference count the structure. | ||
int sam_write1(htsFile *fp, const sam_hdr_t *h, const bam1_t *b) | ||
int sam_write1(htsFile *fp, const sam_hdr_t *hdr, const bam1_t *b) | ||
{ | ||
if (!fp || !b) { errno = EINVAL; return -1; } | ||
const sam_hdr_t *h = hdr ? hdr : fp->bam_header; | ||
if (!h) { hts_log_error("No header available for file \"%s\"", fp->fn); return -1; } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
switch (fp->format.format) { | ||
case binary_format: | ||
fp->format.category = sequence_data; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there other parts of the API that have
…fn
in API function names? I'd rather spell it out as…filename
(and it needs to be clear what if any relationship this has tohts_set_fai_filename
).