Files
silk/server-go/internal/model/molecular.go
T

50 lines
1.2 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package model
import (
"errors"
"path/filepath"
"strings"
)
const maxSpectrumSize = 5 << 20 // 5MB
// ValidDetectionMethod 检测方式枚举
func ValidDetectionMethod(method string) bool {
switch method {
case "lamp", "qpcr", "sers", "hyperspectral":
return true
default:
return false
}
}
// JudgeQPCR qPCR Ct 值自动判读:任一 Ct < threshold 判阳性,无 Ct 判阴性
func JudgeQPCR(cts []float64, threshold float64) (string, string) {
if threshold <= 0 {
threshold = 35
}
if len(cts) == 0 {
return "negative", "未检出 Ct 值,判为阴性"
}
for _, ct := range cts {
if ct < threshold {
return "positive", "存在 Ct 值低于阈值,判为阳性"
}
}
return "negative", "全部 Ct 值不低于阈值,判为阴性"
}
// ValidateSpectrumFile 光谱数据文件校验(csv/txt/json,≤5MB
func ValidateSpectrumFile(filename string, size int64) error {
if size <= 0 || size > maxSpectrumSize {
return errors.New("光谱文件大小需在 1B~5MB 之间")
}
ext := strings.ToLower(filepath.Ext(filename))
switch ext {
case ".csv", ".txt", ".json":
return nil
default:
return errors.New("仅支持 csv/txt/json 光谱数据文件")
}
}