-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: refactor db subset CLI, add subset by VCF and subset by TxId options #641
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -97,6 +97,48 @@ impl TxIntervalTrees { | |
|
||
(contig_to_idx, trees) | ||
} | ||
|
||
pub fn get_tx_for_region( | ||
&self, | ||
tx_seq_db: &TxSeqDatabase, | ||
alt_ac: &str, | ||
_alt_aln_method: &str, | ||
start_i: i32, | ||
end_i: i32, | ||
) -> Result<Vec<TxForRegionRecord>, Error> { | ||
let contig_idx = *self | ||
.contig_to_idx | ||
.get(alt_ac) | ||
.ok_or(Error::NoTranscriptFound(alt_ac.to_string()))?; | ||
let query = start_i..end_i; | ||
let tx_idxs = self.trees[contig_idx].find(query); | ||
|
||
Ok(tx_idxs | ||
.iter() | ||
.map(|entry| { | ||
let tx = &tx_seq_db.tx_db.as_ref().expect("no tx_db?").transcripts | ||
[*entry.data() as usize]; | ||
assert_eq!( | ||
tx.genome_alignments.len(), | ||
1, | ||
"Can only have one alignment in Mehari" | ||
); | ||
let alt_strand = tx.genome_alignments.first().unwrap().strand; | ||
TxForRegionRecord { | ||
tx_ac: tx.id.clone(), | ||
alt_ac: alt_ac.to_string(), | ||
alt_strand: match Strand::try_from(alt_strand).expect("invalid strand") { | ||
Strand::Plus => 1, | ||
Strand::Minus => -1, | ||
_ => unreachable!("invalid strand {}", alt_strand), | ||
}, | ||
alt_aln_method: ALT_ALN_METHOD.to_string(), | ||
start_i, | ||
end_i, | ||
} | ||
}) | ||
.collect()) | ||
} | ||
Comment on lines
+101
to
+141
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Duplicate implementation of The Consider refactoring to reuse the fn get_tx_for_region(
&self,
alt_ac: &str,
_alt_aln_method: &str,
start_i: i32,
end_i: i32,
) -> Result<Vec<TxForRegionRecord>, Error> {
self.tx_trees.get_tx_for_region(
&self.tx_seq_db,
alt_ac,
_alt_aln_method,
start_i,
end_i,
)
} This approach reduces code duplication and centralizes the logic. |
||
} | ||
|
||
/// Configuration for constructing the `Provider`. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid panics with
assert
and provide meaningful errorsUsing
assert_eq!
andunwrap()
can cause the program to panic if conditions are not met. Instead, handle these cases gracefully by returning errors.Replace
assert_eq!
andunwrap()
with proper error handling:This change prevents unexpected panics and provides useful error messages to the caller.