Skip to content

Support for samtools split for non-string tags (e.g. haplotype HP:i) #1956

Description

@ASLeonard

I was hoping to use samtools split -d HP to split a phased bam file into its various haplotypes, but currently only string tags are supported. I tried to find a nicer solution, but this manual branch worked with existing htslib functions (pointers are not my friend) changing the line here. Given there is already a --max-split option, was there a reason why integers are generally unsuitable compared to strings? I would imagine splitting by phase is not an obscure thing to do (and easier than multiple samtools view -d HP:<phase>). The other option would be to also encode phase/haplotype as a string, but would be redundant information.

char *val[2];
if (strcmp(tag, "HP")) sprintf(val,"%ld", bam_aux2i(tag));
else *val = tag ? bam_aux2Z(tag) : NULL;

I also noticed that if you split by tag, the format string is forcibly overwritten from whatever you provide.

samtools/bam_split.c

Lines 145 to 147 in a4c73e4

case 'd':
retval->tag = optarg;
retval->output_format_string = "%*_%!.%.";

The format string documentation definitely seems to indicate you can also change the -f format for TAGs.

Format string expansions:
  %%     %
  %*     basename
  %#     index (of @RG in the header, or count of TAG values seen so far)
  %!     @RG ID or TAG value
  %.     filename extension for output format

Best,
Alex

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions