Documentation
¶
Overview ¶
Package bakpack provides tools for reducing, packing, reading, and extracting Bakta annotation JSON archives.
Use OpenArchive with Archive.Extract when callers want extracted bytes in memory, Archive.ExtractFiles when callers want standard bakpack output files in a directory, and ExtractArchive for one-shot file extraction from an archive path or HTTP(S) URL.
Index ¶
- Constants
- Variables
- func BaktaGFF3(annotation []byte, genome Genome) ([]byte, error)
- func BaktaGFF3WithOptions(annotation []byte, genome Genome, opts BaktaGFF3Options) ([]byte, error)
- func BuildArchive(ctx context.Context, opts BuildOptions) error
- func CanonicalJSON(value any) ([]byte, error)
- func CanonicalJSONSHA256(value any) (string, error)
- func DecodeJSON(data []byte) (any, error)
- func ExtractArchive(ctx context.Context, opts ExtractOptions) error
- func FeatureNT(feature map[string]any, genome Genome) (string, bool)
- func JSONBytesCanonicalSHA256(data []byte) (string, error)
- func OpenManifestSources(path string) (FileSource, FileSource, error)
- func PrettyJSON(value any) ([]byte, error)
- func SHA256Hex(data []byte) string
- func SupportedBaktaFeatureTypes() []string
- type AGCGenomeSource
- type Archive
- type ArchiveIndex
- type BaktaGFF3Options
- type BuildOptions
- type ChunkIndex
- type DirSource
- type ExtractOptions
- type ExtractRequest
- type ExtractedSample
- type FieldCodec
- type FileRecord
- type FileSource
- type Genome
- type JSONChecksums
- type ListSource
- type Manifest
- type ManifestEntry
- type ManifestSource
- type OpenArchiveOptions
- type ReduceResult
- type RestoreResult
- type SampleIndex
- type SchemaIndexEntry
- type SingleFileSource
- func (s SingleFileSource) Get(ctx context.Context, sample string) (FileRecord, error)
- func (s SingleFileSource) Order(context.Context) ([]string, error)
- func (s SingleFileSource) Records(ctx context.Context) ([]FileRecord, error)
- func (s SingleFileSource) WithSampleID(sampleID string) SingleFileSource
- type TarXZSource
Constants ¶
const ( ArchiveMagic = "BAKPACK1" ArchiveVersion = 1 )
Variables ¶
var AnnotationJSONSuffixes = []string{".bakta.json", ".json"}
AnnotationJSONSuffixes lists the recognized Bakta annotation JSON filename suffixes, in the order checked. It's exported so cmd/bakpack's sampleIDFromPath (used by reduce/restore/gff3, which take an explicit JSON path rather than scanning a directory) can derive a sample ID from the same suffix list instead of maintaining its own separate copy.
Functions ¶
func BaktaGFF3 ¶ added in v0.2.0
BaktaGFF3 renders a Bakta JSON annotation as GFF3 using the observed Bakta JSON/GFF3 file formats. The input may be either original JSON or bakpack reduced JSON; reduced input is restored before rendering.
func BaktaGFF3WithOptions ¶ added in v0.2.0
func BaktaGFF3WithOptions(annotation []byte, genome Genome, opts BaktaGFF3Options) ([]byte, error)
BaktaGFF3WithOptions renders a Bakta JSON annotation as GFF3 with explicit output options.
func BuildArchive ¶
func BuildArchive(ctx context.Context, opts BuildOptions) error
func CanonicalJSON ¶
func CanonicalJSONSHA256 ¶
func DecodeJSON ¶
func ExtractArchive ¶
func ExtractArchive(ctx context.Context, opts ExtractOptions) error
ExtractArchive opens opts.ArchivePath and writes the selected sample outputs to opts.OutputDir using the same filenames as the CLI. It is a convenience wrapper around OpenArchive and Archive.ExtractFiles for callers that do not need to keep the archive open across requests.
func OpenManifestSources ¶
func OpenManifestSources(path string) (FileSource, FileSource, error)
func PrettyJSON ¶
func SupportedBaktaFeatureTypes ¶ added in v0.2.0
func SupportedBaktaFeatureTypes() []string
SupportedBaktaFeatureTypes returns the Bakta feature types currently handled by reduction, archive compression/extraction, and GFF3 rendering.
Types ¶
type AGCGenomeSource ¶
func (AGCGenomeSource) Get ¶
func (s AGCGenomeSource) Get(ctx context.Context, sample string) (FileRecord, error)
func (AGCGenomeSource) Order ¶
func (s AGCGenomeSource) Order(ctx context.Context) ([]string, error)
func (AGCGenomeSource) Records ¶
func (s AGCGenomeSource) Records(ctx context.Context) ([]FileRecord, error)
type Archive ¶
type Archive struct {
// contains filtered or unexported fields
}
Archive is an opened bakpack archive. It keeps the archive index in memory and can extract one or more samples without reopening the archive.
func OpenArchive ¶
OpenArchive opens a local .bakpack path or HTTP(S) URL. HTTP(S) archives are read with byte-range requests.
func (*Archive) Extract ¶
func (a *Archive) Extract(ctx context.Context, req ExtractRequest) ([]ExtractedSample, error)
Extract extracts one or more samples from the archive. Without OnSample, results are returned in the same order as req.Samples. With OnSample, results are delivered to the callback and the returned slice is nil.
func (*Archive) ExtractFiles ¶ added in v0.2.0
ExtractFiles extracts one or more samples and writes the selected outputs to outputDir using the same filenames as the CLI: SAMPLE.reduced.bakta.json, SAMPLE.bakta.json, SAMPLE.fa, and SAMPLE.gff3. If no output mode is selected, reduced JSON files are written. If outputDir is empty, "." is used.
ExtractFiles streams samples through OnSample and does not accumulate output bytes in memory. If req.OnSample is set, it is called after files for that sample have been written.
func (*Archive) Index ¶
func (a *Archive) Index() ArchiveIndex
Index returns a copy of the archive index.
type ArchiveIndex ¶
type ArchiveIndex struct {
Format string `json:"format"`
Version int `json:"version"`
PayloadFormat string `json:"payload_format"`
ChunkSize int `json:"chunk_size"`
Chunks []ChunkIndex `json:"chunks"`
Samples []SampleIndex `json:"samples"`
}
func ReadArchiveIndex ¶
func ReadArchiveIndex(path string) (ArchiveIndex, error)
ReadArchiveIndex reads the front index from a local or HTTP(S) archive using a background context.
func ReadArchiveIndexContext ¶
func ReadArchiveIndexContext(ctx context.Context, path string, opts ...OpenArchiveOptions) (ArchiveIndex, error)
ReadArchiveIndexContext reads the front index from a local or HTTP(S) archive. HTTP(S) archives are accessed with byte-range requests.
type BaktaGFF3Options ¶ added in v0.2.0
type BaktaGFF3Options struct {
// AnnotationOnly omits the terminal ##FASTA section containing contig
// sequences.
AnnotationOnly bool
// BakpackVersion overrides the version written in the generated-by header.
// When empty, the build-time bakpack version is used.
BakpackVersion string
}
BaktaGFF3Options configures Bakta JSON to GFF3 rendering.
type BuildOptions ¶
type BuildOptions struct {
Annotations FileSource
Genomes FileSource
Order []string
ChunkSize int
OutputPath string
XZThreads int
// AnnotationSpoolCompression controls temporary files made when building
// from annotation tar.xz sources whose order differs from genome order.
// Supported values are "", "gzip", "none", and "raw"; "" defaults to gzip.
AnnotationSpoolCompression string
}
type ChunkIndex ¶
type ChunkIndex struct {
ID int `json:"id"`
Offset int64 `json:"offset"`
CompressedSize int64 `json:"compressed_size"`
UncompressedSize int64 `json:"uncompressed_size"`
TopKeys []string `json:"top_keys,omitempty"`
ValueSchemas []SchemaIndexEntry `json:"value_schemas,omitempty"`
FeatureSchemas []SchemaIndexEntry `json:"feature_schemas,omitempty"`
FeatureFields []string `json:"feature_fields,omitempty"`
FieldCodecs []FieldCodec `json:"field_codecs,omitempty"`
}
type ExtractOptions ¶
type ExtractOptions struct {
// ArchivePath is a local .bakpack path or HTTP(S) URL.
ArchivePath string
// OpenOptions configures archive reads, including custom HTTP clients for
// HTTP(S) archives.
OpenOptions OpenArchiveOptions
// Genomes is required when Original, Genome, or GFF3 output is requested.
Genomes FileSource
// Samples are the sample IDs to extract.
Samples []string
// OutputDir receives extracted files. If empty, "." is used.
OutputDir string
// Reduced writes SAMPLE.reduced.bakta.json.
Reduced bool
// Original writes SAMPLE.bakta.json.
Original bool
// Genome writes SAMPLE.fa.
Genome bool
// GFF3 writes SAMPLE.gff3.
GFF3 bool
// GFF3AnnotationOnly writes SAMPLE.gff3 without the terminal ##FASTA
// section. It implies GFF3.
GFF3AnnotationOnly bool
}
ExtractOptions configures one-shot extraction from an archive path or HTTP(S) URL to files on disk.
type ExtractRequest ¶
type ExtractRequest struct {
// Genomes is required when Original, Genome, or GFF3 output is requested.
Genomes FileSource
// Samples are the sample IDs to extract.
Samples []string
// Reduced returns reduced Bakta JSON.
Reduced bool
// Original reconstructs original Bakta JSON and verifies its canonical hash.
Original bool
// Genome returns matching genome FASTA.
Genome bool
// GFF3 renders a Bakta-style GFF3 annotation.
GFF3 bool
// GFF3AnnotationOnly returns GFF3 output without the terminal ##FASTA section.
// It implies GFF3.
GFF3AnnotationOnly bool
// OnSample is called for each extracted sample. When nil, Extract returns
// accumulated results in the same order as Samples.
OnSample func(ExtractedSample) error
}
ExtractRequest configures extraction from an opened archive.
type ExtractedSample ¶
type ExtractedSample struct {
SampleID string
AnnotationName string
GenomeName string
ReducedJSON []byte
OriginalJSON []byte
GenomeFASTA []byte
GFF3 []byte
OriginalJSONCanonicalSHA256 string
ReducedJSONCanonicalSHA256 string
}
ExtractedSample contains the bytes extracted or reconstructed for one sample.
type FieldCodec ¶
type FileRecord ¶
type FileSource ¶
type FileSource interface {
Records(context.Context) ([]FileRecord, error)
Get(context.Context, string) (FileRecord, error)
Order(context.Context) ([]string, error)
}
func OpenSource ¶
func OpenSource(path, kind, role string) (FileSource, error)
type Genome ¶
type Genome struct {
SampleID string
Filename string
Contigs []seqio.SeqRecord
// contains filtered or unexported fields
}
func (*Genome) Contig ¶
Contig has a pointer receiver so the lazily-built byName cache actually persists on the caller's Genome instead of being discarded with a copy; ReadGenome always populates byName up front, but a Genome built directly (e.g. Genome{Contigs: ...}) relies on this cache being retained across calls.
type JSONChecksums ¶
type JSONChecksums struct {
CanonicalSHA256 string `json:"canonical_sha256"`
}
type ListSource ¶
func (ListSource) Get ¶
func (s ListSource) Get(ctx context.Context, sample string) (FileRecord, error)
func (ListSource) Records ¶
func (s ListSource) Records(ctx context.Context) ([]FileRecord, error)
type ManifestEntry ¶
type ManifestSource ¶
func (ManifestSource) Get ¶
func (s ManifestSource) Get(ctx context.Context, sample string) (FileRecord, error)
func (ManifestSource) Records ¶
func (s ManifestSource) Records(ctx context.Context) ([]FileRecord, error)
type OpenArchiveOptions ¶
type OpenArchiveOptions struct {
// HTTPClient is used for byte-range requests when the archive path is an
// HTTP(S) URL. A nil client uses http.DefaultClient.
HTTPClient *http.Client
}
OpenArchiveOptions configures archive reads.
type ReduceResult ¶
type ReduceResult struct {
ReducedJSON []byte
Original JSONChecksums
Reduced JSONChecksums
// contains filtered or unexported fields
}
func ReduceBaktaJSON ¶
func ReduceBaktaJSON(original []byte, genome Genome) (ReduceResult, error)
type RestoreResult ¶
type RestoreResult struct {
OriginalJSON []byte
Original JSONChecksums
}
func RestoreBaktaJSON ¶
func RestoreBaktaJSON(reduced []byte, genome Genome) (RestoreResult, error)
type SampleIndex ¶
type SampleIndex struct {
SampleID string `json:"sample_id"`
AnnotationName string `json:"annotation_name"`
GenomeName string `json:"genome_name"`
ChunkID int `json:"chunk_id"`
OriginalJSONCanonicalSHA256 string `json:"original_json_canonical_sha256"`
ReducedJSONCanonicalSHA256 string `json:"reduced_json_canonical_sha256"`
}
type SchemaIndexEntry ¶
type SingleFileSource ¶ added in v0.3.0
type SingleFileSource struct {
File sourceFile
}
SingleFileSource exposes one genome file as a source. Its sample ID is inferred from the file name, including recognised compression suffixes.
func (SingleFileSource) Get ¶ added in v0.3.0
func (s SingleFileSource) Get(ctx context.Context, sample string) (FileRecord, error)
func (SingleFileSource) Order ¶ added in v0.3.0
func (s SingleFileSource) Order(context.Context) ([]string, error)
func (SingleFileSource) Records ¶ added in v0.3.0
func (s SingleFileSource) Records(ctx context.Context) ([]FileRecord, error)
func (SingleFileSource) WithSampleID ¶ added in v0.3.0
func (s SingleFileSource) WithSampleID(sampleID string) SingleFileSource
WithSampleID returns a copy that exposes the genome as sampleID. It is used by the CLI when a single genome file accompanies an explicit sample argument.
type TarXZSource ¶
func (TarXZSource) Get ¶
func (s TarXZSource) Get(ctx context.Context, sample string) (FileRecord, error)
func (TarXZSource) Records ¶
func (s TarXZSource) Records(ctx context.Context) ([]FileRecord, error)