11/* The MIT License
22
3- Copyright (c) 2021 Genome Research Ltd.
3+ Copyright (c) 2021-2022 Genome Research Ltd.
44
55 Author: Petr Danecek <[email protected] > 6-
6+
77 Permission is hereby granted, free of charge, to any person obtaining a copy
88 of this software and associated documentation files (the "Software"), to deal
99 in the Software without restriction, including without limitation the rights
1010 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1111 copies of the Software, and to permit persons to whom the Software is
1212 furnished to do so, subject to the following conditions:
13-
13+
1414 The above copyright notice and this permission notice shall be included in
1515 all copies or substantial portions of the Software.
16-
16+
1717 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1818 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1919 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -117,7 +117,7 @@ void abuf_set(abuf_t *buf, abuf_opt_t key, void *value)
117117 if ( key == INFO_TAG )
118118 {
119119 buf -> split .info_tag = * ((char * * )value );
120- bcf_hdr_printf (buf -> out_hdr ,"##INFO=<ID=%s,Number=1,Type=String,Description=\"Original variant. Format: CHR|POS|REF|ALT|USED_ALT_IDX\">" ,buf -> split .info_tag );
120+ bcf_hdr_printf (buf -> out_hdr ,"##INFO=<ID=%s,Number=1,Type=String,Description=\"Original variant. Format: CHR|POS|REF|ALT|USED_ALT_IDX\">" ,buf -> split .info_tag );
121121 return ;
122122 }
123123 if ( key == STAR_ALLELE ) { buf -> star_allele = * ((int * )value ); return ; }
@@ -141,7 +141,7 @@ static void _atomize_allele(abuf_t *buf, bcf1_t *rec, int ial)
141141 while ( rlen > 1 && alen > 1 && ref [rlen - 1 ]== alt [alen - 1 ] ) rlen -- , alen -- ;
142142 int Mlen = rlen > alen ? rlen : alen ;
143143
144- atom_t * atom = NULL ;
144+ atom_t * atom = NULL ;
145145 int i ;
146146 for (i = 0 ; i < Mlen ; i ++ )
147147 {
@@ -374,7 +374,7 @@ static void _split_table_set_info(abuf_t *buf, bcf_info_t *info, merge_rule_t mo
374374 memcpy (buf -> tmp2 + num_size ,missing_ptr ,num_size );
375375 else
376376 memcpy (buf -> tmp2 + num_size ,buf -> tmp + num_size * iori ,num_size );
377- if ( type == BCF_HT_INT && mode == M_SUM )
377+ if ( type == BCF_HT_INT && mode == M_SUM )
378378 {
379379 uint8_t * tbl = buf -> split .tbl + iout * buf -> split .nori ;
380380 for (i = iori ; i < buf -> split .nori ; i ++ )
@@ -466,7 +466,10 @@ static void _split_table_set_gt(abuf_t *buf)
466466 error ("Out-of-bounds genotypes at %s:%" PRIhts_pos "\n" ,bcf_seqname (buf -> hdr ,rec ),rec -> pos + 1 );
467467 int ial = _split_table_get_ial (buf ,iout ,iori );
468468 if ( ial == 2 && !star_allele )
469+ {
469470 dst [j ] = bcf_gt_missing ;
471+ if ( bcf_gt_is_phased (src [j ]) ) dst [j ] |= 1 ;
472+ }
470473 else
471474 dst [j ] = bcf_gt_is_phased (src [j ]) ? bcf_gt_phased (ial ) : bcf_gt_unphased (ial );
472475 }
@@ -542,7 +545,7 @@ static void _split_table_set_format(abuf_t *buf, bcf_fmt_t *fmt, merge_rule_t mo
542545 {
543546 int star_allele = _has_star_allele (buf ,iout );
544547 bcf1_t * out = buf -> vcf [rbuf_kth (& buf -> rbuf ,iout )];
545- int ret = 0 ;
548+ int ret = 0 ;
546549 if ( len == BCF_VL_FIXED || len == BCF_VL_VAR )
547550 ret = bcf_update_format (buf -> out_hdr , out , tag , buf -> tmp , nval , type );
548551 else if ( len == BCF_VL_A && type != BCF_HT_STR )
@@ -707,7 +710,7 @@ void _abuf_split(abuf_t *buf, bcf1_t *rec)
707710 buf -> vcf [j ] = bcf_dup (rec );
708711 return ;
709712 }
710- for (i = 1 ; i < rec -> n_allele ; i ++ )
713+ for (i = 0 ; i < rec -> n_allele ; i ++ )
711714 {
712715 if ( _is_acgtn (rec -> d .allele [i ]) ) continue ;
713716 rbuf_expand0 (& buf -> rbuf , bcf1_t * , buf -> rbuf .n + 1 , buf -> vcf );
0 commit comments