amr

package
v0.13.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 29, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const AMRFileName = "amrfinderplus.parquet"

AMRFileName is the single merged parquet file containing all AMR data.

View Source
const PartitionDir = "amr"

PartitionDir is the subdirectory under the data dir where genus partitions live.

View Source
const PartitionThreshold = 10_000

PartitionThreshold is the minimum number of rows a genus must have to get its own partition file. Genera below this threshold are grouped into _other.parquet.

Variables

This section is empty.

Functions

func BuildIndexes

func BuildIndexes(dataDir string, logFn func(string, ...any)) error

BuildIndexes reads each .parquet file in the partition directory and builds a corresponding .sqlite index. Builds run in parallel (one goroutine per file, bounded by NumCPU).

func BuildPartitions

func BuildPartitions(dataDir string, logFn func(string, ...any)) error

BuildPartitions reads the monolithic amrfinderplus.parquet and writes per-genus partition files into <dataDir>/amr/. Uses a streaming two-pass approach:

  1. First pass: count rows per genus (reads only Genus column equivalent).
  2. Second pass: stream rows into per-genus writers, routing small genera to _other.

logFn is called with progress messages (pass nil to suppress output).

func IndexPath

func IndexPath(dataDir, genus string) string

IndexPath returns the path to a genus SQLite index if it exists.

func PartitionPath

func PartitionPath(dataDir, genus string) string

PartitionPath returns the path to a genus partition file if it exists. Returns empty string if the partition doesn't exist.

Types

type Filters

type Filters struct {
	// Samples restricts results to a specific set of sample accessions.
	// Nil or empty means no restriction.
	Samples map[string]struct{}
	// Class filters by drug class (case-insensitive substring match). Empty means all.
	Class string
	// GenePattern filters by gene symbol. Supports % wildcards (prefix/suffix/contains). Empty means all.
	GenePattern string
	// MinCoverage is the minimum coverage percentage (0 = no minimum).
	MinCoverage float64
	// MinIdentity is the minimum identity percentage (0 = no minimum).
	MinIdentity float64
	// ElementType restricts to a specific element type ("AMR", "STRESS", "VIRULENCE"). Empty means all.
	ElementType string
	// Genera restricts results to specific bacterial genera (case-insensitive).
	// Nil or empty means all genera (full scan).
	Genera []string
	// Species restricts results to specific full species names, e.g. "Escherichia coli"
	// (case-insensitive exact match against the row's Species field).
	// Nil or empty means no species-level restriction.
	Species []string
	// Limit caps the number of returned results. 0 means no limit.
	Limit int
}

Filters controls which AMR rows are returned by Query.

type Result

type Result struct {
	SampleAccession string
	GeneSymbol      string
	ElementType     string
	ElementSubtype  string
	Coverage        float64
	Identity        float64
	Method          string
	Class           string
	Subclass        string
	Species         string
	Genus           string
}

Result is a single AMR gene hit associated with a sample.

func Query

func Query(dataDir string, filters Filters) ([]Result, error)

Query reads AMR data from dataDir, applies filters, and returns matching results. For each genus, it tries (in order): SQLite index, parquet partition, monolithic file. When no genera are given, it scans the full monolithic amrfinderplus.parquet.

func QueryIndex

func QueryIndex(dbPath string, filters Filters) ([]Result, error)

QueryIndex runs a SQL query against a genus SQLite index and returns results.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL