Skip to main content

MetaboLights - MHD Model Integration Framework

Quickstart

If you have a python environment (>=3.12) on your local, you may use it or create a virtual one.

# uninstall previous versions
pip uninstall gnps-mhd-integration -y

# installed the latest version
pip install gnps-mhd-integration

gnps-mhd-cli --version
#gnps-mhd-cli, version v0.1.0

Legacy study workflow (on test MHD server)

# Set parameter values
# If it is private study, update MSV_SERVER_URL, MSV_REST_API_USERNAME and MSV_REST_API_PASSWORD
# Files will be stored on mhd-files folder by default
MSV_STUDY_ID=MSV000099141
MSV_SERVER_URL=<define it, such as https://massive.ucsd.edu, http://dev.massive.ucsd.edu:XXXX>
MSV_REST_API_USERNAME=<define it for private studies>
MSV_REST_API_PASSWORD=<define it for private studies>
MHD_API_TOKEN=<define it>


MHD_INPUT_DIR=mhd-files/$MSV_STUDY_ID/inputs
MHD_OUTPUT_DIR=mhd-files/$MSV_STUDY_ID/outputs
MHD_FILE_URL=$MSV_SERVER_URL/ProteoSAFe/DownloadResultFile?file=f.${MSV_STUDY_ID}%2Fccms_parameters%2F${MSV_STUDY_ID}.mhd.json
MHD_FILE_NAME=$MSV_STUDY_ID.mhd.json
ANNOUNCEMENT_FILE_NAME=$MSV_STUDY_ID.announcement.json
ANNOUNCEMENT_REASON="First release"
MHD_SERVER_URL=https://www.metabolomicshub.org/test/api/submission


mkdir -p $MHD_INPUT_DIR
mkdir -p $MHD_OUTPUT_DIR

################################################################
# Download a legacy study metadata.
################################################################
gnps-mhd-cli download \
  --massive-server-url "$MSV_SERVER_URL" \
  --username "$MSV_REST_API_USERNAME" \
  --password "$MSV_REST_API_PASSWORD" \
  mhd-converter-input \
  --massive-study-id $MSV_STUDY_ID \
  --output-dir $MHD_INPUT_DIR

################################################################
# Verify the downloaded files
################################################################
ls -al $MHD_INPUT_DIR

################################################################
# Convert MW study metadata to MHD file
################################################################
gnps-mhd-cli convert to-mhd-legacy-file \
  --massive-study-id $MSV_STUDY_ID \
  --input-dir $MHD_INPUT_DIR \
  --output-dir $MHD_OUTPUT_DIR \
  --output-filename $MHD_FILE_NAME

################################################################
# Verify created mhd file and logs
################################################################
ls -al $MHD_OUTPUT_DIR

################################################################
# Validate MHD file
################################################################
gnps-mhd-cli validate mhd \
  --output-file-path "$MHD_OUTPUT_DIR/$MSV_STUDY_ID.mhd_errors.json" \
  "$MHD_OUTPUT_DIR/$MHD_FILE_NAME"

################################################################
# View MHD validation status and errors (if exist)
################################################################
cat $MHD_OUTPUT_DIR/$MSV_STUDY_ID.mhd_errors.json

################################################################
#***************************************************************
# * If there are errors, fix the dataset metadata and run again
#***************************************************************
################################################################

################################################################
# Create announcement file
################################################################
gnps-mhd-cli create announcement \
  --mhd-common-data-file-path $MHD_OUTPUT_DIR/$MHD_FILE_NAME \
  --target-mhd-common-data-file-url "$MHD_FILE_URL" \
  --output-dir "$MHD_OUTPUT_DIR" \
  --output-filename $ANNOUNCEMENT_FILE_NAME

ls -al $MHD_OUTPUT_DIR

################################################################
# Create announcement file
################################################################

gnps-mhd-cli validate announcement \
  --output-file-path $MHD_OUTPUT_DIR/$MSV_STUDY_ID.announcement_errors.json \
  $MHD_OUTPUT_DIR/$ANNOUNCEMENT_FILE_NAME

################################################################
# View Announcement validation status and errors (if exist)
################################################################
cat $MHD_OUTPUT_DIR/$MSV_STUDY_ID.announcement_errors.json


################################################################
# After a study is public or its new revision:
# 1- Update MW database (release date, etc.),
# 2- Re-run all previous commands
# 3- Upload MHD and Announcement files on server
# 4- Make announcement with the following command
# Announcement will fail if $MHD_FILE_URL is not accessible.
################################################################
gnps-mhd-cli client \
  --mhd-server-url $MHD_SERVER_URL \
  announce \
  --dataset-repository-identifier $MSV_STUDY_ID \
  --mhd-id $MSV_STUDY_ID \
  --announcement-reason "$ANNOUNCEMENT_REASON" \
  --announcement-file-path $MHD_OUTPUT_DIR/$ANNOUNCEMENT_FILE_NAME \
  --api-token $MHD_API_TOKEN

Development Environment

Development environment for linux or mac

# install python package manager uv
curl -LsSf https://astral.sh/uv/install.sh | sh

# add $HOME/.local/bin to your PATH, either restart your shell or run
PATH=$HOME/.local/bin:$PATH

# install git from https://git-scm.com/downloads
# Linux command
apt update; apt install git -y

# Mac command
# brew install git

# clone project from github
git clone https://github.com/MetabolomicsHub/gnps-mhd-integration.git

cd gnps-mhd-integration

# install python if it is not installed
uv python install 3.12

# install python dependencies
uv sync --group dev

# install pre-commit to check repository integrity and format checking
uv run pre-commit

# open your IDE (vscode, pycharm, etc.) and set python interpreter as .venv/bin/python

Commandline Usage

# you can use any python version >= 3.12
pip install gnps-mhd-integration

gnps-mhd-cli
####################################################################
# Usage: gnps-mhd-cli [OPTIONS] COMMAND [ARGS]...

#   GNPS/MassIVE - MHD Integration CLI.

#   Use this cli to create MHD model file, convert MHD model file to
#   announcement file, and fetch GNPS/MassIVE params.xml metadata file.

# Options:
#   --version   Show the version and exit.
#   -h, --help  Show this message and exit.

# Commands:
#   create    Create MHD model or announcement file.
#   download  Fetch a GNPS/MassIVE study params.xml and convert it to json.
#   validate  Validate MHD model or announcement file.
####################################################################


gnps-mhd-cli create mhd
####################################################################
# Usage: gnps-mhd-cli create mhd [OPTIONS] MASSIVE_STUDY_ID MHD_IDENTIFIER

#   Convert a GNPS/MassIVE study to MHD model file.

# Options:
#   --input-file-path TEXT  Input file path of params.xml. If it is not defined,
#                           the params.xml will be fetched from MassIVE.
#   --output-dir TEXT       Output directory for MHD file  [default: outputs]
#   --output-filename TEXT  MHD filename (e.g., MHD000001.mhd.json,
#                           ST000001.mhd.json)
#   --schema_uri TEXT       Target MHD model schema. It defines format of MHD
#                           model structure.  [default:
#                           https://metabolomicshub.github.io/mhd-
#                           model/schemas/v0_1/common-data-
#                           model-v0.1.schema.json]
#   --profile_uri TEXT      Target MHD model profile. It is used to validate MHD
#                           model  [default:
#                           https://metabolomicshub.github.io/mhd-
#                           model/schemas/v0_1/common-data-model-v0.1.legacy-
#                           profile.json]
#   -h, --help              Show this message and exit.
####################################################################

gnps-mhd-cli create mhd MSV000099062 MSV000099062
####################################################################
# MSV000099062 is converted successfully. Output file: outputs/MSV000099062.mhd.json
####################################################################

ls outputs
# MSV000099062.mhd.json


gnps-mhd-cli download

####################################################################
# Usage: gnps-mhd-cli download [OPTIONS] STUDY_ID

#   Download a GNPS/MassIVE study as json file.

# Options:
#   --output-dir TEXT       Output directory for MHD file  [default: outputs]
#   --output-filename TEXT  MHD filename (e.g., MHD000001.mhd.json,
#                           MSV000001.mhd.json)
#   -h, --help              Show this message and exit.
####################################################################

gnps-mhd-cli download MSV000099062
# MSV000099062 is downloaded

ls outputs
# MSV000099062.json


gnps-mhd-cli validate mhd MSV000099062 outputs/MSV000099062.mhd.json
####################################################################
# MSV000099062: outputs/MSV000099062.mhd.json MHD file validation started.
# Used schema: https://metabolomicshub.github.io/mhd-model/schemas/v0_1/common-data-model-v0.1.schema.json
# Validation profile: https://metabolomicshub.github.io/mhd-model/schemas/v0_1/common-data-model-v0.1.legacy-profile.json
# MSV000099062: File 'outputs/MSV000099062.mhd.json' is validated successfully.####################################################################

gnps-mhd-cli create announcement

####################################################################
# Usage: gnps-mhd-cli create announcement [OPTIONS] MHD_STUDY_ID
#                                         MHD_MODEL_FILE_PATH
#                                         TARGET_MHD_MODEL_FILE_URL

#   Create announcement file from MHD data model file.

#   Args:

#   mhd_study_id (str): MHD study identifier

#   mhd_model_file_path (str): MHD data model path

#   target_mhd_model_file_url (str): target URL of MHD data model

#   output_dir (str): Output directory of announcement file

#   output_filename (str): Name of MHD announcement file. Default is <repository
#   identifier>.announcement.json

# Options:
#   --output-dir TEXT       Output directory for MHD file  [default: outputs]
#   --output-filename TEXT  MHD announcement filename (e.g.,
#                           MHD000001.announcement.json,
#                           ST000001.announcement.json)
#   -h, --help              Show this message and exit.
####################################################################


# MHD identifier will be reserved for each private study
# Assumption: MSV000099062.mhd.json will be accessible on
# https://www.gnps.org/data?MHD_ID=MHD0123456789
gnps-mhd-cli create announcement MHD0123456789  outputs/MSV000099062.mhd.json "https://www.gnps.org/data?MHD_ID=MHD0123456789"
####################################################################
# MSV000099062 announcement file conversion completed.
####################################################################

ls outputs
####################################################################
# MHD0123456789.announcement.json  MSV000099062.mhd.json
####################################################################

gnps-mhd-cli validate announcement

####################################################################
# Usage: gnps-mhd-cli validate announcement [OPTIONS] MHD_STUDY_ID
#                                         ANNOUNCEMENT_FILE_PATH
#   Validate MHD announcement file.
#   Args:
#   mhd_study_id (str): MHD study id
#   announcement_file_path (str): MHD announcement file path
#   output_path (None | str): If it is defined, validation results are saved in
#   output file path.

# Options:
#   --output-path TEXT  Validation output file path
#   -h, --help          Show this message and exit.
####################################################################

gnps-mhd-cli validate announcement MSV000099062 outputs/MSV000099062.announcement.json

####################################################################
# MHD0123456789: File 'outputs/MSV000099062.announcement.json' is validated successfully.
####################################################################

Metadata

Release files for gnps-mhd-integration 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gnps-mhd-integration 0.1.0
File Size Uploaded Provenance Actions
gnps_mhd_integration-0.1.0.tar.gz 33.0 kB Without provenance Details for gnps_mhd_integration-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for gnps-mhd-integration 0.1.0
File Interpreter ABI Platform Actions
gnps_mhd_integration-0.1.0-py3-none-any.whl Python 3 none any Details for gnps_mhd_integration-0.1.0-py3-none-any.whl

Total release size: 70.5 kB

Release files / gnps_mhd_integration-0.1.0.tar.gz

Download URL gnps_mhd_integration-0.1.0.tar.gz
Size 33.0 kB
Tags Source
SHA-256 checksum
How to use checksums
3a233d3cae447d598270cbe77158eac49424d3ff8127ec256bd1e8c583d377a1
BLAKE2b-256 checksum
How to use checksums
028380a329f79d7ba8576056cb0528e5ab22647b32e38be8d5a6d4917596fc94
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.12 {"installer":{"name":"uv","version":"0.13.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / gnps_mhd_integration-0.1.0-py3-none-any.whl

Download URL gnps_mhd_integration-0.1.0-py3-none-any.whl
Size 37.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
573b076211c8677dd183ddb7524447e52bdcaaa633299313bd044f811b6485f3
BLAKE2b-256 checksum
How to use checksums
fffc196c3448d7b50b49c7d7915a41ac7874fa2cf83a6d950dab3296851598ee
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.12 {"installer":{"name":"uv","version":"0.13.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for gnps-mhd-integration 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page