Ejemplo n.º 1
0
def test_floating_point(sqlite):
    compound = mo.Compound(name="foo", mono_isotopic_molecular_weight=1.0)
    mo.store(compound)
    compound.mono_isotopic_molecular_weight = 1.000007
    mo.store(compound)
    test = mo.retrieve("compound", name="foo")[-1]
    assert test.mono_isotopic_molecular_weight == 1.000007, test.mono_isotopic_molecular_weight
Ejemplo n.º 2
0
def test_get_latest():
    test = mo.Compound(name="hello")
    mo.store(test)
    test.name = "goodbye"
    mo.store(test)
    test = mo.retrieve("compound", unique_id=test.unique_id)
    assert len(test) == 1
    assert test[0].name == "goodbye"
Ejemplo n.º 3
0
def test_retrieve01(sqlite):
    compound = mo.Compound(name="foo",
                           inchi=ADENOSINE_INCHI,
                           inchi_key="foobar")
    mo.store(compound)
    assert mo.retrieve("Compounds", inchi_key=[], username="******") == []
    assert mo.retrieve("Compounds", inchi=[ADENOSINE_INCHI],
                       username="******")[0].inchi == ADENOSINE_INCHI
Ejemplo n.º 4
0
def make_atlas_df(atlas):
    mz = []
    rt = []
    atlas_compound = []
    label = []
    for compound in atlas.compound_identifications:
        label.append(compound.name)
        if compound.mz_references:
            mz.append(compound.mz_references[0])
        else:
            mz.append(metob.MzReference())
        if compound.rt_references:
            rt.append(compound.rt_references[0])
        else:
            rt.append(metob.RtReference())
        if compound.compound:
            atlas_compound.append(compound.compound[0])
        else:
            atlas_compound.append(metob.Compound())

    compound_df = metob.to_dataframe(atlas_compound)
    compound_df.rename(columns={
        'name': 'compound_name',
        'description': 'compound_description'
    },
                       inplace=True)
    #.rename(columns = {'name':'compound_name'}, inplace = True)
    atlas_df = pd.concat(
        [metob.to_dataframe(rt),
         metob.to_dataframe(mz), compound_df], axis=1)
    # atlas_df['label'] = label

    atlas_keys = [
        u'inchi_key', 'compound_name', u'rt_max', u'rt_min', u'rt_peak',
        u'rt_units', u'detected_polarity', u'mz', u'mz_tolerance',
        u'mz_tolerance_units', 'mono_isotopic_molecular_weight',
        'pubchem_compound_id', 'synonyms', 'inchi', 'adduct'
    ]

    # atlas_keys = [u'label','compound_name','compound_description',u'synonyms', u'num_free_radicals', u'number_components', u'permanent_charge', u'rt_max', u'rt_min', u'rt_peak',
    #        u'rt_units', u'detected_polarity', u'mz', u'mz_tolerance',u'mz_tolerance_units',
    #         u'inchi', u'inchi_key', u'neutralized_2d_inchi', u'neutralized_2d_inchi_key', u'neutralized_inchi',
    #        u'neutralized_inchi_key',u'chebi_id', u'hmdb_id', u'img_abc_id', u'kegg_id',u'lipidmaps_id', u'metacyc_id',
    #        u'mono_isotopic_molecular_weight', u'pubchem_compound_id', u'kegg_url', u'chebi_url', u'hmdb_url', u'lipidmaps_url', u'pubchem_url',u'wikipedia_url',  u'source']

    atlas_df = atlas_df[atlas_keys]
    print((atlas_df.shape, len(label)))
    atlas_df['label'] = label
    return atlas_df
Ejemplo n.º 5
0
def make_atlas_df(atlas):
    """
    inputs:
        atlas: metatlas.datastructures.metatlas_objects.Atlas
    output:
        pandas DataFrame with one row per CompoundIdentification in atlas and each row also includes
        the first RtReference, MzReference, and Compound from the CompoundIdentification
    """
    mzs = [extract(aci, ['mz_references', 0], metob.MzReference()) for aci in atlas.compound_identifications]
    rts = [extract(aci, ['rt_references', 0], metob.RtReference()) for aci in atlas.compound_identifications]
    compounds = [extract(aci, ['compound', 0], metob.Compound()) for aci in atlas.compound_identifications]

    ci_df = metob.to_dataframe(atlas.compound_identifications)
    ci_df.rename(columns={'name': 'label'}, inplace=True)
    compound_df = metob.to_dataframe(compounds)
    compound_df.rename(columns={'name': 'compound_name', 'description': 'compound_description'}, inplace=True)
    atlas_df = pd.concat([metob.to_dataframe(rts), metob.to_dataframe(mzs), compound_df, ci_df], axis=1)

    atlas_keys = ['inchi_key', 'compound_name', 'rt_max', 'rt_min', 'rt_peak', 'rt_units',
                  'detected_polarity', 'mz', 'mz_tolerance', 'mz_tolerance_units',
                  'mono_isotopic_molecular_weight', 'pubchem_compound_id', 'synonyms', 'inchi', 'adduct',
                  'label', 'ms1_notes', 'ms2_notes', 'identification_notes']
    return atlas_df[atlas_keys]