Skip to content

Commit

Permalink
fix: missing file
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob Patro committed Sep 30, 2023
1 parent f0e5bb8 commit 0118da7
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions src/utils/io.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
use crate::utils::parquet_utils;
use anyhow::Result;
use arrow2::{
array::Array,
chunk::Chunk,
datatypes::{Field, Schema},
};
use libradicl::rad_types;
use path_tools::WithAdditionalExtension;
use std::fs::File;
use std::io::Write;
use std::path::Path;

pub(crate) fn write_results(
output: &Path,
hdr: &rad_types::RadHeader,
e_counts: &[f64],
eff_lengths: &[f64],
) -> anyhow::Result<()> {
let mut ofile = File::create(output)?;

ofile.write_all("target_name\teelen\tecount\n".to_string().as_bytes())?;

for (i, name) in hdr.ref_names.iter().enumerate() {
let l = format!("{}\t{:.3}\t{:.3}\n", name, eff_lengths[i], e_counts[i]);
ofile.write_all(l.as_bytes())?;
}

Ok(())
}
pub(crate) fn write_fld_file(
output_path: &Path,
fields: Vec<Field>,
chunk: Chunk<Box<dyn Array>>,
) -> Result<()> {
let output_path = output_path
.clone()
.to_path_buf()
.with_additional_extension(".fld.pq");
let schema = Schema::from(fields);
parquet_utils::write_chunk_to_file(output_path.to_str().unwrap(), schema, chunk)
}

pub(crate) fn write_infrep_file(
output_path: &Path,
fields: Vec<Field>,
chunk: Chunk<Box<dyn Array>>,
) -> Result<()> {
let output_path = output_path
.clone()
.to_path_buf()
.with_additional_extension(".infreps.pq");
let schema = Schema::from(fields);
parquet_utils::write_chunk_to_file(output_path.to_str().unwrap(), schema, chunk)
}

0 comments on commit 0118da7

Please sign in to comment.