Galaxy | Tool Preview

Filter BAM or SAM (version 1.1)
See below for query syntax.
Regions can be specified as 'chr2' (the whole chr2), 'chr2:1000000' (region starting from 1,000,000bp) or 'chr2:1,000,000-2,000,000' (region between 1,000,000 and 2,000,000bp including the end points). The coordinates are 1-based.

Sambamba Filter Overview

This tool uses the sambamba view command to filter BAM/SAM on flags, fields, tags, and region. Input is SAM or BAM file.

Filter Syntax

A filter expression is a number of basic conditions linked by and, or, not logical operators, and enclosed in parentheses where needed.

Basic condition is a one for a single record field, tag, or flag.

You can use ==, !=, >, <, >=, <= comparison operators for both integers and strings.

Strings are delimited by single quotes, if you need a single quote inside a string, escape it with \\.

Examples of filter expressions

mapping_quality >= 30 and ([RG] =~ /^abcd/ or [NM] == 7)
read_name == 'abc\'def'

Basic conditions for flags

The following flag names are recognized:
  • paired
  • proper_pair
  • unmapped
  • mate_is_unmapped
  • reverse_strand
  • mate_is_reverse_strand
  • first_of_pair
  • second_of_pair
  • secondary_alignment
  • failed_quality_control
  • duplicate

Example

not (unmapped or mate_is_unmapped) and first_of_pair

Basic conditions for fields

Conditions for integer and string fields are supported.

List of integer fields:
  • ref_id
  • position
  • mapping_quality
  • sequence_length
  • mate_ref_id
  • mate_position
  • template_length
List of string fields:
  • read_name
  • sequence
  • cigar

Example

ref_id == 3 and mapping_quality >= 50 and sequence_length >= 80

Basic conditions for tags

Tags are denoted by their names in square brackets, for instance, [RG] or [Q2]. They support conditions for both integers and strings, i.e. the tag must also hold value of the corresponding type.

In order to do filtering based on the presence of a particular tag, you can use special null value.

Example

[RG] != null and [AM] == 37