# Path: metatlas/datastructures/metatlas_objects.py
# FETCH_STUBS = True
# ADDUCTS = ('','[M]+','[M+H]+','[M+H]2+','[M+2H]2+','[M+H-H2O]2+','[M+K]2+','[M+NH4]+','[M+Na]+','[M+H-H2O]+','[M-H]-','[M-2H]-','[M-H+Cl]-','[M-2H]2-','[M+Cl]-','[2M+H]+','[2M-H]-','[M-H+Na]+','[M+K]+','[M+2Na]2+','[M-e]+','[M+acetate]-','[M+formate]-','[M-H+Cl]2-','[M-H+2Na]+')
# POLARITY = ('positive', 'negative', 'alternating')
# FRAGMENTATION_TECHNIQUE = ('hcd','cid','etd','ecd','irmpd')
# ID_GRADES: Dict[str, IdentificationGrade] = dict()
#     FETCH_STUBS = False
#         FETCH_STUBS = True
#     FETCH_STUBS = True
# def retrieve(object_type, **kwargs):
# def remove(object_type, **kwargs):
# def remove_objects(objects, all_versions=True, **kwargs):
# def store(objects, **kwargs):
#     def __init__(self, **kwargs):
#     def _update(self, override_user=False):
#     def clone(self, recursive=False):
#     def show_diff(self, unique_id=None):
#     def _on_update(self, change):
#     def __str__(self):
#     def __repr__(self):
#     def __getattribute__(self, name):
#     def validate(self, obj, value):
# def find_invalid_runs(**kwargs):
# def to_dataframe(objects):
# class MetatlasObject(HasTraits):
# class Method(MetatlasObject):
# class Sample(MetatlasObject):
# class LcmsRun(MetatlasObject):
# class FunctionalSet(MetatlasObject):
# class Compound(MetatlasObject):
# class Reference(MetatlasObject):
# class IdentificationGrade(MetatlasObject):
# class _IdGradeTrait(MetInstance):
# class Group(MetatlasObject):
# class MzIntensityPair(MetatlasObject):
# class FragmentationReference(Reference):
# class RtReference(Reference):
# class MzReference(Reference):
# class IntensityReference(Reference):
# class CompoundIdentification(MetatlasObject):
# class Atlas(MetatlasObject):
# class MZMineTask(MetatlasObject):
# 
# Path: metatlas/io/h5_query.py
# def get_data(h5file, **kwargs):
# def get_chromatogram(h5file, min_mz, max_mz, aggregator=np.sum, **kwargs):
# def get_heatmap(h5file, mz_bins, **kwargs):
# def get_spectrogram(h5file, min_rt, max_rt, bins=2000, **kwargs):
# def get_info(h5file):
# 
# Path: metatlas/io/write_utils.py
# def make_dir_for(file_path):
# def check_existing_file(file_path, overwrite=False):
# def export_dataframe(dataframe, file_path, description, overwrite=False, **kwargs):
# def raise_on_diff(dataframe, file_path, description, **kwargs):
# def export_dataframe_die_on_diff(dataframe, file_path, description, overwrite=False, **kwargs):


import copy
import logging
import math
import os.path
import re
import sys
import dill
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import six
import tables
from collections import defaultdict
from textwrap import wrap
from metatlas.datastructures import metatlas_objects as metob
from metatlas.io import h5_query as h5q
from metatlas.io import write_utils
        polarity = 1
    else:
        polarity = 0


    mz_theor = mz_ref.mz
    if mz_ref.mz_tolerance_units  == 'ppm': #convert to ppm
        ppm_uncertainty = mz_ref.mz_tolerance
    else:
        ppm_uncertainty = mz_ref.mz_tolerance / mz_ref.mz * 1e6

#     if 'min' in rt_ref.rt_units: #convert to seconds
#     rt_min = rt_ref.rt_min / 60
#     rt_max = rt_ref.rt_max / 60
#     else:
    rt_min = rt_ref.rt_min
    rt_max = rt_ref.rt_max

    mz_min = mz_theor - mz_theor * ppm_uncertainty / 1e6
    mz_max = mz_theor + mz_theor * ppm_uncertainty / 1e6

    return_data = {}

    if 'ms1_summary' in what_to_get:
        #Get Summary Data

        #First get MS1 Raw Data
        ms_level=1
        return_data['ms1_summary'] = {}
        try:

# Path: metatlas/datastructures/metatlas_objects.py
# FETCH_STUBS = True
# ADDUCTS = ('','[M]+','[M+H]+','[M+H]2+','[M+2H]2+','[M+H-H2O]2+','[M+K]2+','[M+NH4]+','[M+Na]+','[M+H-H2O]+','[M-H]-','[M-2H]-','[M-H+Cl]-','[M-2H]2-','[M+Cl]-','[2M+H]+','[2M-H]-','[M-H+Na]+','[M+K]+','[M+2Na]2+','[M-e]+','[M+acetate]-','[M+formate]-','[M-H+Cl]2-','[M-H+2Na]+')
# POLARITY = ('positive', 'negative', 'alternating')
# FRAGMENTATION_TECHNIQUE = ('hcd','cid','etd','ecd','irmpd')
# ID_GRADES: Dict[str, IdentificationGrade] = dict()
#     FETCH_STUBS = False
#         FETCH_STUBS = True
#     FETCH_STUBS = True
# def retrieve(object_type, **kwargs):
# def remove(object_type, **kwargs):
# def remove_objects(objects, all_versions=True, **kwargs):
# def store(objects, **kwargs):
#     def __init__(self, **kwargs):
#     def _update(self, override_user=False):
#     def clone(self, recursive=False):
#     def show_diff(self, unique_id=None):
#     def _on_update(self, change):
#     def __str__(self):
#     def __repr__(self):
#     def __getattribute__(self, name):
#     def validate(self, obj, value):
# def find_invalid_runs(**kwargs):
# def to_dataframe(objects):
# class MetatlasObject(HasTraits):
# class Method(MetatlasObject):
# class Sample(MetatlasObject):
# class LcmsRun(MetatlasObject):
# class FunctionalSet(MetatlasObject):
# class Compound(MetatlasObject):
# class Reference(MetatlasObject):
# class IdentificationGrade(MetatlasObject):
# class _IdGradeTrait(MetInstance):
# class Group(MetatlasObject):
# class MzIntensityPair(MetatlasObject):
# class FragmentationReference(Reference):
# class RtReference(Reference):
# class MzReference(Reference):
# class IntensityReference(Reference):
# class CompoundIdentification(MetatlasObject):
# class Atlas(MetatlasObject):
# class MZMineTask(MetatlasObject):
# 
# Path: metatlas/io/h5_query.py
# def get_data(h5file, **kwargs):
# def get_chromatogram(h5file, min_mz, max_mz, aggregator=np.sum, **kwargs):
# def get_heatmap(h5file, mz_bins, **kwargs):
# def get_spectrogram(h5file, min_rt, max_rt, bins=2000, **kwargs):
# def get_info(h5file):
# 
# Path: metatlas/io/write_utils.py
# def make_dir_for(file_path):
# def check_existing_file(file_path, overwrite=False):
# def export_dataframe(dataframe, file_path, description, overwrite=False, **kwargs):
# def raise_on_diff(dataframe, file_path, description, **kwargs):
# def export_dataframe_die_on_diff(dataframe, file_path, description, overwrite=False, **kwargs):


# Path: metatlas/io/metatlas_get_data_helper_fun.py
import copy
import logging
import math
import os.path
import re
import sys
import dill
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import six
import tables
from collections import defaultdict
from textwrap import wrap
from metatlas.datastructures import metatlas_objects as metob
from metatlas.io import h5_query as h5q
from metatlas.io import write_utils

        polarity = 1
    else:
        polarity = 0


    mz_theor = mz_ref.mz
    if mz_ref.mz_tolerance_units  == 'ppm': #convert to ppm
        ppm_uncertainty = mz_ref.mz_tolerance
    else:
        ppm_uncertainty = mz_ref.mz_tolerance / mz_ref.mz * 1e6

#     if 'min' in rt_ref.rt_units: #convert to seconds
#     rt_min = rt_ref.rt_min / 60
#     rt_max = rt_ref.rt_max / 60
#     else:
    rt_min = rt_ref.rt_min
    rt_max = rt_ref.rt_max

    mz_min = mz_theor - mz_theor * ppm_uncertainty / 1e6
    mz_max = mz_theor + mz_theor * ppm_uncertainty / 1e6

    return_data = {}

    if 'ms1_summary' in what_to_get:
        #Get Summary Data

        #First get MS1 Raw Data
        ms_level=1
        return_data['ms1_summary'] = {}
        try:

            ms1_data = h5q.get_data(fid,