g
gcw_coj3XaOd/maxentscan-score3
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

MaxEntScan Score3 — Ascend NPU Adaptation

1. 模型简介(Model Overview)

FieldValue
Modelmultimolecule/maxentscan-score3
Task3' splice-site (acceptor) maximum-entropy scoring
SourceHuggingFace
BaseMaximum-entropy model (Yeo & Burge, 2004) — no trainable weights
Window23 nucleotides
ConsensusAG at positions 18-19
OutputSingle log2 maximum-entropy score per 23-mer

2. 环境依赖(Environment)

DependencyVersion
Python3.11
torch2.9.0+cpu
torch-npu2.9.0.post1
CANN8.5.1
NPUAscend 910_9362

Adaptation Approach

The MaxEntScan model is a deterministic lookup-table model with no neural network weights. The original multimolecule framework depends on transformers APIs incompatible with the Ascend NPU runtime. This adaptation:

  1. Bypasses the full multimolecule import chain — directly ports the scoring logic from modeling_maxentscan.py
  2. Loads score tables (score3_me2x3acc.txt) from the published Yeo & Burge (2004) parameters
  3. Runs inference on NPU via torch_npu with zero training/inference API dependencies on transformers

3. 启动服务与推理调用(Usage)

3.1 启动服务(Start Service)

# Single sequence inference
python inference.py --model-path /tmp/inspect_maxentscan --seq AUGCACAGCUCAGCACUGCUCUG --device npu

# Full verification suite
python verify.py --device npu

3.2 推理调用(Inference)

# Single sequence inference
python inference.py --model-path /tmp/inspect_maxentscan --seq AUGCACAGCUCAGCACUGCUCUG --device npu

# Full verification suite
python verify.py --device npu

Inference Output (NPU)

======================================================================
MaxEntScan-score3  Ascend NPU Inference
======================================================================
  torch         : 2.9.0+cpu
  torch_npu     : 2.9.0.post1+gitee7ba04
  NPU count     : 2
  NPU name      : Ascend 910_9362
  Model path    : /tmp/inspect_maxentscan
  Mode          : score3 (3' splice site acceptor)
  Window        : 23 nt
======================================================================

Inference:
----------------------------------------------------------------------
  Sequence      : AUGCACAGCUCAGCACUGCUCUG
  Input shape   : [1, 23]
  Score         : -37.1781
  Elapsed       : 2.52 ms
  Status        : SUCCESS
----------------------------------------------------------------------

Test Cases & Results

#SequenceCategoryCPU ScoreNPU ScoreDiffStatus
1AUGCACAGCUCAGCACUGCUCUGstrong-37.1781-37.17810.000000PASS
2CAGAAUGAAUGGAGACGUGCUGCstrong-26.0646-26.06460.000000PASS
3GGCUGAGUGAGAGACAUGCGCUCstrong-39.0624-39.06240.000000PASS
4UUUUUAGUUGUUGUGCUUGCUGAweak-11.0786-11.07860.000000PASS
5AACCAAGAAAUGCUUGGCUCUACweak-18.5432-18.54320.000002PASS

Accuracy Evaluation

Methodology

  1. Independent numpy reference — A standalone numpy implementation (no torch dependency) was written following the original Yeo & Burge (2004) algorithm:

    • Base-4 hash of k-mer submodels
    • Consensus ratio: cons1[b0] * cons2[b1] / (bgd[b0] * bgd[b1])
    • Decomposition: sc0*sc1*sc2*sc3*sc4 / (sc5*sc6*sc7*sc8)
    • Final score: log2(consensus * decomposition)
  2. Cross-validation — All 5 test sequences were scored by:

    • numpy reference implementation (float64)
    • torch inference.py (float32, CPU)
    • torch inference.py (float32, NPU)
  3. Score table validation — The score3_me2x3acc.txt from the multimolecule package was verified against the original Burge lab parameters.

Numerical Agreement

ComparisonMax Absolute DiffStatus
numpy vs torch (CPU)0.000002PASS
torch (CPU) vs torch (NPU)0.000002PASS
numpy vs torch (NPU)0.000002PASS

All scores agree to within float32 precision (tolerance < 1e-3).

Performance

DeviceAvg Inference TimeNotes
CPU0.83 msSingle sequence, no batching
NPU2.52 msIncludes NPU-CPU synchronization overhead

Note: The NPU overhead for single-sequence inference (~2.5 ms) is dominated by kernel launch and synchronization. For batched inference (batch_size ≥ 32), the NPU throughput advantage over CPU is expected to be significant.

Algorithm Details

The score3 model scores a 23-nucleotide window for 3' splice-site acceptor strength:

23-mer: (intron) X*20 | XXX (exon)
                  ↑AG↑
  1. Consensus score — The AG dinucleotide at positions 18-19 is scored against background frequencies:

    consensus_ratio = cons1[b18] * cons2[b19] / (bgd[b18] * bgd[b19])
  2. Rest score — The remaining 21 positions (0-17, 20-22) are scored by nine overlapping submodels:

    decomposition = sc0*sc1*sc2*sc3*sc4 / (sc5*sc6*sc7*sc8)
  3. Final score:

    score = log2(consensus_ratio * rest_score)

Files

FileDescription
inference.pyStandalone NPU inference script
verify.pyVerification suite (CPU vs NPU comparison)
assets/Screenshots and documentation assets

References

  • Yeo G, Burge CB (2004). "Maximum entropy modeling of short sequence motifs with applications to RNA splicing signals." Journal of Computational Biology, 11(2-3):377-394.
  • multimolecule/maxentscan-score3
  • Christopher Burge Laboratory — MaxEntScan