In [1]:
%load_ext autoreload
%autoreload 2
%matplotlib inline
import sys
basedir = '/Users/joewandy/git/ms2ldaviz/ms2ldaviz/'
sys.path.append(basedir)
import annotation.annotate_methods as annot
Prepare some example spectra
In [2]:
parentmass_1 = 282.1194
spectrum_1 = [
(55.0294, 1621769.0),
(57.0450, 1439267.4),
(82.0399, 2838900.0),
(92.0243, 1328631.9),
(94.0398, 3758106.0),
(106.0400, 1654438.4),
(108.0431, 1235484.9),
(108.0552, 1236242.4),
(109.0509, 9854405.0),
(119.0351, 3175437.8),
(123.0665, 1405464.4),
(133.0509, 8247930.5),
(135.0538, 2464020.5),
(150.0774, 152486528.0),
(282.1199, 1746824.8),
]
# should see adenine substructure here
parentmass_2 = 382.1357
spectrum_2 = [
(67.0544, 26619.8),
(94.0400, 29748.1),
(95.0490, 22403.4),
(119.0352, 120205.6),
(136.0618, 1572447.9),
(137.0458, 79233.2),
(188.1280, 44683.2),
]
spectra = {
parentmass_1: spectrum_1,
parentmass_2: spectrum_2
}
db_name = 'MASSBANK' # either 'MASSBANK' or 'GNPS'
# db_name = 'GNPS' # either 'MASSBANK' or 'GNPS'
Call the batch annotation function on these spectra
In [3]:
results = annot.batch_annotate(spectra, db_name)
Annotation results are produced as a JSON object, which can be converted into a dictionary. The keys are:
In [4]:
for key in results:
if key == 'status':
print key, ' --> ', results[key]
else:
print key, ' --> ', results[key].keys()
Here we retrieve the annotation result for the first spectra
In [5]:
first = str(results.keys()[2])
spectra_annotations = results[first]
print first
Print how many fragment and loss features can be matched for the annotation of that spectra
In [6]:
print spectra_annotations['fragment_match']
print spectra_annotations['loss_match']
Print the taxonomy terms for this spectra with probability > 0.5
In [7]:
for taxa_term, prob in spectra_annotations['taxa_term_probs']:
if prob > 0.5:
print taxa_term, prob
Print the substituent terms for this spectra with probability > 0.5
In [8]:
for taxa_term, prob in spectra_annotations['sub_term_probs']:
if prob > 0.5:
print taxa_term, prob
Print the Mass2Motif annotations for this spectra with probability > 0.01
In [9]:
for motif, annotation, theta, overlap in spectra_annotations['motif_theta_overlap']:
if theta > 0.01:
print motif, annotation, theta, overlap
In [ ]: