You are an expert programmer, this is my code: pub type ConsensusTx = Vec<(u32, u32,…
- User
You are an expert programmer, this is my code:
pub type ConsensusTx = Vec<(u32, u32, Vec<(u32, u32)>)>; pub type TranscriptMap = HashMap<Chromosome, Vec>; pub type ConsensusMap = HashMap<Chromosome, ConsensusTx>; pub type Transcript = (u32, u32, HashSet<(u32, u32)>, String); pub type Chromosome = String;
let tracks = parse_tracks(&bed).unwrap(); let consensus = consensus(tracks); let reads = parse_tracks(&isoseq).unwrap(); let num_threads = num_cpus::get(); let (tx, rx) = mpsc::sync_channel(num_threads); scope(|s| { for _ in 0..num_threads { let tx = tx.clone(); let consensus = Arc::clone(&consensus); s.spawn(move |_| {}); } // end for }); // end scopewhere consensus is of the form:
ConsensusMap
and reads is of the form:
Result<TranscriptMap, &'static str>
what I want to do inside s.spawn is something like this:
reads.par_iter().for_each(|(chr, txs)| { let cn = consensus.get(chr).unwrap(); txs.par_iter().for_each(|tx| { pseudomap(cn, tx); }); });
this is pseudomap:
fn pseudomap(consensus: &ConsensusTx, tx: &Transcript) { let mut tx_exs = tx.2.iter().collect::<Vec<_>>(); tx_exs.par_sort_unstable_by_key(|x| (x.0, x.1));
consensus.par_iter().any(|(start, end, exons)| { if tx.0 >= *start - BOUNDARY && tx.1 <= *end + BOUNDARY { // read is within the boundaries of a consensus group let mut acc = exons.to_owned(); let (status, matches) = cmp_exons(&mut acc, tx_exs.clone()); let cov = (matches.len() as f64 / acc.len() as f64) * 100.0; true } else { // start/end of read is outside of consensus boundaries -> unmapped // println!("{:?} {}-{} could not be aligned", tx.3, tx.0, tx.1); false } });}
could you help me here?
- Assistant
- User
let tracks = parse_tracks(&bed).unwrap(); let consensus = Arc::new(consensus(tracks)); let reads = parse_tracks(&isoseq);
let num_threads = num_cpus::get(); let (tx, rx) = mpsc::sync_channel(num_threads); if let Ok(reads) = reads { scope(|s| { for _ in 0..num_threads { let tx: SyncSender<()> = tx.clone(); let consensus = Arc::clone(&consensus); s.spawn(move |_| { reads.par_iter().for_each(|(chr, txs)| { if let Some(cn) = consensus.get(chr) { txs.par_iter().for_each(|t| { pseudomap(cn, t); }); } }); }); } // end for drop(tx); }); // end scope } else { error!("Error parsing reads"); }error[E0382]: use of moved value:
reads--> src/main.rs:78:25 | 78 | s.spawn(move |_| { | ^^^^^^^^ value moved into closure here, in previous iteration of loop 79 | reads.par_iter().for_each(|(chr, txs)| { | ----- use occurs due to use in closure | = note: move occurs becausereadshas typehashbrown::HashMap<std::string::String, Vec<(u32, u32, hashbrown::HashSet<(u32, u32)>, std::string::String)>>, which does not implement the trait - Assistant
- User
what are the benefits of this approach?
- Assistant
The approach I described has several benefits in the context of concurrent and parallel computing with Rust:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.