Пример #1
0
def test_floating_point():
    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
Пример #2
0
def test_get_latest():
    test = mo.Compound(name='hello')
    mo.store(test)
    test.name = 'goodbye'
    mo.store(test)
    test = mo.retrieve('compound', creation_time=test.creation_time)
    assert len(test) == 1, len(test)
    assert test[0].name == 'goodbye'
Пример #3
0
def test_remove_objects():
    compound = mo.Compound(name='foo',
                           MonoIsotopic_molecular_weight=1.0,
                           reference_xrefs=[mo.ReferenceDatabase(name='baz')])
    sub_id = compound.reference_xrefs[0].unique_id
    mo.store(compound)
    db = mo.retrieve('referencedatabase', unique_id=sub_id)[0]
    assert db.unique_id == sub_id
    mo.remove_objects(compound, _override=True)
    test = mo.retrieve('compound', name='foo')
    assert not test
    test_sub = mo.retrieve('compounds_reference_xrefs', target_id=sub_id)
    assert not test_sub
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