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.
|
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
I was hoping to use
samtools split -d HPto 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-splitoption, 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 multiplesamtools view -d HP:<phase>). The other option would be to also encode phase/haplotype as a string, but would be redundant information.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
The format string documentation definitely seems to indicate you can also change the
-fformat for TAGs.Best,
Alex