-
How to write bigWig when input comes from memory (e.g. 3 vectors) instead of a file? Suppose I have 3 sets of vectors for each chromosome with chromosome names (all the same), starts and ends for each interval (already correctly sorted), how can I write them directly to a bigWig file? let chroms = vec!["chrY", "chrY", "chrY", "chrY", "chrY", "chrY", "chrY", "chrY", "chrY", "chrY"];
let starts = vec![530, 538, 584, 713, 751, 860, 865, 873, 879, 902];
let ends = vec![538, 584, 713, 751, 860, 865, 873, 879, 902, 923]; |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
So sorry! I never saw this. This is definitely doable, I'll share a code snippet tomorrow or this weekend. |
Beta Was this translation helpful? Give feedback.
-
This works: use std::collections::HashMap;
use bigtools::bed::bedparser::BedParser;
use bigtools::bedchromdata::BedParserStreamingIterator;
use bigtools::{BigWigWrite, Value};
let chroms = vec![
"chrY", "chrY", "chrY", "chrY", "chrY", "chrY", "chrY", "chrY", "chrY", "chrY",
];
let starts: Vec<u32> = vec![530, 538, 584, 713, 751, 860, 865, 873, 879, 902];
let ends: Vec<u32> = vec![538, 584, 713, 751, 860, 865, 873, 879, 902, 923];
let iter = chroms
.into_iter()
.zip(starts.into_iter().zip(ends.into_iter()));
let iter = iter.map(|(chrom, (start, end))| {
Ok::<(String, Value), std::io::Error>((
chrom.to_string(),
Value {
start,
end,
value: 0.0,
},
))
});
let vals_iter = BedParserStreamingIterator::new(BedParser::wrap_iter(iter), true);
let chrom_map = HashMap::from([("chrY".to_string(), 57_227_415)]);
let runtime = tokio::runtime::Builder::new_current_thread()
.build()
.expect("Unable to create runtime.");
let outb = BigWigWrite::create_file("test.bigWig".to_string());
outb.write_singlethreaded(chrom_map, vals_iter, runtime)
.unwrap(); I've added it as a test too. |
Beta Was this translation helpful? Give feedback.
-
Just pushed some changes to make this a bit nicer (don't have to call let chroms = vec![
"chrY", "chrY", "chrY", "chrY", "chrY", "chrY", "chrY", "chrY", "chrY", "chrY",
];
let starts: Vec<u32> = vec![530, 538, 584, 713, 751, 860, 865, 873, 879, 902];
let ends: Vec<u32> = vec![538, 584, 713, 751, 860, 865, 873, 879, 902, 923];
let iter = chroms
.into_iter()
.zip(starts.into_iter().zip(ends.into_iter()));
let iter = iter.map(|(chrom, (start, end))| {
(
chrom,
Value {
start,
end,
value: 0.0,
},
)
});
let vals_iter = BedParserStreamingIterator::new(BedParser::wrap_infallible_iter(iter), true);
let chrom_map = HashMap::from([("chrY".to_string(), 57_227_415)]);
let runtime = tokio::runtime::Builder::new_current_thread()
.build()
.expect("Unable to create runtime.");
let outb = BigWigWrite::create_file("test.bigWig".to_string());
outb.write_singlethreaded(chrom_map, vals_iter, runtime)
.unwrap(); This will be in the next release. |
Beta Was this translation helpful? Give feedback.
Just pushed some changes to make this a bit nicer (don't have to call
to_string()
and don't need toOk
wrap):