Creates a Read from a given rust_htslib bam record
(
record: rust_htslib::bam::record::Record,
ref_path: P,
target: &str,
aux_tags: &Option<Vec<String>>,
)
| 611 | impl Read { |
| 612 | /// Creates a Read from a given rust_htslib bam record |
| 613 | fn from_record<P: AsRef<Path> + std::fmt::Debug>( |
| 614 | record: rust_htslib::bam::record::Record, |
| 615 | ref_path: P, |
| 616 | target: &str, |
| 617 | aux_tags: &Option<Vec<String>>, |
| 618 | ) -> Result<Option<Read>> { |
| 619 | let read_seq = record |
| 620 | .seq() |
| 621 | .as_bytes() |
| 622 | .iter() |
| 623 | .map(|u| char::from(*u)) |
| 624 | .collect_vec(); |
| 625 | if read_seq.is_empty() && record.cigar().iter().next().is_some() { |
| 626 | warn!( |
| 627 | "Skipping read '{}': empty sequence but non-empty CIGAR string ('{}').", |
| 628 | String::from_utf8_lossy(record.qname()), |
| 629 | record.cigar(), |
| 630 | ); |
| 631 | return Ok(None); |
| 632 | } |
| 633 | let ref_length = get_fasta_length(&ref_path.as_ref().to_path_buf(), target)?; |
| 634 | let read_start = record.pos() - record.cigar().leading_softclips(); |
| 635 | let read_end = record.reference_end() + record.cigar().trailing_softclips(); |
| 636 | |
| 637 | let record = if read_start < 0 || read_end > ref_length as i64 { |
| 638 | clip_read(record, ref_length)? |
| 639 | } else { |
| 640 | record |
| 641 | }; |
| 642 | let region = cli::Region { |
| 643 | target: target.to_string(), |
| 644 | start: record.pos() - record.cigar().leading_softclips(), |
| 645 | end: record.reference_end() + record.cigar().trailing_softclips(), |
| 646 | }; |
| 647 | let ref_seq = read_fasta(ref_path, ®ion)?; |
| 648 | let mpos = if record.is_paired() { |
| 649 | record.mpos() |
| 650 | } else { |
| 651 | -1 |
| 652 | }; |
| 653 | Ok(Some(Read { |
| 654 | name: String::from_utf8(record.qname().to_vec())?, |
| 655 | cigar: PlotCigar::from_cigar(record.cigar(), read_seq, ref_seq)?, |
| 656 | position: record.pos() - record.cigar().leading_softclips(), |
| 657 | flags: record.flags(), |
| 658 | mapq: record.mapq(), |
| 659 | row: None, |
| 660 | end_position: record.reference_end(), |
| 661 | mpos, |
| 662 | aux: AuxRecord::new(&record, aux_tags), |
| 663 | raw_cigar: record.cigar().to_string(), |
| 664 | })) |
| 665 | } |
| 666 | |
| 667 | /// Sets the row of the Read |
| 668 | fn set_row(&mut self, row: u32) { |
nothing calls this directly
no test coverage detected