Skip to content

Commit

Permalink
feat: refactor db subset CLI, add subset by VCF and subset by TxId op…
Browse files Browse the repository at this point in the history
…tions (#641)
  • Loading branch information
tedil authored Dec 3, 2024
1 parent 1ec23df commit 9286286
Show file tree
Hide file tree
Showing 2 changed files with 265 additions and 76 deletions.
42 changes: 42 additions & 0 deletions src/annotate/seqvars/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}

/// Configuration for constructing the `Provider`.
Expand Down
Loading

0 comments on commit 9286286

Please sign in to comment.