Hi. Could you please help me with this problem? Check this function: pub fn…
- User
Hi. Could you please help me with this problem? Check this function:
pub fn consensus(tracks: FendTxMap) -> FendCMap { let cmap: Mutex = Mutex::new(HashMap::new());
codetracks.into_par_iter().for_each(|(chr, records)| { let mut acc: FendCGroup = HashMap::new(); for tx in records { let tx = Arc::new(tx); let group = acc.iter_mut().any(|(coords, txs)| { let (group_start, group_end) = coords; if tx.start >= *group_start && tx.start <= *group_end { txs.push(tx.clone()); true } else { false } }); if !group { acc.insert((tx.start, tx.end), vec![tx]); } } cmap.lock().unwrap().insert(chr, acc); }); cmap.into_inner().unwrap()}
This are the types referred there:
pub type FendTxMap = HashMap<Chrom, Vec>; pub type FendCMap = HashMap<Chrom, FendCGroup>; pub type FendCGroup = HashMap<(u64, u64), Vec<Arc>>;
#[derive(Debug, PartialEq, Clone)] pub struct FendPred { pub name: Arc, pub chrom: Arc, pub strand: char, pub start: u64, pub end: u64, pub exons: Vec<(u64, u64)>, pub introns: Vec<(u64, u64)>, pub utr: Utr, pub exon_count: usize, pub line: String, }
What I am trying to do is to sort the Vec<Arc> for each (u64, u64) key in the FendCGroup. The sort should be made by the start and end of the first value of the exons key (pub exons: Vec<(u64, u64)>). What I mean by "made by the start and end" is that the smaller start and the smaller end should be first.
- Assistant
To accomplish the sorting of each in the by the start and end of the first tuple in the vector, you can adjust your loop where the map is built by adding the sort function right after populating it and before inserting it into the .