Visualizing read information in BAM files

Single-ended read view

class genomeview.SingleEndBAMTrack(bam_path, name=None)[source]

Displays bam as single-ended reads

nuc_colors

defines the SVG colors used to display mismatched nucleotides

Type:dict
insertion_color, deletion_color, clipping_color

SVG colors for insertions, deletions and soft/hard clipping

Type:str
quick_consensus

specify whether the quick consensus mode should be used. When activated, mismatches wrt the reference genome are only shown when at least several reads support a variant at that position (useful when displaying high-error rate data types eg pacbio). Only relevant if draw_mismatches is also True. (default: True)

Type:bool
draw_mismatches

whether to show mismatches with respect to the reference genome. (default: True).

Type:bool
include_secondary

whether to draw alignments specified as “secondary” in the BAM flags (default: True).

Type:bool
include_read_fn

callback function used to specify which reads should be included in the display. The function takes as its only argument a read (pysam.AlignedSegment) and returns True (yes, display the read) or False (no, don’t display). If this function is not specified, by default all reads are shown.

draw_interval(renderer, interval)[source]

Draw a read and then, if self.draw_mismatches is True, draw mismatches/indels on top.

fetch()[source]

Iterator over reads from the bam file

Overload this method in subclasses to feed this track reads from a different source (for example, reads that are already in memory, rather than being read from a file).

match_chrom_format(chrom)[source]

Ensures that the input argument chrom matches the chromosome name formatting in the bam file being visualized (ie “chr14” vs “14”).

Paired-ended read view

class genomeview.PairedEndBAMTrack(bam_path, name=None)[source]

Displays paired-end reads together (otherwise, same as genomeview.SingleEndBAMTrack).

overlap_color

color used to highlight portions of read pairs that are overlapping one another

Grouping reads by attribute

class genomeview.GroupedBAMTrack(bam_path, keyfn, bam_track_class, name=None)[source]

Displays reads from a BAM, separated out into groups based on a feature of the reads. For example, group reads based on the value of tag.

keyfn

the function used to specify the groupings of reads. Takes as input a read (pysam.AlignedSegment).

bam_track_class

the class used to display each group of reads, should probably be either genomeview.bamtrack.PairedEndBAMTrack or genomeview.bamtrack.SingleEndBAMTrack

space_between

the amount of space (pixels) between groups. (Default: 10)

Type:float
category_label_fn

a function that nicely formats the category labels. Takes as argument the result of the keyfn and should return a string. (Default: render as string)