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

fix: ensure FORMAT sample order is in-sync with header sample order #671

Merged
merged 8 commits into from
Jan 21, 2025
27 changes: 21 additions & 6 deletions src/annotate/strucvars/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
/// Path to the input VCF files.
#[arg(long, required = true)]
pub path_input_vcf: Vec<String>,

#[command(flatten)]
pub output: PathOutput,

Expand Down Expand Up @@ -126,6 +127,7 @@
use noodles::vcf::variant::record::info::field::key::{
END_CONFIDENCE_INTERVALS, END_POSITION, POSITION_CONFIDENCE_INTERVALS, SV_TYPE,
};
use std::collections::HashMap;

use noodles::vcf::variant::record::samples::keys::key::{
CONDITIONAL_GENOTYPE_QUALITY, FILTER, GENOTYPE, GENOTYPE_COPY_NUMBER,
Expand Down Expand Up @@ -358,7 +360,7 @@
Map::<Format>::new(FormatNumber::Count(1), Type::Integer, "Split-end coverage"),
)
.add_format(
"src",
"src", // FIXME this is clearly the same format as above?!
Map::<Format>::new(
FormatNumber::Count(1),
Type::Integer,
Expand Down Expand Up @@ -424,10 +426,21 @@
// Wait for https://github.com/zaeleus/noodles/issues/162#issuecomment-1514444101
// let mut b: record::value::map::Builder<record::value::map::Other> = Map::<noodles::vcf::header::record::value::map::Other>::builder();

for i in pedigree.individuals.values() {
if header.sample_names().contains(&i.name) {
builder = builder.add_sample_name(i.name.clone());
let individuals = pedigree
.individuals
.values()
.map(|i| (i.name.clone(), i))
.collect::<HashMap<_, _>>();

for sample in header.sample_names() {
let individual = individuals.get(sample);
if individual.is_none() {
tracing::debug!("Sample {} not part of the pedigree, skipping.", sample);
continue;
}
let i = individual.unwrap();

builder = builder.add_sample_name(i.name.clone());

// Add SAMPLE entry.
builder = builder.insert(
Expand Down Expand Up @@ -832,15 +845,17 @@
}

// First, create genotype info records.
let mut gt_it = record.samples().values();
for sample_name in header.sample_names() {
tsv_record.genotype.entries.push(GenotypeInfo {
name: sample_name.clone(),
..Default::default()
});

let entry = tsv_record.genotype.entries.last_mut().expect("just pushed");
let sample = gt_it.next().expect("genotype iterator exhausted");
let sample = record
.samples()
.get(&header, sample_name)

Check warning on line 857 in src/annotate/strucvars/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

this expression creates a reference which is immediately dereferenced by the compiler

warning: this expression creates a reference which is immediately dereferenced by the compiler --> src/annotate/strucvars/mod.rs:857:22 | 857 | .get(&header, sample_name) | ^^^^^^^ help: change this to: `header` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow = note: `#[warn(clippy::needless_borrow)]` on by default
.expect("sample not found");
tedil marked this conversation as resolved.
Show resolved Hide resolved

for (key, value) in sample.keys().as_ref().iter().zip(sample.values().iter()) {
match (key.as_ref(), value) {
Expand Down
Loading