mtbls-mhd-integration 0.0.12__tar.gz → 0.0.14__tar.gz

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.
Files changed (29) hide show
  1. {mtbls_mhd_integration-0.0.12/mtbls_mhd_integration.egg-info → mtbls_mhd_integration-0.0.14}/PKG-INFO +2 -2
  2. {mtbls_mhd_integration-0.0.12 → mtbls_mhd_integration-0.0.14}/mtbls2mhd/__init__.py +1 -1
  3. {mtbls_mhd_integration-0.0.12 → mtbls_mhd_integration-0.0.14}/mtbls2mhd/convertor_factory.py +5 -1
  4. {mtbls_mhd_integration-0.0.12 → mtbls_mhd_integration-0.0.14}/mtbls2mhd/v0_1/legacy/builder.py +82 -26
  5. mtbls_mhd_integration-0.0.14/mtbls2mhd/v0_1/ms/convertor.py +59 -0
  6. {mtbls_mhd_integration-0.0.12 → mtbls_mhd_integration-0.0.14/mtbls_mhd_integration.egg-info}/PKG-INFO +2 -2
  7. {mtbls_mhd_integration-0.0.12 → mtbls_mhd_integration-0.0.14}/mtbls_mhd_integration.egg-info/requires.txt +1 -1
  8. {mtbls_mhd_integration-0.0.12 → mtbls_mhd_integration-0.0.14}/pyproject.toml +3 -3
  9. mtbls_mhd_integration-0.0.12/mtbls2mhd/v0_1/ms/convertor.py +0 -3
  10. {mtbls_mhd_integration-0.0.12 → mtbls_mhd_integration-0.0.14}/LICENSE +0 -0
  11. {mtbls_mhd_integration-0.0.12 → mtbls_mhd_integration-0.0.14}/README.md +0 -0
  12. {mtbls_mhd_integration-0.0.12 → mtbls_mhd_integration-0.0.14}/mtbls2mhd/commands/__init__.py +0 -0
  13. {mtbls_mhd_integration-0.0.12 → mtbls_mhd_integration-0.0.14}/mtbls2mhd/commands/cli.py +0 -0
  14. {mtbls_mhd_integration-0.0.12 → mtbls_mhd_integration-0.0.14}/mtbls2mhd/commands/create.py +0 -0
  15. {mtbls_mhd_integration-0.0.12 → mtbls_mhd_integration-0.0.14}/mtbls2mhd/commands/create_mhd_file.py +0 -0
  16. {mtbls_mhd_integration-0.0.12 → mtbls_mhd_integration-0.0.14}/mtbls2mhd/commands/validate.py +0 -0
  17. {mtbls_mhd_integration-0.0.12 → mtbls_mhd_integration-0.0.14}/mtbls2mhd/config.py +0 -0
  18. {mtbls_mhd_integration-0.0.12 → mtbls_mhd_integration-0.0.14}/mtbls2mhd/v0_1/__init__.py +0 -0
  19. {mtbls_mhd_integration-0.0.12 → mtbls_mhd_integration-0.0.14}/mtbls2mhd/v0_1/legacy/__init__.py +0 -0
  20. {mtbls_mhd_integration-0.0.12 → mtbls_mhd_integration-0.0.14}/mtbls2mhd/v0_1/legacy/convertor.py +0 -0
  21. {mtbls_mhd_integration-0.0.12 → mtbls_mhd_integration-0.0.14}/mtbls2mhd/v0_1/legacy/db_metadata_collector.py +0 -0
  22. {mtbls_mhd_integration-0.0.12 → mtbls_mhd_integration-0.0.14}/mtbls2mhd/v0_1/legacy/folder_metadata_collector.py +0 -0
  23. {mtbls_mhd_integration-0.0.12 → mtbls_mhd_integration-0.0.14}/mtbls2mhd/v0_1/legacy/mtbls_study_schema.py +0 -0
  24. {mtbls_mhd_integration-0.0.12 → mtbls_mhd_integration-0.0.14}/mtbls2mhd/v0_1/ms/__init__.py +0 -0
  25. {mtbls_mhd_integration-0.0.12 → mtbls_mhd_integration-0.0.14}/mtbls_mhd_integration.egg-info/SOURCES.txt +0 -0
  26. {mtbls_mhd_integration-0.0.12 → mtbls_mhd_integration-0.0.14}/mtbls_mhd_integration.egg-info/dependency_links.txt +0 -0
  27. {mtbls_mhd_integration-0.0.12 → mtbls_mhd_integration-0.0.14}/mtbls_mhd_integration.egg-info/entry_points.txt +0 -0
  28. {mtbls_mhd_integration-0.0.12 → mtbls_mhd_integration-0.0.14}/mtbls_mhd_integration.egg-info/top_level.txt +0 -0
  29. {mtbls_mhd_integration-0.0.12 → mtbls_mhd_integration-0.0.14}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mtbls-mhd-integration
3
- Version: 0.0.12
3
+ Version: 0.0.14
4
4
  Summary: MetaboLights - MetabolomicsHub Integration
5
5
  Author-email: MetaboLights Team <metabolights-help@ebi.ac.uk>
6
6
  License-Expression: Apache-2.0
@@ -9,7 +9,7 @@ Description-Content-Type: text/markdown
9
9
  License-File: LICENSE
10
10
  Requires-Dist: asyncpg>=0.30.0
11
11
  Requires-Dist: metabolights-utils>=1.4.16
12
- Requires-Dist: mhd-model>=0.1.41
12
+ Requires-Dist: mhd-model>=0.1.43
13
13
  Requires-Dist: psycopg[binary,pool]>=3.3.2
14
14
  Requires-Dist: pydantic>=2.12.4
15
15
  Requires-Dist: pydantic-settings>=2.10.1
@@ -1,4 +1,4 @@
1
- __version__ = "v0.0.12"
1
+ __version__ = "v0.0.14"
2
2
 
3
3
  import pathlib
4
4
  import sys
@@ -6,6 +6,7 @@ from mhd_model.model.definitions import (
6
6
  )
7
7
 
8
8
  from mtbls2mhd.v0_1.legacy.convertor import LegacyProfileV01Convertor
9
+ from mtbls2mhd.v0_1.ms.convertor import MsProfileConvertor
9
10
 
10
11
 
11
12
  class Mtbls2MhdConvertorFactory(BaseMhdConvertorFactory):
@@ -21,7 +22,10 @@ class Mtbls2MhdConvertorFactory(BaseMhdConvertorFactory):
21
22
  target_mhd_model_profile_uri=target_mhd_model_profile_uri,
22
23
  )
23
24
  elif target_mhd_model_profile_uri == MHD_MODEL_V0_1_MS_PROFILE_NAME:
24
- raise NotImplementedError()
25
+ return MsProfileConvertor(
26
+ target_mhd_model_schema_uri=target_mhd_model_schema_uri,
27
+ target_mhd_model_profile_uri=target_mhd_model_profile_uri,
28
+ )
25
29
  raise NotImplementedError()
26
30
  else:
27
31
  raise NotImplementedError()
@@ -53,11 +53,7 @@ logger = logging.getLogger(__name__)
53
53
  MTBLS_ASSAY_TYPES = {
54
54
  "LC-MS": COMMON_ASSAY_TYPES["OBI:0003097S"],
55
55
  "GC-MS": COMMON_ASSAY_TYPES["OBI:0003110"],
56
- "CE-MS": CvTerm(
57
- source="OBI",
58
- accession="OBI:0003741",
59
- name="capillary electrophoresis mass spectrometry assay",
60
- ),
56
+ "CE-MS": COMMON_ASSAY_TYPES["OBI:0003741"],
61
57
  "GCxGC-MS": COMMON_ASSAY_TYPES["OBI:0003110"],
62
58
  "FIA-MS": COMMON_ASSAY_TYPES["OBI:0000470"],
63
59
  "MALDI-MS": COMMON_ASSAY_TYPES["OBI:0000470"],
@@ -1433,7 +1429,10 @@ class MhdLegacyDatasetBuilder:
1433
1429
  return protocols
1434
1430
 
1435
1431
  def add_keywords(
1436
- self, mhd_builder: MhDatasetBuilder, mhd_study: mhd_domain.Study, study: Study
1432
+ self,
1433
+ mhd_builder: MhDatasetBuilder,
1434
+ mhd_study: mhd_domain.Study,
1435
+ study: Study,
1437
1436
  ):
1438
1437
  for item in study.study_design_descriptors.design_types:
1439
1438
  keyword = create_cv_term_object(
@@ -1447,12 +1446,62 @@ class MhdLegacyDatasetBuilder:
1447
1446
  name=item.term or "",
1448
1447
  )
1449
1448
  mhd_builder.add_node(keyword)
1450
- mhd_builder.link(
1451
- mhd_study,
1452
- "has-submitter-keyword",
1453
- keyword,
1454
- reverse_relationship_name="keyword-of",
1455
- )
1449
+
1450
+ if item.source and item.source.lower() in ("data-curation", "workflows"):
1451
+ mhd_builder.link(
1452
+ mhd_study,
1453
+ "has-repository-keyword",
1454
+ keyword,
1455
+ reverse_relationship_name="keyword-of",
1456
+ )
1457
+ else:
1458
+ mhd_builder.link(
1459
+ mhd_study,
1460
+ "has-submitter-keyword",
1461
+ keyword,
1462
+ reverse_relationship_name="keyword-of",
1463
+ )
1464
+
1465
+ def add_assay_keywords(
1466
+ self,
1467
+ mhd_builder: MhDatasetBuilder,
1468
+ assays: dict[str, mhd_domain.Assay],
1469
+ study: Study,
1470
+ ):
1471
+ for assay in study.study_assays.assays:
1472
+ mhd_assay = assays.get(assay.file_name)
1473
+ if not mhd_assay:
1474
+ continue
1475
+ for item in assay.assay_descriptors:
1476
+ keyword = create_cv_term_object(
1477
+ type_="descriptor",
1478
+ source=item.term_source_ref or "",
1479
+ accession=self.convert_to_curie(
1480
+ item.term_source_ref,
1481
+ item.term_accession_number,
1482
+ )
1483
+ or "",
1484
+ name=item.term or "",
1485
+ )
1486
+ mhd_builder.add_node(keyword)
1487
+
1488
+ if item.source and item.source.lower() in (
1489
+ "data-curation",
1490
+ "workflows",
1491
+ ):
1492
+ mhd_builder.link(
1493
+ mhd_assay,
1494
+ "has-repository-keyword",
1495
+ keyword,
1496
+ reverse_relationship_name="keyword-of",
1497
+ )
1498
+ else:
1499
+ mhd_builder.link(
1500
+ mhd_assay,
1501
+ "has-submitter-keyword",
1502
+ keyword,
1503
+ reverse_relationship_name="keyword-of",
1504
+ )
1456
1505
 
1457
1506
  def find_file_format(
1458
1507
  self,
@@ -1757,9 +1806,9 @@ class MhdLegacyDatasetBuilder:
1757
1806
  metadata_files: dict[str, mhd_domain.CvTermObject],
1758
1807
  samples: dict[str, mhd_domain.Sample],
1759
1808
  files_map,
1760
- ) -> mhd_domain.Assay:
1809
+ ) -> dict[str, mhd_domain.Assay]:
1761
1810
  protocol_summaries: OrderedDict[str, ProtocolRunSummary] = OrderedDict()
1762
- assays: list[mhd_domain.Assay] = []
1811
+ assays: OrderedDict[str, mhd_domain.Assay] = OrderedDict()
1763
1812
  for assay in selected_assays:
1764
1813
  if assay.file_name not in data.assays:
1765
1814
  continue
@@ -1773,7 +1822,7 @@ class MhdLegacyDatasetBuilder:
1773
1822
  )
1774
1823
 
1775
1824
  mhd_builder.add(mhd_assay)
1776
- assays.append(mhd_assay)
1825
+ assays[assay.file_name] = mhd_assay
1777
1826
  mhd_builder.link(
1778
1827
  mhd_study, "has-assay", mhd_assay, reverse_relationship_name="part-of"
1779
1828
  )
@@ -1882,8 +1931,7 @@ class MhdLegacyDatasetBuilder:
1882
1931
  samples,
1883
1932
  protocol_summaries,
1884
1933
  )
1885
-
1886
- for mhd_assay in assays:
1934
+ for _, mhd_assay in assays.items():
1887
1935
  self.add_assay_protocols(mhd_builder, mhd_study, data, mhd_assay)
1888
1936
  return assays
1889
1937
 
@@ -2020,20 +2068,28 @@ class MhdLegacyDatasetBuilder:
2020
2068
  data.study_db_metadata.release_date,
2021
2069
  )
2022
2070
  # actual or estimated
2023
- public_release_date_str = (
2024
- db_metadata.first_public_date or db_metadata.release_date or None
2025
- )
2071
+ submission_date_str = None
2072
+ public_release_date_str = None
2073
+ if db_metadata:
2074
+ if db_metadata.first_private_date:
2075
+ submission_date_str = db_metadata.first_private_date
2076
+ elif db_metadata.submission_date:
2077
+ submission_date_str = db_metadata.submission_date
2078
+ if db_metadata.first_public_date:
2079
+ public_release_date_str = db_metadata.first_public_date
2080
+ elif db_metadata.release_date:
2081
+ public_release_date_str = db_metadata.release_date
2082
+
2026
2083
  public_release_date = (
2027
2084
  datetime.datetime.strptime(public_release_date_str, "%Y-%m-%d")
2028
2085
  if public_release_date_str
2029
2086
  else None
2030
2087
  )
2031
2088
  submission_date = (
2032
- datetime.datetime.strptime(db_metadata.first_private_date, "%Y-%m-%d")
2033
- if db_metadata and db_metadata.first_private_date
2089
+ datetime.datetime.strptime(submission_date_str, "%Y-%m-%d")
2090
+ if submission_date_str
2034
2091
  else None
2035
2092
  )
2036
-
2037
2093
  mhd_study = mhd_domain.Study(
2038
2094
  repository_identifier=study.identifier,
2039
2095
  created_by_ref=dataset_provider.id_,
@@ -2078,8 +2134,6 @@ class MhdLegacyDatasetBuilder:
2078
2134
  self.add_publications(data, mhd_builder, mhd_study)
2079
2135
  self.add_protocols(mhd_builder, mhd_study, study)
2080
2136
 
2081
- self.add_keywords(mhd_builder, mhd_study, study)
2082
-
2083
2137
  result_files = self.add_result_files(
2084
2138
  mhd_builder, mhd_study, data, config=config
2085
2139
  )
@@ -2093,7 +2147,7 @@ class MhdLegacyDatasetBuilder:
2093
2147
  result_files,
2094
2148
  config=config,
2095
2149
  )
2096
- self.add_assays(
2150
+ mhd_assays = self.add_assays(
2097
2151
  mhd_builder,
2098
2152
  mhd_study,
2099
2153
  data,
@@ -2102,6 +2156,8 @@ class MhdLegacyDatasetBuilder:
2102
2156
  samples,
2103
2157
  files_map,
2104
2158
  )
2159
+ self.add_keywords(mhd_builder, mhd_study, study)
2160
+ self.add_assay_keywords(mhd_builder, mhd_assays, study)
2105
2161
 
2106
2162
  mhd_dataset: MhDatasetBaseProfile = mhd_builder.create_dataset(
2107
2163
  start_item_refs=[mhd_study.id_], dataset_class=MhDatasetLegacyProfile
@@ -0,0 +1,59 @@
1
+ from pathlib import Path
2
+
3
+ from mhd_model.convertors.mhd.convertor import BaseMhdConvertor
4
+ from mhd_model.shared.model import Revision
5
+
6
+ from mtbls2mhd.config import Mtbls2MhdConfiguration, get_default_config
7
+ from mtbls2mhd.v0_1.legacy.builder import BuildType, MhdLegacyDatasetBuilder
8
+
9
+
10
+ class MsProfileConvertor(BaseMhdConvertor):
11
+ def __init__(
12
+ self,
13
+ target_mhd_model_schema_uri: str,
14
+ target_mhd_model_profile_uri: str,
15
+ ):
16
+ self.target_mhd_model_schema_uri = target_mhd_model_schema_uri
17
+ self.target_mhd_model_profile_uri = target_mhd_model_profile_uri
18
+
19
+ def convert(
20
+ self,
21
+ repository_name: str,
22
+ repository_identifier: str,
23
+ mhd_identifier: None | str,
24
+ repository_revision: None | Revision = None,
25
+ config: None | Mtbls2MhdConfiguration = None, # noqa: F821
26
+ cached_mtbls_model_file_path: None | str = None,
27
+ **kwargs,
28
+ ):
29
+ if not config:
30
+ config = get_default_config()
31
+ mhd_dataset_builder = MhdLegacyDatasetBuilder()
32
+ mtbls_study_repository_url = (
33
+ f"{config.study_http_base_url}/{repository_identifier}"
34
+ )
35
+
36
+ mtbls_study_path = Path(config.mtbls_studies_root_path) / Path(
37
+ repository_identifier
38
+ )
39
+ try:
40
+ success, message = mhd_dataset_builder.build(
41
+ mhd_id=mhd_identifier,
42
+ mtbls_study_id=repository_identifier,
43
+ mtbls_study_path=mtbls_study_path,
44
+ mtbls_study_repository_url=mtbls_study_repository_url,
45
+ target_mhd_model_schema_uri=self.target_mhd_model_schema_uri,
46
+ target_mhd_model_profile_uri=self.target_mhd_model_profile_uri,
47
+ config=config,
48
+ cached_mtbls_model_file_path=cached_mtbls_model_file_path,
49
+ revision=repository_revision,
50
+ repository_name=repository_name,
51
+ build_type=BuildType.FULL_AND_CUSTOM_NODES,
52
+ **kwargs,
53
+ )
54
+ return success, message
55
+ except Exception as ex:
56
+ import traceback
57
+
58
+ traceback.print_exc()
59
+ return False, str(ex)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mtbls-mhd-integration
3
- Version: 0.0.12
3
+ Version: 0.0.14
4
4
  Summary: MetaboLights - MetabolomicsHub Integration
5
5
  Author-email: MetaboLights Team <metabolights-help@ebi.ac.uk>
6
6
  License-Expression: Apache-2.0
@@ -9,7 +9,7 @@ Description-Content-Type: text/markdown
9
9
  License-File: LICENSE
10
10
  Requires-Dist: asyncpg>=0.30.0
11
11
  Requires-Dist: metabolights-utils>=1.4.16
12
- Requires-Dist: mhd-model>=0.1.41
12
+ Requires-Dist: mhd-model>=0.1.43
13
13
  Requires-Dist: psycopg[binary,pool]>=3.3.2
14
14
  Requires-Dist: pydantic>=2.12.4
15
15
  Requires-Dist: pydantic-settings>=2.10.1
@@ -1,6 +1,6 @@
1
1
  asyncpg>=0.30.0
2
2
  metabolights-utils>=1.4.16
3
- mhd-model>=0.1.41
3
+ mhd-model>=0.1.43
4
4
  psycopg[binary,pool]>=3.3.2
5
5
  pydantic>=2.12.4
6
6
  pydantic-settings>=2.10.1
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "mtbls-mhd-integration"
3
- version = "0.0.12"
3
+ version = "0.0.14"
4
4
  description = "MetaboLights - MetabolomicsHub Integration"
5
5
  authors = [{"name" = "MetaboLights Team", "email" = "metabolights-help@ebi.ac.uk"}]
6
6
  license = "Apache-2.0"
@@ -9,7 +9,7 @@ requires-python = ">=3.12,<4.0"
9
9
  dependencies = [
10
10
  "asyncpg>=0.30.0",
11
11
  "metabolights-utils>=1.4.16",
12
- "mhd-model>=0.1.41",
12
+ "mhd-model>=0.1.43",
13
13
  "psycopg[binary,pool]>=3.3.2",
14
14
  "pydantic>=2.12.4",
15
15
  "pydantic-settings>=2.10.1",
@@ -54,7 +54,7 @@ exclude = ["tests*", "docs*"]
54
54
  [tool.commitizen]
55
55
  name = "cz_conventional_commits"
56
56
  version_provider = "uv"
57
- version = "0.0.123"
57
+ version = "0.0.143"
58
58
  tag_format = "v$major.$minor.$patch"
59
59
  version_files = [
60
60
  "pyproject.toml:version",
@@ -1,3 +0,0 @@
1
- class Mtbs2MhdMsProfileConvertor:
2
- def convert():
3
- raise NotImplementedError()