In [1]:
%matplotlib inline
from matplotlib import pylab as plt

from metatlas import metatlas_objects
from metatlas import h5_query
from metatlas.metatlas_objects import Atlas

# import glob, os

Select an experiment


In [3]:
# myExperiment = metatlas_objects.get_experiment(name = 'Test_20150722')
metatlas_objects.list_experiments()


Out[3]:
[]

In [10]:
import pandas as pd
atlas_file = '/global/homes/b/bpb/20150804_POS_pHILIC_R2A_Small.txt'
df = pd.read_csv(atlas_file,sep='\t')
df.fillna('',inplace=True)
comp_list = df.to_dict('records')
print comp_list


Out[10]:
name pubchem_id formula neutral_mass mz mz_threshold adducts rt_max rt_min rt_peak
0 tyramine 137.084200 138.091200 15 H+ 2.630000 1.630000 2.130000
1 dopamine 153.083000 154.090000 15 H+ 2.680000 1.680000 2.180000
2 L-Ala-gamma-D-Glu-DAP-D-Ala 461.205900 462.212900 15 H+ 2.790000 1.790000 2.290000
3 PheAla 236.116486 237.123486 15 2.835096 1.835096 2.335096
4 Nicotinamide riboside 271.116794 272.123794 15 2.875936 1.875936 2.375936

In [ ]:
a = metatlas_objects.Atlas(name = 'Positive Mode R2A Media Hilic',
                           compounds=[c1,c2,c3,c4,c5,
                                     c6,c7,c8,c9,c10,
                                     c11,c12,c13,c14,c15,
                                     c16,c17,c18,c19,c20,
                                     c21,c22,c23,c24,c25,
                                     c26,c27])
myExperiment.atlases.append(a)
myExperiment.save()

In [5]:
a = Atlas(name = 'Positive Mode R2A Media Hilic',
                           compounds=[c1,c2,c3,c4,c5,
                                     c6,c7,c8,c9,c10,
                                     c11,c12,c13,c14,c15,
                                     c16,c17,c18,c19,c20,
                                     c21,c22,c23,c24,c25,
                                     c26,c27])
a.edit()



In [ ]:
# for i,a in enumerate(myExperiment.atlases):
#     for c in a.compounds:
#         print i,c.name,c.mz,c.pubchem_id
a = myExperiment.atlases[-1]
for i,c in enumerate(a.compounds):
    print i,c.name,c.mz,c.pubchem_id

In [ ]:
print len(myExperiment.atlases[-1].compounds)

In [ ]:
# http://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/cid/857,791,94244,614,1054,247,352038,107738,588,6140,80817,9837272,444109,938,6287,33032,118276,6057,6137,673,/property/MonoisotopicMass,MolecularFormula,InChI/CSV
import requests, json
# url = 'http://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/cid/857/JSON'
url = 'http://pubchem.ncbi.nlm.nih.gov/rest/pug_view/data/compound/857/JSON'
r = requests.get(url)
d = r.json()
print d
# print d['Record']['Section'][2]['Section'][0]['Information'][0]['StringValue']
# print d
# print d['PC_Compounds'][0].keys()
# for p in d['PC_Compounds'][0]['id']:
#     print p
#     if 'name' in p['urn'].keys():
#         print p['urn']['name'],p['urn']['label'],p['value']

In [ ]:


In [2]:
c1 = metatlas_objects.Compound(name = 'DL-Leucine', 
                               formula = 'C6H13NO2', 
                               adducts = 'H+', 
                               mz = 132.10190559999998, 
                               mz_threshold = 10,
                               rt_min = 6.93, 
                               rt_max = 7.93, 
                               rt_peak = 7.43,
                               neutral_mass = 131.0946296,
                               pubchem_id = 857)

c2 = metatlas_objects.Compound(name = 'DL-Isoleucine', 
                               formula = 'C6H13NO2', 
                               adducts = 'H+', 
                               mz = 132.10190559999998, 
                               mz_threshold = 10,
                               rt_min = 7.25, 
                               rt_max = 8.25, 
                               rt_peak = 7.75,
                               neutral_mass = 131.0946296,
                               pubchem_id = 791)

c3 = metatlas_objects.Compound(name = 'Leucyl-leucine', 
                               formula = 'C12H24N2O3', 
                               adducts = 'H+', 
                               mz = 245.185969, 
                               mz_threshold = 50,
                               rt_min = 3.9, 
                               rt_max = 4.9, 
                               rt_peak = 4.4,
                               neutral_mass = 244.178693,
                               pubchem_id = 94244)

c4 = metatlas_objects.Compound(name = 'DL-Proline', 
                               formula = 'C5H9NO2', 
                               adducts = 'H+', 
                               mz = 116.070605, 
                               mz_threshold = 10,
                               rt_min = 8.16, 
                               rt_max = 9.16, 
                               rt_peak = 8.66,
                               neutral_mass = 115.063329,
                               pubchem_id = 614)

c5 = metatlas_objects.Compound(name = 'Pyridoxine', 
                               formula = 'C8H11NO3', 
                               adducts = 'H+', 
                               mz = 170.081169, 
                               mz_threshold = 10,
                               rt_min = 2.17, 
                               rt_max = 3.17, 
                               rt_peak = 2.67,
                               neutral_mass = 169.073893,
                               pubchem_id = 1054)

c6 = metatlas_objects.Compound(name = 'Betaine', 
                               formula = 'C5H11NO2', 
                               adducts = 'H+', 
                               mz = 118.086255, 
                               mz_threshold = 10,
                               rt_min = 6.02, 
                               rt_max = 7.02, 
                               rt_peak = 6.52,
                               neutral_mass = 117.078979,
                               pubchem_id = 247)

c7 = metatlas_objects.Compound(name = 'Leu-Val', 
                               formula = 'C11H22N2O3', 
                               adducts = 'H+', 
                               mz = 231.170319, 
                               mz_threshold = 10,
                               rt_min = 5.03, 
                               rt_max = 6.03, 
                               rt_peak = 5.53,
                               neutral_mass = 230.163043,
                               pubchem_id = 352038)

c8 = metatlas_objects.Compound(name = 'Propionyl Carnitine', 
                               formula = 'C10H19NO4', 
                               adducts = 'NH4+', #18.033823
                               mz = 235.165231, 
                               mz_threshold = 10,
                               rt_min = 6, 
                               rt_max = 7, 
                               rt_peak = 6.5,
                               neutral_mass = 217.131408,
                               pubchem_id = 107738)

c9 = metatlas_objects.Compound(name = 'Creatinine', 
                               formula = 'C4H7N3O', 
                               adducts = 'H+',
                               mz = 113.058912 + 1.007276, 
                               mz_threshold = 10,
                               rt_min = 4.17, 
                               rt_max = 5.17, 
                               rt_peak = 4.67,
                               neutral_mass = 113.058912,
                               pubchem_id = 588)

c10 = metatlas_objects.Compound(name = 'Phenylalanine', 
                               formula = 'C9H11NO2', 
                               adducts = 'H+',
                               mz = 165.078979 + 1.007276, 
                               mz_threshold = 10,
                               rt_min = 7.04, 
                               rt_max = 8.04, 
                               rt_peak = 7.54,
                               neutral_mass = 165.078979,
                               pubchem_id = 6140)

c11 = metatlas_objects.Compound(name = 'Leu-Pro', 
                               formula = 'C11H20N2O3', 
                               adducts = 'H+',
                               mz = 228.147393 + 1.007276, 
                               mz_threshold = 10,
                               rt_min = 6.88, 
                               rt_max = 7.88, 
                               rt_peak = 7.38,
                               neutral_mass = 228.147393,
                               pubchem_id = 80817)

c12 = metatlas_objects.Compound(name = 'Val-Pro', 
                               formula = 'C10H18N2O3', 
                               adducts = 'H+',
                               mz = 214.131742 + 1.007276, 
                               mz_threshold = 10,
                               rt_min = 7.44, 
                               rt_max = 8.44, 
                               rt_peak = 7.94,
                               neutral_mass = 214.131742,
                               pubchem_id = 9837272 )

c13 = metatlas_objects.Compound(name = 'Pro-Leu', 
                               formula = 'C11H20N2O3', 
                               adducts = 'H+',
                               mz = 228.147393 + 1.007276, 
                               mz_threshold = 10,
                               rt_min = 5.47, 
                               rt_max = 6.47, 
                               rt_peak = 5.97,
                               neutral_mass = 228.147393,
                               pubchem_id = 444109 )


c14 = metatlas_objects.Compound(name = 'Nicotinic acid', 
                               formula = 'C6H5NO2', 
                               adducts = 'H+',
                               mz = 123.032028 + 1.007276, 
                               mz_threshold = 10,
                               rt_min = 5.39, 
                               rt_max = 6.39, 
                               rt_peak = 5.89,
                               neutral_mass = 123.032028,
                               pubchem_id = 938 )

c15 = metatlas_objects.Compound(name = 'Valine', 
                               formula = 'C5H11NO2', 
                               adducts = 'H+',
                               mz = 117.078979 + 1.007276, 
                               mz_threshold = 10,
                               rt_min = 8.43, 
                               rt_max = 9.43, 
                               rt_peak = 8.93,
                               neutral_mass = 117.078979,
                               pubchem_id = 6287  )

c16 = metatlas_objects.Compound(name = 'L-Glutamic Acid', 
                               formula = 'C5H9NO4', 
                               adducts = 'H+',
                               mz = 147.053158 + 1.007276, 
                               mz_threshold = 10,
                               rt_min = 13.42, 
                               rt_max = 14.42, 
                               rt_peak = 13.92,
                               neutral_mass = 147.0531583,
                               pubchem_id = 33032 )

c17 = metatlas_objects.Compound(name = 'Leu-Met', 
                               formula = 'C11H22N2O3S', 
                               adducts = 'H+',
                               mz = 262.135114 + 1.007276, 
                               mz_threshold = 10,
                               rt_min = 6.39, 
                               rt_max = 7.39, 
                               rt_peak = 6.89,
                               neutral_mass = 262.135114,
                               pubchem_id = 118276  )

c18 = metatlas_objects.Compound(name = 'Tyrosine', 
                               formula = 'C9H11NO3', 
                               adducts = 'H+',
                               mz = 181.073893 + 1.007276, 
                               mz_threshold = 10,
                               rt_min = 9.53, 
                               rt_max = 10.53, 
                               rt_peak = 10.03,
                               neutral_mass = 181.073893,
                               pubchem_id = 6057 )

c19 = metatlas_objects.Compound(name = 'Methionine', 
                               formula = 'C5H11NO2S', 
                               adducts = 'H+',
                               mz = 149.05105 + 1.007276, 
                               mz_threshold = 10,
                               rt_min = 8.09, 
                               rt_max = 9.09, 
                               rt_peak = 8.59,
                               neutral_mass = 149.05105,
                               pubchem_id = 6137 )

c20 = metatlas_objects.Compound(name = 'Adenosine', 
                               formula = 'C10H13N5O4', 
                               adducts = 'H+',
                               mz = 268.1040304, 
                               mz_threshold = 10,
                               rt_min = 3.91, 
                               rt_max = 4.91, 
                               rt_peak = 4.41,
                               neutral_mass = 267.0967539,
                               pubchem_id = 60961 )

c21 = metatlas_objects.Compound(name = 'Histidine', 
                               formula = '', 
                               adducts = 'H+',
                               mz = 156.0766, 
                               mz_threshold = 10,
                               rt_min = 13.68, 
                               rt_max = 14.68, 
                               rt_peak = 14.18,
                               neutral_mass = 155.0694,
                               pubchem_id = 6274 )

c22 = metatlas_objects.Compound(name = 'Tryptophan', 
                               formula = 'C11H12N2O2', 
                               adducts = 'H+',
                               mz = 205.0971541, 
                               mz_threshold = 10,
                               rt_min = 8.02, 
                               rt_max = 9.02, 
                               rt_peak = 8.52,
                               neutral_mass = 204.0898776,
                               pubchem_id = 6305 )

c23 = metatlas_objects.Compound(name = 'Adenine', 
                               formula = 'C5H5N5', 
                               adducts = 'H+',
                               mz = 136.0617716, 
                               mz_threshold = 10,
                               rt_min = 3.83, 
                               rt_max = 4.83, 
                               rt_peak = 4.33,
                               neutral_mass = 135.0544952,
                               pubchem_id = 190 )

c24 = metatlas_objects.Compound(name = 'Dimethylglycine', 
                               formula = 'C4H9NO2', 
                               adducts = 'H+',
                               mz = 103.063329 + 1.007276, 
                               mz_threshold = 10,
                               rt_min = 11.44, 
                               rt_max = 12.44, 
                               rt_peak = 11.94,
                               neutral_mass = 103.063329 ,
                               pubchem_id = 673  )

c25 = metatlas_objects.Compound(name = 'Threonine', 
                               formula = 'C11H20N2O3', 
                               adducts = 'H+',
                               mz = 120.0656, 
                               mz_threshold = 10,
                               rt_min = 11.03, 
                               rt_max = 12.03, 
                               rt_peak = 11.53,
                               neutral_mass = 119.0584,
                               pubchem_id = 6288 )

c26 = metatlas_objects.Compound(name = 'Alanine', 
                               formula = '', 
                               adducts = 'H+',
                               mz = 90.0555, 
                               mz_threshold = 10,
                               rt_min = 10.72, 
                               rt_max = 11.72, 
                               rt_peak = 11.22,
                               neutral_mass = 89.0483,
                               pubchem_id = 5950 )

c27 = metatlas_objects.Compound(name = 'Serine', 
                               formula = '', 
                               adducts = 'H+',
                               mz = 106.0501, 
                               mz_threshold = 10,
                               rt_min = 12.29, 
                               rt_max = 13.29, 
                               rt_peak = 12.79,
                               neutral_mass = 105.0429,
                               pubchem_id = 5951 )

# Rename and check! Isoprene			85.0898	86.097	15	NH4+	7.89	6.89	7.39
# See if propionyl carnitine is right.  weird that its an ammonium adduct.

In [14]:
url = 'https://docs.google.com/spreadsheets/d/1vh97rZwT9OGydqnVEQQaye-kVF3UtLSKWePzFeOdFXc'
def load_from_google_doc(url):
    import requests
    url = url.rpartition('/')[0]
    r = requests.get(url + '/pub?output=csv')
    print url + '/pub?output=csv'
    print r.text
load_from_google_doc(url)


https://docs.google.com/spreadsheets/d/pub?output=csv
<!DOCTYPE html><html lang="en" ><head><meta name="description" content="Web word processing, presentations and spreadsheets"><link rel="shortcut icon" href="//ssl.gstatic.com/docs/common/drive_favicon1.ico"><title>Google Drive -- Page Not Found</title><link href="//fonts.googleapis.com/css?family=Open+Sans:300" rel="stylesheet" type="text/css"><style>/* Copyright 2015 Google Inc. All Rights Reserved. */
.goog-inline-block{position:relative;display:-moz-inline-box;display:inline-block}* html .goog-inline-block{display:inline}*:first-child+html .goog-inline-block{display:inline}#drive-logo{color:#91959c;font-family:"Open Sans",Arial,sans-serif;font-size:27px;font-weight:300;position:absolute;text-shadow:0 1px 1px white;white-space:nowrap}#drive-logo img{padding:0 0.4em 0 0;position:relative;top:2px;vertical-align:middle}#drive-logo a{color:#91959c;text-decoration:none}#drive-logo span.goog-inline-block{margin-top:2px;vertical-align:top}</style><style type="text/css">body {background-color: #fff; font-family: Arial,sans-serif; font-size: 13px; margin: 0; padding: 0;}a, a:link, a:visited {color: #112ABB;}</style><style type="text/css">.errorMessage {font-size: 12pt; font-weight: bold; line-height: 150%;}</style></head><body><div style="margin: auto; max-width: 750px;"><div style="margin: 80px 40px 20px 40px; position:relative; "><div style="position: absolute; top: -80px;"><h1 id="drive-logo"><a href="/"><img src="//www.google.com/images/logos/google_logo_41.png" width="116" height="41" alt="Google logo" ><span class="goog-inline-block">Drive</span></a></h1></div><div align="center"><p class="errorMessage" style="padding-top: 50px">Sorry, the file you have requested does not exist.</p><p>Make sure that you have the correct URL and that the owner of the file hasn&#39;t deleted it.</p><div style="background: #F0F6FF; border: 1px solid black; margin-top: 35px; padding: 10px 125px; width: 300px;"><p><strong>Get stuff done with Google Drive</strong></p><p>Apps in Google Drive make it easy to create, store and share online documents, spreadsheets, presentations and more.</p><p>Learn more at <a href="https://drive.google.com/start/apps">drive.google.com/start/apps</a>.</p></div></div></div></div></body></html>

In [ ]: