osf

package
v0.18.0-beta.2 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const CacheMaxAge = 7 * 24 * time.Hour

Variables

This section is empty.

Functions

func SpeciesFromArchive

func SpeciesFromArchive(name string) string

SpeciesFromArchive derives the species prefix from an AGC archive name by splitting on the literal "_global_ordered_" token. This keeps GTDB letter-suffixes ("Streptococcus_suis_AA") and the special "subthreshold_remainder" batch intact. The ".agc" extension is optional.

func WriteAGCIndexTSV added in v0.18.0

func WriteAGCIndexTSV(idx *Index, w io.Writer) error

WriteAGCIndexTSV writes the index as a 6-column TSV in the same layout as the master OSF index, so ParseIndex round-trips it.

Types

type Entry

type Entry struct {
	Project   string
	ProjectID string
	Filename  string
	URL       string
	MD5       string
	SizeMB    float64
}

type Index

type Index struct {
	Entries []Entry
}

func CrawlAGCIndex

func CrawlAGCIndex(rootURL, nodeID string) (*Index, error)

CrawlAGCIndex resolves the agc_batches/ folder from an OSF node's root listing (rootURL, build it with sources.OSFNodeFilesURL) and crawls every page of that folder into an Index, with no caching side effect. Each entry's ProjectID is stamped with nodeID. This is the network half of FetchAGCIndex, exposed so `atb agc index` can crawl on demand and write the TSV wherever the user wants it.

func CrawlAGCNode added in v0.18.0

func CrawlAGCNode(client *http.Client, startURL, nodeID string) (*Index, error)

CrawlAGCNode walks an OSF folder listing starting at startURL, following the "next" link until exhausted, and returns an Index of every .agc file found. Each entry's ProjectID is stamped with nodeID. A nil client gets a default.

func FetchAGCIndex

func FetchAGCIndex(cacheDir, rootURL, nodeID string, force bool) (*Index, error)

FetchAGCIndex returns the AGC batch index for an OSF node, mirroring FetchIndex: a cached TSV is reused while younger than CacheMaxAge and while its source marker still matches rootURL, otherwise the node's agc_batches/ folder is crawled and the result written atomically to <cacheDir>/atb_agc_files.tsv (alongside a refreshed marker). rootURL is the node's osfstorage listing (build it with sources.OSFNodeFilesURL); it is a parameter so the crawl is testable against a local server. nodeID is stamped onto every entry's ProjectID. Set force=true to bypass a fresh cache.

func FetchAGCIndexFromURL added in v0.18.0

func FetchAGCIndexFromURL(cacheDir, url string, force bool) (*Index, error)

FetchAGCIndexFromURL returns the AGC batch index by downloading a pre-built TSV from url, mirroring FetchIndex: a cached copy under <cacheDir>/atb_agc_files.tsv is reused while younger than CacheMaxAge and while its source marker still matches url, otherwise the file is downloaded and written atomically (alongside a refreshed marker) before parsing. This is the hosted counterpart to FetchAGCIndex's live crawl — once the index has been published as a single OSF file (sources.AGCIndexURL) there is no need to walk the node's agc_batches/ folder page by page. Set force=true to bypass a fresh cache.

func FetchIndex

func FetchIndex(cacheDir string, force bool) (*Index, error)

FetchIndex returns a parsed index, using a cached copy if fresh enough. Set force=true to always re-download.

func ParseIndex

func ParseIndex(r io.Reader) (*Index, error)

ParseIndex reads the TSV index from r. Expected columns: project, project_id, filename, url, md5, size(MB)

func (*Index) Filter

func (idx *Index) Filter(project, pattern string) ([]Entry, error)

Filter returns entries matching the given criteria. If project is non-empty, only entries whose Project starts with that prefix are included. If pattern is non-empty, it is compiled as a regex and matched against "project/filename".

func (*Index) MatchProject

func (idx *Index) MatchProject(query string) []Entry

MatchProject returns entries whose project matches a case-insensitive substring.

func (*Index) Projects

func (idx *Index) Projects() []ProjectSummary

Projects returns a summary of each unique project with file count and total size.

type ProjectSummary

type ProjectSummary struct {
	Project   string
	FileCount int
	TotalMB   float64
}

Jump to

Keyboard shortcuts

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