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

Escape characters #144

Open
Akazhiel opened this issue May 12, 2021 · 0 comments
Open

Escape characters #144

Akazhiel opened this issue May 12, 2021 · 0 comments

Comments

@Akazhiel
Copy link

  • vcfpy version: 0.13.3
  • Python version: 3.6.1
  • Operating System: Linux (Ubuntu)

Description

I'm having a hard time understanding why there is a mapping of escape characters, because when I write a vcf if I have some % in my fields, this gets changed to %25 instead of remaining as % like in the original. And I believe this can cause conflicts when using tools on the VCF with the field formatted like %25.

What I Did

I ran this custom function to split the VCF in samples.

def split_vcf(vcf_path):
    reader_main = vcfpy.Reader.from_path(vcf_path)
    samples = list(set([x.replace('NORMAL.', '').replace('TUMOR.', '') for x in reader_main.header.samples.names]))
    reader_main.close()
    for sample in samples:
        reader_1 = vcfpy.Reader.from_path(vcf_path)
        reader_2 = vcfpy.Reader.from_path(vcf_path)
        header = reader_2.header
        header.samples.names = [x for x in header.samples.names if x in [f'NORMAL.{sample}', f'TUMOR.{sample}']]
        header.samples.name_to_idx = {x: header.samples.name_to_idx[x] for x in [f'NORMAL.{sample}', f'TUMOR.{sample}']}
        writer = vcfpy.Writer.from_path('./{}.vcf'.format(sample), header)
        for record in reader_1:
            if any(sample == s for s in record.INFO['set'].split('-')):
                writer.write_record(record)
        writer.close()
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