Skip to content

Commit

Permalink
feat: use file_prefix as feature name
Browse files Browse the repository at this point in the history
  • Loading branch information
zietzm committed Jul 22, 2024
1 parent aa47ebd commit 566cb8b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
3 changes: 3 additions & 0 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ fn gwas_path_to_phenotype(filename: &str) -> String {
.unwrap()
.to_str()
.unwrap()
.split('.')
.next()
.unwrap()
.to_string()
}

Expand Down
21 changes: 5 additions & 16 deletions tests/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ fn write_gwas_results(results: &Vec<GwasResults>, output_path: &str, compress: b
}
}

fn write_test_data(test_data: &TestData, dir: &Path, compress: bool) -> Result<()> {
fn write_test_data(test_data: &TestData, dir: &Path) -> Result<()> {
let mut writer = csv::Writer::from_path(dir.join("genotypes.csv"))?;
for row in test_data.genotypes.row_iter() {
writer.write_record(row.iter().map(|x| x.to_string()))?;
Expand All @@ -185,29 +185,18 @@ fn write_test_data(test_data: &TestData, dir: &Path, compress: bool) -> Result<(
writer.write_record(header_row)?;
for (idx, row) in test_data.projection_matrix.row_iter().enumerate() {
let mut row_vec = row.iter().map(|x| x.to_string()).collect::<Vec<String>>();
row_vec.insert(
0,
test_data.phenotype_ids[idx].clone() + ".tsv" + if compress { ".zst" } else { "" },
);
row_vec.insert(0, test_data.phenotype_ids[idx].clone());
writer.write_record(row_vec)?;
}
writer.flush()?;

let mut writer = csv::Writer::from_path(dir.join("covariance_matrix.csv"))?;
let mut header_row = test_data
.phenotype_ids
.clone()
.into_iter()
.map(|x| x + ".tsv" + if compress { ".zst" } else { "" })
.collect::<Vec<String>>();
let mut header_row = test_data.phenotype_ids.clone();
header_row.insert(0, "phenotype_id".to_string());
writer.write_record(header_row)?;
for (idx, row) in test_data.covariance_matrix.row_iter().enumerate() {
let mut row_vec = row.iter().map(|x| x.to_string()).collect::<Vec<String>>();
row_vec.insert(
0,
test_data.phenotype_ids[idx].clone() + ".tsv" + if compress { ".zst" } else { "" },
);
row_vec.insert(0, test_data.phenotype_ids[idx].clone());
writer.write_record(row_vec)?;
}
writer.flush()?;
Expand All @@ -232,7 +221,7 @@ pub fn setup_test(
n_phenotypes,
n_projections,
);
write_test_data(&test_data, dir, compress).unwrap();
write_test_data(&test_data, dir).unwrap();

let do_gwas =
|phenotypes: &DMatrix<f32>, phenotype_ids: &Vec<String>| -> Vec<Vec<GwasResults>> {
Expand Down

0 comments on commit 566cb8b

Please sign in to comment.