Open karinkumar opened 12 months ago
@karinkumar, please make sure that rec.alts
in alleles=[str(rec.ref),str(rec.alts)])
contains a single allele.
I rewrote your example to skip the input file and just create one variant with three samples and it seems to accept 2-tuple for PL just fine.
import pysam
from pysam import VariantFile
vcfh = pysam.VariantHeader()
for s in ["A", "B", "C"]:
vcfh.add_sample(s)
vcfh.add_meta("contig", items=[("ID", "chr20")])
vcfh.add_meta(
"FORMAT",
items=[
("ID", "PL"),
("Number", "G"),
("Type", "Integer"),
("Description", "Phred Scaled Likelihood"),
],
)
vcfh.add_meta(
"FORMAT",
items=[("ID", "GT"), ("Number", "1"), ("Type", "String"), ("Description", "True Genotype")],
)
vcf_out = VariantFile("-", "w", header=vcfh)
r = vcf_out.new_record(contig="chr20", start=1, stop=1, alleles=["C", "T"])
for n, samp in enumerate(r.samples.values()):
samp["GT"] = (0,)
samp["PL"] = [0, 1]
vcf_out.write(r)
vcf_out.close()
I get the same error as you do if I change the alleles to alleles=["C", str(("T", "G"))])
, which would happen if a record in your input vcf would contain more than one alt allele.
Hello I am trying to write out GT and PL fields for haploid samples. In the header PL must have Number = G. However, even though my GT is either (0,) or (1,) I get this error: TypeError: values expected to be 3-tuple, given len=2 I'm not sure why because clearly my GT is haploid. Furthermore, if I enter the sample['GT] as a 2-tuple (0,0). It expects the PL to be a 6-tuple. However, clearly a 2 tuple GT is diploid rather than triploid. How do I resolve this issue and tell the vcf that I want haploid PL.
My code and full error message is below: