MCPcopy Index your code
hub / github.com/alignoth/alignoth / create_plot_data

Function create_plot_data

src/plot.rs:25–70  ·  view source on GitHub ↗

Generates the plot data for a given region of a bam file

(
    bam_path: P,
    ref_path: P,
    region: &Region,
    max_read_depth: usize,
    aux_tags: Option<Vec<String>>,
    mismatch_display_min_percent: f64,
)

Source from the content-addressed store, hash-verified

23
24/// Generates the plot data for a given region of a bam file
25pub(crate) fn create_plot_data<P: AsRef<Path> + std::fmt::Debug>(
26 bam_path: P,
27 ref_path: P,
28 region: &Region,
29 max_read_depth: usize,
30 aux_tags: Option<Vec<String>>,
31 mismatch_display_min_percent: f64,
32) -> Result<(Vec<EncodedRead>, Reference, usize, Coverage, usize)> {
33 let mut bam = bam::IndexedReader::from_path(&bam_path)?;
34 let tid = bam
35 .header()
36 .tid(region.target.as_bytes())
37 .context(format!(
38 "bam header does not contain given region target {}",
39 &region.target
40 ))
41 .unwrap() as i32;
42 bam.fetch(FetchRegion(tid, region.start, region.end))?;
43 let mut data = bam
44 .records()
45 .filter_map(|r| r.ok())
46 .filter_map(|r| {
47 Read::from_record(r, &ref_path, &region.target, &aux_tags)
48 .context(format!(
49 "bam file does not contain given region target {}",
50 &region.target
51 ))
52 .unwrap()
53 })
54 .collect_vec();
55 let coverage = Coverage::from_reads(&data, region, mismatch_display_min_percent);
56 let total_read_count = data.len();
57 data.order(max_read_depth)?;
58 let retained_reads = data.len();
59 let reference_data = Reference {
60 start: region.start,
61 reference: read_fasta(ref_path, region)?.iter().collect(),
62 };
63 Ok((
64 vec![EncodedRead::from_reads(data)],
65 reference_data,
66 total_read_count,
67 coverage,
68 retained_reads,
69 ))
70}
71
72/// Reads the given region from the given fasta file and returns it as a vec of the bases as chars
73fn read_fasta<P: AsRef<Path> + std::fmt::Debug>(path: P, region: &Region) -> Result<Vec<char>> {

Callers 5

mainFunction · 0.85
test_create_plot_dataFunction · 0.85
test_create_plot_data_2Function · 0.85

Calls 4

read_fastaFunction · 0.85
OkFunction · 0.85
orderMethod · 0.80
contextMethod · 0.45