zaeleus / noodles

Bioinformatics I/O libraries in Rust
MIT License
477 stars 53 forks source link

Missing newlines in `header::record::write_other` when writing collections #259

Closed tedil closed 3 months ago

tedil commented 3 months ago

noodles-vcf: 0.55.0 When writing a VCF header which contains a collection of "other" (##META) entries, newlines are missing. E.g.:

let builder = noodles_vcf::header::Builder::default();
let builder = builder
    .insert(
        "META".parse()?,
        noodles_vcf::header::record::Value::Map(
            String::from("First"),
            Map::<Other>::builder()
                .insert("Type".parse()?, "String")
                .insert("Number".parse()?, "1")
                .insert("Values".parse()?, "First META")
                .build()?,
        ),
    )?
    .insert(
        "META".parse()?,
        noodles_vcf::header::record::Value::Map(
            String::from("Second"),
            Map::<Other>::builder()
                .insert("Type".parse()?, "String")
                .insert("Number".parse()?, "1")
                .insert(
                    "Values".parse()?,
                    "Second META",
                )
                .build()?,
        ),
    )?;
let header = builder.build();
let mut writer = noodles_vcf::io::Writer::new(Vec::new());
writer.write_header(&header)?;

let expected = "##fileformat=VCFv4.4\n##META=<ID=First,Type=String,Number=1,Values=First META>\n##META=<ID=Second,Type=String,Number=1,Values=Second META>\n#CHROM\tPOS\tID\tREF\tALT\tQUAL\tFILTER\tINFO\n";
assert_eq!(expected, std::str::from_utf8(&writer.get_ref()[..])?);

fails.

zaeleus commented 3 months ago

Thanks for reporting and the example. This is fixed in noodles 0.72.0/noodles-vcf 0.56.0. It affected other collections with more than one record.