msIO 1.0.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- msIO/__init__.py +15 -0
- msIO/_templates/__init__.py +12 -0
- msIO/_templates/_many_to_many.py +39 -0
- msIO/_templates/_many_to_many_bidirectional.py +43 -0
- msIO/_templates/_many_to_one.py +22 -0
- msIO/_templates/_many_to_one_bidirectional.py +23 -0
- msIO/_templates/_one_to_many.py +33 -0
- msIO/_templates/_one_to_many_bidirectional.py +32 -0
- msIO/_templates/_one_to_one.py +26 -0
- msIO/_templates/relationship_patterns.py +65 -0
- msIO/_version.py +2 -0
- msIO/annotations/__init__.py +0 -0
- msIO/annotations/main.py +228 -0
- msIO/core.py +29 -0
- msIO/environmental/__init__.py +0 -0
- msIO/environmental/location.py +21 -0
- msIO/environmental/sample.py +48 -0
- msIO/export_manager/__init__.py +0 -0
- msIO/export_manager/main.py +34 -0
- msIO/feature_managers/__init__.py +0 -0
- msIO/feature_managers/_read_mzio_graphml_as_xml.py +68 -0
- msIO/feature_managers/base.py +45 -0
- msIO/feature_managers/combined.py +171 -0
- msIO/feature_managers/db.py +1305 -0
- msIO/feature_managers/gnps.py +75 -0
- msIO/feature_managers/metaboscape.py +114 -0
- msIO/feature_managers/sirius.py +162 -0
- msIO/feature_managers/util_library.py +42 -0
- msIO/features/__init__.py +0 -0
- msIO/features/base.py +80 -0
- msIO/features/combined.py +143 -0
- msIO/features/gnps.py +59 -0
- msIO/features/metaboscape.py +128 -0
- msIO/features/mgf.py +171 -0
- msIO/features/sirius.py +228 -0
- msIO/features/util.py +13 -0
- msIO/general.py +55 -0
- msIO/gui/__init__.py +0 -0
- msIO/gui/_gui_log.py +32 -0
- msIO/gui/about +16 -0
- msIO/gui/annotation/__init__.py +3 -0
- msIO/gui/annotation/annotations.py +169 -0
- msIO/gui/annotation/app.py +916 -0
- msIO/gui/annotation/common.py +694 -0
- msIO/gui/annotation/database_panel.py +51 -0
- msIO/gui/annotation/dialogs.py +688 -0
- msIO/gui/annotation/export.py +105 -0
- msIO/gui/annotation/filter_panel.py +398 -0
- msIO/gui/annotation/matching.py +294 -0
- msIO/gui/annotation/matching_panel.py +99 -0
- msIO/gui/annotation/overview_panel.py +367 -0
- msIO/gui/annotation/results_panel.py +400 -0
- msIO/gui/annotation/scatter_panel.py +898 -0
- msIO/gui/annotation/series.py +334 -0
- msIO/gui/annotation/shortcuts.py +213 -0
- msIO/gui/csv_to_sqlite_gui.py +266 -0
- msIO/gui/feature_overview.py +467 -0
- msIO/gui/find_lib_matches.py +13 -0
- msIO/gui/library_search_by_name.py +222 -0
- msIO/gui/main.py +85 -0
- msIO/gui/msp_to_sqlite_gui.py +142 -0
- msIO/list_of_ions/__init__.py +0 -0
- msIO/list_of_ions/base.py +299 -0
- msIO/list_of_ions/read_library.py +76 -0
- msIO/list_of_ions/read_mca.py +237 -0
- msIO/list_of_ions/read_mgf.py +161 -0
- msIO/list_of_ions/read_msp.py +281 -0
- msIO/metrics.py +72 -0
- msIO/sql/__init__.py +0 -0
- msIO/sql/create_library.py +151 -0
- msIO/sql/session.py +32 -0
- msIO/sql/visualize.py +61 -0
- msio-1.0.3.dist-info/METADATA +151 -0
- msio-1.0.3.dist-info/RECORD +77 -0
- msio-1.0.3.dist-info/WHEEL +5 -0
- msio-1.0.3.dist-info/licenses/LICENSE +21 -0
- msio-1.0.3.dist-info/top_level.txt +1 -0
msIO/__init__.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
from importlib.util import find_spec as _find_spec
|
|
2
|
+
|
|
3
|
+
from ._version import __version__
|
|
4
|
+
|
|
5
|
+
# LipidCalculator is not on PyPI yet, so `pip install msIO` can't pull it in: fail with instructions instead of an
|
|
6
|
+
# ImportError deep inside msIO. find_spec only looks the package up without importing it (LipidCalculator imports msIO).
|
|
7
|
+
if _find_spec("LipidCalculator") is None:
|
|
8
|
+
raise ImportError(
|
|
9
|
+
"msIO needs LipidCalculator, install it with\n"
|
|
10
|
+
" pip install git+https://github.com/yaza11/LipidCalculator.git"
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
from .list_of_ions.base import PeakList
|
|
14
|
+
from .list_of_ions.read_mgf import MgfImportManager
|
|
15
|
+
from .list_of_ions.read_msp import MSPReader
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Defining the right relationship patterns is crucial for the efficent functioning of the database.
|
|
3
|
+
|
|
4
|
+
We distinguish the types
|
|
5
|
+
- one to many (parent can have many children)
|
|
6
|
+
- many to one (
|
|
7
|
+
- many to many
|
|
8
|
+
|
|
9
|
+
We use the declarative form and we use Mapped on type annotations (so we don't need to specify all parameters in
|
|
10
|
+
mapped column explicitly
|
|
11
|
+
"""
|
|
12
|
+
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import List
|
|
4
|
+
|
|
5
|
+
from sqlalchemy import Column
|
|
6
|
+
from sqlalchemy import Table
|
|
7
|
+
from sqlalchemy import ForeignKey
|
|
8
|
+
from sqlalchemy import Integer
|
|
9
|
+
from sqlalchemy.orm import Mapped
|
|
10
|
+
from sqlalchemy.orm import mapped_column
|
|
11
|
+
from sqlalchemy.orm import DeclarativeBase
|
|
12
|
+
from sqlalchemy.orm import relationship
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class Base(DeclarativeBase):
|
|
16
|
+
pass
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
# note for a Core table, we use the sqlalchemy.Column construct,
|
|
20
|
+
# not sqlalchemy.orm.mapped_column
|
|
21
|
+
association_table = Table(
|
|
22
|
+
"association_table",
|
|
23
|
+
Base.metadata,
|
|
24
|
+
Column("left_id", ForeignKey("left_table.id")),
|
|
25
|
+
Column("right_id", ForeignKey("right_table.id")),
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class Parent(Base):
|
|
30
|
+
__tablename__ = "left_table"
|
|
31
|
+
|
|
32
|
+
id: Mapped[int] = mapped_column(primary_key=True)
|
|
33
|
+
children: Mapped[List[Child]] = relationship(secondary=association_table)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class Child(Base):
|
|
37
|
+
__tablename__ = "right_table"
|
|
38
|
+
|
|
39
|
+
id: Mapped[int] = mapped_column(primary_key=True)
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"""also define back_populates"""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
from typing import List
|
|
5
|
+
|
|
6
|
+
from sqlalchemy import Column
|
|
7
|
+
from sqlalchemy import Table
|
|
8
|
+
from sqlalchemy import ForeignKey
|
|
9
|
+
from sqlalchemy import Integer
|
|
10
|
+
from sqlalchemy.orm import Mapped
|
|
11
|
+
from sqlalchemy.orm import mapped_column
|
|
12
|
+
from sqlalchemy.orm import DeclarativeBase
|
|
13
|
+
from sqlalchemy.orm import relationship
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class Base(DeclarativeBase):
|
|
17
|
+
pass
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
association_table = Table(
|
|
21
|
+
"association_table",
|
|
22
|
+
Base.metadata,
|
|
23
|
+
Column("left_id", ForeignKey("left_table.id"), primary_key=True),
|
|
24
|
+
Column("right_id", ForeignKey("right_table.id"), primary_key=True),
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class Parent(Base):
|
|
29
|
+
__tablename__ = "left_table"
|
|
30
|
+
|
|
31
|
+
id: Mapped[int] = mapped_column(primary_key=True)
|
|
32
|
+
children: Mapped[List[Child]] = relationship(
|
|
33
|
+
secondary=association_table, back_populates="parents"
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class Child(Base):
|
|
38
|
+
__tablename__ = "right_table"
|
|
39
|
+
|
|
40
|
+
id: Mapped[int] = mapped_column(primary_key=True)
|
|
41
|
+
parents: Mapped[List[Parent]] = relationship(
|
|
42
|
+
secondary=association_table, back_populates="children"
|
|
43
|
+
)
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
from typing import Optional
|
|
2
|
+
|
|
3
|
+
from sqlalchemy import ForeignKey
|
|
4
|
+
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
5
|
+
|
|
6
|
+
class Base:
|
|
7
|
+
pass
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class Parent(Base):
|
|
11
|
+
__tablename__ = "parent_table"
|
|
12
|
+
|
|
13
|
+
id: Mapped[int] = mapped_column(primary_key=True)
|
|
14
|
+
# place foreign key in parent table
|
|
15
|
+
child_id: Mapped[Optional[int]] = mapped_column(ForeignKey("child_table.id"))
|
|
16
|
+
child: Mapped[Optional["Child"]] = relationship()
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class Child(Base):
|
|
20
|
+
__tablename__ = "child_table"
|
|
21
|
+
|
|
22
|
+
id: Mapped[int] = mapped_column(primary_key=True)
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"""this is the same as one to many bidirectional with the names of Parent and child swapped"""
|
|
2
|
+
from typing import List
|
|
3
|
+
|
|
4
|
+
from sqlalchemy import ForeignKey
|
|
5
|
+
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
6
|
+
|
|
7
|
+
class Base:
|
|
8
|
+
pass
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class Parent(Base):
|
|
12
|
+
__tablename__ = "parent_table"
|
|
13
|
+
|
|
14
|
+
id: Mapped[int] = mapped_column(primary_key=True)
|
|
15
|
+
child_id: Mapped[int] = mapped_column(ForeignKey("child_table.id"))
|
|
16
|
+
child: Mapped["Child"] = relationship(back_populates="parents")
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class Child(Base):
|
|
20
|
+
__tablename__ = "child_table"
|
|
21
|
+
|
|
22
|
+
id: Mapped[int] = mapped_column(primary_key=True)
|
|
23
|
+
parents: Mapped[List["Parent"]] = relationship(back_populates="child")
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"""
|
|
2
|
+
(parent can have many children)
|
|
3
|
+
|
|
4
|
+
need to choose delete behavior for children
|
|
5
|
+
|
|
6
|
+
"""
|
|
7
|
+
from typing import List
|
|
8
|
+
|
|
9
|
+
from sqlalchemy import ForeignKey
|
|
10
|
+
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
11
|
+
|
|
12
|
+
class Base:
|
|
13
|
+
pass
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class Parent(Base):
|
|
17
|
+
__tablename__ = "parent_table"
|
|
18
|
+
|
|
19
|
+
id: Mapped[int] = mapped_column(primary_key=True)
|
|
20
|
+
children: Mapped[List["Child"]] = relationship()
|
|
21
|
+
# or if children should be deleted if parent is deleted
|
|
22
|
+
children: Mapped[List["Child"]] = relationship(
|
|
23
|
+
cascade="all, delete-orphan",
|
|
24
|
+
passive_deletes=True
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class Child(Base):
|
|
29
|
+
__tablename__ = "child_table"
|
|
30
|
+
|
|
31
|
+
id: Mapped[int] = mapped_column(primary_key=True)
|
|
32
|
+
parent_id: Mapped[int] = mapped_column(ForeignKey("parent_table.id"))
|
|
33
|
+
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"""
|
|
2
|
+
(parent can have many children)
|
|
3
|
+
|
|
4
|
+
need to choose delete behavior for children
|
|
5
|
+
|
|
6
|
+
for bidirectional, the child to parent relationship is many to one
|
|
7
|
+
"""
|
|
8
|
+
from typing import List
|
|
9
|
+
|
|
10
|
+
from sqlalchemy import ForeignKey
|
|
11
|
+
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
12
|
+
|
|
13
|
+
class Base:
|
|
14
|
+
pass
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class Parent(Base):
|
|
18
|
+
# this is "one"
|
|
19
|
+
__tablename__ = "parent_table"
|
|
20
|
+
|
|
21
|
+
id: Mapped[int] = mapped_column(primary_key=True)
|
|
22
|
+
children: Mapped[List["Child"]] = relationship(back_populates="parent") # could use Set here instead of List
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class Child(Base):
|
|
26
|
+
# this is "many"
|
|
27
|
+
__tablename__ = "child_table"
|
|
28
|
+
|
|
29
|
+
id: Mapped[int] = mapped_column(primary_key=True)
|
|
30
|
+
parent_id: Mapped[int] = mapped_column(ForeignKey("parent_table.id"))
|
|
31
|
+
parent: Mapped["Parent"] = relationship(back_populates="children")
|
|
32
|
+
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"""same as one to many bidirectional but we use Mapped[Child] instead of Mapped[List[Child]]"""
|
|
2
|
+
from sqlalchemy import ForeignKey, UniqueConstraint
|
|
3
|
+
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class Base:
|
|
7
|
+
pass
|
|
8
|
+
|
|
9
|
+
class Parent(Base):
|
|
10
|
+
__tablename__ = "parent_table"
|
|
11
|
+
|
|
12
|
+
id: Mapped[int] = mapped_column(primary_key=True)
|
|
13
|
+
child: Mapped["Child"] = relationship(back_populates="parent")
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class Child(Base):
|
|
17
|
+
__tablename__ = "child_table"
|
|
18
|
+
|
|
19
|
+
id: Mapped[int] = mapped_column(primary_key=True)
|
|
20
|
+
parent_id: Mapped[int] = mapped_column(ForeignKey("parent_table.id"))
|
|
21
|
+
parent: Mapped["Parent"] = relationship(back_populates="child")
|
|
22
|
+
# we can enforece single parent like this (otherwise it will not be detected)
|
|
23
|
+
parent: Mapped["Parent"] = relationship(back_populates="child", single_parent = True)
|
|
24
|
+
|
|
25
|
+
# should always use this
|
|
26
|
+
__table_args__ = (UniqueConstraint("parent_id"),)
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
from typing import List
|
|
2
|
+
|
|
3
|
+
from sqlalchemy import ForeignKey
|
|
4
|
+
from sqlalchemy.orm import Mapped
|
|
5
|
+
from sqlalchemy.orm import mapped_column
|
|
6
|
+
from sqlalchemy.orm import DeclarativeBase
|
|
7
|
+
from sqlalchemy.orm import relationship
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class Base(DeclarativeBase):
|
|
11
|
+
pass
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
# %% One to many
|
|
15
|
+
# (One parent, many children)
|
|
16
|
+
|
|
17
|
+
# class Parent(Base):
|
|
18
|
+
# __tablename__ = "parent_table"
|
|
19
|
+
#
|
|
20
|
+
# id: Mapped[int] = mapped_column(primary_key=True)
|
|
21
|
+
# children: Mapped[List["Child"]] = relationship()
|
|
22
|
+
#
|
|
23
|
+
#
|
|
24
|
+
# class Child(Base):
|
|
25
|
+
# __tablename__ = "child_table"
|
|
26
|
+
#
|
|
27
|
+
# id: Mapped[int] = mapped_column(primary_key=True)
|
|
28
|
+
# parent_id: Mapped[int] = mapped_column(ForeignKey("parent_table.id"))
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
# %%% bidirectional
|
|
32
|
+
|
|
33
|
+
class Parent(Base):
|
|
34
|
+
__tablename__ = "parent_table"
|
|
35
|
+
|
|
36
|
+
id: Mapped[int] = mapped_column(primary_key=True)
|
|
37
|
+
children: Mapped[List["Child"]] = relationship(back_populates="parent")
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class Child(Base):
|
|
41
|
+
__tablename__ = "child_table"
|
|
42
|
+
|
|
43
|
+
id: Mapped[int] = mapped_column(primary_key=True)
|
|
44
|
+
parent_id: Mapped[int] = mapped_column(ForeignKey("parent_table.id"))
|
|
45
|
+
parent: Mapped["Parent"] = relationship(back_populates="children")
|
|
46
|
+
|
|
47
|
+
# %%% one to one
|
|
48
|
+
|
|
49
|
+
class Parent(Base):
|
|
50
|
+
__tablename__ = "parent_table"
|
|
51
|
+
|
|
52
|
+
id: Mapped[int] = mapped_column(primary_key=True)
|
|
53
|
+
child: Mapped["Child"] = relationship(back_populates="parent")
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
class Child(Base):
|
|
57
|
+
__tablename__ = "child_table"
|
|
58
|
+
|
|
59
|
+
id: Mapped[int] = mapped_column(primary_key=True)
|
|
60
|
+
parent_id: Mapped[int] = mapped_column(ForeignKey("parent_table.id"))
|
|
61
|
+
parent: Mapped["Parent"] = relationship(back_populates="child")
|
|
62
|
+
|
|
63
|
+
c = Child()
|
|
64
|
+
|
|
65
|
+
p = Parent(child=c)
|
msIO/_version.py
ADDED
|
File without changes
|
msIO/annotations/main.py
ADDED
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
"""Keep this separated from main database for now"""
|
|
2
|
+
from typing import Optional, List
|
|
3
|
+
|
|
4
|
+
from sqlalchemy import Integer, String, ForeignKey, Boolean, Float, create_engine, Table, Column
|
|
5
|
+
from sqlalchemy.orm import Mapped, relationship, mapped_column, Session
|
|
6
|
+
from sqlalchemy.orm import DeclarativeBase
|
|
7
|
+
|
|
8
|
+
from msIO.core import PeakBaseClass
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class SqlBaseClassComp(DeclarativeBase):
|
|
12
|
+
pass
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
compound_group_to_compound_association_table = Table(
|
|
16
|
+
"association_table",
|
|
17
|
+
SqlBaseClassComp.metadata,
|
|
18
|
+
Column("compound_group_id", ForeignKey("compound_group.id")),
|
|
19
|
+
Column("compound_id", ForeignKey("compound.id")),
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class CompoundGroup(SqlBaseClassComp):
|
|
24
|
+
__tablename__ = "compound_group"
|
|
25
|
+
|
|
26
|
+
id: Mapped[int] = mapped_column(Integer, primary_key=True)
|
|
27
|
+
name: Mapped[str] = mapped_column(String, nullable=False)
|
|
28
|
+
abbreviation: Mapped[str | None] = mapped_column(String, nullable=True)
|
|
29
|
+
|
|
30
|
+
molecule_id: Mapped[Optional[int]] = mapped_column(ForeignKey("molecule.id"),
|
|
31
|
+
nullable=True)
|
|
32
|
+
molecule: Mapped[Optional["Molecule"]] = relationship()
|
|
33
|
+
|
|
34
|
+
compounds: Mapped[List['Compound']] = relationship(
|
|
35
|
+
secondary=compound_group_to_compound_association_table,
|
|
36
|
+
back_populates="compound_groups"
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
# --- Self-referential FK for parent group ---
|
|
40
|
+
parent_id: Mapped[Optional[int]] = mapped_column(
|
|
41
|
+
ForeignKey("compound_group.id"), nullable=True)
|
|
42
|
+
|
|
43
|
+
# --- Relationships for hierarchy ---
|
|
44
|
+
parent: Mapped[Optional["CompoundGroup"]] = relationship(
|
|
45
|
+
remote_side="CompoundGroup.id", # resolves circular relationship
|
|
46
|
+
back_populates="children"
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
children: Mapped[List["CompoundGroup"]] = relationship(
|
|
50
|
+
back_populates="parent",
|
|
51
|
+
cascade="all, delete-orphan"
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
class Compound(SqlBaseClassComp):
|
|
56
|
+
__tablename__ = "compound"
|
|
57
|
+
|
|
58
|
+
id: Mapped[int] = mapped_column(Integer, primary_key=True)
|
|
59
|
+
name: Mapped[str] = mapped_column(String, nullable=False)
|
|
60
|
+
|
|
61
|
+
# many to one
|
|
62
|
+
molecule_id: Mapped[Optional[int]] = mapped_column(ForeignKey("molecule.id"),
|
|
63
|
+
nullable=True)
|
|
64
|
+
molecule: Mapped[Optional["Molecule"]] = relationship()
|
|
65
|
+
|
|
66
|
+
# Relationship: Compound → IonPeak
|
|
67
|
+
ions: Mapped[List["IonPeak"]] = relationship(
|
|
68
|
+
back_populates="compound", cascade="all, delete-orphan"
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
compound_groups: Mapped[List["CompoundGroup"]] = relationship(
|
|
72
|
+
secondary=compound_group_to_compound_association_table,
|
|
73
|
+
back_populates="compounds"
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
class Molecule(SqlBaseClassComp):
|
|
78
|
+
__tablename__ = "molecule"
|
|
79
|
+
|
|
80
|
+
# TODO: use inchkey as index instead
|
|
81
|
+
id: Mapped[int] = mapped_column(Integer, primary_key=True)
|
|
82
|
+
|
|
83
|
+
smiles: Mapped[str | None] = mapped_column(String, nullable=True)
|
|
84
|
+
inchi: Mapped[str | None] = mapped_column(String, nullable=True)
|
|
85
|
+
inchkey: Mapped[str | None] = mapped_column(String, nullable=True)
|
|
86
|
+
formula: Mapped[str | None] = mapped_column(String, nullable=True)
|
|
87
|
+
M: Mapped[float | None] = mapped_column(Float, nullable=True)
|
|
88
|
+
|
|
89
|
+
charge: Mapped[int | None] = mapped_column(Float, nullable=True)
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
class IonPeak(SqlBaseClassComp, PeakBaseClass):
|
|
93
|
+
__tablename__ = "ion_peak"
|
|
94
|
+
|
|
95
|
+
id: Mapped[int] = mapped_column(Integer, primary_key=True)
|
|
96
|
+
compound_id: Mapped[int] = mapped_column(ForeignKey("compound.id"), nullable=False)
|
|
97
|
+
|
|
98
|
+
is_ion: Mapped[bool] = mapped_column(Boolean, default=True)
|
|
99
|
+
|
|
100
|
+
compound: Mapped["Compound"] = relationship(back_populates="ions")
|
|
101
|
+
|
|
102
|
+
# Relationship: IonPeak → IsotopePeak
|
|
103
|
+
isotopes: Mapped[List["IsotopePeak"]] = relationship(
|
|
104
|
+
back_populates="ion_peak", cascade="all, delete-orphan"
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
# many to one
|
|
108
|
+
molecule_id: Mapped[Optional[int]] = mapped_column(ForeignKey("molecule.id"),
|
|
109
|
+
nullable=True)
|
|
110
|
+
molecule: Mapped[Optional["Molecule"]] = relationship()
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
class IsotopePeak(SqlBaseClassComp, PeakBaseClass):
|
|
114
|
+
__tablename__ = "isotope_peak"
|
|
115
|
+
|
|
116
|
+
id: Mapped[int] = mapped_column(Integer, primary_key=True)
|
|
117
|
+
ion_peak_id: Mapped[int] = mapped_column(ForeignKey("ion_peak.id"), nullable=False)
|
|
118
|
+
|
|
119
|
+
isotope_order: Mapped[Optional[int]] = mapped_column(Integer)
|
|
120
|
+
is_isotope: Mapped[bool] = mapped_column(Boolean, default=True)
|
|
121
|
+
|
|
122
|
+
ion_peak: Mapped["IonPeak"] = relationship(back_populates="isotopes")
|
|
123
|
+
|
|
124
|
+
# Relationship: IsotopePeak → FragmentPeak
|
|
125
|
+
fragments: Mapped[List["FragmentPeak"]] = relationship(
|
|
126
|
+
back_populates="isotope_peak", cascade="all, delete-orphan"
|
|
127
|
+
)
|
|
128
|
+
|
|
129
|
+
# many to one
|
|
130
|
+
molecule_id: Mapped[Optional[int]] = mapped_column(ForeignKey("molecule.id"),
|
|
131
|
+
nullable=True)
|
|
132
|
+
molecule: Mapped[Optional["Molecule"]] = relationship()
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
class FragmentPeak(SqlBaseClassComp, PeakBaseClass):
|
|
136
|
+
__tablename__ = "fragment_peak"
|
|
137
|
+
|
|
138
|
+
id: Mapped[int] = mapped_column(Integer, primary_key=True)
|
|
139
|
+
|
|
140
|
+
is_fragment: Mapped[bool | None] = mapped_column(Boolean, default=True)
|
|
141
|
+
is_neutral_loss: Mapped[bool | None] = mapped_column(Boolean, nullable=True)
|
|
142
|
+
|
|
143
|
+
isotope_peak_id: Mapped[int | None] = mapped_column(
|
|
144
|
+
ForeignKey("isotope_peak.id"), nullable=False)
|
|
145
|
+
isotope_peak: Mapped["IsotopePeak"] = relationship(back_populates="fragments")
|
|
146
|
+
|
|
147
|
+
# many to one
|
|
148
|
+
molecule_id: Mapped[Optional[int]] = mapped_column(ForeignKey("molecule.id"),
|
|
149
|
+
nullable=True)
|
|
150
|
+
molecule: Mapped[Optional["Molecule"]] = relationship()
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def test():
|
|
154
|
+
# --- SQLITE in-memory engine ---
|
|
155
|
+
engine = create_engine("sqlite:///:memory:", echo=False)
|
|
156
|
+
|
|
157
|
+
# create tables
|
|
158
|
+
SqlBaseClassComp.metadata.create_all(engine)
|
|
159
|
+
|
|
160
|
+
# --- TEST INSERTION ---
|
|
161
|
+
with Session(engine) as session:
|
|
162
|
+
# Create a Compound
|
|
163
|
+
ipl = CompoundGroup(name='intact polar lipids', abbreviation='IPL')
|
|
164
|
+
head_1g = CompoundGroup(name='head', abbreviation='1G', parent=ipl)
|
|
165
|
+
|
|
166
|
+
mol = Molecule(
|
|
167
|
+
formula="C10H20O",
|
|
168
|
+
)
|
|
169
|
+
|
|
170
|
+
cmp = Compound(
|
|
171
|
+
name="TestCompound",
|
|
172
|
+
molecule=mol
|
|
173
|
+
)
|
|
174
|
+
|
|
175
|
+
cmp.compound_groups.append(ipl)
|
|
176
|
+
cmp.compound_groups.append(head_1g)
|
|
177
|
+
|
|
178
|
+
# Create IonPeak
|
|
179
|
+
ion = IonPeak(
|
|
180
|
+
mz=250.13,
|
|
181
|
+
rt=5.5,
|
|
182
|
+
intensity=1000.0,
|
|
183
|
+
adduct="[M+H]+",
|
|
184
|
+
is_ion=True
|
|
185
|
+
)
|
|
186
|
+
|
|
187
|
+
# Link Ion to Compound
|
|
188
|
+
cmp.ions.append(ion)
|
|
189
|
+
|
|
190
|
+
# Create IsotopePeak
|
|
191
|
+
iso = IsotopePeak(
|
|
192
|
+
mz=251.13,
|
|
193
|
+
rt=5.5,
|
|
194
|
+
intensity=500.0,
|
|
195
|
+
isotope_order=0,
|
|
196
|
+
is_isotope=True
|
|
197
|
+
)
|
|
198
|
+
|
|
199
|
+
ion.isotopes.append(iso)
|
|
200
|
+
|
|
201
|
+
# Create FragmentPeak
|
|
202
|
+
frag = FragmentPeak(
|
|
203
|
+
rt=5.6,
|
|
204
|
+
intensity=200.0,
|
|
205
|
+
is_fragment=True
|
|
206
|
+
)
|
|
207
|
+
|
|
208
|
+
iso.fragments.append(frag)
|
|
209
|
+
|
|
210
|
+
# Commit to DB
|
|
211
|
+
session.add(cmp)
|
|
212
|
+
session.commit()
|
|
213
|
+
|
|
214
|
+
# --- TEST QUERY ---
|
|
215
|
+
with Session(engine) as session:
|
|
216
|
+
compounds = session.query(Compound).all()
|
|
217
|
+
for c in compounds:
|
|
218
|
+
print(f"Compound: {c.name}, molecule={c.molecule}")
|
|
219
|
+
for ion in c.ions:
|
|
220
|
+
print(f" IonPeak: mz={ion.mz}, adduct={ion.adduct}")
|
|
221
|
+
for iso in ion.isotopes:
|
|
222
|
+
print(f" IsotopePeak: mz={iso.mz}, order={iso.isotope_order}")
|
|
223
|
+
for frag in iso.fragments:
|
|
224
|
+
print(f" FragmentPeak: mz={frag.mz}, intensity={frag.intensity}")
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
if __name__ == '__main__':
|
|
228
|
+
test()
|
msIO/core.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
from sqlalchemy import Float, String, Boolean
|
|
2
|
+
from sqlalchemy.orm import Mapped, mapped_column
|
|
3
|
+
|
|
4
|
+
from msIO.features.base import FeatureBaseClass
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class PeakBaseClass(FeatureBaseClass):
|
|
8
|
+
id: Mapped[int] = mapped_column(primary_key=True)
|
|
9
|
+
mz: Mapped[float | None] = mapped_column(Float, nullable=True)
|
|
10
|
+
rt: Mapped[float | None] = mapped_column(Float, nullable=True)
|
|
11
|
+
ccs: Mapped[float | None] = mapped_column(Float, nullable=True)
|
|
12
|
+
|
|
13
|
+
annotation: Mapped[str | None] = mapped_column(String, nullable=True)
|
|
14
|
+
|
|
15
|
+
# TODO: deprecate intensity
|
|
16
|
+
intensity: Mapped[float | None] = mapped_column(Float, nullable=True)
|
|
17
|
+
height: Mapped[float | None] = mapped_column(Float, nullable=True)
|
|
18
|
+
area: Mapped[float | None] = mapped_column(Float, nullable=True)
|
|
19
|
+
|
|
20
|
+
fwhm: Mapped[float | None] = mapped_column(Float, nullable=True)
|
|
21
|
+
snr: Mapped[float | None] = mapped_column(Float, nullable=True)
|
|
22
|
+
|
|
23
|
+
M: Mapped[float | None] = mapped_column(Float, nullable=True)
|
|
24
|
+
adduct: Mapped[str | None] = mapped_column(String, nullable=True)
|
|
25
|
+
|
|
26
|
+
is_ion: Mapped[bool | None] = mapped_column(Boolean, nullable=True)
|
|
27
|
+
is_isotope: Mapped[bool | None] = mapped_column(Boolean, nullable=True)
|
|
28
|
+
|
|
29
|
+
is_fragment: Mapped[bool | None] = mapped_column(Boolean, nullable=True)
|
|
File without changes
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
from typing import Optional
|
|
2
|
+
|
|
3
|
+
from sqlalchemy import String, Float
|
|
4
|
+
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
5
|
+
|
|
6
|
+
from msIO.environmental.sample import Sample
|
|
7
|
+
from msIO.features.base import SqlBaseClass
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class Location(SqlBaseClass):
|
|
11
|
+
__tablename__ = "locations"
|
|
12
|
+
|
|
13
|
+
id: Mapped[int] = mapped_column(primary_key=True)
|
|
14
|
+
|
|
15
|
+
name: Mapped[Optional[str]] = mapped_column(String, nullable=True)
|
|
16
|
+
|
|
17
|
+
latitude: Mapped[Optional[float]] = mapped_column(Float, nullable=True)
|
|
18
|
+
longitude: Mapped[Optional[float]] = mapped_column(Float, nullable=True)
|
|
19
|
+
depth: Mapped[Optional[float]] = mapped_column(Float, nullable=True)
|
|
20
|
+
|
|
21
|
+
sample: Mapped[Optional["Sample"]] = relationship("Sample", back_populates='location')
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
from typing import Optional
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
from sqlalchemy import String, Float, CheckConstraint, ForeignKey, Boolean
|
|
5
|
+
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
6
|
+
|
|
7
|
+
from msIO.features.base import SqlBaseClass
|
|
8
|
+
from msIO.general import TimeStamp
|
|
9
|
+
|
|
10
|
+
class Sample(SqlBaseClass):
|
|
11
|
+
__tablename__ = "samples"
|
|
12
|
+
|
|
13
|
+
id: Mapped[int] = mapped_column(primary_key=True)
|
|
14
|
+
|
|
15
|
+
sample_name: Mapped[Optional[str]] = mapped_column(String, nullable=True)
|
|
16
|
+
|
|
17
|
+
# TODO: add sample code objects
|
|
18
|
+
sample_code: Mapped[Optional[str]] = mapped_column(String, nullable=True)
|
|
19
|
+
sample_code_type: Mapped[Optional[str]] = mapped_column(String, nullable=True)
|
|
20
|
+
|
|
21
|
+
is_blank: Mapped[bool] = mapped_column(Boolean, nullable=True)
|
|
22
|
+
tags: Mapped[Optional[str]] = mapped_column(String, nullable=True)
|
|
23
|
+
|
|
24
|
+
weight_amount: Mapped[Optional[float]] = mapped_column(Float, nullable=True)
|
|
25
|
+
weight_unit: Mapped[Optional[str]] = mapped_column(String, nullable=True)
|
|
26
|
+
|
|
27
|
+
volume_amount: Mapped[Optional[float]] = mapped_column(Float, nullable=True)
|
|
28
|
+
volume_unit: Mapped[Optional[str]] = mapped_column(String, nullable=True)
|
|
29
|
+
|
|
30
|
+
concentration_percent: Mapped[Optional[float]] = mapped_column(
|
|
31
|
+
Float,
|
|
32
|
+
CheckConstraint("concentration_percent BETWEEN 0 AND 100"),
|
|
33
|
+
nullable=True
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
# many to one
|
|
37
|
+
location_id: Mapped[Optional[int]] = mapped_column(ForeignKey('locations.id'))
|
|
38
|
+
location: Mapped[Optional["Location"]] = relationship(back_populates='sample')
|
|
39
|
+
|
|
40
|
+
# one to one
|
|
41
|
+
time_id: Mapped[Optional[int]] = mapped_column(ForeignKey('times.id'))
|
|
42
|
+
time: Mapped[Optional["TimeStamp"]] = relationship(back_populates='sample')
|
|
43
|
+
|
|
44
|
+
intensities: Mapped[list["Intensity"]] = relationship("Intensity",
|
|
45
|
+
back_populates="sample",
|
|
46
|
+
cascade="all, delete-orphan",
|
|
47
|
+
passive_deletes=True)
|
|
48
|
+
|
|
File without changes
|