From cadbafdb1fea5f95556a04f1855af287bb2935c0 Mon Sep 17 00:00:00 2001 From: ozgury Date: Fri, 6 Dec 2024 09:42:22 +0000 Subject: [PATCH] refactor: refactor code to export modules --- .gitignore | 2 +- metabolights_utils/__init__.py | 608 +++++++++--------- metabolights_utils/commands/__init__.py | 0 metabolights_utils/isa_file_utils.py | 105 +++ metabolights_utils/isatab/__init__.py | 13 + metabolights_utils/isatab/default/__init__.py | 23 + .../isatab/default/parser/__init__.py | 11 + metabolights_utils/models/__init__.py | 9 + metabolights_utils/models/isa/__init__.py | 17 + .../models/metabolights/__init__.py | 4 + metabolights_utils/models/parser/__init__.py | 3 + metabolights_utils/provider/__init__.py | 23 + .../provider/async_provider/__init__.py | 3 + metabolights_utils/provider/ftp/__init__.py | 11 + metabolights_utils/tsv/__init__.py | 3 + metabolights_utils/tsv/actions/__init__.py | 31 + metabolights_utils/utils/__init__.py | 13 + 17 files changed, 583 insertions(+), 296 deletions(-) create mode 100644 metabolights_utils/commands/__init__.py create mode 100644 metabolights_utils/isa_file_utils.py create mode 100644 metabolights_utils/provider/__init__.py create mode 100644 metabolights_utils/provider/async_provider/__init__.py create mode 100644 metabolights_utils/provider/ftp/__init__.py create mode 100644 metabolights_utils/utils/__init__.py diff --git a/.gitignore b/.gitignore index b4216bb..c33ff7b 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,7 @@ test-temp __pycache__/ *.py[cod] *$py.class - +.DS_Store # C extensions *.so diff --git a/metabolights_utils/__init__.py b/metabolights_utils/__init__.py index bc3aef7..5ba8624 100644 --- a/metabolights_utils/__init__.py +++ b/metabolights_utils/__init__.py @@ -1,301 +1,319 @@ -from metabolights_utils.common import CamelCaseModel -from metabolights_utils.isatab import Reader, Writer -from metabolights_utils.isatab.default.assay_file import DefaultAssayFileReader -from metabolights_utils.isatab.default.assignment_file import ( - DefaultAssignmentFileReader, +# from metabolights_utils.common import CamelCaseModel +# from metabolights_utils.isatab import Reader, Writer +# from metabolights_utils.isatab.default.assay_file import DefaultAssayFileReader +# from metabolights_utils.isatab.default.assignment_file import ( +# DefaultAssignmentFileReader, +# ) +# from metabolights_utils.isatab.default.factory import ( +# DefaultIsaTabReaderFactory, +# DefaultIsaTabWriterFactory, +# ) +# from metabolights_utils.isatab.default.investigation_file import ( +# DefaultInvestigationFileReader, +# DefaultInvestigationFileWriter, +# ) +# from metabolights_utils.isatab.default.parser.isa_table_parser import ( +# assay_file_expected_patterns, +# samples_file_expected_patterns, +# ) +# from metabolights_utils.isatab.default.sample_file import DefaultSampleFileReader +# from metabolights_utils.isatab.default.writer import DefaultIsaTableFileWriter +# from metabolights_utils.isatab.reader import ( +# InvestigationFileReader, +# InvestigationFileReaderResult, +# IsaTableFileReader, +# IsaTableFileReaderResult, +# IsaTabReaderFactory, +# ) +# from metabolights_utils.isatab.writer import ( +# InvestigationFileWriter, +# IsaTableFileWriter, +# IsaTabWriterFactory, +# ) +# from metabolights_utils.models.common import GenericMessage, MetabolightsBaseModel +# from metabolights_utils.models.enums import GenericMessageType +# from metabolights_utils.models.isa.assay_file import AssayFile +# from metabolights_utils.models.isa.assignment_file import AssignmentFile +# from metabolights_utils.models.isa.common import ( +# AssayTechnique, +# Comment, +# IsaAbstractModel, +# IsaTable, +# IsaTableColumn, +# IsaTableFile, +# NumericItem, +# OntologyItem, +# OrganismAndOrganismPartPair, +# ) +# from metabolights_utils.models.isa.enums import ( +# ColumnsStructure, +# IsaTableAdditionalColumn, +# ) +# from metabolights_utils.models.isa.investigation_file import ( +# Assay, +# BaseSection, +# Factor, +# Investigation, +# InvestigationContacts, +# InvestigationPublications, +# OntologyAnnotation, +# OntologySourceReference, +# OntologySourceReferences, +# Person, +# Protocol, +# Publication, +# Study, +# StudyAssays, +# StudyContacts, +# StudyFactors, +# StudyProtocols, +# StudyPublications, +# ValueTypeAnnotation, +# ) +# from metabolights_utils.models.metabolights.metabolights_study import ( +# BaseMetabolightsStudyModel, +# ) +# from metabolights_utils.models.parser.common import ParserMessage, ParserReport +# from metabolights_utils.models.parser.enums import ParserMessageType +# from metabolights_utils.tsv.actions.add_column import AddColumnsTsvAction +# from metabolights_utils.tsv.actions.add_row import AddRowsTsvAction +# from metabolights_utils.tsv.actions.base import BaseTsvAction, TsvActionException +# from metabolights_utils.tsv.actions.copy_column import CopyColumnTsvAction +# from metabolights_utils.tsv.actions.copy_row import CopyRowTsvAction +# from metabolights_utils.tsv.actions.delete_column import DeleteColumnsTsvAction +# from metabolights_utils.tsv.actions.delete_row import DeleteRowsTsvAction +# from metabolights_utils.tsv.actions.move_column import MoveColumnTsvAction +# from metabolights_utils.tsv.actions.update_cell import UpdateCellsTsvAction +# from metabolights_utils.tsv.actions.update_column import UpdateColumnsTsvAction +# from metabolights_utils.tsv.actions.update_column_header import ( +# UpdateColumnHeadersTsvAction, +# ) +# from metabolights_utils.tsv.actions.update_row import UpdateRowsTsvAction +# from metabolights_utils.tsv.filter import ( +# BetweenEqualCustomFilter, +# ContainsFilter, +# CustomFilter, +# EmptyFilter, +# EndsWithFilter, +# EnumContainsCustomFilter, +# Filter, +# FilterDataType, +# FilterOperation, +# FilterRegistry, +# GreaterEqualFilter, +# GreaterFilter, +# LessEqualFilter, +# LessFilter, +# RegexFilter, +# StartsWithFilter, +# TsvFileFilterOption, +# TsvFilterException, +# ValidDatetimeCustomFilter, +# ValidNumberCustomFilter, +# ) +# from metabolights_utils.tsv.model import ( +# TsvAction, +# TsvActionReport, +# TsvActionResult, +# TsvActionType, +# TsvAddColumnsAction, +# TsvAddRowsAction, +# TsvCellData, +# TsvColumnData, +# TsvCopyColumnAction, +# TsvCopyRowAction, +# TsvDeleteColumnsAction, +# TsvDeleteRowsAction, +# TsvMoveColumnAction, +# TsvMoveRowAction, +# TsvRowData, +# TsvUpdateCellsAction, +# TsvUpdateColumnHeaderAction, +# TsvUpdateColumnsAction, +# TsvUpdateRowsAction, +# ) +# from metabolights_utils.tsv.sort import ( +# AbstractSorter, +# CustomSorter, +# DateTimeSorter, +# EnumSorter, +# FloatSorter, +# IntegerSorter, +# Sorter, +# SorterRegistry, +# SortType, +# SortValueClassification, +# StringSorter, +# TsvFileSortOption, +# TsvFileSortValueOrder, +# TsvSortException, +# ) +# from metabolights_utils.tsv.tsv_file_updater import TSV_FILE_ACTIONS, TsvFileUpdater +# from metabolights_utils.utils.audit_utils import MetabolightsAuditUtils +# from metabolights_utils.utils.filename_utils import MetabolightsFileNameUtils +# from metabolights_utils.utils.hash_utils import ( +# EMPTY_FILE_HASH, +# IsaMetadataFolderHash, +# MetabolightsHashUtils, +# ) +# from metabolights_utils.utils.search_utils import MetabolightsSearchUtils +from metabolights_utils import ( + isatab, + commands, + models, + provider, + tsv, + utils, + common, + isa_file_utils, ) -from metabolights_utils.isatab.default.factory import ( - DefaultIsaTabReaderFactory, - DefaultIsaTabWriterFactory, -) -from metabolights_utils.isatab.default.investigation_file import ( - DefaultInvestigationFileReader, - DefaultInvestigationFileWriter, -) -from metabolights_utils.isatab.default.parser.isa_table_parser import ( - assay_file_expected_patterns, - samples_file_expected_patterns, -) -from metabolights_utils.isatab.default.sample_file import DefaultSampleFileReader -from metabolights_utils.isatab.default.writer import DefaultIsaTableFileWriter -from metabolights_utils.isatab.reader import ( - InvestigationFileReader, - InvestigationFileReaderResult, - IsaTableFileReader, - IsaTableFileReaderResult, - IsaTabReaderFactory, -) -from metabolights_utils.isatab.writer import ( - InvestigationFileWriter, - IsaTableFileWriter, - IsaTabWriterFactory, -) -from metabolights_utils.models.common import GenericMessage, MetabolightsBaseModel -from metabolights_utils.models.enums import GenericMessageType -from metabolights_utils.models.isa.assay_file import AssayFile -from metabolights_utils.models.isa.assignment_file import AssignmentFile -from metabolights_utils.models.isa.common import ( - AssayTechnique, - Comment, - IsaAbstractModel, - IsaTable, - IsaTableColumn, - IsaTableFile, - NumericItem, - OntologyItem, - OrganismAndOrganismPartPair, -) -from metabolights_utils.models.isa.enums import ( - ColumnsStructure, - IsaTableAdditionalColumn, -) -from metabolights_utils.models.isa.investigation_file import ( - Assay, - BaseSection, - Factor, - Investigation, - InvestigationContacts, - InvestigationPublications, - OntologyAnnotation, - OntologySourceReference, - OntologySourceReferences, - Person, - Protocol, - Publication, - Study, - StudyAssays, - StudyContacts, - StudyFactors, - StudyProtocols, - StudyPublications, - ValueTypeAnnotation, -) -from metabolights_utils.models.metabolights.metabolights_study import ( - BaseMetabolightsStudyModel, -) -from metabolights_utils.models.parser.common import ParserMessage, ParserReport -from metabolights_utils.models.parser.enums import ParserMessageType -from metabolights_utils.tsv.actions.add_column import AddColumnsTsvAction -from metabolights_utils.tsv.actions.add_row import AddRowsTsvAction -from metabolights_utils.tsv.actions.base import BaseTsvAction, TsvActionException -from metabolights_utils.tsv.actions.copy_column import CopyColumnTsvAction -from metabolights_utils.tsv.actions.copy_row import CopyRowTsvAction -from metabolights_utils.tsv.actions.delete_column import DeleteColumnsTsvAction -from metabolights_utils.tsv.actions.delete_row import DeleteRowsTsvAction -from metabolights_utils.tsv.actions.move_column import MoveColumnTsvAction -from metabolights_utils.tsv.actions.update_cell import UpdateCellsTsvAction -from metabolights_utils.tsv.actions.update_column import UpdateColumnsTsvAction -from metabolights_utils.tsv.actions.update_column_header import ( - UpdateColumnHeadersTsvAction, -) -from metabolights_utils.tsv.actions.update_row import UpdateRowsTsvAction -from metabolights_utils.tsv.filter import ( - BetweenEqualCustomFilter, - ContainsFilter, - CustomFilter, - EmptyFilter, - EndsWithFilter, - EnumContainsCustomFilter, - Filter, - FilterDataType, - FilterOperation, - FilterRegistry, - GreaterEqualFilter, - GreaterFilter, - LessEqualFilter, - LessFilter, - RegexFilter, - StartsWithFilter, - TsvFileFilterOption, - TsvFilterException, - ValidDatetimeCustomFilter, - ValidNumberCustomFilter, -) -from metabolights_utils.tsv.model import ( - TsvAction, - TsvActionReport, - TsvActionResult, - TsvActionType, - TsvAddColumnsAction, - TsvAddRowsAction, - TsvCellData, - TsvColumnData, - TsvCopyColumnAction, - TsvCopyRowAction, - TsvDeleteColumnsAction, - TsvDeleteRowsAction, - TsvMoveColumnAction, - TsvMoveRowAction, - TsvRowData, - TsvUpdateCellsAction, - TsvUpdateColumnHeaderAction, - TsvUpdateColumnsAction, - TsvUpdateRowsAction, -) -from metabolights_utils.tsv.sort import ( - AbstractSorter, - CustomSorter, - DateTimeSorter, - EnumSorter, - FloatSorter, - IntegerSorter, - Sorter, - SorterRegistry, - SortType, - SortValueClassification, - StringSorter, - TsvFileSortOption, - TsvFileSortValueOrder, - TsvSortException, -) -from metabolights_utils.tsv.tsv_file_updater import TSV_FILE_ACTIONS, TsvFileUpdater -from metabolights_utils.utils.audit_utils import MetabolightsAuditUtils -from metabolights_utils.utils.filename_utils import MetabolightsFileNameUtils -from metabolights_utils.utils.hash_utils import ( - EMPTY_FILE_HASH, - IsaMetadataFolderHash, - MetabolightsHashUtils, -) -from metabolights_utils.utils.search_utils import MetabolightsSearchUtils __VERSION__ = "1.3.7" __all__ = [ - "Assay", - "BaseSection", - "Factor", - "Investigation", - "InvestigationContacts", - "InvestigationPublications", - "OntologyAnnotation", - "OntologySourceReference", - "OntologySourceReferences", - "Person", - "Protocol", - "Publication", - "Study", - "StudyAssays", - "StudyContacts", - "StudyFactors", - "StudyProtocols", - "StudyPublications", - "ValueTypeAnnotation", - "ColumnsStructure", - "IsaTableAdditionalColumn", - "IsaAbstractModel", - "NumericItem", - "AssayFile", - "AssignmentFile", - "GenericMessage", - "GenericMessageType", - "MetabolightsBaseModel", - "CamelCaseModel", - "AssayTechnique", - "Comment", - "IsaTable", - "IsaTableColumn", - "IsaTableFile", - "OntologyItem", - "OrganismAndOrganismPartPair", - "BaseMetabolightsStudyModel", - "ParserMessage", - "ParserMessageType", - "ParserReport", - "Reader", - "DefaultAssayFileReader", - "InvestigationFileReader", - "DefaultAssignmentFileReader", - "IsaTableFileReader", - "InvestigationFileReaderResult", - "IsaTableFileReaderResult", - "DefaultIsaTabReaderFactory", - "DefaultIsaTabWriterFactory", - "DefaultInvestigationFileReader", - "DefaultInvestigationFileWriter", - "assay_file_expected_patterns", - "samples_file_expected_patterns", - "DefaultSampleFileReader", - "DefaultIsaTableFileWriter", - "IsaTabReaderFactory", - "Writer", - "InvestigationFileWriter", - "IsaTableFileWriter", - "IsaTabWriterFactory", - # TSV - "TsvAction", - "TsvActionReport", - "TsvActionResult", - "TsvActionType", - "TsvAddColumnsAction", - "TsvAddRowsAction", - "TsvCellData", - "TsvColumnData", - "TsvCopyColumnAction", - "TsvCopyRowAction", - "TsvDeleteColumnsAction", - "TsvDeleteRowsAction", - "TsvMoveColumnAction", - "TsvMoveRowAction", - "TsvRowData", - "TsvUpdateCellsAction", - "TsvUpdateColumnHeaderAction", - "TsvUpdateColumnsAction", - "TsvUpdateRowsAction", - "Filter", - "FilterDataType", - "FilterOperation", - "TsvFileFilterOption", - "TsvFilterException", - "CustomFilter", - "FilterRegistry", - "ContainsFilter", - "StartsWithFilter", - "EndsWithFilter", - "GreaterFilter", - "GreaterEqualFilter", - "LessFilter", - "LessEqualFilter", - "EmptyFilter", - "RegexFilter", - "ValidNumberCustomFilter", - "ValidDatetimeCustomFilter", - "EnumContainsCustomFilter", - "BetweenEqualCustomFilter", - "AbstractSorter", - "CustomSorter", - "DateTimeSorter", - "EnumSorter", - "FloatSorter", - "IntegerSorter", - "Sorter", - "SorterRegistry", - "SortType", - "SortValueClassification", - "StringSorter", - "TsvFileSortOption", - "TsvFileSortValueOrder", - "TsvSortException", - "TSV_FILE_ACTIONS", - "TsvFileUpdater", - "TsvActionException", - "BaseTsvAction", - "AddColumnsTsvAction", - "AddRowsTsvAction", - "CopyColumnTsvAction", - "CopyRowTsvAction", - "DeleteColumnsTsvAction", - "DeleteRowsTsvAction", - "MoveColumnTsvAction", - "UpdateCellsTsvAction", - "UpdateColumnsTsvAction", - "UpdateColumnHeadersTsvAction", - "UpdateRowsTsvAction", - # utils - "MetabolightsAuditUtils", - "MetabolightsSearchUtils", - "MetabolightsFileNameUtils", - # hash utils - "MetabolightsHashUtils", - "IsaMetadataFolderHash", - "EMPTY_FILE_HASH", + "commands", + "isatab", + "models", + "provider", + "tsv", + "utils", + "common", + "isa_file_utils", + # "Assay", + # "BaseSection", + # "Factor", + # "Investigation", + # "InvestigationContacts", + # "InvestigationPublications", + # "OntologyAnnotation", + # "OntologySourceReference", + # "OntologySourceReferences", + # "Person", + # "Protocol", + # "Publication", + # "Study", + # "StudyAssays", + # "StudyContacts", + # "StudyFactors", + # "StudyProtocols", + # "StudyPublications", + # "ValueTypeAnnotation", + # "ColumnsStructure", + # "IsaTableAdditionalColumn", + # "IsaAbstractModel", + # "NumericItem", + # "AssayFile", + # "AssignmentFile", + # "GenericMessage", + # "GenericMessageType", + # "MetabolightsBaseModel", + # "CamelCaseModel", + # "AssayTechnique", + # "Comment", + # "IsaTable", + # "IsaTableColumn", + # "IsaTableFile", + # "OntologyItem", + # "OrganismAndOrganismPartPair", + # "BaseMetabolightsStudyModel", + # "ParserMessage", + # "ParserMessageType", + # "ParserReport", + # "Reader", + # "DefaultAssayFileReader", + # "InvestigationFileReader", + # "DefaultAssignmentFileReader", + # "IsaTableFileReader", + # "InvestigationFileReaderResult", + # "IsaTableFileReaderResult", + # "DefaultIsaTabReaderFactory", + # "DefaultIsaTabWriterFactory", + # "DefaultInvestigationFileReader", + # "DefaultInvestigationFileWriter", + # "assay_file_expected_patterns", + # "samples_file_expected_patterns", + # "DefaultSampleFileReader", + # "DefaultIsaTableFileWriter", + # "IsaTabReaderFactory", + # "Writer", + # "InvestigationFileWriter", + # "IsaTableFileWriter", + # "IsaTabWriterFactory", + # # TSV + # "TsvAction", + # "TsvActionReport", + # "TsvActionResult", + # "TsvActionType", + # "TsvAddColumnsAction", + # "TsvAddRowsAction", + # "TsvCellData", + # "TsvColumnData", + # "TsvCopyColumnAction", + # "TsvCopyRowAction", + # "TsvDeleteColumnsAction", + # "TsvDeleteRowsAction", + # "TsvMoveColumnAction", + # "TsvMoveRowAction", + # "TsvRowData", + # "TsvUpdateCellsAction", + # "TsvUpdateColumnHeaderAction", + # "TsvUpdateColumnsAction", + # "TsvUpdateRowsAction", + # "Filter", + # "FilterDataType", + # "FilterOperation", + # "TsvFileFilterOption", + # "TsvFilterException", + # "CustomFilter", + # "FilterRegistry", + # "ContainsFilter", + # "StartsWithFilter", + # "EndsWithFilter", + # "GreaterFilter", + # "GreaterEqualFilter", + # "LessFilter", + # "LessEqualFilter", + # "EmptyFilter", + # "RegexFilter", + # "ValidNumberCustomFilter", + # "ValidDatetimeCustomFilter", + # "EnumContainsCustomFilter", + # "BetweenEqualCustomFilter", + # "AbstractSorter", + # "CustomSorter", + # "DateTimeSorter", + # "EnumSorter", + # "FloatSorter", + # "IntegerSorter", + # "Sorter", + # "SorterRegistry", + # "SortType", + # "SortValueClassification", + # "StringSorter", + # "TsvFileSortOption", + # "TsvFileSortValueOrder", + # "TsvSortException", + # "TSV_FILE_ACTIONS", + # "TsvFileUpdater", + # "TsvActionException", + # "BaseTsvAction", + # "AddColumnsTsvAction", + # "AddRowsTsvAction", + # "CopyColumnTsvAction", + # "CopyRowTsvAction", + # "DeleteColumnsTsvAction", + # "DeleteRowsTsvAction", + # "MoveColumnTsvAction", + # "UpdateCellsTsvAction", + # "UpdateColumnsTsvAction", + # "UpdateColumnHeadersTsvAction", + # "UpdateRowsTsvAction", + # # utils + # "MetabolightsAuditUtils", + # "MetabolightsSearchUtils", + # "MetabolightsFileNameUtils", + # # hash utils + # "MetabolightsHashUtils", + # "IsaMetadataFolderHash", + # "EMPTY_FILE_HASH", ] diff --git a/metabolights_utils/commands/__init__.py b/metabolights_utils/commands/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/metabolights_utils/isa_file_utils.py b/metabolights_utils/isa_file_utils.py new file mode 100644 index 0000000..88844d9 --- /dev/null +++ b/metabolights_utils/isa_file_utils.py @@ -0,0 +1,105 @@ +import logging +import os +from typing import Any, Union + +from metabolights_utils.isatab import Writer +from metabolights_utils.models.isa.common import IsaTableFile +from metabolights_utils.models.metabolights.model import MetabolightsStudyModel + +logger = logging.getLogger(__name__) + + +class IsaFileUtils: + + @staticmethod + async def save_metabolights_study_model( + mtbls_model: MetabolightsStudyModel, + output_dir: str, + values_in_quotation_mark: bool = False, + investigation_module_name: Union[None, str] = None, + ): + if not os.path.exists(output_dir): + logger.info(f"Study save folder % is created", output_dir) + os.makedirs(output_dir, exist_ok=True) + i_file_name = mtbls_model.investigation_file_path + logger.info("Saving investigation file: %s", i_file_name) + Writer.get_investigation_file_writer().write( + mtbls_model.investigation, + f"{output_dir}/{mtbls_model.investigation_file_path}", + values_in_quotation_mark=values_in_quotation_mark, + investigation_module_name=investigation_module_name, + ) + for isa_table_files in ( + mtbls_model.samples, + mtbls_model.assays, + mtbls_model.metabolite_assignments, + ): + for isa_table_file in isa_table_files.values(): + i_file_name = isa_table_file.file_path + await IsaFileUtils.save_isa_table( + isa_table_file, + f"{output_dir}/{isa_table_file.file_path}", + values_in_quotation_mark=values_in_quotation_mark, + ) + + @staticmethod + def sanitise_data(self, value: Union[None, Any]): + if isinstance(value, list): + for idx, val in enumerate(value): + value[idx] = IsaFileUtils.sanitise_single_value(val) + return value + return IsaFileUtils.sanitise_single_value(value) + + @staticmethod + def sanitise_single_value(self, value: Union[None, Any]): + if value is None: + return "" + return ( + str(value).replace("\n", " ").replace("\r", " ").replace("\t", " ").strip() + ) + + @staticmethod + async def save_isa_table( + isa_table_file: IsaTableFile, + file_path: str, + values_in_quotation_mark=False, + ): + column_order_map = {} + column_header_map = {} + data = isa_table_file.table.data + for column_model in isa_table_file.table.headers: + column_order_map[column_model.column_index] = column_model.column_name + column_header_map[column_model.column_index] = column_model.column_header + parent_dir = os.path.dirname(file_path) + basename = os.path.dirname(file_path) + if not os.path.exists(parent_dir): + logger.info(f"Study save folder % is created", parent_dir) + os.makedirs(parent_dir, exist_ok=True) + + logger.info("Saving file: %s", basename) + with open(file_path, "w") as f: + if values_in_quotation_mark: + header = [ + f'"{column_header_map[idx]}"' + for idx in range(len(column_header_map)) + ] + else: + header = [ + column_header_map[idx].strip('"') + for idx in range(len(column_header_map)) + ] + f.write("\t".join(header) + "\n") + + column_names = [ + column_order_map[idx] for idx in range(len(column_order_map)) + ] + for row_idx in range(len(data[column_names[0]])): + row = [data[column_name][row_idx] for column_name in column_names] + for idx, cell in enumerate(row): + cell = IsaFileUtils.sanitise_data(cell) if row[idx] else "" + if values_in_quotation_mark: + cell = f'"{cell}"' + else: + cell = cell.strip('"') + row[idx] = cell + f.write("\t".join(row) + "\n") diff --git a/metabolights_utils/isatab/__init__.py b/metabolights_utils/isatab/__init__.py index 5eec434..601199c 100644 --- a/metabolights_utils/isatab/__init__.py +++ b/metabolights_utils/isatab/__init__.py @@ -15,6 +15,8 @@ IsaTabWriterFactory, ) +from metabolights_utils.isatab import default, reader, writer + @lru_cache def get_reader_factory(): @@ -72,3 +74,14 @@ def get_sample_file_writer(cls) -> IsaTableFileWriter: @classmethod def get_assignment_file_writer(cls) -> IsaTableFileWriter: return cls.writer_factory.get_sample_file_writer() + + +__all__ = [ + "reader", + "default", + "writer", + "Reader", + "Writer", + "get_reader_factory", + "get_writer_factory", +] diff --git a/metabolights_utils/isatab/default/__init__.py b/metabolights_utils/isatab/default/__init__.py index e69de29..307015d 100644 --- a/metabolights_utils/isatab/default/__init__.py +++ b/metabolights_utils/isatab/default/__init__.py @@ -0,0 +1,23 @@ +from metabolights_utils.isatab.default import ( + parser, + assay_file, + assignment_file, + base_isa_table_file, + base_isa_file, + factory, + investigation_file, + sample_file, + writer, +) + +__all__ = [ + "parser", + "assay_file", + "assignment_file", + "base_isa_table_file", + "base_isa_file", + "factory", + "investigation_file", + "sample_file", + "writer", +] diff --git a/metabolights_utils/isatab/default/parser/__init__.py b/metabolights_utils/isatab/default/parser/__init__.py index e69de29..f5fb890 100644 --- a/metabolights_utils/isatab/default/parser/__init__.py +++ b/metabolights_utils/isatab/default/parser/__init__.py @@ -0,0 +1,11 @@ +from metabolights_utils.isatab.default.parser import ( + common, + investigation_parser, + isa_table_parser, +) + +__all__ = [ + "common", + "investigation_parser", + "isa_table_parser", +] diff --git a/metabolights_utils/models/__init__.py b/metabolights_utils/models/__init__.py index e69de29..60b7325 100644 --- a/metabolights_utils/models/__init__.py +++ b/metabolights_utils/models/__init__.py @@ -0,0 +1,9 @@ +from metabolights_utils.models import common, enums, isa, metabolights, parser + +__all__ = [ + "common", + "enums", + "isa", + "metabolights", + "parser", +] diff --git a/metabolights_utils/models/isa/__init__.py b/metabolights_utils/models/isa/__init__.py index e69de29..edc82f1 100644 --- a/metabolights_utils/models/isa/__init__.py +++ b/metabolights_utils/models/isa/__init__.py @@ -0,0 +1,17 @@ +from metabolights_utils.models.isa import ( + assay_file, + assignment_file, + common, + enums, + investigation_file, + samples_file, +) + +__all__ = [ + "assay_file", + "assignment_file", + "common", + "enums", + "investigation_file", + "samples_file", +] diff --git a/metabolights_utils/models/metabolights/__init__.py b/metabolights_utils/models/metabolights/__init__.py index 66850c0..7777174 100644 --- a/metabolights_utils/models/metabolights/__init__.py +++ b/metabolights_utils/models/metabolights/__init__.py @@ -1,6 +1,7 @@ import json import os from typing import Dict, Union +from metabolights_utils.models.metabolights import metabolights_study, model def get_study_model_schema(schema_path: Union[str, None] = None) -> Dict: @@ -12,3 +13,6 @@ def get_study_model_schema(schema_path: Union[str, None] = None) -> Dict: with open(schema_path, "r", encoding="utf-8") as sf: study_model_jsonschema = json.load(sf) return study_model_jsonschema + + +__all__ = ["metabolights_study", "model", "get_study_model_schema"] diff --git a/metabolights_utils/models/parser/__init__.py b/metabolights_utils/models/parser/__init__.py index e69de29..af559c6 100644 --- a/metabolights_utils/models/parser/__init__.py +++ b/metabolights_utils/models/parser/__init__.py @@ -0,0 +1,3 @@ +from metabolights_utils.models.parser import common, enums + +__all__ = ["common", "enums"] diff --git a/metabolights_utils/provider/__init__.py b/metabolights_utils/provider/__init__.py new file mode 100644 index 0000000..611f82e --- /dev/null +++ b/metabolights_utils/provider/__init__.py @@ -0,0 +1,23 @@ +from metabolights_utils.provider import ( + ftp, + async_provider, + definitions, + ftp_repository, + local_folder_metadata_collector, + study_provider, + submission_model, + submission_repository, + utils, +) + +__all__ = [ + "ftp", + "async_provider", + "definitions", + "ftp_repository", + "local_folder_metadata_collector", + "study_provider", + "submission_model", + "submission_repository", + "utils", +] diff --git a/metabolights_utils/provider/async_provider/__init__.py b/metabolights_utils/provider/async_provider/__init__.py new file mode 100644 index 0000000..2b4ec02 --- /dev/null +++ b/metabolights_utils/provider/async_provider/__init__.py @@ -0,0 +1,3 @@ +from metabolights_utils.provider.async_provider import study_provider + +__all__ = ["study_provider"] diff --git a/metabolights_utils/provider/ftp/__init__.py b/metabolights_utils/provider/ftp/__init__.py new file mode 100644 index 0000000..26ba826 --- /dev/null +++ b/metabolights_utils/provider/ftp/__init__.py @@ -0,0 +1,11 @@ +from metabolights_utils.provider.ftp import ( + default_ftp_client, + folder_metadata_collector, + model, +) + +__all__ = [ + "default_ftp_client", + "folder_metadata_collector", + "model", +] diff --git a/metabolights_utils/tsv/__init__.py b/metabolights_utils/tsv/__init__.py index e69de29..450ef4d 100644 --- a/metabolights_utils/tsv/__init__.py +++ b/metabolights_utils/tsv/__init__.py @@ -0,0 +1,3 @@ +from metabolights_utils.tsv import actions, filter, model, sort, tsv_file_updater + +__all__ = ["actions", "filter", "model", "sort", "tsv_file_updater"] diff --git a/metabolights_utils/tsv/actions/__init__.py b/metabolights_utils/tsv/actions/__init__.py index e69de29..29535f8 100644 --- a/metabolights_utils/tsv/actions/__init__.py +++ b/metabolights_utils/tsv/actions/__init__.py @@ -0,0 +1,31 @@ +from metabolights_utils.tsv.actions import ( + add_column, + add_row, + base, + copy_column, + copy_row, + delete_column, + delete_row, + move_column, + move_row, + update_cell, + update_column_header, + update_column, + update_row, +) + +__all__ = [ + "add_column", + "add_row", + "base", + "copy_column", + "copy_row", + "delete_column", + "delete_row", + "move_column", + "move_row", + "update_cell", + "update_column_header", + "update_column", + "update_row", +] diff --git a/metabolights_utils/utils/__init__.py b/metabolights_utils/utils/__init__.py new file mode 100644 index 0000000..c6a5ca8 --- /dev/null +++ b/metabolights_utils/utils/__init__.py @@ -0,0 +1,13 @@ +from metabolights_utils.utils import ( + audit_utils, + filename_utils, + hash_utils, + search_utils, +) + +__all__ = [ + "audit_utils", + "filename_utils", + "hash_utils", + "search_utils", +]