moonbio

moon add caassien/moonbio@0.1.2
Download zip
Author
Version
0.1.2
License
MIT
Last updated
12 days ago
Downloads
21
README

#MoonBio

CI

MoonBio 是一个面向 MoonBit 生态的生物信息学基础库,聚焦序列解析、经典比对算法、简单 MSA 流程、CLI/WASM 演示与可复现验收流程。仓库按 2026 MoonBit OSC2026 的公开开发要求整理,当前主仓库为 GitHub,镜像仓库为 GitLink

#目标

  • 提供可复用的 DNA/RNA 序列基础能力。
  • 提供 MoonBit 可运行的 FASTA / FASTQ 解析实现。
  • 提供 Needleman-Wunsch、Smith-Waterman、Levenshtein 和渐进式 MSA。
  • 提供可验证的 CLI 与 WASM 构建入口。
  • 提供竞赛验收需要的 CI、自查脚本、来源说明和申报材料。

#功能概览

  • src/core
    • DNA 序列类型、反向互补、转录、HMM Viterbi 示例。
  • src/parser
    • 多记录 FASTA 解析。
    • FASTQ 解析与质量长度一致性校验。
    • FASTA / FASTQ 汇总统计。
    • FASTA GC 百分比与 FASTQ Phred+33 质量范围统计。
  • src/align
    • Needleman-Wunsch 全局比对。
    • Smith-Waterman 局部比对。
    • Levenshtein 距离。
    • 基于中心序列的渐进式 MSA。
  • cmd/cli
    • 运行全局比对、MSA 和解析统计示例。
  • cmd/wasm
    • 生成 WASM 入口并导出示例函数。

#仓库结构

. ├── cmd/ │ ├── cli/ │ └── wasm/ ├── docs/ ├── scripts/ ├── src/ │ ├── align/ │ ├── core/ │ └── parser/ ├── moon.mod ├── moon.pkg ├── official-requirements.md ├── proposal-one-page.md ├── source-attribution.md └── submission-status.md

#快速开始

git clone https://github.com/caassien/MoonBio.git cd MoonBio moon update moon fmt --check moon check --target all moon test --target wasm moon test --target wasm-gc moon test --target js

本机若安装了 C 编译器,还可以继续执行:

moon test --target native

#示例

CLI 示例:

moon run cmd/cli

WASM 构建:

moon build --target wasm-gc cmd/wasm

产物默认位于:

_build/wasm-gc/debug/build/cmd/wasm/wasm.wasm

#验收与自查

推荐本地执行:

powershell -ExecutionPolicy Bypass -File .\scripts\verify_acceptance.ps1

若需要强制验证 native 目标:

powershell -ExecutionPolicy Bypass -File .\scripts\verify_acceptance.ps1 -RequireNative

#性能与正确性证据

算法采用可解释的动态规划基线:全局/局部比对的时间复杂度为 O(m*n)、空间复杂度为 O(m*n);渐进式 MSA 以第一条序列为中心,依次合并 两两比对结果。解析器会拒绝缺失头部、空序列、非法字符和 FASTQ 质量长度不一致, 并提供 GC 与质量范围统计,便于在真实数据上复核边界行为。

可复现实验步骤见 docs/benchmarks.md

#MoonBit 包信息

  • Module: caassien/moonbio
  • License: MIT
  • 推荐工具链:moonc v0.10.3

#当前限制

  • cmd/wasm 已提供真实 WASM 构建入口与导出函数,但浏览器侧展示页仍以轻量验收演示为主,后续可以继续扩展为完整交互式前端。
  • 当前 MSA 为可运行的渐进式基线版本,重点在可测试、可维护和可扩展。

#License

MIT

#
AlignmentConfig

pub struct AlignmentConfig {
match_score : Int
mismatch_score : Int
gap_penalty : Int
} derive(Eq,
Debug
)

#
BioEngine

pub struct BioEngine {
config : AlignmentConfig
} derive(Eq,
Debug
)

#
BioEngine::global_align

fn BioEngine::global_align(self : BioEngine, left : String, right : String) ->
AlignmentResult

#
BioEngine::local_align

fn BioEngine::local_align(self : BioEngine, left : String, right : String) ->
AlignmentResult

#
BioEngine::multiple_align

fn BioEngine::multiple_align(self : BioEngine, sequences : Array[String]) ->
MsaResult

#
BioEngine::new

fn BioEngine::new() -> BioEngine

#
BioEngine::summarize_fasta

fn BioEngine::summarize_fasta(self : BioEngine, content : String) -> Result[String, String]

#
BioEngine::summarize_fastq

fn BioEngine::summarize_fastq(self : BioEngine, content : String) -> Result[String, String]

#
BioEngine::with_config

fn BioEngine::with_config(config : AlignmentConfig) -> BioEngine

#
SequenceContext

pub struct SequenceContext {
id : String
sequence : String
length : Int
gc_percent : Int
} derive(Eq,
Debug
)

#
SequenceContext::new

fn SequenceContext::new(id : String, sequence : String) -> SequenceContext

#
default_alignment_config

fn default_alignment_config() -> AlignmentConfig

#
gc_ratio_percent

fn gc_ratio_percent(sequence : String) -> Int

#
normalize_sequence

fn normalize_sequence(sequence : String) -> String

#
validate_dna_string

fn validate_dna_string(sequence : String) -> Result[Unit, String]

#
validate_non_empty_records

fn validate_non_empty_records(record_count : Int, format_name : String) -> Result[Unit, String]