@@ -2723,20 +2723,31 @@ void gvcf_flush(args_t *args, int done)
27232723 }
27242724}
27252725
2726- static inline int is_gvcf_block (bcf1_t * line )
2726+ static inline int is_gvcf_block (args_t * args , bcf1_t * line )
27272727{
27282728 if ( line -> rlen <=1 ) return 0 ;
27292729 if ( strlen (line -> d .allele [0 ])== line -> rlen ) return 0 ;
2730- if ( line -> n_allele == 1 ) return 1 ;
2730+ if ( line -> n_allele == 1 ) goto is_gvcf ;
27312731
27322732 int i ;
27332733 for (i = 1 ; i < line -> n_allele ; i ++ )
27342734 {
2735- if ( !strcmp (line -> d .allele [i ],"<*>" ) ) return 1 ;
2736- if ( !strcmp (line -> d .allele [i ],"<NON_REF>" ) ) return 1 ;
2737- if ( !strcmp (line -> d .allele [i ],"<X>" ) ) return 1 ;
2735+ if ( !strcmp (line -> d .allele [i ],"<*>" ) ) goto is_gvcf ;
2736+ if ( !strcmp (line -> d .allele [i ],"<NON_REF>" ) ) goto is_gvcf ;
2737+ if ( !strcmp (line -> d .allele [i ],"<X>" ) ) goto is_gvcf ;
27382738 }
27392739 return 0 ;
2740+
2741+ is_gvcf :
2742+ maux_t * ma = args -> maux ;
2743+ if ( !ma -> gvcf )
2744+ {
2745+ args -> do_gvcf = 1 ;
2746+ ma -> gvcf = (gvcf_aux_t * ) calloc (ma -> n ,sizeof (gvcf_aux_t )); // -Walloc-size-larger-than gives a harmless warning caused by signed integer ma->n
2747+ for (i = 0 ; i < ma -> n ; i ++ )
2748+ ma -> gvcf [i ].line = bcf_init1 ();
2749+ }
2750+ return 1 ;
27402751}
27412752
27422753/*
@@ -2776,7 +2787,7 @@ void gvcf_stage(args_t *args, int pos)
27762787 int irec = maux -> buf [i ].beg ;
27772788 bcf_hdr_t * hdr = bcf_sr_get_header (files , i );
27782789 bcf1_t * line = args -> files -> readers [i ].buffer [irec ];
2779- int ret = is_gvcf_block (line ) ? bcf_get_info_int32 (hdr ,line ,"END" ,& end ,& nend ) : 0 ;
2790+ int ret = is_gvcf_block (args , line ) ? bcf_get_info_int32 (hdr ,line ,"END" ,& end ,& nend ) : 0 ;
27802791 if ( ret == 1 )
27812792 {
27822793 if ( end [0 ] == line -> pos + 1 ) // POS and INFO/END are identical, treat as if a normal w/o INFO/END
@@ -3133,7 +3144,7 @@ int can_merge(args_t *args)
31333144 var_type &= ~VCF_INDEL ;
31343145 }
31353146 var_type = var_type ? var_type <<1 : ref_mask ;
3136- if ( args -> do_gvcf && is_gvcf_block (line ) ) var_type |= ref_mask ;
3147+ if ( args -> do_gvcf && is_gvcf_block (args , line ) ) var_type |= ref_mask ;
31373148 buf -> rec [j ].var_types = var_type ;
31383149 }
31393150 maux -> var_types |= buf -> rec [j ].var_types ;
@@ -3233,7 +3244,8 @@ void stage_line(args_t *args)
32333244 if ( buf -> rec [j ].skip )
32343245 {
32353246 int is_gvcf = maux -> gvcf && maux -> gvcf [i ].active ? 1 : 0 ;
3236- if ( !is_gvcf && is_gvcf_block (buf -> lines [j ]) ) is_gvcf = 1 ;
3247+ if ( !is_gvcf && is_gvcf_block (args ,buf -> lines [j ]) ) is_gvcf = 1 ;
3248+ if ( is_gvcf && buf -> rec [j ].skip && !maux -> gvcf [i ].active ) continue ;
32373249 if ( !is_gvcf ) continue ; // done or not compatible
32383250 }
32393251 if ( args -> merge_by_id ) break ; // if merging by ID and the line is compatible, the this is THE line
0 commit comments