service

package
v0.1.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package service provides high-level business logic for querying and managing SRA metadata, including study, experiment, sample, and run access.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseService

type BaseService interface {
	// Health checks if the service is operational
	Health(ctx context.Context) error

	// Close releases any resources
	Close() error
}

Common service interfaces that all services should implement

type CountItem

type CountItem struct {
	Name  string `json:"name"`
	Count int64  `json:"count"`
}

CountItem for statistical counts

type ExportRequest

type ExportRequest struct {
	Query   string            `json:"query"`
	Filters map[string]string `json:"filters,omitempty"`
	Format  string            `json:"format"` // json, csv, tsv, xml
	Limit   int               `json:"limit,omitempty"`
	Fields  []string          `json:"fields,omitempty"`
}

ExportRequest for data export

type ExportService

type ExportService struct {
	// contains filtered or unexported fields
}

ExportService handles data export in various formats

func NewExportService

func NewExportService(db *database.DB, searchSvc *SearchService) *ExportService

NewExportService creates a new export service instance

func (*ExportService) Close

func (e *ExportService) Close() error

Close cleans up the export service

func (*ExportService) Export

func (e *ExportService) Export(ctx context.Context, req *ExportRequest, writer io.Writer) error

Export exports data based on the request parameters

func (*ExportService) ExportToFile

func (e *ExportService) ExportToFile(ctx context.Context, req *ExportRequest, filename string) error

ExportToFile exports data to a file

func (*ExportService) Health

func (e *ExportService) Health(ctx context.Context) error

Health checks if the export service is operational

type IndexRequest

type IndexRequest struct {
	Operation   string `json:"operation"` // build, rebuild, update
	BatchSize   int    `json:"batch_size,omitempty"`
	WithVectors bool   `json:"with_vectors,omitempty"`
}

IndexRequest for index operations

type IndexResponse

type IndexResponse struct {
	Status    string        `json:"status"`
	Documents int64         `json:"documents"`
	Duration  time.Duration `json:"duration"`
}

IndexResponse for index operations

type IngestFilters

type IngestFilters struct {
	TaxonIDs   []string  `json:"taxon_ids,omitempty"`
	Platforms  []string  `json:"platforms,omitempty"`
	Strategies []string  `json:"strategies,omitempty"`
	DateFrom   time.Time `json:"date_from,omitempty"`
	DateTo     time.Time `json:"date_to,omitempty"`
}

IngestFilters for selective ingestion

type IngestRequest

type IngestRequest struct {
	Source    string        `json:"source"` // file path or URL
	BatchSize int           `json:"batch_size,omitempty"`
	Filters   IngestFilters `json:"filters,omitempty"`
}

IngestRequest for data ingestion

type IngestResponse

type IngestResponse struct {
	Processed int64         `json:"processed"`
	Inserted  int64         `json:"inserted"`
	Updated   int64         `json:"updated"`
	Errors    int64         `json:"errors"`
	Duration  time.Duration `json:"duration"`
}

IngestResponse for ingestion results

type MetadataRequest

type MetadataRequest struct {
	Accession string `json:"accession"`
	Type      string `json:"type"` // study, experiment, sample, run
}

MetadataRequest for fetching specific records

type MetadataResponse

type MetadataResponse struct {
	Data      interface{} `json:"data"`
	Type      string      `json:"type"`
	Retrieved time.Time   `json:"retrieved"`
}

MetadataResponse for metadata queries

type MetadataService

type MetadataService struct {
	// contains filtered or unexported fields
}

MetadataService provides read access to SRA metadata records across studies, experiments, samples, and runs with pagination and relational lookups.

func NewMetadataService

func NewMetadataService(db *database.DB) *MetadataService

NewMetadataService creates a new metadata service instance

func (*MetadataService) Close

func (m *MetadataService) Close() error

Close releases any resources held by the MetadataService.

func (*MetadataService) GetAccessionType

func (m *MetadataService) GetAccessionType(ctx context.Context, accession string) (string, error)

GetAccessionType determines whether an accession refers to a study, experiment, sample, or run by probing each table. Returns an error if the accession is not found.

func (*MetadataService) GetExperiment

func (m *MetadataService) GetExperiment(ctx context.Context, accession string) (*database.Experiment, error)

GetExperiment retrieves an experiment by accession

func (*MetadataService) GetExperimentsByStudy

func (m *MetadataService) GetExperimentsByStudy(ctx context.Context, studyAccession string) ([]*database.Experiment, error)

GetExperimentsByStudy retrieves all experiments for a study

func (*MetadataService) GetMetadata

func (m *MetadataService) GetMetadata(ctx context.Context, req *MetadataRequest) (*MetadataResponse, error)

GetMetadata retrieves metadata for a specific accession, dispatching to the appropriate record type (study, experiment, sample, or run) based on the request.

func (*MetadataService) GetRun

func (m *MetadataService) GetRun(ctx context.Context, accession string) (*database.Run, error)

GetRun retrieves a run by accession

func (*MetadataService) GetRunsByExperiment

func (m *MetadataService) GetRunsByExperiment(ctx context.Context, experimentAccession string) ([]*database.Run, error)

GetRunsByExperiment retrieves all runs for an experiment

func (*MetadataService) GetRunsByStudy

func (m *MetadataService) GetRunsByStudy(ctx context.Context, studyAccession string, limit int) ([]*database.Run, error)

GetRunsByStudy retrieves all runs for a study

func (*MetadataService) GetSample

func (m *MetadataService) GetSample(ctx context.Context, accession string) (*database.Sample, error)

GetSample retrieves a sample by accession

func (*MetadataService) GetSamplesByStudy

func (m *MetadataService) GetSamplesByStudy(ctx context.Context, studyAccession string) ([]*database.Sample, error)

GetSamplesByStudy retrieves all samples for a study via the experiment_samples junction table

func (*MetadataService) GetStudies

func (m *MetadataService) GetStudies(ctx context.Context, limit, offset int) ([]*database.Study, error)

GetStudies retrieves multiple studies with pagination

func (*MetadataService) GetStudy

func (m *MetadataService) GetStudy(ctx context.Context, accession string) (*database.Study, error)

GetStudy retrieves a study by accession

func (*MetadataService) GetStudyMetadata

func (m *MetadataService) GetStudyMetadata(ctx context.Context, studyAccession string) (map[string]interface{}, error)

GetStudyMetadata retrieves the complete metadata graph for a study, including its experiments, samples, and up to 100 runs.

func (*MetadataService) Health

func (m *MetadataService) Health(ctx context.Context) error

Health verifies the service is operational by checking the database connection and executing a basic query.

type SearchHit

type SearchHit struct {
	Study      *database.Study      `json:"study,omitempty"`
	Experiment *database.Experiment `json:"experiment,omitempty"`
	Sample     *database.Sample     `json:"sample,omitempty"`
	Run        *database.Run        `json:"run,omitempty"`
	Score      float64              `json:"score,omitempty"`
	Confidence string               `json:"confidence,omitempty"`
	Highlights map[string][]string  `json:"highlights,omitempty"`
}

SearchHit represents a single search result with full entities (deprecated, use SearchResult)

type SearchRequest

type SearchRequest struct {
	Query   string            `json:"query"`
	Filters map[string]string `json:"filters,omitempty"`

	// Pagination
	Limit  int `json:"limit,omitempty"`
	Offset int `json:"offset,omitempty"`

	// Output control
	Format string   `json:"format,omitempty"`
	Fields []string `json:"fields,omitempty"`

	// Search options
	Fuzzy      bool   `json:"fuzzy,omitempty"`
	Exact      bool   `json:"exact,omitempty"`
	UseVectors bool   `json:"use_vectors,omitempty"`
	SearchMode string `json:"search_mode,omitempty"`

	// Quality control
	SimilarityThreshold float32 `json:"similarity_threshold,omitempty"`
	MinScore            float32 `json:"min_score,omitempty"`
	TopPercentile       int     `json:"top_percentile,omitempty"`
	ShowConfidence      bool    `json:"show_confidence,omitempty"`
	HybridWeight        float32 `json:"hybrid_weight,omitempty"`
}

SearchRequest represents a search request with all parameters

type SearchResponse

type SearchResponse struct {
	Results      []*SearchResult        `json:"results"`
	TotalResults int                    `json:"total_results"`
	Query        string                 `json:"query"`
	TimeTaken    int64                  `json:"time_taken_ms"`
	SearchMode   string                 `json:"search_mode,omitempty"`
	Facets       map[string]interface{} `json:"facets,omitempty"`
}

SearchResponse represents search results

type SearchResult

type SearchResult struct {
	ID              string                 `json:"id"`
	Type            string                 `json:"type"`
	Title           string                 `json:"title,omitempty"`
	Description     string                 `json:"description,omitempty"`
	Organism        string                 `json:"organism,omitempty"`
	Platform        string                 `json:"platform,omitempty"`
	LibraryStrategy string                 `json:"library_strategy,omitempty"`
	Score           float32                `json:"score,omitempty"`
	Similarity      float32                `json:"similarity,omitempty"`
	Confidence      string                 `json:"confidence,omitempty"`
	Fields          map[string]interface{} `json:"fields,omitempty"`
	Highlights      map[string][]string    `json:"highlights,omitempty"`
}

SearchResult represents a single search result

type SearchService

type SearchService struct {
	// contains filtered or unexported fields
}

SearchService handles search operations

func NewSearchService

func NewSearchService(db *database.DB, indexPath string) (*SearchService, error)

NewSearchService creates a new search service

func (*SearchService) BuildIndex

func (s *SearchService) BuildIndex(ctx context.Context, batchSize int, withEmbeddings bool) error

BuildIndex builds or rebuilds the search index

func (*SearchService) Close

func (s *SearchService) Close() error

Close cleans up the search service

func (*SearchService) GetStats

func (s *SearchService) GetStats(ctx context.Context) (*SearchStats, error)

GetStats retrieves search statistics

func (*SearchService) Health

func (s *SearchService) Health(ctx context.Context) error

Health checks if the search service is healthy

func (*SearchService) Search

Search performs a search using the search manager

type SearchStats

type SearchStats struct {
	TotalDocuments   int64      `json:"total_documents"`
	IndexedDocuments int64      `json:"indexed_documents"`
	IndexSize        int64      `json:"index_size"`
	LastIndexed      time.Time  `json:"last_indexed,omitempty"`
	LastUpdated      time.Time  `json:"last_updated"`
	TopOrganisms     []StatItem `json:"top_organisms,omitempty"`
	TopPlatforms     []StatItem `json:"top_platforms,omitempty"`
	TopStrategies    []StatItem `json:"top_strategies,omitempty"`
}

SearchStats for search service statistics

type ServiceError

type ServiceError struct {
	Code    string      `json:"code"`
	Message string      `json:"message"`
	Details interface{} `json:"details,omitempty"`
}

ServiceError represents a service-level error

func (*ServiceError) Error

func (e *ServiceError) Error() string

type StatItem

type StatItem struct {
	Name  string `json:"name"`
	Count int64  `json:"count"`
}

StatItem for statistical data

type StatsResponse

type StatsResponse struct {
	TotalStudies     int64       `json:"total_studies"`
	TotalExperiments int64       `json:"total_experiments"`
	TotalSamples     int64       `json:"total_samples"`
	TotalRuns        int64       `json:"total_runs"`
	LastUpdate       time.Time   `json:"last_update"`
	IndexSize        int64       `json:"index_size"`
	DatabaseSize     int64       `json:"database_size"`
	TopOrganisms     []CountItem `json:"top_organisms,omitempty"`
	TopPlatforms     []CountItem `json:"top_platforms,omitempty"`
	TopStrategies    []CountItem `json:"top_strategies,omitempty"`
}

StatsResponse for database statistics (alias for API compatibility)

Jump to

Keyboard shortcuts

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