Skip to content

pysam pysam/libcbcf.pyx error when opening vcf.format file #21

@minjaf

Description

@minjaf

Hi! When running cue, I am getting an error:

[E::bcf_hdr_parse_sample_line] Could not parse the "#CHROM.." line, either FORMAT is missing or spaces are present instead of tab
s:                                                                                                                               
        #CHROM  POS     ID      REF     ALT     QUAL    FILTER  INFO    FORMAT                                                   
                                                                                                                                 
Traceback (most recent call last):                                                                                               
  File "pysam/libcbcf.pyx", line 4355, in pysam.libcbcf.VariantFile.open                                                         
  File "pysam/libcbcf.pyx", line 2210, in pysam.libcbcf.makeVariantHeader                                                        
ValueError: cannot create VariantHeader                                                                                          
                                                                                                                                 
During handling of the above exception, another exception occurred:                                                              
                                                                                                                                 
Traceback (most recent call last):                                                                                               
  File "/home/vsfishman/soft/cue/engine/call.py", line 183, in <module>                                                          
    min_score=data_config.min_qual_score, min_len=data_config.min_sv_len)                                                        
  File "/home/vsfishman/soft/cue/seq/io.py", line 360, in bed2vcf                                                                
    vcf_format_file = get_vcf_format_variant_file(vcf_fname + ".format", chr_index.contigs())                                    
  File "/home/vsfishman/soft/cue/seq/io.py", line 327, in get_vcf_format_variant_file                                            
    vcf_file = VariantFile(vcf_fname)                                                                                            
  File "pysam/libcbcf.pyx", line 4117, in pysam.libcbcf.VariantFile.__init__
  File "pysam/libcbcf.pyx", line 4357, in pysam.libcbcf.VariantFile.open
ValueError: file `b'/mnt/10tb/home/vsfishman/genomes/process/1000206901/reports//svs.vcf.format'` does not have valid header (mod
e=`b'r'`) - is it VCF/BCF format?

I believe this is because when pysam is installed with new htclib (>=1.14), which does not accept empty vcf with format field:
samtools/htslib#1328 (comment)

I suggest replacing the line 326 of io.py
vcf.write("#%s\n" % "\t".join(["CHROM", "POS", "ID", "REF", "ALT", "QUAL", "FILTER", "INFO", "FORMAT"]))
with:
vcf.write("#%s\n" % "\t".join(["CHROM", "POS", "ID", "REF", "ALT", "QUAL", "FILTER", "INFO"]))

in this case, FORMAT will be added later on when actually writing records to the vcf file.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions