Skip to content

Commit

Permalink
adding sequence name column to distmats
Browse files Browse the repository at this point in the history
  • Loading branch information
nrminor committed Jan 23, 2024
1 parent 4c78b3e commit e7aaf6c
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/lib/distmat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,15 +406,17 @@ pub fn compute_distance_matrix(
.lazy();

// multiply weights onto each column based on the sequence it represents
for id in ids {
let (weights_header, weights) = weight_by_cluster_size(&id, stringency, &cluster_df)?;
for id in &ids {
let (weights_header, weights) = weight_by_cluster_size(id, stringency, &cluster_df)?;
dist_df = dist_df
.hstack(&[weights])?
.lazy()
.with_columns(&[col(&id).mul(col(&weights_header)).alias(&id)])
.with_columns(&[col(id).mul(col(&weights_header)).alias(id)])
.collect()?
.drop(&weights_header)?
}
let col_series = Series::new("Sequence_Name", &ids);
let dist_df = dist_df.with_column(col_series)?;

// write out the weighted distance matrix
let out_name = format!("{}-dist-matrix.csv", yearmonth);
Expand All @@ -423,7 +425,7 @@ pub fn compute_distance_matrix(
);
CsvWriter::new(out_handle)
.has_header(true)
.finish(&mut dist_df)
.finish(dist_df)
.expect("Weighted distance matrix could not be written.");

Ok(())
Expand Down

0 comments on commit e7aaf6c

Please sign in to comment.