Files
brapi-java/docs/architecture/04-germplasm-seed-data-flow.md
2026-05-28 11:56:17 +08:00

143 lines
8.0 KiB
Markdown
Raw Permalink 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.

# Germplasm 与 Seed 数据流及表关系
本文档整理 Germplasm 模块中以 `germplasm` 为核心,并覆盖 SeedLot、CrossingProject、GermplasmAttribute、Cross、Pedigree 等相关表的关系。重点表包括:
```text
germplasm
seed_lot
seed_lot_content_mixture
crossing_project
cross_entity / planned cross / cross_parent
germplasm_attribute_definition
germplasm_attribute_value
pedigree_node / pedigree_edge
breeding_method
```
## 结论
Germplasm 关系主线可以理解为:
```text
breeding_method -> germplasm -> germplasm_attribute_value -> germplasm_attribute_definition
program -> crossing_project -> cross_entity -> cross_parent -> germplasm
germplasm / cross_entity -> seed_lot_content_mixture -> seed_lot
germplasm -> pedigree_node -> pedigree_edge
```
其中 `plannedcross` 在数据库中不是独立表,而是 `cross_entity` 的自关联:`cross_entity.planned_cross_id -> cross_entity.id`,并通过 `planned` 字段区分计划杂交和实际杂交。
## 图 4 Germplasm 关系架构图
```mermaid
flowchart TD
BM["breeding_method<br/>育种方法"] -->|"breeding_method_id"| G["germplasm<br/>种质主表"]
CROP["crop<br/>作物"] -->|"crop_id"| G
GAD["germplasm_attribute_definition<br/>GermplasmAttribute 定义"] -->|"attribute_id"| GAV["germplasm_attribute_value<br/>GermplasmAttributeValue"]
G -->|"germplasm_id"| GAV
CROP -->|"crop_id"| GAD
TR["trait"] -->|"trait_id"| GAD
ME["method"] -->|"method_id"| GAD
SC["scale"] -->|"scale_id"| GAD
ONT["ontology"] -->|"ontology_id"| GAD
PR["program<br/>项目"] -->|"program_id"| CP["crossing_project<br/>CrossingProject"]
CP -->|"crossing_project_id"| CR["cross_entity<br/>Cross / PlannedCross"]
CP -->|"crossing_project_id"| XP["cross_parent<br/>CrossParent"]
CR -->|"cross_id"| XP
G -->|"germplasm_id"| XP
OU["observation_unit<br/>可选亲本来源"] -->|"observation_unit_id"| XP
CR -->|"planned_cross_id 自关联"| PCR["cross_entity<br/>planned cross"]
G -->|"germplasm_id"| SCM["seed_lot_content_mixture<br/>SeedLot 组成"]
CR -->|"cross_id"| SCM
SCM -->|"seed_lot_id"| SL["seed_lot<br/>SeedLot"]
PR -->|"program_id"| SL
LOC["location<br/>库位/地点"] -->|"location_id"| SL
SL -->|"from_seed_lot_id"| TX["seed_lot_transaction<br/>SeedLot 流转"]
TX -->|"to_seed_lot_id"| SL
CP -->|"crossing_project_id"| PN["pedigree_node<br/>PedigreeNode"]
G -->|"germplasm_id"| PN
PN -->|"this_node_id"| PE["pedigree_edge<br/>亲子/同胞关系"]
PE -->|"connceted_node_id"| PN2["pedigree_node<br/>父本/子代节点"]
```
## 图 4-2 Germplasm ER 关系图
```mermaid
erDiagram
crop ||--o{ germplasm : "crop_id"
breeding_method ||--o{ germplasm : "breeding_method_id"
germplasm ||--o{ germplasm_attribute_value : "germplasm_id"
germplasm ||--o{ germplasm_donor : "germplasm_id"
germplasm ||--o{ germplasm_institute : "germplasm_id"
germplasm ||--o{ germplasm_origin : "germplasm_id"
germplasm ||--o{ germplasm_synonym : "germplasm_id"
germplasm ||--o{ germplasm_taxon : "germplasm_id"
germplasm ||--o| pedigree_node : "germplasm_id"
pedigree_node ||--o{ pedigree_edge : "this_node_id"
pedigree_node ||--o{ pedigree_edge : "connceted_node_id"
crossing_project ||--o{ cross_entity : "crossing_project_id"
cross_entity ||--o{ cross_entity : "planned_cross_id"
cross_entity ||--o{ cross_parent : "cross_id"
crossing_project ||--o{ cross_parent : "crossing_project_id"
germplasm ||--o{ cross_parent : "germplasm_id"
seed_lot ||--o{ seed_lot_content_mixture : "seed_lot_id"
germplasm ||--o{ seed_lot_content_mixture : "germplasm_id"
cross_entity ||--o{ seed_lot_content_mixture : "cross_id"
location ||--o{ seed_lot : "location_id"
program ||--o{ seed_lot : "program_id"
seed_lot ||--o{ seed_lot_transaction : "from_seed_lot_id"
seed_lot ||--o{ seed_lot_transaction : "to_seed_lot_id"
```
## 核心表说明
| 表 | 作用 | 主要上游依赖 | 主要下游 |
| --- | --- | --- | --- |
| `germplasm` | 种质主表,保存 accession、PUI、物种、采集来源、种子来源等信息 | `crop`, `breeding_method` | 属性、机构、来源、系谱、SeedLot 组成、Cross 亲本 |
| `breeding_method` | 育种方法字典 | 无 | `germplasm` |
| `germplasm_attribute_definition` | GermplasmAttribute 定义,继承变量定义体系,可关联 trait/method/scale/ontology/crop | `crop`, `trait`, `method`, `scale`, `ontology` | `germplasm_attribute_value` |
| `germplasm_attribute_value` | GermplasmAttributeValue保存某个 germplasm 在某个属性上的取值 | `germplasm`, `germplasm_attribute_definition` | 属性查询 |
| `crossing_project` | CrossingProject杂交项目 | `program` | `cross_entity`, `cross_parent`, `pedigree_node` |
| `cross_entity` | Cross/PlannedCross 统一落库表;`planned_cross_id` 是对本表的自关联 | `crossing_project`, `cross_entity` | `cross_parent`, `seed_lot_content_mixture` |
| `cross_parent` | CrossParent连接 `cross_entity``germplasm` 或 observation unit | `cross_entity`, `crossing_project`, `germplasm`, `observation_unit` | 杂交亲本 |
| `seed_lot` | 种子批次/库存批次,保存数量、单位、库位、项目、创建和更新时间 | `location`, `program` | `seed_lot_content_mixture`, `seed_lot_transaction` |
| `seed_lot_content_mixture` | SeedLot 组成明细,连接 `seed_lot``germplasm``cross_entity` | `seed_lot`, `germplasm`, `cross_entity` | 表示批次内各成分占比 |
| `seed_lot_transaction` | SeedLot 流转记录,记录从一个批次到另一个批次的数量变化 | `from_seed_lot`, `to_seed_lot` | 库存流向追踪 |
| `pedigree_node` | 系谱节点,一个节点可关联一个 germplasm | `germplasm`, `crossing_project` | `pedigree_edge` |
| `pedigree_edge` | 系谱边,描述 parent/child/sibling 关系 | `pedigree_node` | 系谱查询 |
## 建议录入顺序
1. 先录入上游基础数据:`crop``breeding_method``program``location`,以及属性定义需要的 `trait/method/scale/ontology`
2. 录入 `germplasm_attribute_definition`,定义可采集的 GermplasmAttribute。
3. 录入 `germplasm` 主数据,并通过 `breeding_method_id` 关联育种方法。
4. 录入 `germplasm_attribute_value`,把 germplasm 与 attribute definition 连接起来并保存具体值。
5. 如果涉及杂交,录入 `crossing_project`,再录入计划杂交/实际杂交到 `cross_entity`;计划杂交通过 `planned=true``planned_cross_id` 自关联体现。
6. 录入 `cross_parent`,把 cross 与 parent germplasm 或 observation unit 关联起来。
7. 录入 `pedigree_node``pedigree_edge`,表达 germplasm 的 parent/child/sibling 系谱关系。
8. 录入 `seed_lot`,保存批次数量、单位、库位和项目归属。
9. 录入 `seed_lot_content_mixture`,把 seed lot 与一个或多个 `germplasm`/`cross_entity` 连接起来。
10. 后续出入库、分装、合并或转移时,录入 `seed_lot_transaction`,通过 `from_seed_lot_id``to_seed_lot_id` 追踪流向。
## 关键注意点
1. `germplasm.seedSource``germplasm.seedSourceDescription` 是种质主表上的描述字段,不等同于库存批次。
2. 真正表示库存批次的是 `seed_lot`,而批次与种质的关系在 `seed_lot_content_mixture` 中。
3. `seed_lot_content_mixture` 可以关联 `germplasm`,也可以关联 `cross_entity`,适合表达混合种子批次或由杂交产生的批次。
4. `seed_lot_transaction` 同时有 `fromSeedLot``toSeedLot`,因此它表达的是 seed lot 到 seed lot 的流转关系,而不是 seed lot 到 germplasm 的直接关系。
5. `plannedcross` 没有独立数据库表,统一使用 `cross_entity`,通过 `planned` 字段和 `planned_cross_id` 自关联表达。
6. `germplasm_attribute_definition` 是属性定义,`germplasm_attribute_value` 是种质上的实际属性值,两者通过 `attribute_id` 连接。
7. 系谱关系由 `pedigree_node``pedigree_edge` 表达;杂交流程由 `cross_entity``cross_parent` 表达,两者都可以回到 `germplasm` 主数据。