Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pysam.bcftools.concat Ignores the -o Option #1323

Open
shokrofont opened this issue Dec 19, 2024 · 0 comments
Open

pysam.bcftools.concat Ignores the -o Option #1323

shokrofont opened this issue Dec 19, 2024 · 0 comments

Comments

@shokrofont
Copy link

When using pysam.bcftools.concat to concatenate VCF files, the -o option (for specifying the output file) is ignored. Instead, the concatenated output is written to stdout. This behavior is unexpected and makes it difficult to directly specify an output file during concatenation.

import pysam
import pysam.bcftools
import os

def create_dummy_vcf(filename, chrom, pos, ref, alt):
    """Creates a dummy VCF file with minimal content."""
    header = (
        "##fileformat=VCFv4.2\n"
        f"##contig=<ID={chrom}>\n"  # Add contig definition
        "#CHROM\tPOS\tID\tREF\tALT\tQUAL\tFILTER\tINFO\n"
    )
    content = f"{chrom}\t{pos}\t.\t{ref}\t{alt}\t.\tPASS\t.\n"
    
    with open(filename, "w") as vcf:
        vcf.write(header)
        vcf.write(content)

# Create two dummy VCF files
vcf1 = "dummy1.vcf"
vcf2 = "dummy2.vcf"
output_vcf = "concatenated.vcf"

create_dummy_vcf(vcf1, "chr1", 100, "A", "T")
create_dummy_vcf(vcf2, "chr1", 200, "G", "C")

# Attempt to concatenate using pysam.bcftools.concat
try:
    out = pysam.bcftools.concat( '-o', output_vcf, vcf1, vcf2, catch_stdout=True)    
    if os.path.exists(output_vcf):
        print(f"Output VCF successfully created: {output_vcf}")
    else:
        print(f"Output VCF not created as expected. Check stdout.")
        print(out)
except Exception as e:
    print(f"An error occurred: {e}")

# Clean up dummy files
os.remove(vcf1)
os.remove(vcf2)
if os.path.exists(output_vcf):
    os.remove(output_vcf)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant