Skip to content
/ samql Public
forked from maragkakislab/samql

SQL-like query language for the SAM/BAM file format

License

Notifications You must be signed in to change notification settings

leetaiyi/samql

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

samql Go Report Card Build Status GoDoc

SQL-like query language for the SAM/BAM file format

Install

go get github.com/maragkakislab/samql/...

Objective

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

API example

// 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
}

About

SQL-like query language for the SAM/BAM file format

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 100.0%