Skip to content

Commit

Permalink
better patch to get correct sparsity for tsv input but removing break…
Browse files Browse the repository at this point in the history
… when populating coverages matrix while counting loci with less than 1 allele shown
  • Loading branch information
jeffersonfparil committed Jun 4, 2024
1 parent d31b2dd commit 8331afd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 21 deletions.
20 changes: 2 additions & 18 deletions src/filter_missing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,31 +51,15 @@ impl GenotypesAndPhenotypes {
}

pub fn missing_rate(&mut self) -> Result<f64, ImputefError> {
let (n, p) = self.intercept_and_allele_frequencies.dim();
let (n, _p) = self.intercept_and_allele_frequencies.dim();
let (_n, l) = self.coverages.dim();
// Count missing data based on coverages
let sum_cov: f64 = self.coverages.fold(0.00, |sum, &x| {
let sum: f64 = self.coverages.fold(0.00, |sum, &x| {
if (x.is_nan()) || (x == 0.0) {
sum + 1.00
} else {
sum
}
});
// Count missing data based on missing frequencies
let mut sum_freq: f64 = self.intercept_and_allele_frequencies.fold(0.00, |sum, &x| {
if x.is_nan() {
sum + 1.00
} else {
sum
}
});
sum_freq = sum_freq / (p as f64 / l as f64); // correct by the number of alleles per locus
// Use the larger and more precise missing count
let sum: f64 = if sum_cov > sum_freq {
sum_cov
} else {
sum_freq
};
sensible_round(sum * 100.0 / ((n * l) as f64), 5)
}

Expand Down
8 changes: 5 additions & 3 deletions src/geno.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,11 +347,13 @@ impl LoadAll for FileGeno {
coverages[(i, j)] = f64::NAN;
}
if mat.slice(s![i, idx_ini..idx_fin]).sum() < 1.0 {
freq_sum_less_than_one = true;
break;
freq_sum_less_than_one = if !freq_sum_less_than_one {
true
} else {
freq_sum_less_than_one
};
}
}
// if (n_alleles == 1) || freq_sum_less_than_one {
if freq_sum_less_than_one {
p += 1;
}
Expand Down

0 comments on commit 8331afd

Please sign in to comment.