fn main() { let start = std::time::Instant::now(); let file =…
- User
fn main() { let start = std::time::Instant::now();
codelet file = PathBuf::from("/home/alejandro/Documents/unam/TOGA_old_versions/x/gtf_files/1k.gtf"); let contents = reader(&file).unwrap(); let records = parallel_parse(&contents).unwrap(); // {transcript : (chr, strand, [starts], [ends]))} let mut transcripts: HashMap<String, (String, String, Vec<u32>, Vec<u32>)> = HashMap::new(); records.into_par_iter().for_each(|record| { let (chr, strand, start, end, transcript) = ( record.chr, record.strand, record.start, record.end, record.transcript, ); let entry = transcripts .entry(transcript) .or_insert((chr, strand, Vec::new(), Vec::new())); entry.2.push(start); entry.3.push(end); }); let end = start.elapsed(); println!("Time elapsed: {:?}", end);}
error[E0596]: cannot borrow
transcriptsas mutable, as it is a captured variable in aFnclosure --> src/main.rs:26:21 | 26 | let entry = transcripts | ^ 27 | | .entry(transcript) | |_________^ cannot borrow as mutablecould you help me with this?
- Assistant
- User
Is it there any other parallel approach you would take? maybe fold() or reduce()?
- Assistant
- User
is it possible to introduce an if statement here?:
pub fn parallel_parse<'a>(s: &'a str) -> Result<Vec> { let records = s .par_lines() .map(|line| GeneModel::parse(line, "exon")) .collect::<Vec>();
codereturn Ok(records);}
I just want to map lines that do not start with "#"
- Assistant
Yes, you can introduce a conditional within your parallel iterator to filter out lines that start with
#. To do this, you can use thefiltermethod before callingmapto ensure that only lines not starting with#are parsed.Here's how you might modify your
parallel_parsefunction:rust - User
is it possible to implement this:
match strand.as_str() { "+" => { starts.sort_unstable(); ends.sort_unstable();
codefor (i, start) in starts.iter().enumerate() { let end = ends[i]; let part = get_sequence(&mut records, chr, *start, end, strand).unwrap(); seq.push_str(&String::from_utf8(part).unwrap()); } } "-" => { starts.sort_unstable_by(|a, b| b.cmp(a)); ends.sort_unstable_by(|a, b| b.cmp(a)); for (i, start) in starts.iter().enumerate() { let end = ends[i]; let part = get_sequence(&mut records, chr, *start, end, strand).unwrap(); seq.push_str(&String::from_utf8(part).unwrap()); } } _ => continue, }into the first response you gave?
- Assistant