SQL-like query language for the SAM/BAM file format
go get github.com/maragkakislab/samql/...
To provide a command line utility and a clean API for filtering SAM/BAM files using simple SQL-like commands. The samql command already showcases part of the envisioned functionality.
# Simple
samql --where "RNAME = chr1" test.bam # Reference name is "chr1"
samql --where "QNAME = read1" test.bam # Query name is "read1"
samql --where "POS > 100" test.bam # Position (0-based) greater than 1
samql --where "FLAG & 16 = 16" test.bam # Flag arithmetics (Negative strand)
# Regex
samql --where "CIGAR =~ /^15M/" test.bam # Alignment starts with 15 matches
# More complex
samql --where "RNAME = chr1 OR QNAME = read1 AND POS > 100" test.bam
# Counting
samql -c --where "RNAME = chr1" test.bam
// Open github.com/biogo/hts/sam reader
f := os.Open("test.sam")
sr, _ := sam.NewReader(f)
// Do the filtering
r := samql.NewReader(sr)
filter, _ := samql.Where("POS = 1")
r.Filters = append(r.Filters, filter)
for {
rec, err := r.Read()
if err != nil {
if err == io.EOF {
break
}
panic(err)
}
// Do sth with rec
}